show spinning wheel in restore backup activity
This commit is contained in:
parent
a32bb652f7
commit
11e0ff4006
|
@ -21,6 +21,7 @@ import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -101,6 +102,10 @@ public class ImportBackupService extends Service {
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getLoadingState() {
|
||||||
|
return running.get();
|
||||||
|
}
|
||||||
|
|
||||||
public void loadBackupFiles(OnBackupFilesLoaded onBackupFilesLoaded) {
|
public void loadBackupFiles(OnBackupFilesLoaded onBackupFilesLoaded) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
List<Jid> accounts = mDatabaseBackend.getAccountJids(false);
|
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);
|
onBackupFilesLoaded.onBackupFilesLoaded(backupFiles);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startForegroundService() {
|
private void startForegroundService() {
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext(), "backup");
|
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)
|
.setSmallIcon(R.drawable.ic_unarchive_white_24dp)
|
||||||
.setProgress(1, 0, true);
|
.setProgress(1, 0, true);
|
||||||
startForeground(NOTIFICATION_ID, mBuilder.build());
|
startForeground(NOTIFICATION_ID, mBuilder.build());
|
||||||
|
|
|
@ -2,11 +2,9 @@ package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.databinding.DataBindingUtil;
|
import android.databinding.DataBindingUtil;
|
||||||
import android.databinding.ViewDataBinding;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
|
@ -15,7 +13,7 @@ import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.widget.Toast;
|
import android.view.View;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -64,6 +62,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
||||||
ImportBackupService.ImportBackupServiceBinder binder = (ImportBackupService.ImportBackupServiceBinder) service;
|
ImportBackupService.ImportBackupServiceBinder binder = (ImportBackupService.ImportBackupServiceBinder) service;
|
||||||
this.service = binder.getService();
|
this.service = binder.getService();
|
||||||
this.service.addOnBackupProcessedListener(this);
|
this.service.addOnBackupProcessedListener(this);
|
||||||
|
setLoadingState(this.service.getLoadingState());
|
||||||
this.service.loadBackupFiles(this);
|
this.service.loadBackupFiles(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,9 +73,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackupFilesLoaded(final List<ImportBackupService.BackupFile> files) {
|
public void onBackupFilesLoaded(final List<ImportBackupService.BackupFile> files) {
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> backupFileAdapter.setFiles(files));
|
||||||
backupFileAdapter.setFiles(files);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,12 +90,20 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
||||||
Intent intent = new Intent(this, ImportBackupService.class);
|
Intent intent = new Intent(this, ImportBackupService.class);
|
||||||
intent.putExtra("password", password);
|
intent.putExtra("password", password);
|
||||||
intent.putExtra("file", backupFile.getFile().getAbsolutePath());
|
intent.putExtra("file", backupFile.getFile().getAbsolutePath());
|
||||||
|
setLoadingState(true);
|
||||||
ContextCompat.startForegroundService(this, intent);
|
ContextCompat.startForegroundService(this, intent);
|
||||||
});
|
});
|
||||||
builder.setCancelable(false);
|
builder.setCancelable(false);
|
||||||
builder.create().show();
|
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
|
@Override
|
||||||
public void onBackupRestored() {
|
public void onBackupRestored() {
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
|
@ -112,6 +117,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
||||||
@Override
|
@Override
|
||||||
public void onBackupDecryptionFailed() {
|
public void onBackupDecryptionFailed() {
|
||||||
runOnUiThread(()-> {
|
runOnUiThread(()-> {
|
||||||
|
setLoadingState(false);
|
||||||
Snackbar.make(binding.coordinator,R.string.unable_to_decrypt_backup,Snackbar.LENGTH_LONG).show();
|
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
|
@Override
|
||||||
public void onBackupRestoreFailed() {
|
public void onBackupRestoreFailed() {
|
||||||
runOnUiThread(()-> {
|
runOnUiThread(()-> {
|
||||||
|
setLoadingState(false);
|
||||||
Snackbar.make(binding.coordinator,R.string.unable_to_restore_backup,Snackbar.LENGTH_LONG).show();
|
Snackbar.make(binding.coordinator,R.string.unable_to_restore_backup,Snackbar.LENGTH_LONG).show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,19 @@
|
||||||
<include
|
<include
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
layout="@layout/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.support.design.widget.CoordinatorLayout
|
||||||
android:id="@+id/coordinator"
|
android:id="@+id/coordinator"
|
||||||
|
|
|
@ -317,7 +317,7 @@
|
||||||
<string name="pref_create_backup">Create backup</string>
|
<string name="pref_create_backup">Create backup</string>
|
||||||
<string name="pref_create_backup_summary">Write backup files to %s</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_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_title">Your backup has been restored</string>
|
||||||
<string name="notification_restored_backup_subtitle">Do not forget to enable the account.</string>
|
<string name="notification_restored_backup_subtitle">Do not forget to enable the account.</string>
|
||||||
<string name="choose_file">Choose file</string>
|
<string name="choose_file">Choose file</string>
|
||||||
|
@ -816,7 +816,7 @@
|
||||||
<string name="restore">Restore</string>
|
<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="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’ve lost the original device.</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’ve lost the original device.</string>
|
||||||
<string name="unable_to_restore_backup">Unable to restore backup</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_decrypt_backup">Unable to decrypt backup. Is the password correct?</string>
|
||||||
<string name="backup_channel_name"><![CDATA[Backup & Restore]]></string>
|
<string name="backup_channel_name">Backup & Restore</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue