Show dialog explaining auto-restore after a restore failed due to not all apps being installed

This commit is contained in:
Torsten Grote 2020-10-15 14:08:03 -03:00
parent 0f0f198228
commit a833df2165
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 18 additions and 0 deletions

View file

@ -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()

View file

@ -118,6 +118,8 @@
<string name="restore_installing_tap_to_install">Tap to install</string>
<string name="restore_next">Next</string>
<string name="restore_restoring">Restoring backup</string>
<string name="restore_restoring_error_title">Unable to restore some apps</string>
<string name="restore_restoring_error_message">You can re-install these apps manually and "Automatic restore" will attempt to restore their data (when enabled).</string>
<string name="restore_magic_package">System package manager</string>
<string name="restore_finished_success">Restore complete</string>
<string name="restore_finished_error">An error occurred while restoring the backup.</string>