diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-01-26 15:12:38 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-01-26 15:12:38 +0100 |
commit | 05c1aa03779b6bf2a45e2ab89cb7e7f486eac037 (patch) | |
tree | d005f99a390efb3d3e14760c75d58e0359049e2f /src | |
parent | 28c12f9fa868dd5273a80c305c69ae0106329c37 (diff) |
show spinning wheel in restore backup activity
Diffstat (limited to 'src')
4 files changed, 36 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/services/ImportBackupService.java b/src/main/java/de/pixart/messenger/services/ImportBackupService.java index e73b1972f..63d6c7b41 100644 --- a/src/main/java/de/pixart/messenger/services/ImportBackupService.java +++ b/src/main/java/de/pixart/messenger/services/ImportBackupService.java @@ -102,6 +102,10 @@ public class ImportBackupService extends Service { return START_NOT_STICKY; } + public boolean getLoadingState() { + return running.get(); + } + public void loadBackupFiles(OnBackupFilesLoaded onBackupFilesLoaded) { executor.execute(() -> { List<Jid> accounts = mDatabaseBackend.getAccountJids(false); @@ -128,13 +132,14 @@ public class ImportBackupService extends Service { } } } + Collections.sort(backupFiles, (a, b) -> a.header.getJid().toString().compareTo(b.header.getJid().toString())); onBackupFilesLoaded.onBackupFilesLoaded(backupFiles); }); } private void startForegroundService() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext(), "backup"); - mBuilder.setContentTitle(getString(R.string.notification_restore_backup_title)) + mBuilder.setContentTitle(getString(R.string.restoring_backup)) .setSmallIcon(R.drawable.ic_unarchive_white_24dp) .setProgress(1, 0, true); startForeground(NOTIFICATION_ID, mBuilder.build()); diff --git a/src/main/java/de/pixart/messenger/ui/ImportBackupActivity.java b/src/main/java/de/pixart/messenger/ui/ImportBackupActivity.java index f1c9eea25..4aa4dbfed 100644 --- a/src/main/java/de/pixart/messenger/ui/ImportBackupActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ImportBackupActivity.java @@ -14,6 +14,7 @@ import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.LayoutInflater; +import android.view.View; import android.widget.Toast; import java.util.List; @@ -63,6 +64,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo ImportBackupService.ImportBackupServiceBinder binder = (ImportBackupService.ImportBackupServiceBinder) service; this.service = binder.getService(); this.service.addOnBackupProcessedListener(this); + setLoadingState(this.service.getLoadingState()); this.service.loadBackupFiles(this); } @@ -73,9 +75,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo @Override public void onBackupFilesLoaded(final List<ImportBackupService.BackupFile> files) { - runOnUiThread(() -> { - backupFileAdapter.setFiles(files); - }); + runOnUiThread(() -> backupFileAdapter.setFiles(files)); } @Override @@ -92,12 +92,20 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo Intent intent = new Intent(this, ImportBackupService.class); intent.putExtra("password", password); intent.putExtra("file", backupFile.getFile().getAbsolutePath()); + setLoadingState(true); ContextCompat.startForegroundService(this, intent); }); builder.setCancelable(false); builder.create().show(); } + private void setLoadingState(final boolean loadingState) { + binding.coordinator.setVisibility(loadingState ? View.GONE : View.VISIBLE); + binding.inProgress.setVisibility(loadingState ? View.VISIBLE : View.GONE); + setTitle(loadingState ? R.string.restoring_backup : R.string.restore_backup); + configureActionBar(getSupportActionBar(), !loadingState); + } + @Override public void onBackupRestored() { runOnUiThread(() -> { @@ -111,6 +119,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo @Override public void onBackupDecryptionFailed() { runOnUiThread(() -> { + setLoadingState(false); Snackbar.make(binding.coordinator, R.string.unable_to_decrypt_backup, Snackbar.LENGTH_LONG).show(); }); } @@ -118,6 +127,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo @Override public void onBackupRestoreFailed() { runOnUiThread(() -> { + setLoadingState(false); Snackbar.make(binding.coordinator, R.string.unable_to_restore_backup, Snackbar.LENGTH_LONG).show(); }); } diff --git a/src/main/res/layout/activity_import_backup.xml b/src/main/res/layout/activity_import_backup.xml index bc5ccecc1..e9ee433fe 100644 --- a/src/main/res/layout/activity_import_backup.xml +++ b/src/main/res/layout/activity_import_backup.xml @@ -13,6 +13,19 @@ android:id="@+id/toolbar" layout="@layout/toolbar" /> + <LinearLayout + android:id="@+id/in_progress" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:visibility="gone"> + + <ProgressBar + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" /> + </LinearLayout> + <android.support.design.widget.CoordinatorLayout android:id="@+id/coordinator" android:layout_width="match_parent" diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 1f227a3ff..058ae89e0 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -317,7 +317,7 @@ <string name="pref_create_backup">Create backup</string> <string name="pref_create_backup_summary">Write backup files to %s</string> <string name="notification_create_backup_title">Creating backup files</string> - <string name="notification_restore_backup_title">Restoring backup</string> + <string name="restoring_backup">Restoring backup</string> <string name="notification_restored_backup_title">Your backup has been restored</string> <string name="notification_restored_backup_subtitle">Do not forget to enable the account.</string> <string name="choose_file">Choose file</string> @@ -823,7 +823,7 @@ <string name="pref_more_notification_settings">Notification Settings</string> <string name="pref_more_notification_settings_summary">Importance, Sound, Vibrate</string> <string name="video_compression_channel_name">Video compression</string> - <string name="backup_channel_name"><![CDATA[Backup & Restore]]></string> + <string name="backup_channel_name">Backup & Restore</string> <string name="app_update_channel_name">App update</string> <string name="action_group_details">Group details</string> <string name="view_media">View media</string> @@ -866,6 +866,6 @@ <string name="restore">Restore</string> <string name="enter_password_to_restore">Enter your password for the account %s to restore the backup.</string> <string name="restore_warning">Do not use the restore backup feature in an attempt to clone (run simultaneously) an installation. Restoring a backup is only meant for migrations or in case you have lost the original device.</string> - <string name="unable_to_restore_backup">Unable to restore backup</string> - <string name="unable_to_decrypt_backup">Unable to decrypt backup</string> + <string name="unable_to_restore_backup">Unable to restore backup.</string> + <string name="unable_to_decrypt_backup">Unable to decrypt backup. Is the password correct?</string> </resources> |