Use file picker for export DB
This commit is contained in:
parent
1164ea52f9
commit
cb4e6159c4
2 changed files with 20 additions and 29 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue