mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
Fix threading issues while restoring keys backup.
This commit is contained in:
parent
571db7da55
commit
a97971dd84
16 changed files with 51 additions and 45 deletions
|
@ -14,6 +14,7 @@ Improvements 🙌:
|
|||
Bugfix 🐛:
|
||||
- Account creation: wrongly hints that an email can be used to create an account (#941)
|
||||
- Fix crash in the room directory, when public room has no name (#1023)
|
||||
- Fix restoring keys backup with passphrase (#526)
|
||||
|
||||
Translations 🗣:
|
||||
-
|
||||
|
|
|
@ -887,7 +887,7 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
throw Exception("Error")
|
||||
}
|
||||
|
||||
megolmSessionDataImporter.handle(importedSessions, true, uiHandler, progressListener)
|
||||
megolmSessionDataImporter.handle(importedSessions, true, progressListener)
|
||||
}
|
||||
}.foldToCallback(callback)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package im.vector.matrix.android.internal.crypto.actions
|
||||
|
||||
import android.os.Handler
|
||||
import androidx.annotation.WorkerThread
|
||||
import im.vector.matrix.android.api.listeners.ProgressListener
|
||||
import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
||||
|
@ -46,7 +45,6 @@ internal class MegolmSessionDataImporter @Inject constructor(private val olmDevi
|
|||
@WorkerThread
|
||||
fun handle(megolmSessionsData: List<MegolmSessionData>,
|
||||
fromBackup: Boolean,
|
||||
uiHandler: Handler,
|
||||
progressListener: ProgressListener?): ImportRoomKeysResult {
|
||||
val t0 = System.currentTimeMillis()
|
||||
|
||||
|
@ -54,11 +52,7 @@ internal class MegolmSessionDataImporter @Inject constructor(private val olmDevi
|
|||
var lastProgress = 0
|
||||
var totalNumbersOfImportedKeys = 0
|
||||
|
||||
if (progressListener != null) {
|
||||
uiHandler.post {
|
||||
progressListener.onProgress(0, 100)
|
||||
}
|
||||
}
|
||||
progressListener?.onProgress(0, 100)
|
||||
val olmInboundGroupSessionWrappers = olmDevice.importInboundGroupSessions(megolmSessionsData)
|
||||
|
||||
megolmSessionsData.forEachIndexed { cpt, megolmSessionData ->
|
||||
|
@ -89,14 +83,12 @@ internal class MegolmSessionDataImporter @Inject constructor(private val olmDevi
|
|||
}
|
||||
|
||||
if (progressListener != null) {
|
||||
uiHandler.post {
|
||||
val progress = 100 * cpt / totalNumbersOfKeys
|
||||
val progress = 100 * cpt / totalNumbersOfKeys
|
||||
|
||||
if (lastProgress != progress) {
|
||||
lastProgress = progress
|
||||
if (lastProgress != progress) {
|
||||
lastProgress = progress
|
||||
|
||||
progressListener.onProgress(progress, 100)
|
||||
}
|
||||
progressListener.onProgress(progress, 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -692,7 +692,7 @@ internal class DefaultKeysBackupService @Inject constructor(
|
|||
null
|
||||
}
|
||||
|
||||
val result = megolmSessionDataImporter.handle(sessionsData, !backUp, uiHandler, progressListener)
|
||||
val result = megolmSessionDataImporter.handle(sessionsData, !backUp, progressListener)
|
||||
|
||||
// Do not back up the key if it comes from a backup recovery
|
||||
if (backUp) {
|
||||
|
|
|
@ -19,7 +19,6 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.Observer
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.extensions.addFragmentToBackstack
|
||||
|
@ -79,7 +78,6 @@ class KeysBackupRestoreActivity : SimpleFragmentActivity() {
|
|||
addFragmentToBackstack(R.id.container, KeysBackupRestoreFromKeyFragment::class.java)
|
||||
}
|
||||
KeysBackupRestoreSharedViewModel.NAVIGATE_TO_SUCCESS -> {
|
||||
supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
||||
replaceFragment(R.id.container, KeysBackupRestoreSuccessFragment::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,21 +62,21 @@ class KeysBackupRestoreFromKeyViewModel @Inject constructor() : ViewModel() {
|
|||
override fun onStepProgress(step: StepProgressListener.Step) {
|
||||
when (step) {
|
||||
is StepProgressListener.Step.DownloadingKey -> {
|
||||
sharedViewModel.loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
+ "\n" + context.getString(R.string.keys_backup_restoring_downloading_backup_waiting_message),
|
||||
isIndeterminate = true)
|
||||
isIndeterminate = true))
|
||||
}
|
||||
is StepProgressListener.Step.ImportingKey -> {
|
||||
is StepProgressListener.Step.ImportingKey -> {
|
||||
// Progress 0 can take a while, display an indeterminate progress in this case
|
||||
if (step.progress == 0) {
|
||||
sharedViewModel.loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
+ "\n" + context.getString(R.string.keys_backup_restoring_importing_keys_waiting_message),
|
||||
isIndeterminate = true)
|
||||
isIndeterminate = true))
|
||||
} else {
|
||||
sharedViewModel.loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
+ "\n" + context.getString(R.string.keys_backup_restoring_importing_keys_waiting_message),
|
||||
step.progress,
|
||||
step.total)
|
||||
step.total))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,27 +63,28 @@ class KeysBackupRestoreFromPassphraseViewModel @Inject constructor() : ViewModel
|
|||
override fun onStepProgress(step: StepProgressListener.Step) {
|
||||
when (step) {
|
||||
is StepProgressListener.Step.ComputingKey -> {
|
||||
sharedViewModel.loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
+ "\n" + context.getString(R.string.keys_backup_restoring_computing_key_waiting_message),
|
||||
step.progress,
|
||||
step.total)
|
||||
step.total))
|
||||
}
|
||||
is StepProgressListener.Step.DownloadingKey -> {
|
||||
sharedViewModel.loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
+ "\n" + context.getString(R.string.keys_backup_restoring_downloading_backup_waiting_message),
|
||||
isIndeterminate = true)
|
||||
isIndeterminate = true))
|
||||
}
|
||||
is StepProgressListener.Step.ImportingKey -> {
|
||||
Timber.d("backupKeys.ImportingKey.progress: " + step.progress)
|
||||
// Progress 0 can take a while, display an indeterminate progress in this case
|
||||
if (step.progress == 0) {
|
||||
sharedViewModel.loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
+ "\n" + context.getString(R.string.keys_backup_restoring_importing_keys_waiting_message),
|
||||
isIndeterminate = true)
|
||||
isIndeterminate = true))
|
||||
} else {
|
||||
sharedViewModel.loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
|
||||
+ "\n" + context.getString(R.string.keys_backup_restoring_importing_keys_waiting_message),
|
||||
step.progress,
|
||||
step.total)
|
||||
step.total))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package im.vector.riotx.features.crypto.keysbackup.restore
|
|||
|
||||
import android.os.Bundle
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import butterknife.BindView
|
||||
import butterknife.OnClick
|
||||
import im.vector.riotx.R
|
||||
|
@ -39,16 +40,20 @@ class KeysBackupRestoreSuccessFragment @Inject constructor() : VectorBaseFragmen
|
|||
super.onActivityCreated(savedInstanceState)
|
||||
sharedViewModel = activityViewModelProvider.get(KeysBackupRestoreSharedViewModel::class.java)
|
||||
|
||||
sharedViewModel.importKeyResult?.let {
|
||||
val part1 = resources.getQuantityString(R.plurals.keys_backup_restore_success_description_part1,
|
||||
it.totalNumberOfKeys, it.totalNumberOfKeys)
|
||||
val part2 = resources.getQuantityString(R.plurals.keys_backup_restore_success_description_part2,
|
||||
it.successfullyNumberOfImportedKeys, it.successfullyNumberOfImportedKeys)
|
||||
mSuccessDetailsText.text = String.format("%s\n%s", part1, part2)
|
||||
if (compareValues(sharedViewModel.importKeyResult?.totalNumberOfKeys, 0) > 0) {
|
||||
sharedViewModel.importKeyResult?.let {
|
||||
val part1 = resources.getQuantityString(R.plurals.keys_backup_restore_success_description_part1,
|
||||
it.totalNumberOfKeys, it.totalNumberOfKeys)
|
||||
val part2 = resources.getQuantityString(R.plurals.keys_backup_restore_success_description_part2,
|
||||
it.successfullyNumberOfImportedKeys, it.successfullyNumberOfImportedKeys)
|
||||
mSuccessDetailsText.text = String.format("%s\n%s", part1, part2)
|
||||
}
|
||||
// We don't put emoji in string xml as it will crash on old devices
|
||||
mSuccessText.text = context?.getString(R.string.keys_backup_restore_success_title, "🎉")
|
||||
} else {
|
||||
mSuccessText.text = context?.getString(R.string.keys_backup_restore_success_title_already_up_to_date)
|
||||
mSuccessDetailsText.isVisible = false
|
||||
}
|
||||
|
||||
// We don't put emoji in string xml as it will crash on old devices
|
||||
mSuccessText.text = context?.getString(R.string.keys_backup_restore_success_title, "🎉")
|
||||
}
|
||||
|
||||
@OnClick(R.id.keys_backup_setup_done_button)
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/keys_backup_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="?riotx_background">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/keys_backup_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="?riotx_background">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -64,9 +65,9 @@
|
|||
android:id="@+id/keys_backup_view_show_password"
|
||||
android:layout_width="@dimen/layout_touch_size"
|
||||
android:layout_height="@dimen/layout_touch_size"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:scaleType="center"
|
||||
android:layout_marginTop="8dp"
|
||||
android:src="@drawable/ic_eye_black"
|
||||
android:tint="?colorAccent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="?riotx_background">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/keys_backup_shield"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
android:id="@+id/keysBackupSettingsRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?riotx_background"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="@dimen/layout_vertical_margin"
|
||||
android:paddingBottom="@dimen/layout_vertical_margin_big"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?riotx_background"
|
||||
tools:context=".features.crypto.keysbackup.setup.KeysBackupSetupStep1Fragment">
|
||||
|
||||
<ImageView
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
android:id="@+id/keys_backup_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?riotx_background"
|
||||
tools:context=".features.crypto.keysbackup.setup.KeysBackupSetupStep2Fragment">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
android:id="@+id/keys_backup_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?riotx_background"
|
||||
tools:context=".features.crypto.keysbackup.setup.KeysBackupSetupStep3Fragment">
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
|
||||
<string name="event_redacted_by_user_reason_with_reason">Event deleted by user, reason: %1$s</string>
|
||||
<string name="event_redacted_by_admin_reason_with_reason">Event moderated by room admin, reason: %1$s</string>
|
||||
|
||||
<string name="keys_backup_restore_success_title_already_up_to_date">Keys are already up to date!</string>
|
||||
<!-- END Strings added by Onuray -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue