-
-
Save romansl/cc9ce61e6dc824fe197d3b6d2170c15b to your computer and use it in GitHub Desktop.
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
package com.kaspersky.security_pulse_android.buisness.interactor | |
import com.kaspersky.security_pulse_android.buisness.repository.ILanguageRepository | |
import com.kaspersky.security_pulse_android.buisness.repository.ILoginRepository | |
import kotlinx.coroutines.experimental.async | |
import java.util.* | |
interface ILoginRepository { | |
// Если функции репорзитория всегда планируется запускать из другого треда, | |
// то разумно позаботиться о том, чтобы они сами для себя решали на каком | |
// контексте им выполняться. | |
suspend fun getLanguages(...) = withContext(IO) { ... } | |
suspend fun loginWithDeviceUuid(...) = withContext(IO) { ... } | |
} | |
class LoginInteractor(private val languageRepository: ILanguageRepository, | |
private val loginRepository: ILoginRepository) : ILoginInteractor { | |
override suspend fun skipAuthLogin() { | |
val uuid = UUID.randomUUID().toString() | |
val systemLanguage = Locale.getDefault().language | |
val languages = languageRepository.getLanguages() // Больше нет сбивающих с толку async-ов. | |
val actualLanguage = languages.find { it.code == systemLanguage } | |
actualLanguage?.let { | |
loginRepository.loginWithDeviceUuid(uuid, it.id) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment