diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/LaunchActivity.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/LaunchActivity.kt index 0a40779ac..bfb0af411 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/LaunchActivity.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/LaunchActivity.kt @@ -24,10 +24,17 @@ import androidx.activity.ComponentActivity import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import com.infomaniak.swisstransfer.ui.utils.AccountUtils import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch +import javax.inject.Inject @AndroidEntryPoint @SuppressLint("CustomSplashScreen") -class LaunchActivity(private val accountUtils: AccountUtils) : ComponentActivity() { +class LaunchActivity : ComponentActivity() { + + @Inject + lateinit var accountUtils: AccountUtils + override fun onCreate(savedInstanceState: Bundle?) { installSplashScreen() diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt index 9ed8b2d68..289a8816f 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt @@ -34,11 +34,14 @@ import kotlinx.coroutines.launch import javax.inject.Inject @HiltAndroidApp -class MainApplication(private val accountUtils: AccountUtils) : Application(), Configuration.Provider { +class MainApplication : Application(), Configuration.Provider { @Inject lateinit var accountManager: AccountManager + @Inject + lateinit var accountUtils: AccountUtils + @Inject lateinit var uploadRecaptcha: UploadRecaptcha @@ -55,7 +58,7 @@ class MainApplication(private val accountUtils: AccountUtils) : Application(), C super.onCreate() globalCoroutineScope.launch { - accountUtils.init() // TODO: Move to the end of the onboarding activity + accountUtils.init() uploadRecaptcha.initializeClient() } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/AccountUtils.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/AccountUtils.kt index 0a7f1526c..c05a6943b 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/AccountUtils.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/AccountUtils.kt @@ -27,7 +27,15 @@ class AccountUtils @Inject constructor( private val accountPreferences: AccountPreferences, ) { - suspend fun init(userId: Int = DEFAULT_USER_ID) { + suspend fun init() { + accountPreferences.currentUserId?.let { + accountManager.loadUser(it) + } ?: run { + login() // TODO: Move logic for when user needs to connect to the end of the onboarding activity + } + } + + suspend fun login(userId: Int = DEFAULT_USER_ID) { accountPreferences.currentUserId = userId accountManager.loadUser(userId) }