diff --git a/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java b/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java index 988e0328a..9892e6492 100644 --- a/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java +++ b/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java @@ -21,6 +21,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -101,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 accounts = mDatabaseBackend.getAccountJids(false); @@ -127,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/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java b/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java index 153fc76a3..77a6787f5 100644 --- a/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java +++ b/src/conversations/java/eu/siacs/conversations/ui/ImportBackupActivity.java @@ -2,11 +2,9 @@ package eu.siacs.conversations.ui; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.databinding.DataBindingUtil; -import android.databinding.ViewDataBinding; import android.os.Bundle; import android.os.IBinder; import android.support.design.widget.Snackbar; @@ -15,7 +13,7 @@ import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.LayoutInflater; -import android.widget.Toast; +import android.view.View; import java.util.List; @@ -64,6 +62,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); } @@ -74,9 +73,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo @Override public void onBackupFilesLoaded(final List files) { - runOnUiThread(() -> { - backupFileAdapter.setFiles(files); - }); + runOnUiThread(() -> backupFileAdapter.setFiles(files)); } @Override @@ -93,12 +90,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(() -> { @@ -112,6 +117,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(); }); } @@ -119,6 +125,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/conversations/res/layout/activity_import_backup.xml b/src/conversations/res/layout/activity_import_backup.xml index bc5ccecc1..b1d0bd9b0 100644 --- a/src/conversations/res/layout/activity_import_backup.xml +++ b/src/conversations/res/layout/activity_import_backup.xml @@ -12,6 +12,19 @@ + + + + + Create backup Write backup files to %s Creating backup files - Restoring backup + Restoring backup Your backup has been restored Do not forget to enable the account. Choose file @@ -816,7 +816,7 @@ Restore Enter your password for the account %s to restore the backup. 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’ve lost the original device. - Unable to restore backup - Unable to decrypt backup - + Unable to restore backup. + Unable to decrypt backup. Is the password correct? + Backup & Restore