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
public void getUser(String userId) { | |
getView().showLoading(“fetching user…”); | |
Subscription sub = userRepository.getUser(userId) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidScheduler.mainThread()) | |
.subscribe(user -> { | |
getView().stopLoading(); | |
getView().render(user); | |
},e->{ |
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
interface MovieService { | |
@GET("movie/now_playing") | |
suspend fun getUpcomingMovies(@Query("api_key") apiKey: String): Response<MovieResponse> | |
} |
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
interface MovieService { | |
@GET("movie/now_playing") | |
suspend fun getUpcomingMovies(@Query("api_key") apiKey: String): Response<MovieResponse> | |
} |
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
viewModelScope.launch { | |
try { | |
val movies = movieService.getUpcomingMovies() | |
} catch (e: Exception) { | |
//... | |
} | |
} |
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
data class MovieResponse( | |
val errorCode: Int?, | |
val errorMessage: String?, | |
val results: List<MovieData> | |
) |
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
class FetchMacsUseCase constructor( | |
private val productRepository: ProductRepository | |
) { | |
fun run(): Observable<MacsPartialState> { | |
return productRepository.fetchMacs() | |
.toObservable() | |
.map { MacsPartialState.MacsResult(it) } | |
.cast(MacsPartialState::class.java) | |
.startWith(MacsPartialState.LoadingMacs) | |
.onErrorReturn { error -> MacsPartialState.LoadMacsError(error) } |
OlderNewer