Prevent crash when logging in #81

Merged
AmineB merged 3 commits from davidoskky/ReaderForSelfoss-multiplatform:login_crash into master 2022-10-22 19:54:01 +00:00
Showing only changes of commit c25e8889a4 - Show all commits

View File

@ -43,10 +43,11 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
init {
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
connectivityStatus.start()
runBlocking {
updateApiVersion()
dateUtils = DateUtils(appSettingsService)
reloadBadges()
if (appSettingsService.getBaseUrl() != "") {
AmineB marked this conversation as resolved Outdated

getBaseUrl should never return an empty string.

There is a verification done before even logging-in (and saving the settings), so this should never happen.

`getBaseUrl` should never return an empty string. There is a verification done before even logging-in (and saving the settings), so this should never happen.

The repository is initialized before logging in, at that point appSettingsService returns an empty string

The repository is initialized before logging in, at that point appSettingsService returns an empty string

Ok, so this is a workaround.

The issue is that the runBlocking block is called even when the user is'nt updated. This should be fixed.

Ok, so this is a workaround. The issue is that the `runBlocking` block is called even when the user is'nt updated. This should be fixed.

I could remove this from the init method and make a new public method which is called by the login activity after it checks that the user is correctly set.

I could remove this from the init method and make a new public method which is called by the login activity after it checks that the user is correctly set.

that could be better, yes !

that could be better, yes !
runBlocking {
updateApiVersion()
reloadBadges()
}
}
}
@ -408,6 +409,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
appSettingsService.updateApiVersion(fetchedVersion.data.getApiMajorVersion())
}
}
dateUtils = DateUtils(appSettingsService)
AmineB marked this conversation as resolved Outdated

why was this added ?

why was this added ?

If the repository is initialized before the login, this is required to initialize the dateUtils after logging in

If the repository is initialized before the login, this is required to initialize the dateUtils after logging in
}
fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride