Navigation Menu

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 / shape.xml
Created July 13, 2020 00:04
shape for custom switch
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FAFAFA"/>
<corners android:radius="40dp"/>
</shape>
@DjangoLC
DjangoLC / attrs.xml
Created July 12, 2020 23:48
custom switch attrs custom switch attrs
<declare-styleable name="CustomSwitch">
<attr name="textOn" format="string|reference" />
<attr name="textOff" format="string|reference" />
<attr name="backColorGroundShip" format="reference" />
<attr name="backColorGroundSwitch" format="reference" />
</declare-styleable>
@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"
@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
fun Application.initDi() {
startKoin {
androidLogger()
androidContext(this@initDi)
modules(listOf(appModule, dataModule, summaryModule, oweModule))
}
}
val appModule = module {
single<FirebaseDataSource> {
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)
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)
@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,
@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 {
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())
}