From fd4408e572f5c5aacf5c74ace91ef7c1ed46c474 Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Mon, 31 May 2021 12:36:21 +0200 Subject: [PATCH] Set ImportExportDataPath only on successful export --- .../settings/ContentSettingsFragment.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index ab6ff7414bb..ef1558186b5 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -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; @@ -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) @@ -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);