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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// With Dagger2 or dagger.android | |
class CustomTestRunner : AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { | |
return super.newApplication(cl, MainTestApplication::class.java.name, context) | |
} | |
} |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// With Dagger2 or dagger.android | |
@Binds | |
@IntoMap | |
@ViewModelKey(SessionDetailViewModel::class) | |
abstract fun bindSessionDetailFragmentViewModel(viewModel: SessionDetailViewModel): ViewModel | |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// With Dagger2 or dagger.android | |
@Target( | |
AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, | |
AnnotationTarget.PROPERTY_SETTER | |
) | |
@Retention(AnnotationRetention.RUNTIME) | |
@MapKey |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// With Dagger2 or dagger.android | |
class SessionDetailFragment : ... { | |
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory | |
private lateinit var sessionDetailViewModel: SessionDetailViewModel | |
… | |
override fun onCreateView(...) { |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// With dagger.android | |
@FragmentScoped | |
@ContributesAndroidInjector | |
internal abstract fun contributeOnboardingFragment(): OnboardingFragment | |
@FragmentScoped | |
@ContributesAndroidInjector |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// With dagger.android | |
@ActivityScoped | |
@ContributesAndroidInjector( | |
modules = [ | |
OnboardingModule::class, | |
SignInDialogModule::class | |
] |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
fun flowFrom(api: CallbackBasedApi): Flow<T> = callbackFlow { | |
val callback = object : Callback { | |
override fun onNextValue(value: T) { | |
offer(value) | |
} | |
override fun onApiError(cause: Throwable) { | |
close(cause) |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
override fun fetchWeatherFlow(): Flow<String> = flow { | |
var counter = 0 | |
while(true) { | |
counter++ | |
delay(2000) | |
emit(weatherConditions[counter % weatherConditions.size]) | |
} |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
suspend fun doOneShot(param: String) : Result<String> = | |
suspendCancellableCoroutine { continuation -> | |
api.addOnCompleteListener { result -> | |
continuation.resume(result) | |
}.addOnFailureListener { error -> | |
continuation.resumeWithException(error) | |
}.fetchSomething(param) |
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 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
suspend fun doOneShot(param: String) : String = | |
retrofitClient.doSomething(param) |