open backup files on view action
This commit is contained in:
parent
603e1b35a5
commit
cb1feab350
|
@ -23,7 +23,20 @@
|
|||
<activity
|
||||
android:name=".ui.ImportBackupActivity"
|
||||
android:label="@string/restore_backup"
|
||||
android:launchMode="singleTask" />
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="application/vnd.conversations.backup" />
|
||||
<data android:scheme="content" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="application/vnd.conversations.backup" />
|
||||
<data android:scheme="file" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -28,7 +28,6 @@ import eu.siacs.conversations.databinding.ActivityImportBackupBinding;
|
|||
import eu.siacs.conversations.databinding.DialogEnterPasswordBinding;
|
||||
import eu.siacs.conversations.services.ImportBackupService;
|
||||
import eu.siacs.conversations.ui.adapter.BackupFileAdapter;
|
||||
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
||||
import eu.siacs.conversations.utils.ThemeHelper;
|
||||
|
||||
public class ImportBackupActivity extends ActionBarActivity implements ServiceConnection, ImportBackupService.OnBackupFilesLoaded, BackupFileAdapter.OnItemClickedListener, ImportBackupService.OnBackupProcessed {
|
||||
|
@ -49,7 +48,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
|||
super.onCreate(savedInstanceState);
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_import_backup);
|
||||
setSupportActionBar((Toolbar) binding.toolbar);
|
||||
configureActionBar(getSupportActionBar());
|
||||
setLoadingState(savedInstanceState != null && savedInstanceState.getBoolean("loading_state", false));
|
||||
this.backupFileAdapter = new BackupFileAdapter();
|
||||
this.binding.list.setAdapter(this.backupFileAdapter);
|
||||
this.backupFileAdapter.setOnItemClickedListener(this);
|
||||
|
@ -63,6 +62,12 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle bundle) {
|
||||
bundle.putBoolean("loading_state", this.mLoadingState);
|
||||
super.onSaveInstanceState(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
@ -72,6 +77,13 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
|||
} else {
|
||||
bindService(new Intent(this, ImportBackupService.class), this, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
final Intent intent = getIntent();
|
||||
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction()) && !this.mLoadingState) {
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null) {
|
||||
openBackupFileFromUri(uri, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,26 +116,30 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
|||
|
||||
@Override
|
||||
public void onClick(final ImportBackupService.BackupFile backupFile) {
|
||||
showEnterPasswordDialog(backupFile);
|
||||
showEnterPasswordDialog(backupFile, false);
|
||||
}
|
||||
|
||||
private void openBackupFileFromUri(final Uri uri) {
|
||||
private void openBackupFileFromUri(final Uri uri, final boolean finishOnCancel) {
|
||||
try {
|
||||
final ImportBackupService.BackupFile backupFile = ImportBackupService.BackupFile.read(this, uri);
|
||||
showEnterPasswordDialog(backupFile);
|
||||
showEnterPasswordDialog(backupFile, finishOnCancel);
|
||||
} catch (IOException e) {
|
||||
Snackbar.make(binding.coordinator, R.string.not_a_backup_file, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void showEnterPasswordDialog(final ImportBackupService.BackupFile backupFile) {
|
||||
private void showEnterPasswordDialog(final ImportBackupService.BackupFile backupFile, final boolean finishOnCancel) {
|
||||
final DialogEnterPasswordBinding enterPasswordBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.dialog_enter_password, null, false);
|
||||
Log.d(Config.LOGTAG, "attempting to import " + backupFile.getUri());
|
||||
enterPasswordBinding.explain.setText(getString(R.string.enter_password_to_restore, backupFile.getHeader().getJid().toString()));
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setView(enterPasswordBinding.getRoot());
|
||||
builder.setTitle(R.string.enter_password);
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.setNegativeButton(R.string.cancel, (dialog, which) -> {
|
||||
if (finishOnCancel) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(R.string.restore, (dialog, which) -> {
|
||||
final String password = enterPasswordBinding.accountPassword.getEditableText().toString();
|
||||
final Uri uri = backupFile.getUri();
|
||||
|
@ -156,7 +172,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
|||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == 0xbac) {
|
||||
openBackupFileFromUri(intent.getData());
|
||||
openBackupFileFromUri(intent.getData(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,8 +213,7 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_open_backup_file:
|
||||
if (item.getItemId() == R.id.action_open_backup_file) {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
|
|
|
@ -92,7 +92,6 @@
|
|||
android:theme="@style/SplashTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
|
Loading…
Reference in a new issue