Show different app state messages for backup and restore

This commit is contained in:
Torsten Grote 2020-10-07 15:15:36 -03:00 committed by Chirayu Desai
parent 3a31e09a04
commit 9830d2db95
17 changed files with 103 additions and 78 deletions

View file

@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView.Adapter
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
import com.stevesoltys.seedvault.R
import com.stevesoltys.seedvault.restore.RestoreProgressAdapter.PackageViewHolder
import com.stevesoltys.seedvault.ui.AppBackupState
import com.stevesoltys.seedvault.ui.AppViewHolder
import java.util.LinkedList
@ -64,26 +65,14 @@ internal class RestoreProgressAdapter : Adapter<PackageViewHolder>() {
appIcon.setImageResource(R.drawable.ic_launcher_default)
}
}
setStatus(item.status)
setState(item.state, true)
}
}
}
enum class AppRestoreStatus {
IN_PROGRESS,
SUCCEEDED,
NOT_YET_BACKED_UP,
FAILED,
FAILED_NO_DATA,
FAILED_WAS_STOPPED,
FAILED_NOT_ALLOWED,
FAILED_QUOTA_EXCEEDED,
FAILED_NOT_INSTALLED,
}
internal data class AppRestoreResult(
val packageName: String,
val name: CharSequence,
val status: AppRestoreStatus
val state: AppBackupState
)

View file

@ -15,6 +15,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import com.stevesoltys.seedvault.ui.AppBackupState
import com.stevesoltys.seedvault.BackupMonitor
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
import com.stevesoltys.seedvault.R
@ -26,14 +27,14 @@ import com.stevesoltys.seedvault.metadata.PackageState.NO_DATA
import com.stevesoltys.seedvault.metadata.PackageState.QUOTA_EXCEEDED
import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR
import com.stevesoltys.seedvault.metadata.PackageState.WAS_STOPPED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NOT_ALLOWED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NOT_INSTALLED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NO_DATA
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_QUOTA_EXCEEDED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.IN_PROGRESS
import com.stevesoltys.seedvault.restore.AppRestoreStatus.NOT_YET_BACKED_UP
import com.stevesoltys.seedvault.restore.AppRestoreStatus.SUCCEEDED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_NOT_ALLOWED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_NOT_INSTALLED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_NO_DATA
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_QUOTA_EXCEEDED
import com.stevesoltys.seedvault.ui.AppBackupState.IN_PROGRESS
import com.stevesoltys.seedvault.ui.AppBackupState.NOT_YET_BACKED_UP
import com.stevesoltys.seedvault.ui.AppBackupState.SUCCEEDED
import com.stevesoltys.seedvault.restore.DisplayFragment.RESTORE_APPS
import com.stevesoltys.seedvault.restore.DisplayFragment.RESTORE_BACKUP
import com.stevesoltys.seedvault.settings.SettingsManager
@ -99,7 +100,7 @@ internal class RestoreViewModel(
AppRestoreResult(
packageName = MAGIC_PACKAGE_MANAGER,
name = getAppName(app, MAGIC_PACKAGE_MANAGER),
status = IN_PROGRESS
state = IN_PROGRESS
)
)
}
@ -222,9 +223,9 @@ internal class RestoreViewModel(
private fun updateLatestPackage(list: LinkedList<AppRestoreResult>) {
val latestResult = list[0]
if (restoreCoordinator.isFailedPackage(latestResult.packageName)) {
list[0] = latestResult.copy(status = getFailedStatus(latestResult.packageName))
list[0] = latestResult.copy(state = getFailedStatus(latestResult.packageName))
} else {
list[0] = latestResult.copy(status = SUCCEEDED)
list[0] = latestResult.copy(state = SUCCEEDED)
}
}
@ -232,7 +233,7 @@ internal class RestoreViewModel(
private fun getFailedStatus(
packageName: String,
restorableBackup: RestorableBackup = chosenRestorableBackup.value!!
): AppRestoreStatus {
): AppBackupState {
val metadata = restorableBackup.packageMetadataMap[packageName] ?: return FAILED
return when (metadata.state) {
NO_DATA -> FAILED_NO_DATA

View file

@ -16,9 +16,9 @@ import androidx.recyclerview.widget.DiffUtil.DiffResult
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.NO_POSITION
import com.stevesoltys.seedvault.R
import com.stevesoltys.seedvault.restore.AppRestoreStatus
import com.stevesoltys.seedvault.restore.AppRestoreStatus.SUCCEEDED
import com.stevesoltys.seedvault.settings.AppStatusAdapter.AppStatusViewHolder
import com.stevesoltys.seedvault.ui.AppBackupState
import com.stevesoltys.seedvault.ui.AppBackupState.SUCCEEDED
import com.stevesoltys.seedvault.ui.AppViewHolder
import com.stevesoltys.seedvault.ui.toRelativeTime
@ -81,7 +81,7 @@ internal class AppStatusAdapter(private val toggleListener: AppStatusToggleListe
startActivity(context, intent, null)
true
}
setStatus(item.status)
setState(item.status, false)
if (item.status == SUCCEEDED) {
appInfo.text = item.time.toRelativeTime(context)
appInfo.visibility = VISIBLE
@ -110,7 +110,7 @@ data class AppStatus(
val icon: Drawable,
val name: String,
val time: Long,
val status: AppRestoreStatus
val status: AppBackupState
)
internal class AppStatusDiff(

View file

@ -25,15 +25,15 @@ import com.stevesoltys.seedvault.metadata.PackageState.QUOTA_EXCEEDED
import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR
import com.stevesoltys.seedvault.metadata.PackageState.WAS_STOPPED
import com.stevesoltys.seedvault.permitDiskReads
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NOT_ALLOWED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NO_DATA
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_QUOTA_EXCEEDED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_WAS_STOPPED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.NOT_YET_BACKED_UP
import com.stevesoltys.seedvault.restore.AppRestoreStatus.SUCCEEDED
import com.stevesoltys.seedvault.transport.backup.PackageService
import com.stevesoltys.seedvault.transport.requestBackup
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_NOT_ALLOWED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_NO_DATA
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_QUOTA_EXCEEDED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED_WAS_STOPPED
import com.stevesoltys.seedvault.ui.AppBackupState.NOT_YET_BACKED_UP
import com.stevesoltys.seedvault.ui.AppBackupState.SUCCEEDED
import com.stevesoltys.seedvault.ui.RequireProvisioningViewModel
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
import com.stevesoltys.seedvault.ui.notification.getAppName

View file

@ -0,0 +1,43 @@
package com.stevesoltys.seedvault.ui
import android.content.Context
import com.stevesoltys.seedvault.R
enum class AppBackupState {
IN_PROGRESS,
SUCCEEDED,
NOT_YET_BACKED_UP,
FAILED,
FAILED_NO_DATA,
FAILED_WAS_STOPPED,
FAILED_NOT_ALLOWED,
FAILED_QUOTA_EXCEEDED,
FAILED_NOT_INSTALLED;
private val notShownString = "Please report a bug after you read this."
fun getBackupText(context: Context): String = when (this) {
IN_PROGRESS -> notShownString
SUCCEEDED -> notShownString
NOT_YET_BACKED_UP -> context.getString(R.string.backup_app_not_yet_backed_up)
FAILED -> notShownString
FAILED_NO_DATA -> context.getString(R.string.backup_app_no_data)
FAILED_WAS_STOPPED -> context.getString(R.string.backup_app_was_stopped)
FAILED_NOT_ALLOWED -> context.getString(R.string.backup_app_not_allowed)
FAILED_NOT_INSTALLED -> notShownString
FAILED_QUOTA_EXCEEDED -> context.getString(R.string.backup_app_quota_exceeded)
}
fun getRestoreText(context: Context): String = when (this) {
IN_PROGRESS -> notShownString
SUCCEEDED -> notShownString
NOT_YET_BACKED_UP -> context.getString(R.string.restore_app_not_yet_backed_up)
FAILED -> notShownString
FAILED_NO_DATA -> context.getString(R.string.backup_app_no_data)
FAILED_WAS_STOPPED -> context.getString(R.string.restore_app_was_stopped)
FAILED_NOT_ALLOWED -> context.getString(R.string.restore_app_not_allowed)
FAILED_NOT_INSTALLED -> context.getString(R.string.restore_app_not_installed)
FAILED_QUOTA_EXCEEDED -> context.getString(R.string.restore_app_quota_exceeded)
}
}

View file

@ -12,16 +12,9 @@ import android.widget.Switch
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.stevesoltys.seedvault.R
import com.stevesoltys.seedvault.restore.AppRestoreStatus
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NOT_ALLOWED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NOT_INSTALLED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_NO_DATA
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_QUOTA_EXCEEDED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.FAILED_WAS_STOPPED
import com.stevesoltys.seedvault.restore.AppRestoreStatus.IN_PROGRESS
import com.stevesoltys.seedvault.restore.AppRestoreStatus.NOT_YET_BACKED_UP
import com.stevesoltys.seedvault.restore.AppRestoreStatus.SUCCEEDED
import com.stevesoltys.seedvault.ui.AppBackupState.FAILED
import com.stevesoltys.seedvault.ui.AppBackupState.IN_PROGRESS
import com.stevesoltys.seedvault.ui.AppBackupState.SUCCEEDED
internal abstract class AppViewHolder(protected val v: View) : RecyclerView.ViewHolder(v) {
@ -41,8 +34,8 @@ internal abstract class AppViewHolder(protected val v: View) : RecyclerView.View
v.background = null
}
protected fun setStatus(status: AppRestoreStatus) {
if (status == IN_PROGRESS) {
protected fun setState(state: AppBackupState, isRestore: Boolean) {
if (state == IN_PROGRESS) {
appInfo.visibility = GONE
appStatus.visibility = INVISIBLE
progressBar.visibility = VISIBLE
@ -50,26 +43,18 @@ internal abstract class AppViewHolder(protected val v: View) : RecyclerView.View
appStatus.visibility = VISIBLE
progressBar.visibility = INVISIBLE
appInfo.visibility = GONE
when (status) {
when (state) {
SUCCEEDED -> appStatus.setImageResource(R.drawable.ic_check_green)
FAILED -> appStatus.setImageResource(R.drawable.ic_error_red)
else -> {
appStatus.setImageResource(R.drawable.ic_warning_yellow)
appInfo.text = status.getInfo()
appInfo.text =
if (isRestore) state.getRestoreText(context)
else state.getBackupText(context)
appInfo.visibility = VISIBLE
}
}
}
}
private fun AppRestoreStatus.getInfo(): String = when (this) {
NOT_YET_BACKED_UP -> context.getString(R.string.restore_app_not_yet_backed_up)
FAILED_NO_DATA -> context.getString(R.string.restore_app_no_data)
FAILED_WAS_STOPPED -> context.getString(R.string.restore_app_was_stopped)
FAILED_NOT_ALLOWED -> context.getString(R.string.restore_app_not_allowed)
FAILED_NOT_INSTALLED -> context.getString(R.string.restore_app_not_installed)
FAILED_QUOTA_EXCEEDED -> context.getString(R.string.restore_app_quota_exceeded)
else -> "Please report a bug after you read this."
}
}

View file

@ -49,7 +49,7 @@
<string name="restore_app_quota_exceeded">Έγινε υπέρβαση του ορίου αντιγράφων ασφαλείας</string>
<string name="restore_app_not_installed">Η εφαρμογή δεν έχει εγκατασταθεί</string>
<string name="restore_app_not_allowed">Η εφαρμογή δεν επιτρέπει τη δημιουργία αντιγράφων ασφαλείας</string>
<string name="restore_app_no_data">Η εφαρμογή δεν ανέφερε δεδομένα για δημιουργία αντιγράφων ασφαλείας</string>
<string name="backup_app_no_data">Η εφαρμογή δεν ανέφερε δεδομένα για δημιουργία αντιγράφων ασφαλείας</string>
<string name="restore_magic_package">Διαχειριστής πακέτων συστήματος</string>
<string name="restore_restoring">Επαναφορά αντιγράφου ασφαλείας</string>
<string name="restore_next">Επόμενο</string>

View file

@ -17,7 +17,7 @@
<string name="restore_app_quota_exceeded">Cuota de respaldo excedida</string>
<string name="restore_app_not_installed">Aplicación no instalada</string>
<string name="restore_app_not_allowed">La aplicación no permite respaldo</string>
<string name="restore_app_no_data">La aplicación no reportó datos para respaldo</string>
<string name="backup_app_no_data">La aplicación no reportó datos para respaldo</string>
<string name="restore_magic_package">Administrador de Paquetes del Sistema</string>
<string name="restore_restoring">Restaurando Respaldo</string>
<string name="restore_next">Próximo</string>

View file

@ -48,7 +48,7 @@
<string name="restore_app_quota_exceeded">Se ha superado la cuota de la copia de seguridad</string>
<string name="restore_app_not_installed">La aplicación no está instalada</string>
<string name="restore_app_not_allowed">La aplicación no permite copias de seguridad</string>
<string name="restore_app_no_data">La aplicación no reportó datos para la copia de seguridad</string>
<string name="backup_app_no_data">La aplicación no reportó datos para la copia de seguridad</string>
<string name="restore_magic_package">Administrador de paquetes del sistema</string>
<string name="restore_restoring">Restaurando copia de seguridad</string>
<string name="restore_installing_packages">Re-Instalando aplicaciones</string>

View file

@ -72,7 +72,7 @@
<string name="restore_app_quota_exceeded">Quota de sauvegarde dépassé</string>
<string name="restore_app_not_installed">Application non installée</string>
<string name="restore_app_not_allowed">L\'application n\'autorise pas la sauvegarde</string>
<string name="restore_app_no_data">L\'application n\'a signalé aucune donnée à sauvegarder</string>
<string name="backup_app_no_data">L\'application n\'a signalé aucune donnée à sauvegarder</string>
<string name="restore_magic_package">Gestionnaire de paquets système</string>
<string name="restore_restoring">Restauration de la sauvegarde</string>
<string name="restore_installing_packages">Réinstallation des applications</string>

View file

@ -19,7 +19,7 @@
<string name="restore_app_quota_exceeded">Kvota za sigurnosne kopije premašena</string>
<string name="restore_app_not_installed">Aplikacija nije instalirana</string>
<string name="restore_app_not_allowed">Aplikacija ne dozvoljava sigurnosne kopije</string>
<string name="restore_app_no_data">Aplikacija nema podataka za sigurnosnu kopiju</string>
<string name="backup_app_no_data">Aplikacija nema podataka za sigurnosnu kopiju</string>
<string name="restore_magic_package">Upravljanje paketima sustava</string>
<string name="restore_restoring">Vraćanje sigurnosne kopije</string>
<string name="restore_next">Sljedeća</string>

View file

@ -16,7 +16,7 @@
<string name="restore_finished_success">Endurvakningu lokið</string>
<string name="restore_app_quota_exceeded">Afritunarrými búið</string>
<string name="restore_app_not_installed">Appið er ekki uppsett</string>
<string name="restore_app_no_data">Appið tilkynnti að engin gögn væru til öryggisafritunar</string>
<string name="backup_app_no_data">Appið tilkynnti að engin gögn væru til öryggisafritunar</string>
<string name="restore_app_not_allowed">Appið leyfir ekki öryggisafritun</string>
<string name="restore_magic_package">Pakkastjóri kerfis</string>
<string name="restore_restoring">Endurvek öryggisafrit</string>

View file

@ -11,7 +11,7 @@
<string name="notification_restore_error_text">Plugg i din %1$s før du installerer programmet for å gjenopprette dataen fra sikkerhetskopi.</string>
<string name="storage_internal_warning_choose_other">Velg \"Annet\"</string>
<string name="restore_app_not_allowed">Programmet tillater ikke sikkerhetskopiering</string>
<string name="restore_app_no_data">Programmet sier ingen data skal sikkerhetskopieres</string>
<string name="backup_app_no_data">Programmet sier ingen data skal sikkerhetskopieres</string>
<string name="restore_magic_package">System-pakkebehandler</string>
<string name="notification_restore_error_channel_title">Minnepinnefeil ved automatisk gjenoppretting</string>
<string name="about_license">Lisens: <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache2</a></string>

View file

@ -97,7 +97,7 @@
<string name="restore_app_quota_exceeded">Cota de backup excedida</string>
<string name="restore_app_not_installed">Aplicativo não instalado</string>
<string name="restore_app_not_allowed">O aplicativo não permite backup</string>
<string name="restore_app_no_data">O aplicativo não relatou nenhum dado para backup</string>
<string name="backup_app_no_data">O aplicativo não relatou nenhum dado para backup</string>
<string name="restore_magic_package">Gerenciador de pacote do sistema</string>
<string name="restore_restoring">Restaurando backup</string>
<string name="restore_next">Próximo</string>

View file

@ -19,7 +19,7 @@
<string name="restore_app_quota_exceeded">Cota de backup excedida</string>
<string name="restore_app_not_installed">App não instalado</string>
<string name="restore_app_not_allowed">A app não permite backup</string>
<string name="restore_app_no_data">A app não relatou nenhuns dados para backup</string>
<string name="backup_app_no_data">A app não relatou nenhuns dados para backup</string>
<string name="restore_magic_package">Gestor de pacote do sistema</string>
<string name="restore_restoring">Restaurando backup</string>
<string name="restore_next">Próximo</string>

View file

@ -23,7 +23,7 @@
<string name="restore_app_quota_exceeded">Превышена квота резервного копирования</string>
<string name="restore_app_not_installed">Приложение не установлено</string>
<string name="restore_app_not_allowed">Приложение не разрешает резервное копирование</string>
<string name="restore_app_no_data">Приложение не сообщило об отсутствии данных для резервного копирования</string>
<string name="backup_app_no_data">Приложение не сообщило об отсутствии данных для резервного копирования</string>
<string name="restore_magic_package">Системный менеджер пакетов</string>
<string name="restore_restoring">Восстановление резервной копии</string>
<string name="restore_next">Следующий</string>

View file

@ -89,6 +89,20 @@
<string name="notification_restore_error_text">Plug in your %1$s before installing the app to restore its data from backup.</string>
<string name="notification_restore_error_action">Uninstall app</string>
<!-- App Backup and Restore State -->
<!-- This text gets shown for apps that the OS did not try to backup for whatever reason e.g. no backup was run yet -->
<string name="backup_app_not_yet_backed_up">Waiting to back up…</string>
<string name="restore_app_not_yet_backed_up">Was not yet backed up</string>
<string name="backup_app_was_stopped">Not backed up as it wasn\'t used recently</string>
<string name="restore_app_was_stopped">Was not backed up as it hadn\'t been used recently</string>
<string name="backup_app_no_data">App reported no data for backup</string>
<string name="backup_app_not_allowed">App doesn\'t allow backup</string>
<string name="restore_app_not_allowed">App didn\'t allow backup</string>
<string name="backup_app_quota_exceeded">Backup quota exceeded</string>
<string name="restore_app_quota_exceeded">Backup quota was exceeded</string>
<string name="restore_app_not_installed">App not installed</string>
<!-- Restore -->
<string name="restore_title">Restore from backup</string>
<string name="restore_choose_restore_set">Choose a backup to restore</string>
@ -102,13 +116,6 @@
<string name="restore_next">Next</string>
<string name="restore_restoring">Restoring backup</string>
<string name="restore_magic_package">System package manager</string>
<!-- This text gets shown for apps that the OS did not try to backup for whatever reason e.g. no backup was run yet -->
<string name="restore_app_not_yet_backed_up">Not yet backed up</string>
<string name="restore_app_was_stopped">Not backed up as it wasn\'t used recently</string>
<string name="restore_app_no_data">App reported no data for backup</string>
<string name="restore_app_not_allowed">App doesn\'t allow backup</string>
<string name="restore_app_not_installed">App not installed</string>
<string name="restore_app_quota_exceeded">Backup quota exceeded</string>
<string name="restore_finished_success">Restore complete</string>
<string name="restore_finished_error">An error occurred while restoring the backup.</string>
<string name="restore_finished_button">Finish</string>