From 9767e98e50e14bfa824572a2be5f7967737f2e2a Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Sun, 20 Jun 2021 09:17:55 +0200 Subject: [PATCH] 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. --- .../newpipe/settings/ContentSettingsFragment.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 b66300759..0d67c9a48 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -199,7 +199,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { .getDefaultSharedPreferences(requireContext()); 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(); } catch (final Exception e) { ErrorActivity.reportUiErrorInSnackbar(this, "Exporting database", e); @@ -252,8 +252,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment { * Save import path and restart system. */ private void finishImport() { - // save import path only on success; save immediately because app is about to exit - saveLastImportExportDataUri(true); + // save import path only on success + saveLastImportExportDataUri(); // restart app to properly load db NavigationHelper.restartApp(requireActivity()); } @@ -263,16 +263,11 @@ public class ContentSettingsFragment extends BasePreferenceFragment { return isBlank(path) ? null : Uri.parse(path); } - private void saveLastImportExportDataUri(final boolean immediately) { + private void saveLastImportExportDataUri() { if (lastImportExportDataUri != null) { final SharedPreferences.Editor editor = defaultPreferences.edit() .putString(importExportDataPathKey, lastImportExportDataUri.toString()); - if (immediately) { - // noinspection ApplySharedPref - editor.commit(); // app about to be restarted, commit immediately - } else { - editor.apply(); - } + editor.apply(); } } }