Skip to content

Instantly share code, notes, and snippets.

View FarshidABZ's full-sized avatar
🎮
Enjoing

Farshid Abazari FarshidABZ

🎮
Enjoing
View GitHub Profile
@FarshidABZ
FarshidABZ / DoubleTriggerLiveData.kt
Created April 20, 2021 10:37
DoubleTriggerLiveData to use multiple transformation on an object
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
/**
* DoubleTriggerLiveData to use multiple transformation on an object
* */
class DoubleTriggerLiveData<A, B>(a: LiveData<A>, b: LiveData<B>) : MediatorLiveData<Pair<A?, B?>>() {
init {
addSource(a) { value = it to b.value }
addSource(b) { value = a.value to it }