Skip to content

Instantly share code, notes, and snippets.

@GokhanBilgin
GokhanBilgin / ServiceConMadeEasy
Created May 30, 2018 06:47
Easy coroutines api to value example
class StoreViewModel @Inject constructor(private val api: ServiceInterface, private val netManager: NetManager): ViewModel() {
val isLoading = ObservableField<Boolean>()
var storeData = MutableLiveData<Store>()
fun fetchStore(storeId: Int, failFunc: (String, String) -> Unit) = launch(UI) {
netManager.isConnectedToInternet?.let {
if(it) {
isLoading.set(true)
api.getStore(storeId).await().handleResponse(failFunc)?.let { storeData.value = it}