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:
Torsten Grote 2019-09-17 16:45:56 -03:00
parent 55d92aec39
commit 0e5f9cff0f
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
5 changed files with 20 additions and 43 deletions

View file

@ -13,6 +13,7 @@ import androidx.lifecycle.ViewModelProviders
import com.stevesoltys.backup.R import com.stevesoltys.backup.R
import com.stevesoltys.backup.getAppName import com.stevesoltys.backup.getAppName
import com.stevesoltys.backup.isDebugBuild import com.stevesoltys.backup.isDebugBuild
import com.stevesoltys.backup.settings.getStorage
import kotlinx.android.synthetic.main.fragment_restore_progress.* import kotlinx.android.synthetic.main.fragment_restore_progress.*
class RestoreProgressFragment : Fragment() { class RestoreProgressFragment : Fragment() {
@ -32,29 +33,27 @@ class RestoreProgressFragment : Fragment() {
viewModel = ViewModelProviders.of(requireActivity()).get(RestoreViewModel::class.java) 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 -> viewModel.chosenRestoreSet.observe(this, Observer { set ->
backupNameView.text = set.device backupNameView.text = set.device
}) })
viewModel.restoreProgress.observe(this, Observer { progress -> viewModel.restoreProgress.observe(this, Observer { currentPackage ->
progressBar.progress = progress.nowBeingRestored val appName = getAppName(requireActivity().packageManager, currentPackage)
val appName = getAppName(requireActivity().packageManager, progress.currentPackage) val displayName = if (isDebugBuild()) "$appName (${currentPackage})" else appName
val displayName = if (isDebugBuild()) "$appName (${progress.currentPackage})" else appName
currentPackageView.text = getString(R.string.restore_current_package, displayName) currentPackageView.text = getString(R.string.restore_current_package, displayName)
}) })
viewModel.restoreFinished.observe(this, Observer { finished -> viewModel.restoreFinished.observe(this, Observer { finished ->
progressBarIndefinite.visibility = INVISIBLE progressBar.visibility = INVISIBLE
progressBar.progress = viewModel.numPackages.value ?: progressBar.max
button.visibility = VISIBLE button.visibility = VISIBLE
if (finished == 0) { if (finished == 0) {
// success // success
currentPackageView.text = getString(R.string.restore_finished_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 warningView.visibility = VISIBLE
} else { } else {
// error // error

View file

@ -32,11 +32,8 @@ class RestoreViewModel(app: Application) : RequireProvisioningViewModel(app), Re
private val mChosenRestoreSet = MutableLiveData<RestoreSet>() private val mChosenRestoreSet = MutableLiveData<RestoreSet>()
internal val chosenRestoreSet: LiveData<RestoreSet> get() = mChosenRestoreSet internal val chosenRestoreSet: LiveData<RestoreSet> get() = mChosenRestoreSet
private var mNumPackages = MutableLiveData<Int>() private val mRestoreProgress = MutableLiveData<String>()
internal val numPackages: LiveData<Int> get() = mNumPackages internal val restoreProgress: LiveData<String> get() = mRestoreProgress
private val mRestoreProgress = MutableLiveData<RestoreProgress>()
internal val restoreProgress: LiveData<RestoreProgress> get() = mRestoreProgress
private val mRestoreFinished = MutableLiveData<Int>() private val mRestoreFinished = MutableLiveData<Int>()
// Zero on success; a nonzero error code if the restore operation as a whole failed. // 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 @WorkerThread
private inner class RestoreObserver : IRestoreObserver.Stub() { private inner class RestoreObserver : IRestoreObserver.Stub() {
private var correctedNow: Int = -1
/** /**
* Supply a list of the restore datasets available from the current transport. * 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 * 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. * @param numPackages The total number of packages being processed in this restore operation.
*/ */
override fun restoreStarting(numPackages: Int) { 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. * @param currentPackage The name of the package now being restored.
*/ */
override fun onUpdate(nowBeingRestored: Int, currentPackage: String) { override fun onUpdate(nowBeingRestored: Int, currentPackage: String) {
if (nowBeingRestored <= correctedNow) { // nowBeingRestored reporting is buggy, so don't use it
correctedNow += 1 mRestoreProgress.postValue(currentPackage)
} else {
correctedNow = nowBeingRestored
}
mRestoreProgress.postValue(RestoreProgress(correctedNow, currentPackage))
} }
/** /**
@ -155,7 +146,3 @@ internal class RestoreSetResult(
internal fun hasError(): Boolean = errorMsg != null internal fun hasError(): Boolean = errorMsg != null
} }
internal class RestoreProgress(
internal val nowBeingRestored: Int,
internal val currentPackage: String)

View file

@ -141,7 +141,7 @@ class KVBackup(
val base64Key = key.encodeBase64() val base64Key = key.encodeBase64()
val dataSize = changeSet.dataSize val dataSize = changeSet.dataSize
// read and encrypt value // read value
val value = if (dataSize >= 0) { val value = if (dataSize >= 0) {
Log.v(TAG, " Delta operation key $key size $dataSize key64 $base64Key") Log.v(TAG, " Delta operation key $key size $dataSize key64 $base64Key")
val bytes = ByteArray(dataSize) val bytes = ByteArray(dataSize)

View file

@ -56,7 +56,7 @@
tools:text="@string/restore_current_package" /> tools:text="@string/restore_current_package" />
<ProgressBar <ProgressBar
android:id="@+id/progressBarIndefinite" android:id="@+id/progressBar"
style="?android:attr/progressBarStyle" style="?android:attr/progressBarStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -66,17 +66,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/currentPackageView" /> 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 <TextView
android:id="@+id/warningView" android:id="@+id/warningView"
android:layout_width="0dp" android:layout_width="0dp"
@ -84,6 +73,7 @@
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginTop="32dp" android:layout_marginTop="32dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:textSize="18sp"
android:text="@string/restore_finished_warning_only_installed" android:text="@string/restore_finished_warning_only_installed"
android:textColor="@android:color/holo_red_dark" android:textColor="@android:color/holo_red_dark"
android:visibility="gone" android:visibility="gone"

View file

@ -98,7 +98,8 @@
<string name="restore_current_package">Restoring %s…</string> <string name="restore_current_package">Restoring %s…</string>
<string name="restore_finished_success">Restore complete.</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_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="restore_finished_button">Finish</string>
<string name="storage_internal_warning_title">Warning</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> <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>