Remove the progress bar for restore operation as progress reporting is bugyy
This also adds an additional warning when the user is using ejectable storage
This commit is contained in:
parent
55d92aec39
commit
0e5f9cff0f
5 changed files with 20 additions and 43 deletions
|
@ -13,6 +13,7 @@ import androidx.lifecycle.ViewModelProviders
|
|||
import com.stevesoltys.backup.R
|
||||
import com.stevesoltys.backup.getAppName
|
||||
import com.stevesoltys.backup.isDebugBuild
|
||||
import com.stevesoltys.backup.settings.getStorage
|
||||
import kotlinx.android.synthetic.main.fragment_restore_progress.*
|
||||
|
||||
class RestoreProgressFragment : Fragment() {
|
||||
|
@ -32,29 +33,27 @@ class RestoreProgressFragment : Fragment() {
|
|||
|
||||
viewModel = ViewModelProviders.of(requireActivity()).get(RestoreViewModel::class.java)
|
||||
|
||||
viewModel.numPackages.observe(this, Observer { numPackages ->
|
||||
progressBar.min = 0
|
||||
progressBar.max = numPackages
|
||||
})
|
||||
|
||||
viewModel.chosenRestoreSet.observe(this, Observer { set ->
|
||||
backupNameView.text = set.device
|
||||
})
|
||||
|
||||
viewModel.restoreProgress.observe(this, Observer { progress ->
|
||||
progressBar.progress = progress.nowBeingRestored
|
||||
val appName = getAppName(requireActivity().packageManager, progress.currentPackage)
|
||||
val displayName = if (isDebugBuild()) "$appName (${progress.currentPackage})" else appName
|
||||
viewModel.restoreProgress.observe(this, Observer { currentPackage ->
|
||||
val appName = getAppName(requireActivity().packageManager, currentPackage)
|
||||
val displayName = if (isDebugBuild()) "$appName (${currentPackage})" else appName
|
||||
currentPackageView.text = getString(R.string.restore_current_package, displayName)
|
||||
})
|
||||
|
||||
viewModel.restoreFinished.observe(this, Observer { finished ->
|
||||
progressBarIndefinite.visibility = INVISIBLE
|
||||
progressBar.progress = viewModel.numPackages.value ?: progressBar.max
|
||||
progressBar.visibility = INVISIBLE
|
||||
button.visibility = VISIBLE
|
||||
if (finished == 0) {
|
||||
// success
|
||||
currentPackageView.text = getString(R.string.restore_finished_success)
|
||||
warningView.text = if (getStorage(requireContext())?.ejectable == true) {
|
||||
getString(R.string.restore_finished_warning_only_installed, getString(R.string.restore_finished_warning_ejectable))
|
||||
} else {
|
||||
getString(R.string.restore_finished_warning_only_installed, null)
|
||||
}
|
||||
warningView.visibility = VISIBLE
|
||||
} else {
|
||||
// error
|
||||
|
|
|
@ -32,11 +32,8 @@ class RestoreViewModel(app: Application) : RequireProvisioningViewModel(app), Re
|
|||
private val mChosenRestoreSet = MutableLiveData<RestoreSet>()
|
||||
internal val chosenRestoreSet: LiveData<RestoreSet> get() = mChosenRestoreSet
|
||||
|
||||
private var mNumPackages = MutableLiveData<Int>()
|
||||
internal val numPackages: LiveData<Int> get() = mNumPackages
|
||||
|
||||
private val mRestoreProgress = MutableLiveData<RestoreProgress>()
|
||||
internal val restoreProgress: LiveData<RestoreProgress> get() = mRestoreProgress
|
||||
private val mRestoreProgress = MutableLiveData<String>()
|
||||
internal val restoreProgress: LiveData<String> get() = mRestoreProgress
|
||||
|
||||
private val mRestoreFinished = MutableLiveData<Int>()
|
||||
// Zero on success; a nonzero error code if the restore operation as a whole failed.
|
||||
|
@ -84,8 +81,6 @@ class RestoreViewModel(app: Application) : RequireProvisioningViewModel(app), Re
|
|||
@WorkerThread
|
||||
private inner class RestoreObserver : IRestoreObserver.Stub() {
|
||||
|
||||
private var correctedNow: Int = -1
|
||||
|
||||
/**
|
||||
* Supply a list of the restore datasets available from the current transport.
|
||||
* This method is invoked as a callback following the application's use of the
|
||||
|
@ -109,7 +104,7 @@ class RestoreViewModel(app: Application) : RequireProvisioningViewModel(app), Re
|
|||
* @param numPackages The total number of packages being processed in this restore operation.
|
||||
*/
|
||||
override fun restoreStarting(numPackages: Int) {
|
||||
mNumPackages.postValue(numPackages)
|
||||
// noop
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,12 +117,8 @@ class RestoreViewModel(app: Application) : RequireProvisioningViewModel(app), Re
|
|||
* @param currentPackage The name of the package now being restored.
|
||||
*/
|
||||
override fun onUpdate(nowBeingRestored: Int, currentPackage: String) {
|
||||
if (nowBeingRestored <= correctedNow) {
|
||||
correctedNow += 1
|
||||
} else {
|
||||
correctedNow = nowBeingRestored
|
||||
}
|
||||
mRestoreProgress.postValue(RestoreProgress(correctedNow, currentPackage))
|
||||
// nowBeingRestored reporting is buggy, so don't use it
|
||||
mRestoreProgress.postValue(currentPackage)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +146,3 @@ internal class RestoreSetResult(
|
|||
|
||||
internal fun hasError(): Boolean = errorMsg != null
|
||||
}
|
||||
|
||||
internal class RestoreProgress(
|
||||
internal val nowBeingRestored: Int,
|
||||
internal val currentPackage: String)
|
||||
|
|
|
@ -141,7 +141,7 @@ class KVBackup(
|
|||
val base64Key = key.encodeBase64()
|
||||
val dataSize = changeSet.dataSize
|
||||
|
||||
// read and encrypt value
|
||||
// read value
|
||||
val value = if (dataSize >= 0) {
|
||||
Log.v(TAG, " Delta operation key $key size $dataSize key64 $base64Key")
|
||||
val bytes = ByteArray(dataSize)
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
tools:text="@string/restore_current_package" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarIndefinite"
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -66,17 +66,6 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/currentPackageView" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/progressBarIndefinite"
|
||||
tools:progress="50" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/warningView"
|
||||
android:layout_width="0dp"
|
||||
|
@ -84,6 +73,7 @@
|
|||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textSize="18sp"
|
||||
android:text="@string/restore_finished_warning_only_installed"
|
||||
android:textColor="@android:color/holo_red_dark"
|
||||
android:visibility="gone"
|
||||
|
|
|
@ -98,7 +98,8 @@
|
|||
<string name="restore_current_package">Restoring %s…</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_warning_only_installed">Note that we could only restore data for apps that are already installed.\n\nWhen you install more apps, we will try to restore their data and settings from this backup. So please do not delete it as long as it might still be needed.</string>
|
||||
<string name="restore_finished_warning_only_installed">Note that we could only restore data for apps that are already installed.\n\nWhen you install more apps, we will try to restore their data and settings from this backup. So please do not delete it as long as it might still be needed.%s</string>
|
||||
<string name="restore_finished_warning_ejectable">\n\nPlease also ensure that the storage medium is plugged in when re-installing your apps.</string>
|
||||
<string name="restore_finished_button">Finish</string>
|
||||
<string name="storage_internal_warning_title">Warning</string>
|
||||
<string name="storage_internal_warning_message">You have chosen internal storage for your backup. This will not be available when your phone is lost or broken.</string>
|
||||
|
|
Loading…
Reference in a new issue