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
| import app.cash.turbine.test | |
| import kotlinx.coroutines.flow.flow | |
| import kotlinx.coroutines.test.runTest | |
| import org.junit.Test | |
| import kotlin.test.assertEquals | |
| class ResultKtTest { | |
| @Test | |
| fun Result_catches_errors() = runTest { |
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
| import kotlinx.coroutines.flow.Flow | |
| import kotlinx.coroutines.flow.catch | |
| import kotlinx.coroutines.flow.map | |
| import kotlinx.coroutines.flow.onStart | |
| fun <T> Flow<T>.asResult(): Flow<Result<T>> { | |
| return this | |
| .map<T, Result<T>> { | |
| Result.Success(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
| subprojects { | |
| tasks.withType(KotlinCompile).configureEach { | |
| kotlinOptions { | |
| languageVersion = "1.9" | |
| } | |
| } | |
| } |
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
| sealed interface Result<out T> { | |
| data class Success<T>(val data: T) : Result<T> | |
| data class Error(val exception: Throwable? = null) : Result<Nothing> | |
| data object Loading : Result<Nothing> | |
| } |
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 | |
| @InstallIn(SingletonComponent::class) | |
| object CoroutineScopesModule { | |
| @Provides | |
| @Singleton | |
| @ApplicationScope | |
| fun providesApplicationScopeWithIODiapatcher( | |
| @Dispatcher(IO) ioDispatcher: CoroutineDispatcher, | |
| @ApplicationScope scope: CoroutineScope, | |
| ): CoroutineScope = CoroutineScope(scope.coroutineContext + ioDispatcher) // <- What I meant by updating dispatcher |
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
| import [your_app_package].core.network.Dispatcher | |
| import [your_app_package].core.network.AppDispatchers.Default | |
| import dagger.Module | |
| import dagger.Provides | |
| import dagger.hilt.InstallIn | |
| import dagger.hilt.components.SingletonComponent | |
| import kotlinx.coroutines.CoroutineDispatcher | |
| import kotlinx.coroutines.CoroutineScope | |
| import kotlinx.coroutines.SupervisorJob | |
| import javax.inject.Qualifier |
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
| import [your_app_package].common.network.AppDispatchers.Default | |
| import [your_app_package].common.network.AppDispatchers.IO | |
| import [your_app_package].common.network.Dispatcher | |
| import dagger.Module | |
| import dagger.Provides | |
| import dagger.hilt.InstallIn | |
| import dagger.hilt.components.SingletonComponent | |
| import kotlinx.coroutines.CoroutineDispatcher | |
| import kotlinx.coroutines.Dispatchers |
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
| import javax.inject.Qualifier | |
| @Qualifier | |
| annotation class Dispatcher(val appDispatcher: AppDispatchers) | |
| enum class AppDispatchers { | |
| Default, | |
| IO, | |
| } |
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 Button( | |
| private val onClick: () -> Unit | |
| ) { | |
| fun performClick() { | |
| onClick() | |
| } | |
| } | |
| class ButtonClickListener( | |
| var name: String |
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 class foo { | |
| private boolean isOldSignature() { | |
| Context context = this; | |
| final String SIGNATURE = "Put your app signature after retrive in log"; | |
| final boolean VALID = true; | |
| final boolean INVALID = false; | |
| try { | |
| PackageInfo packageInfo = context.getPackageManager() | |
| .getPackageInfo(context.getPackageName(), |
NewerOlder