Skip to content

Instantly share code, notes, and snippets.

@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 / 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>
}
private fun firebaseAuth(loginModelPost: LoginModelPost?,callback: () -> Unit): Either<Failure, Boolean>? {
@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">
@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
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 / BreakALoop.kt
Created November 6, 2018 10:59
how to break a loop
run breaker@{
collectionModified.forEach { itC ->
when {
!itC.checked && selectedCount >= 3 -> {maxSizeListener(); return@breaker}
else -> {
when {
itC.id == category.id -> {
itC.checked = itemView.switchCategorySelector.isChecked
when {
!itemView.switchCategorySelector.isChecked -> itC.subCategories?.map { it.checked = false }
@EmmanuelGuther
EmmanuelGuther / AnonymousFunUseExample.kt
Created October 29, 2018 20:28
notifyWhitAction waits as a second argument for a function, and for something as simple as closing an activity we are not going to create a function ... we use an anonymous one.
when (layoutEditableMode) {
true -> notifyWithAction(message, (R.string.exit), { fun() = activity?.finish() }, circleImageViewProfessionalProfileEditable)
false -> notifyWithAction(message, R.string.refresh, ::loadData, circleImageViewProfessionalProfile)
}
semicircleHeader?.animate()?.scaleX(1f)?.scaleY(1f)?.setDuration(100)?.start()
@EmmanuelGuther
EmmanuelGuther / listHaveElementSpecificId.kt
Last active October 26, 2018 00:57
To check if a list have contains an element that have specific “id”, we can use any functions like this:
fun foo(){
myList.any { it -> it.id == valueToCheck }
}