Skip to content

Commit

Permalink
Set ImportExportDataPath only on successful export
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangRongLin committed May 31, 2021
1 parent a84ab74 commit fd4408e
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.util.FilePickerActivityHelper;
import org.schabi.newpipe.util.FilePathUtils;
import org.schabi.newpipe.util.FilePickerActivityHelper;
import org.schabi.newpipe.util.ZipHelper;

import java.io.File;
Expand Down Expand Up @@ -178,11 +178,9 @@ public void onActivityResult(final int requestCode, final int resultCode,
&& resultCode == Activity.RESULT_OK && data.getData() != null) {
final File file = Utils.getFileForUri(data.getData());
final String path = file.getAbsolutePath();
setImportExportDataPath(file);

if (requestCode == REQUEST_EXPORT_PATH) {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
exportDatabase(path + "/NewPipeData-" + sdf.format(new Date()) + ".zip");
exportDatabase(file);
} else {
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
builder.setMessage(R.string.override_current_data)
Expand All @@ -195,15 +193,21 @@ public void onActivityResult(final int requestCode, final int resultCode,
}
}

private void exportDatabase(final String path) {
private void exportDatabase(final File folder) {
try {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
final String path = folder.getAbsolutePath() + "/NewPipeData-"
+ sdf.format(new Date()) + ".zip";

//checkpoint before export
NewPipeDatabase.checkpoint();

final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(requireContext());
.getDefaultSharedPreferences(requireContext());
manager.exportDatabase(preferences, path);

setImportExportDataPath(folder);

Toast.makeText(getContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT).show();
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Exporting database", e);
Expand Down

0 comments on commit fd4408e

Please sign in to comment.