Skip to content

Instantly share code, notes, and snippets.

View HomeViewModelTest.kt
package com.kavak.android.kavakops.modules.home.viewModel
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.kavak.android.content_data.repository.PostalCodesRepo
import com.kavak.android.content_domain.ColonyData
import com.kavak.android.content_usecases.zipCodesAndColonies.GetColoniesByPostalCodeUseCase
import com.kavak.android.kavakops.providers.SchedulerProvider
import com.kavak.android.kavakops.utils.LiveDataTestUtil
import io.reactivex.Single
import io.reactivex.observers.TestObserver
View BaseFullFragment.kt
abstract class BaseFullFragment: DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.AppTheme)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@DjangoLC
DjangoLC / RemoteDataSourceImpl.kt
Created Mar 18, 2021
implementation of firestore with clean
View RemoteDataSourceImpl.kt
class RemoteDataSourceImpl : RemoteDataSource {
private val db = FirebaseFirestore.getInstance().apply {
this.firestoreSettings = FirebaseFirestoreSettings
.Builder()
.setPersistenceEnabled(true)
.build()
}
companion object {
@DjangoLC
DjangoLC / StringUtils.kt
Created Mar 17, 2021
md5 method kotlin
View StringUtils.kt
fun md5(input:String): String {
val md = MessageDigest.getInstance("MD5")
return BigInteger(1, md.digest(input.toByteArray())).toString(16).padStart(32, '0')
}
@DjangoLC
DjangoLC / Aes256.kt
Created Jan 12, 2021
Aes Util fo rencrypt to aes 256
View Aes256.kt
object Aes256 {
private fun cipher(operationMode: Int, secretKey: String = BuildConfig.KEY_ENCRYPT): Cipher {
if (secretKey.length != 32) throw RuntimeException("SecretKey length is not 32 chars")
val c = Cipher.getInstance("AES/CBC/PKCS5Padding")
val sk = SecretKeySpec(secretKey.toByteArray(Charsets.UTF_8), "AES")
val iv = IvParameterSpec(secretKey.substring(0, 16).toByteArray(Charsets.UTF_8))
c.init(operationMode, sk, iv)
return c
}
@DjangoLC
DjangoLC / Event.kt
Created Dec 1, 2020
Event and custom Observer for return the data only if have not been handle before
View Event.kt
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
*/
fun getContentIfNotHandled(): T? {
return if (hasBeenHandled) {
View Event.kt
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
*/
fun getContentIfNotHandled(): T? {
return if (hasBeenHandled) {
View LocationServiceImpl.kt
package com.google.android.gms.location.sample.locationupdates
import android.annotation.SuppressLint
import android.app.Application
import android.location.Location
import android.os.Looper
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.location.*
import com.google.android.gms.tasks.OnCompleteListener
View BaseUiModel.kt
sealed class BaseUiModel<out T> {
object Loading : BaseUiModel<Nothing>()
class Success<T>(val data: T) : BaseUiModel<T>()
class Error(val error: String) : BaseUiModel<Nothing>()
class ErrorEx(val data: Exception) : BaseUiModel<Nothing>()
}
@DjangoLC
DjangoLC / shape.xml
Created Jul 13, 2020
shape for custom switch
View shape.xml
<?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>