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
2 changed files with 4 additions and 11 deletions
Showing only changes of commit 53b1d1f8b2 - Show all commits

View File

@ -93,6 +93,9 @@ class LoginActivity : AppCompatActivity(), DIAware {
}
private fun goToMain() {
CoroutineScope(Dispatchers.Main).launch {
repository.updateApiVersion()
}
val intent = Intent(this, HomeActivity::class.java)
startActivity(intent)
finish()

View File

@ -41,14 +41,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
private var fetchedTags = false
init {
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
connectivityStatus.start()
if (appSettingsService.getBaseUrl() != "") {
runBlocking {
updateApiVersion()
reloadBadges()
}
}
}
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 !
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
@ -384,9 +377,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
try {
val response = api.login()
result = response.isSuccess == true
if (result) {
updateApiVersion()
}
} catch (cause: Throwable) {
Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.updateRemote")
}
@ -400,7 +390,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
api.refreshLoginInformation()
}
private suspend fun updateApiVersion() {
suspend fun updateApiVersion() {
val apiMajorVersion = appSettingsService.getApiVersion()
if (isNetworkAvailable()) {