This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.properties.ReadWriteProperty | |
import kotlin.reflect.KProperty | |
/** | |
* getValue returns only once the exact value, in other cases [default] value will be returned | |
*/ | |
private class OneShotFieldDelegate<T : Any?>( | |
private val default: T, | |
) : ReadWriteProperty<Any?, T> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.Lifecycle | |
import androidx.lifecycle.LifecycleObserver | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.OnLifecycleEvent | |
import java.util.WeakHashMap | |
/** | |
* LifecycleEventBus - simplifies the communication between components with LifecycleOwner | |
*/ | |
object LifecycleEventBus { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.LiveData | |
import com.google.firebase.firestore.DocumentSnapshot | |
import com.google.firebase.firestore.FirebaseFirestore | |
import com.google.firebase.firestore.ListenerRegistration | |
import com.google.firebase.firestore.QuerySnapshot | |
/** | |
* Custom [LiveData] to works with [FirebaseFirestore] snapshots | |
* | |
* @param collection The current collection's name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Hold not observed values to notify UI about these values after appearance of active observers | |
*/ | |
class BufferedLiveData<T> : LiveData<T>() { | |
/** | |
* Object to synchronize adding values to buffer in #postValue | |
*/ | |
private val lock = Any() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.CancellationException | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.launch | |
/** | |
* Launch new block in coroutine and invoke callbacks after execution | |
* | |
* @param onComplete Called when launch was success | |
* @param onError Called when launch had an exception | |
* @param onFinally Called after launch (ignore result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.CancellationException | |
import kotlinx.coroutines.Deferred | |
import kotlinx.coroutines.Dispatchers | |
/** | |
* Coroutine dispatcher that is confined to the Main thread operating with UI objects | |
*/ | |
val UI = Dispatchers.Main | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.koin.standalone.KoinComponent | |
import org.koin.standalone.getKoin | |
import kotlin.reflect.KProperty | |
class KoinPropertyDelegate<R, T : Any>(private val key: String, private val default: T) : | |
KoinComponent { | |
operator fun getValue(thisRef: R, property: KProperty<*>): T { | |
return getKoin().getProperty<Any>(key, default) as T | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.koin.core.KoinContext | |
import org.koin.core.parameter.ParameterDefinition | |
import org.koin.core.parameter.emptyParameterDefinition | |
import org.koin.core.scope.Scope | |
import org.koin.standalone.StandAloneContext | |
/** | |
* inject lazily given dependency | |
* @param name - bean canonicalName | |
* @param parameters - injection parameters |