show a warning dialog when importing a database (#4011)

This commit is contained in:
Tony Tam 2020-04-06 15:08:40 -07:00 committed by GitHub
parent da5a715860
commit b6eba9cc61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@ -173,16 +174,29 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
}
private void importDatabase() {
if (Build.VERSION.SDK_INT >= 19) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_CODE_RESTORE_DATABASE);
} else {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent,
getString(R.string.import_select_file)), REQUEST_CODE_RESTORE_DATABASE);
}
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.database_import_label);
builder.setMessage(R.string.database_import_warning);
// add a button
builder.setNegativeButton(R.string.no, null);
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
if (Build.VERSION.SDK_INT >= 19) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_CODE_RESTORE_DATABASE);
} else {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent,
getString(R.string.import_select_file)), REQUEST_CODE_RESTORE_DATABASE);
}
}
);
// create and show the alert dialog
builder.show();
}
private void showDatabaseImportSuccessDialog() {

View File

@ -561,6 +561,7 @@
<string name="html_export_label">HTML export</string>
<string name="database_export_label">Database export</string>
<string name="database_import_label">Database import</string>
<string name="database_import_warning">Importing a database will replace all of your current subscriptions and playing history. You should export your current database as a backup. Do you want to replace?</string>
<string name="please_wait">Please wait&#8230;</string>
<string name="export_error_label">Export error</string>
<string name="export_success_title">Export successful</string>