From a833df2165e625c1a4b35c7de88096e21f9480e9 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 15 Oct 2020 14:08:03 -0300 Subject: [PATCH] Show dialog explaining auto-restore after a restore failed due to not all apps being installed --- .../seedvault/restore/RestoreProgressFragment.kt | 16 ++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 18 insertions(+) diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreProgressFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreProgressFragment.kt index adec8467..e3b4ce77 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreProgressFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreProgressFragment.kt @@ -9,6 +9,7 @@ import android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON import android.widget.Button import android.widget.ProgressBar import android.widget.TextView +import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat.getColor import androidx.fragment.app.Fragment import androidx.lifecycle.Observer @@ -17,6 +18,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL import androidx.recyclerview.widget.RecyclerView import com.stevesoltys.seedvault.R +import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_NOT_INSTALLED import org.koin.androidx.viewmodel.ext.android.sharedViewModel class RestoreProgressFragment : Fragment() { @@ -83,11 +85,25 @@ class RestoreProgressFragment : Fragment() { backupNameView.setTextColor(getColor(requireContext(), R.color.red)) } else { backupNameView.text = getString(R.string.restore_finished_success) + onRestoreFinished() } activity?.window?.clearFlags(FLAG_KEEP_SCREEN_ON) }) } + private fun onRestoreFinished() { + // check if any restore failed, because the app is not installed + val failed = viewModel.restoreProgress.value?.any { it.state == FAILED_NOT_INSTALLED } + if (failed != true) return // nothing left to do if there's no failures due to not installed + AlertDialog.Builder(requireContext()) + .setTitle(R.string.restore_restoring_error_title) + .setMessage(R.string.restore_restoring_error_message) + .setPositiveButton(android.R.string.ok) { dialog, _ -> + dialog.dismiss() + } + .show() + } + private fun stayScrolledAtTop(add: () -> Unit) { val position = layoutManager.findFirstVisibleItemPosition() add.invoke() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 54ff96a0..c45c7a1c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -118,6 +118,8 @@ Tap to install Next Restoring backup + Unable to restore some apps + You can re-install these apps manually and "Automatic restore" will attempt to restore their data (when enabled). System package manager Restore complete An error occurred while restoring the backup.