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 QueryViewModelArc @Inject | |
constructor(private val searchShows: SearchShows?) : ViewModel() { | |
val result = MutableLiveData<String>() | |
val query = MutableLiveData<String>() | |
val showLoading = MutableLiveData<Boolean>() | |
val searchEnabled = MutableLiveData<Boolean>() |
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
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 |
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<Show>() { | |
var id: String? = null | |
override suspend fun executeOnBackground(): Show { | |
id?.let { | |
val showDetail = background{ | |
showRepository.showDetail(it) |
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 { |
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() { | |
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) : 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
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
/** | |
* (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 |