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
flow { emit("whatever") } |
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
// In an Android ViewModel you will use the viewModelScope: | |
viewModelScope.launch { someFlow.collect { /* do whatever */ } } | |
// In a Fragment we have the lifecycleScope : | |
lifecycleScope.launch { someFlow.collect { /* do whatever */ } } | |
// Or with the launchIn method: | |
someFlow.launchIn(viewModelScope) |
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
fun getFlow() = flow { emit(1) } | |
.flowOn(Dispatchers.IO) | |
// and the subscription... | |
runBlocking { | |
getFlow().collect {} | |
} |
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
fun getObservable() = Observable.just(1) | |
.subscribeOn(Schedulers.io()) | |
// and in a different file... | |
getObservable().subscribe() |
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
val disposable = someObservable.subscribe() | |
disposable.dispose() | |
// or... | |
val compositeDisposable = CompositeDisposable() | |
compositeDisposable.add(disposable) | |
compositeDisposable.dispose() |
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
flowReturningAnError | |
.catch { emit(defaultValue) } |
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
flow { | |
var x = 0 | |
do { | |
delay(1000) | |
emit(x) | |
x++ | |
} while (x < 1000) | |
} |
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
package com.antonicastejon.cryptodata.viewmodels | |
import android.arch.core.executor.testing.InstantTaskExecutorRule | |
import android.arch.lifecycle.Observer | |
import com.antonicastejon.cryptodata.common.limitCryptoListSizeArrayEmptyCryptoViewModel | |
import com.antonicastejon.cryptodata.common.mock | |
import com.antonicastejon.cryptodata.common.whenever | |
import com.antonicastejon.cryptodata.domain.CryptoListUseCases | |
import com.antonicastejon.cryptodata.domain.CryptoViewModel | |
import com.antonicastejon.cryptodata.presentation.main.crypto_list.* |
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
fun limitCryptoListSizeArrayEmptyCryptoViewModel(): List<CryptoViewModel> = | |
ArrayList<CryptoViewModel>(Collections.nCopies(LIMIT_CRYPTO_LIST, CryptoViewModel())) | |
fun cryptoPOJOmodel() = | |
Crypto("1", "name", "sy", 10, "100", "0.1", "100", "1000", "0", "500", "5", "10", "-10", "") | |
fun cryptoViewModelFrom(crypto:Crypto) = | |
CryptoViewModel(crypto.id, crypto.name, crypto.symbol, crypto.rank, crypto.priceUsd.toFloat(), crypto.priceBtc.toFloat(), crypto.percentChange24h.toFloat()) |
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
package com.antonicastejon.cryptodata.usecases | |
import android.arch.core.executor.testing.InstantTaskExecutorRule | |
import com.antonicastejon.cryptodata.common.cryptoPOJOmodel | |
import com.antonicastejon.cryptodata.common.cryptoViewModelFrom | |
import com.antonicastejon.cryptodata.common.mock | |
import com.antonicastejon.cryptodata.common.whenever | |
import com.antonicastejon.cryptodata.domain.CryptoListInteractor | |
import com.antonicastejon.cryptodata.model.CoinMarketCapRepository | |
import io.reactivex.Single |
NewerOlder