Skip to content

Instantly share code, notes, and snippets.

class MainActivity : AppCompatActivity() {
private var selectedView: View? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main)
@EmmanuelGuther
EmmanuelGuther / CustomDialog.kt
Last active December 12, 2018 10:54
Template for custom dialog whit callback
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.timbrit.profesionales.R
import org.jetbrains.anko.sdk27.coroutines.onClick
@EmmanuelGuther
EmmanuelGuther / AnimationResources
Created February 7, 2019 16:08
Animations xml
Animation Resource - push_down_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="-100%p" android:toYDelta="0" android:duration="5000"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="5000" />
</set>
Animation Resource - push_down_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
private fun firebaseAuth(loginModelPost: LoginModelPost?,callback: () -> Unit): Either<Failure, Boolean>? {
@EmmanuelGuther
EmmanuelGuther / ApiRefreshToken.kt
Last active May 15, 2023 09:01
Retrofit builder to handle calls with authorization requirements and interceptor with refresh token.
interface ApiRefreshToken {
companion object {
private const val REFRESH_TOKEN = "/refreshToken"
}
@FormUrlEncoded
@POST(REFRESH_TOKEN)
fun refreshToken(@Field("refreshToken") refreshToken: String?): Call<TokenModel>
}
@EmmanuelGuther
EmmanuelGuther / AuthenticationInterceptorRefreshTokenr.kt
Created February 16, 2019 10:40
Refresh token interceptor whit multiple calls at same time supported
private fun createClientAuth(): OkHttpClient {
//ADD DISPATCHER WITH MAX REQUEST TO 1
val dispatcher = Dispatcher()
dispatcher.maxRequests = 1
val okHttpClientBuilder: OkHttpClient.Builder = OkHttpClient.Builder()
okHttpClientBuilder.dispatcher(dispatcher)
okHttpClientBuilder.addInterceptor(AuthenticationInterceptorRefreshToken(this, UserManager()))
return okHttpClientBuilder.build()
}
}
@EmmanuelGuther
EmmanuelGuther / functionAsParameter.kt
Created April 4, 2019 18:10
Kotlin pass a function as parameter and execute
internal fun handleChatMessages(messages: List<MessageModel>?) {
hideProgress()
adapter.collection = messages.orEmpty()
animate { runLayoutAnimation() }
}
private fun animate(function: () -> Unit) {
when {
firstTimeCreated -> function.invoke()
}
@EmmanuelGuther
EmmanuelGuther / AndroidScreenSizesReferences.txt
Created April 25, 2019 10:23
Android screen sizes references
--------------------------- ----- ------------ --------------- ------- ----------- ---------------- --- ----------
Device Inches ResolutionPX Density DPI ResolutionDP AspectRatios SysNavYorN ContentResolutionDP
--------------------------- ----- ------------ --------------- ------- ----------- ---------------- --- ----------
Galaxy Y 320 x 240 ldpi 0.75 120 427 x 320 4:3 1.3333 427 x 320
? 400 x 240 ldpi 0.75 120 533 x 320 5:3 1.6667 533 x 320
? 432 x 240 ldpi 0.75 120 576 x 320 9:5 1.8000 576 x 320
Galaxy Ace 480 x 320 mdpi 1 160 480 x 320 3:2 1.5000
@EmmanuelGuther
EmmanuelGuther / ExtensionFunctionChecktimeOldThan.kt
Created May 8, 2019 17:55
Extension function to check if timestamp value is before X days
fun Long.checkTimeIsOldThan(days: Int): Boolean {
val daysInMillis = TimeUnit.DAYS.toMillis(days.toLong())
val currentTime = Date().time
val previousTime = this
val differ = currentTime - previousTime
return !(differ < daysInMillis && differ > -daysInMillis)
}
val fiveMinutes = (1000 * 60 * 5).toLong() //5m in milliseconds