Skip to content

Instantly share code, notes, and snippets.

View DjangoLC's full-sized avatar
🏠
Working from home

Enrique Perez DjangoLC

🏠
Working from home
View GitHub Profile
@DjangoLC
DjangoLC / Coroutines snippet.kt
Created February 26, 2020 22:55
Snippet code about how to implement coroutines with retrofit and viewmodel
// Method in retrofit Ws
suspend fun getDestinyRequestR() : Response<List<ResponseDestinyRequest>>
// Method in repository
override suspend fun getDestinyRequest(): List<DestinyRequest> {
val response = destinyRequestWs.getDestinyRequestR()
//Do stuff
return response
}
package com.djangomx.airsale.utils.dialogs
import android.content.Context
import androidx.appcompat.app.AlertDialog
typealias onClickAllow = (Boolean) -> Unit
object Dialogs {
var alertDialog: AlertDialog.Builder? = null
private val database = FirebaseDatabase.getInstance()
override fun getSummary(): Observable<OweSummaryDomain> =
Observable.create { emitter ->
val summary = database.getReference("summary")
summary.addValueEventListener(object : ValueEventListener {
override fun onCancelled(error: DatabaseError) {
Timber.e("summary error: ${error.message}")
emitter.onError(error.toException())
}
@DjangoLC
DjangoLC / AuthImpl.kt
Created May 12, 2020 15:11
Clase que implementa la interfaz que data utiliza para hacer login con biometrics
package com.example.cleanarchme.data
import android.app.Application
import android.widget.Toast
import androidx.biometric.BiometricPrompt
import androidx.fragment.app.FragmentActivity
import com.example.data.auth.Auth
import java.util.concurrent.Executor
class AuthImpl(private val context: Application, private var activity: FragmentActivity) : Auth {
@DjangoLC
DjangoLC / UserRepository.kt
Created May 12, 2020 15:12
Repository que hace la validacion para iniciar sesion con usuario o contrasenia o biometrics en caso de tener uno activo
package com.example.data.repository
import com.example.data.UserPreferences
import com.example.data.auth.Auth
import com.example.data.auth.AuthValidator
import com.example.data.source.LocalDataSource
class UserRepository(
private val auth: Auth,
private val authValidator: AuthValidator,
class MyFirebaseMessagingService : FirebaseMessagingService() {
private val userPreferences: UserPreferences by inject()
override fun onMessageReceived(remoteMessage: RemoteMessage) {
// ...
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Timber.e("From: %s", remoteMessage.from)
class UserPreferences(context: Context) {
companion object {
const val USER_PREFERENCES = "USER_PREFERENCES"
const val USER_TOKEN = "USER_TOKEN"
}
private val preferences = context.applicationContext
.getSharedPreferences(USER_PREFERENCES, Context.MODE_PRIVATE)
fun Application.initDi() {
startKoin {
androidLogger()
androidContext(this@initDi)
modules(listOf(appModule, dataModule, summaryModule, oweModule))
}
}
val appModule = module {
single<FirebaseDataSource> {
@DjangoLC
DjangoLC / CustomSwitch.kt
Created July 12, 2020 23:47
custom switch
package com.example.cleanarchme.views
import android.animation.ObjectAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
import android.view.View
@DjangoLC
DjangoLC / switch_layout.xml
Created July 12, 2020 23:48
custom switch layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_switch_container"
android:layout_width="222dp"
android:layout_height="33dp"
android:background="@drawable/shape"
android:backgroundTint="#82BC00"
android:clickable="true"