This file contains hidden or 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
interface ViewModelLiveDataExtension { | |
operator fun <T> LiveData<T>.invoke(value: T) { | |
if (this is ViewModelLiveData) { | |
val viewModelLiveData = this | |
viewModelLiveData.setValue(value) | |
} | |
} | |
fun <T> ViewModel.liveData(value: T? = null) = lazy { | |
ViewModelLiveData<T>().apply { value?.let { setValue(value) } } as LiveData<T> |
This file contains hidden or 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
abstract class BaseViewModel: ViewModel() { | |
protected operator fun <T> LiveData<T>.invoke(value: T) { | |
if (this is ViewModelLiveData) { | |
val viewModelLiveData = this | |
viewModelLiveData.setValue(value) | |
} | |
} | |
protected fun <T> liveData(value: T) = lazy { | |
ViewModelLiveData(value) as LiveData<T> |
This file contains hidden or 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 onRestResult(response:Response){ | |
if (response.data != null){ | |
showItensOnScreen(response.data) | |
}else{ | |
showError() | |
} | |
} | |
fun showItensOnScreen(model:RestModel){ | |
livedataName.value = model.name |
This file contains hidden or 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
queryViewModelArc.searchEnabled.bind(searchButton::setEnabled) | |
queryViewModelArc.showLoading.bind { loadinLayout.present = it } | |
queryViewModelArc.queryValue.twoWayBind(queryEditText.bindableText) |
This file contains hidden or 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
/** | |
* (C) Copyright 2018 Paulo Vitor Sato Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains hidden or 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
public suspend fun <T : Any> Call<T>.await(): T { | |
return suspendCancellableCoroutine { continuation -> | |
enqueue(object : Callback<T> { | |
override fun onResponse(call: Call<T>?, response: Response<T?>) { | |
if (response.isSuccessful) { | |
val body = response.body() | |
if (body == null) { | |
continuation.resumeWithException( | |
NullPointerException("Response body is null: $response") | |
) |
This file contains hidden or 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
class SearchShows @Inject | |
constructor(private val showRepository: ShowRepository) : UseCase() { | |
var query: String? = null | |
override fun buildUseCaseObservable(): Single<List<ShowResponse>> { | |
return showRepository.searchShow(query).flatMapPublisher { Flowable.fromIterable(it) } | |
.flatMapSingle({ showInfo:ShowInfo -> | |
showRepository.showRating(showInfo.show.ids.trakt) | |
.subscribeOn(Schedulers.io()) | |
.map { rating -> |
This file contains hidden or 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
class SearchShows @Inject | |
constructor(private val showRepository: ShowRepository) : UseCase() { | |
var id: String? = null | |
override suspend fun executeOnBackground(): Single<Show> { | |
val singleDetail = showRepository.showDetail(id).subscribeOn(Schedulers.io()) | |
val singleBanner = showRepository.showBanner(id).subscribeOn(Schedulers.io()) | |
return Single.zip(singleDetail, singleBanner, BiFunction { detail, banner -> Show(detail, banner}) | |
} | |
} |
This file contains hidden or 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
class SearchShows @Inject | |
constructor(private val showRepository: ShowRepository, private val resourceRepository: ResourceRepository) : UseCase() { | |
private var query: String? = null | |
fun setQuery(query: String) { | |
this.query = query | |
} | |
override fun buildUseCaseObservable(): Single<String> { | |
return showRepository.searchShow(query).map { showInfos -> |
This file contains hidden or 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
class SearchShows @Inject | |
constructor(private val showRepository: ShowRepository) : | |
UseCase<List<ShowResponse>>() { | |
var query: String? = null | |
override suspend fun executeOnBackground(): List<ShowResponse> { | |
query?.let { query -> | |
return showRepository.searchShow(query).map { | |
background { |
NewerOlder