show spinning wheel in restore backup activity

This commit is contained in:
Daniel Gultsch 2019-01-23 19:13:04 +01:00
parent a32bb652f7
commit 11e0ff4006
4 changed files with 37 additions and 11 deletions

View file

@ -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<Jid> 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());

View file

@ -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<ImportBackupService.BackupFile> 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();
});
}

View file

@ -12,6 +12,19 @@
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<LinearLayout
android:visibility="gone"
android:id="@+id/in_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<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"

View file

@ -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>
@ -816,7 +816,7 @@
<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 youve 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="backup_channel_name"><![CDATA[Backup & Restore]]></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>
<string name="backup_channel_name">Backup &amp; Restore</string>
</resources>