Set ImportExportDataPath only on successful export

This commit is contained in:
XiangRongLin 2021-05-31 12:36:21 +02:00
parent a84ab7413c
commit fd4408e572

View file

@ -25,8 +25,8 @@ import org.schabi.newpipe.error.ReCaptchaActivity;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.util.FilePickerActivityHelper;
import org.schabi.newpipe.util.FilePathUtils; import org.schabi.newpipe.util.FilePathUtils;
import org.schabi.newpipe.util.FilePickerActivityHelper;
import org.schabi.newpipe.util.ZipHelper; import org.schabi.newpipe.util.ZipHelper;
import java.io.File; import java.io.File;
@ -178,11 +178,9 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
&& resultCode == Activity.RESULT_OK && data.getData() != null) { && resultCode == Activity.RESULT_OK && data.getData() != null) {
final File file = Utils.getFileForUri(data.getData()); final File file = Utils.getFileForUri(data.getData());
final String path = file.getAbsolutePath(); final String path = file.getAbsolutePath();
setImportExportDataPath(file);
if (requestCode == REQUEST_EXPORT_PATH) { if (requestCode == REQUEST_EXPORT_PATH) {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); exportDatabase(file);
exportDatabase(path + "/NewPipeData-" + sdf.format(new Date()) + ".zip");
} else { } else {
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()); final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
builder.setMessage(R.string.override_current_data) builder.setMessage(R.string.override_current_data)
@ -195,15 +193,21 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
} }
} }
private void exportDatabase(final String path) { private void exportDatabase(final File folder) {
try { try {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
final String path = folder.getAbsolutePath() + "/NewPipeData-"
+ sdf.format(new Date()) + ".zip";
//checkpoint before export //checkpoint before export
NewPipeDatabase.checkpoint(); NewPipeDatabase.checkpoint();
final SharedPreferences preferences = PreferenceManager final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(requireContext()); .getDefaultSharedPreferences(requireContext());
manager.exportDatabase(preferences, path); manager.exportDatabase(preferences, path);
setImportExportDataPath(folder);
Toast.makeText(getContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT).show();
} catch (final Exception e) { } catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Exporting database", e); ErrorActivity.reportUiErrorInSnackbar(this, "Exporting database", e);