Fix crash in the setting when enabling/disabling integration manager and there is no network.

This commit is contained in:
Benoit Marty 2023-06-15 14:39:34 +02:00
parent 8433e222ad
commit ae52d4cd3c
1 changed files with 12 additions and 1 deletions

View File

@ -71,6 +71,7 @@ import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerC
import org.matrix.android.sdk.api.session.integrationmanager.IntegrationManagerService
import org.matrix.android.sdk.flow.flow
import org.matrix.android.sdk.flow.unwrap
import timber.log.Timber
import java.io.File
import java.net.URL
import java.util.UUID
@ -265,7 +266,17 @@ class VectorSettingsGeneralFragment :
// Disable it while updating the state, will be re-enabled by the account data listener.
it.isEnabled = false
lifecycleScope.launch {
session.integrationManagerService().setIntegrationEnabled(newValue as Boolean)
try {
session.integrationManagerService().setIntegrationEnabled(newValue as Boolean)
} catch (failure: Throwable) {
Timber.e(failure, "Failed to update integration manager state")
activity?.let { activity ->
Toast.makeText(activity, errorFormatter.toHumanReadable(failure), Toast.LENGTH_SHORT).show()
}
// Restore the previous state
it.isChecked = !it.isChecked
it.isEnabled = true
}
}
true
}