Skip to content

Commit

Permalink
fix: Inject arguments correctly and always init the AccountUtils even…
Browse files Browse the repository at this point in the history
… when there's no connected user
  • Loading branch information
LunarX committed Nov 27, 2024
1 parent 5813baf commit 1b3816e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 1b3816e

Please sign in to comment.