Commit path immediately when import backup
This commit is contained in:
parent
f13a1b04e6
commit
05eb0d0fbe
1 changed files with 15 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
package org.schabi.newpipe.settings;
|
package org.schabi.newpipe.settings;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -205,7 +206,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
.getDefaultSharedPreferences(requireContext());
|
.getDefaultSharedPreferences(requireContext());
|
||||||
manager.exportDatabase(preferences, path);
|
manager.exportDatabase(preferences, path);
|
||||||
|
|
||||||
setImportExportDataPath(folder);
|
setImportExportDataPath(folder, false);
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -230,7 +231,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
|
|
||||||
if (!manager.extractDb(filePath)) {
|
if (!manager.extractDb(filePath)) {
|
||||||
Toast.makeText(getContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG)
|
Toast.makeText(getContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
//If settings file exist, ask if it should be imported.
|
//If settings file exist, ask if it should be imported.
|
||||||
|
@ -264,14 +265,16 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
*/
|
*/
|
||||||
private void finishImport(final File file) {
|
private void finishImport(final File file) {
|
||||||
if (file.getParentFile() != null) {
|
if (file.getParentFile() != null) {
|
||||||
setImportExportDataPath(file.getParentFile());
|
//immediately because app is about to exit
|
||||||
|
setImportExportDataPath(file.getParentFile(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// restart app to properly load db
|
// restart app to properly load db
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setImportExportDataPath(final File file) {
|
@SuppressLint("ApplySharedPref")
|
||||||
|
private void setImportExportDataPath(final File file, final boolean immediately) {
|
||||||
final String directoryPath;
|
final String directoryPath;
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
directoryPath = file.getAbsolutePath();
|
directoryPath = file.getAbsolutePath();
|
||||||
|
@ -283,6 +286,13 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
directoryPath = "";
|
directoryPath = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defaultPreferences.edit().putString(importExportDataPathKey, directoryPath).apply();
|
final SharedPreferences.Editor editor = defaultPreferences
|
||||||
|
.edit()
|
||||||
|
.putString(importExportDataPathKey, directoryPath);
|
||||||
|
if (immediately) {
|
||||||
|
editor.commit();
|
||||||
|
} else {
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue