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
allprojects { | |
afterEvaluate { | |
extensions.findByName('kapt')?.arguments { | |
arg("dagger.formatGeneratedSource", "disabled") | |
arg("dagger.gradle.incremental", "enabled") | |
} | |
} | |
} |
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
kapt { | |
arguments { | |
arg("dagger.formatGeneratedSource", "disabled") | |
arg("dagger.gradle.incremental", "enabled") | |
} | |
} |
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
@Module | |
object NetworkModule { | |
@JvmStatic | |
@Provides | |
fun provideOkHttpClient(): OkHttpClient { | |
return OkHttpClient.Builder().build() | |
} | |
} |
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
@Module | |
abstract class NetworkModule { | |
@Binds abstract fun provideService(retrofitService: RetrofitService): Service | |
@Module | |
companion object { | |
@JvmStatic | |
@Provides |
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
@Module(includes = [OkHttpClientModule::java]) | |
abstract class NetworkModule { | |
@Binds abstract fun provideService(retrofitService: RetrofitService): Service | |
} | |
@Module | |
object OkHttpClientModule { | |
@JvmStatic |
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
@Provides | |
fun provideNetworkPrinter() = NetworkPrinter() | |
@Provides | |
fun provideNetworkPrinter(): NetworkPrinter = NetworkPrinter() | |
@Provides | |
fun provideNetworkPrinter(): NetworkPrinter { | |
return NetworkPrinter() | |
} |
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
@Provides | |
// configures a `Printer` | |
fun providePrinter(): Printer = NetworkPrinter() | |
@Provides | |
// configures a `NetworkPrinter`, not a plain `Printer`! | |
fun providePrinter() = NetworkPrinter() |
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
/* | |
* Copyright 2019 Google Inc. | |
* | |
* 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 ShotViewModel(...) { | |
init { | |
val result = shotsRepository.getShot(shotId) | |
if (result is Result.Success) { | |
// FIRST UI EMISSION with an incomplete UI Model | |
_shotUiModel.value = result.data.toShotUiModel() | |
processUiModel(result.data) | |
} else { ... } | |
} |
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
@Test | |
fun loadShot_emitsTwoUiModels() { | |
// When the ViewModel has started | |
val viewModel = ... // Creates viewModel | |
// Then the fast result has been emitted | |
val fastResult = viewModel.shotUiModel.getOrAwaitValue() | |
// THIS FAILS!!! The slow result has already been emitted because the coroutine | |
// was executed immediately and shotUiModel LiveData contains the slow result | |
assertTrue(fastResult.formattedDescription.isEmpty()) |