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