https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
s

Slackbot

07/10/2020, 7:56 AM
This message was deleted.
m

Mayank

07/10/2020, 12:41 PM
You can define a channel and use this channel as an event to emit loadCoins flow
Copy code
private val refreshChannel = ConflatedBroadcastChannel<Unit>()
private val coinsFlow: Flow<Resource<List<Coin>>> = refreshChannel.asFlow().transformLatest { emitAll(loadCoins()) }
val coins = coinsFlow.asLiveData()

fun onSwipeRefresh() {
    refreshChannel.offer(Unit)
}
You can also use live data for refresh
Copy code
private val refreshLiveData = MutableLiveData<Unit>(Unit)
val coins: LiveData<Resource<List<Coin>>> = refreshLiveData.switchMap { loadCoins().asLiveData() }

fun onSwipeRefresh() {
    refreshLiveData.value = Unit
}
2 Views