Skip to content

Instantly share code, notes, and snippets.

class QueryViewModelArc @Inject
constructor(private val searchShows: SearchShows?) : ViewModel() {
val result = MutableLiveData<String>()
val query = MutableLiveData<String>()
val showLoading = MutableLiveData<Boolean>()
val searchEnabled = MutableLiveData<Boolean>()
/**
* (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
class SearchShows @Inject
constructor(private val showRepository: ShowRepository, private val resourceRepository: ResourceRepository) :
UseCase<String>() {
var query: String? = null
override suspend fun executeOnBackground(): String {
query?.let {
val showsInfo = showRepository.searchShow(it)
val showName: String? = showsInfo?.getOrNull(0)?.show?.title
class SearchShows @Inject
constructor(private val showRepository: ShowRepository, private val resourceRepository: ResourceRepository) :
UseCase<Show>() {
var id: String? = null
override suspend fun executeOnBackground(): Show {
id?.let {
val showDetail = background{
showRepository.showDetail(it)
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 {
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 ->
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})
}
}
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 ->
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")
)
/**
* (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