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 6e020e368..e564073b8 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -36,7 +36,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -import org.schabi.newpipe.streams.io.StoredDirectoryHelper; import org.schabi.newpipe.streams.io.StoredFileHelper; import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; @@ -70,8 +69,9 @@ public class ContentSettingsFragment extends BasePreferenceFragment { final Preference exportDataPreference = findPreference(getString(R.string.export_data)); exportDataPreference.setOnPreferenceClickListener((final Preference p) -> { - startActivityForResult(StoredDirectoryHelper.getPicker(getContext()), - REQUEST_EXPORT_PATH); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); + startActivityForResult(StoredFileHelper.getNewPicker(getContext(), null, + "NewPipeData-" + sdf.format(new Date()) + ".zip"), REQUEST_EXPORT_PATH); return true; }); @@ -160,31 +160,22 @@ public class ContentSettingsFragment extends BasePreferenceFragment { if ((requestCode == REQUEST_IMPORT_PATH || requestCode == REQUEST_EXPORT_PATH) && resultCode == Activity.RESULT_OK && data != null && data.getData() != null) { - try { - Uri uri = data.getData(); - if (FilePickerActivityHelper.isOwnFileUri(requireContext(), uri)) { - uri = Uri.fromFile(Utils.getFileForUri(uri)); - } - if (requestCode == REQUEST_EXPORT_PATH) { - final StoredDirectoryHelper directory - = new StoredDirectoryHelper(requireContext(), uri, null); - final SimpleDateFormat sdf - = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); - exportDatabase(directory.createFile("NewPipeData-" - + sdf.format(new Date()) + ".zip", "application/zip")); - } else { - final StoredFileHelper file = new StoredFileHelper(getContext(), uri, - StoredFileHelper.DEFAULT_MIME); - final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()); - builder.setMessage(R.string.override_current_data) - .setPositiveButton(R.string.finish, - (DialogInterface d, int id) -> importDatabase(file)) - .setNegativeButton(R.string.cancel, - (DialogInterface d, int id) -> d.cancel()); - builder.create().show(); - } - } catch (final IOException e) { - e.printStackTrace(); + Uri uri = data.getData(); + if (FilePickerActivityHelper.isOwnFileUri(requireActivity(), uri)) { + uri = Uri.fromFile(Utils.getFileForUri(uri)); + } + final StoredFileHelper file = new StoredFileHelper(getContext(), uri, + "application/zip"); + if (requestCode == REQUEST_EXPORT_PATH) { + exportDatabase(file); + } else { + final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()); + builder.setMessage(R.string.override_current_data) + .setPositiveButton(R.string.finish, + (DialogInterface d, int id) -> importDatabase(file)) + .setNegativeButton(R.string.cancel, + (DialogInterface d, int id) -> d.cancel()); + builder.create().show(); } } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt index 6c70776ec..cb4c14796 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt @@ -2,8 +2,8 @@ package org.schabi.newpipe.settings import android.content.SharedPreferences import org.schabi.newpipe.streams.io.SharpOutputStream +import org.schabi.newpipe.streams.io.StoredFileHelper import org.schabi.newpipe.util.ZipHelper -import us.shandian.giga.io.StoredFileHelper import java.io.BufferedOutputStream import java.io.FileInputStream import java.io.FileOutputStream