Skip to content

Instantly share code, notes, and snippets.

Victor Mykhailiv vitoksmile

Block or report user

Report or block vitoksmile

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vitoksmile
vitoksmile / LifecycleEventBus.kt
Created Jun 19, 2019
LifecycleEventBus - simplifies the communication between components with LifecycleOwner
View LifecycleEventBus.kt
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 {
@vitoksmile
vitoksmile / FirestoreLiveData.kt
Last active Jun 22, 2019
Custom LiveData to works with FirebaseFirestore snapshots
View FirestoreLiveData.kt
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
@vitoksmile
vitoksmile / BufferedLiveData.kt
Last active Jun 18, 2019
LiveData to hold not observed values to notify UI about these values after appearance of active observers
View BufferedLiveData.kt
/**
* 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()
@vitoksmile
vitoksmile / CoolJob.kt
Last active Dec 11, 2018
Wrapper over Coroutine Job to catch exception
View CoolJob.kt
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)
@vitoksmile
vitoksmile / DeferredX.kt
Created Nov 1, 2018
Extension to Deferred to await values without need catch Exception
View DeferredX.kt
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
/**
@vitoksmile
vitoksmile / KoinPropertyDelegate.kt
Last active Oct 26, 2018
Saving values to Koin's property with delegating
View KoinPropertyDelegate.kt
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
}
@vitoksmile
vitoksmile / KoinUtils.kt
Created Oct 26, 2018
Using dependency injections by Koin without implementing KoinComponent
View KoinUtils.kt
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
You can’t perform that action at this time.