Remove option to immediately commit pref changes on import
System is now not restarted with `System.exit(0)`. Instead it is done properly by finishing the activity and restarting the activity. This allows preference changes which are queued up asynchronously through `apply` to be applied.
This commit is contained in:
parent
74ad488f4a
commit
9767e98e50
|
@ -199,7 +199,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
.getDefaultSharedPreferences(requireContext());
|
.getDefaultSharedPreferences(requireContext());
|
||||||
manager.exportDatabase(preferences, file);
|
manager.exportDatabase(preferences, file);
|
||||||
|
|
||||||
saveLastImportExportDataUri(false); // save export path only on success
|
saveLastImportExportDataUri(); // save export path only on success
|
||||||
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);
|
||||||
|
@ -252,8 +252,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
* Save import path and restart system.
|
* Save import path and restart system.
|
||||||
*/
|
*/
|
||||||
private void finishImport() {
|
private void finishImport() {
|
||||||
// save import path only on success; save immediately because app is about to exit
|
// save import path only on success
|
||||||
saveLastImportExportDataUri(true);
|
saveLastImportExportDataUri();
|
||||||
// restart app to properly load db
|
// restart app to properly load db
|
||||||
NavigationHelper.restartApp(requireActivity());
|
NavigationHelper.restartApp(requireActivity());
|
||||||
}
|
}
|
||||||
|
@ -263,16 +263,11 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
return isBlank(path) ? null : Uri.parse(path);
|
return isBlank(path) ? null : Uri.parse(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveLastImportExportDataUri(final boolean immediately) {
|
private void saveLastImportExportDataUri() {
|
||||||
if (lastImportExportDataUri != null) {
|
if (lastImportExportDataUri != null) {
|
||||||
final SharedPreferences.Editor editor = defaultPreferences.edit()
|
final SharedPreferences.Editor editor = defaultPreferences.edit()
|
||||||
.putString(importExportDataPathKey, lastImportExportDataUri.toString());
|
.putString(importExportDataPathKey, lastImportExportDataUri.toString());
|
||||||
if (immediately) {
|
|
||||||
// noinspection ApplySharedPref
|
|
||||||
editor.commit(); // app about to be restarted, commit immediately
|
|
||||||
} else {
|
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue