Expose time of next backup in UI
to help debugging scheduling issues
This commit is contained in:
parent
8da73ad8d1
commit
911a8dabf4
4 changed files with 56 additions and 6 deletions
|
@ -140,7 +140,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel.lastBackupTime.observe(viewLifecycleOwner) { time ->
|
||||
setAppBackupStatusSummary(time)
|
||||
setAppBackupStatusSummary(time, viewModel.nextScheduleTimeMillis.value)
|
||||
}
|
||||
viewModel.nextScheduleTimeMillis.observe(viewLifecycleOwner) { time ->
|
||||
setAppBackupStatusSummary(viewModel.lastBackupTime.value, time)
|
||||
}
|
||||
|
||||
val backupFiles: Preference = findPreference("backup_files")!!
|
||||
|
@ -159,6 +162,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
setBackupEnabledState()
|
||||
setBackupLocationSummary()
|
||||
setAutoRestoreState()
|
||||
setAppBackupStatusSummary(
|
||||
lastBackupInMillis = viewModel.lastBackupTime.value,
|
||||
nextScheduleTimeMillis = viewModel.nextScheduleTimeMillis.value,
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
|
@ -244,10 +251,42 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
backupLocation.summary = storage?.name ?: getString(R.string.settings_backup_location_none)
|
||||
}
|
||||
|
||||
private fun setAppBackupStatusSummary(lastBackupInMillis: Long) {
|
||||
// set time of last backup
|
||||
val lastBackup = lastBackupInMillis.toRelativeTime(requireContext())
|
||||
backupStatus.summary = getString(R.string.settings_backup_status_summary, lastBackup)
|
||||
private fun setAppBackupStatusSummary(
|
||||
lastBackupInMillis: Long?,
|
||||
nextScheduleTimeMillis: Long?,
|
||||
) {
|
||||
val sb = StringBuilder()
|
||||
if (lastBackupInMillis != null) {
|
||||
// set time of last backup
|
||||
val lastBackup = lastBackupInMillis.toRelativeTime(requireContext())
|
||||
sb.append(getString(R.string.settings_backup_status_summary, lastBackup))
|
||||
}
|
||||
if (nextScheduleTimeMillis != null) {
|
||||
// insert linebreak, if we have text before
|
||||
if (sb.isNotEmpty()) sb.append("\n")
|
||||
// set time of next backup
|
||||
when (nextScheduleTimeMillis) {
|
||||
-1L -> {
|
||||
val text = getString(R.string.settings_backup_last_backup_never)
|
||||
sb.append(getString(R.string.settings_backup_status_next_backup, text))
|
||||
}
|
||||
|
||||
Long.MAX_VALUE -> {
|
||||
val text = if (backupManager.isBackupEnabled) {
|
||||
getString(R.string.notification_title)
|
||||
} else {
|
||||
getString(R.string.settings_backup_last_backup_never)
|
||||
}
|
||||
sb.append(getString(R.string.settings_backup_status_next_backup, text))
|
||||
}
|
||||
|
||||
else -> {
|
||||
val text = nextScheduleTimeMillis.toRelativeTime(requireContext())
|
||||
sb.append(getString(R.string.settings_backup_status_next_backup_estimate, text))
|
||||
}
|
||||
}
|
||||
}
|
||||
backupStatus.summary = sb.toString()
|
||||
}
|
||||
|
||||
private fun onEnablingStorageBackup() {
|
||||
|
|
|
@ -22,9 +22,11 @@ import androidx.core.content.ContextCompat.startForegroundService
|
|||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.liveData
|
||||
import androidx.lifecycle.map
|
||||
import androidx.lifecycle.switchMap
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.recyclerview.widget.DiffUtil.calculateDiff
|
||||
import androidx.work.WorkManager
|
||||
import com.stevesoltys.seedvault.R
|
||||
import com.stevesoltys.seedvault.crypto.KeyManager
|
||||
import com.stevesoltys.seedvault.metadata.MetadataManager
|
||||
|
@ -35,6 +37,7 @@ import com.stevesoltys.seedvault.storage.StorageBackupService.Companion.EXTRA_ST
|
|||
import com.stevesoltys.seedvault.ui.RequireProvisioningViewModel
|
||||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
||||
import com.stevesoltys.seedvault.worker.AppBackupWorker
|
||||
import com.stevesoltys.seedvault.worker.AppBackupWorker.Companion.UNIQUE_WORK_NAME
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
@ -61,6 +64,7 @@ internal class SettingsViewModel(
|
|||
private val contentResolver = app.contentResolver
|
||||
private val connectivityManager: ConnectivityManager? =
|
||||
app.getSystemService(ConnectivityManager::class.java)
|
||||
private val workManager = WorkManager.getInstance(app)
|
||||
|
||||
override val isRestoreOperation = false
|
||||
|
||||
|
@ -68,6 +72,11 @@ internal class SettingsViewModel(
|
|||
val backupPossible: LiveData<Boolean> = mBackupPossible
|
||||
|
||||
internal val lastBackupTime = metadataManager.lastBackupTime
|
||||
val nextScheduleTimeMillis =
|
||||
workManager.getWorkInfosForUniqueWorkLiveData(UNIQUE_WORK_NAME).map {
|
||||
if (it.size > 0) it[0].nextScheduleTimeMillis
|
||||
else -1L
|
||||
}
|
||||
|
||||
private val mAppStatusList = lastBackupTime.switchMap {
|
||||
// updates app list when lastBackupTime changes
|
||||
|
|
|
@ -35,7 +35,7 @@ class AppBackupWorker(
|
|||
|
||||
companion object {
|
||||
private val TAG = AppBackupWorker::class.simpleName
|
||||
private const val UNIQUE_WORK_NAME = "com.stevesoltys.seedvault.APP_BACKUP"
|
||||
internal const val UNIQUE_WORK_NAME = "com.stevesoltys.seedvault.APP_BACKUP"
|
||||
private const val TAG_NOW = "com.stevesoltys.seedvault.TAG_NOW"
|
||||
|
||||
fun schedule(context: Context, existingWorkPolicy: ExistingPeriodicWorkPolicy = UPDATE) {
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
<string name="settings_backup_apk_dialog_disable">Disable app backup</string>
|
||||
<string name="settings_backup_status_title">Backup status</string>
|
||||
<string name="settings_backup_status_summary">Last backup: %1$s</string>
|
||||
<string name="settings_backup_status_next_backup">Next backup: %1$s</string>
|
||||
<string name="settings_backup_status_next_backup_estimate">Next backup (estimate): %1$s</string>
|
||||
<string name="settings_backup_exclude_apps">Exclude apps</string>
|
||||
<string name="settings_backup_now">Backup now</string>
|
||||
<string name="settings_category_storage">Storage backup (beta)</string>
|
||||
|
|
Loading…
Reference in a new issue