From a570f70fce15baa0035d8b000651afa6c90152d2 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Mon, 24 Oct 2022 09:54:22 +1100 Subject: [PATCH 01/17] Added reset button but not working as intended. --- .../settings/AppearanceSettingsFragment.java | 18 ++++++++++++++++++ .../settings/ResetSettingsFragment.java | 14 ++++++++++++++ app/src/main/res/values/settings_keys.xml | 2 ++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/main_settings.xml | 8 ++++++++ gradle/wrapper/gradle-wrapper.properties | 2 ++ settings.gradle | 10 +++++----- 7 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java diff --git a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java index ef0e8670c..c8fa3e392 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java @@ -80,4 +80,22 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment { ActivityCompat.recreate(getActivity()); } } + + public void resetToDefault() { + final String themeKey = getString(R.string.theme_key); + final String startThemeKey = defaultPreferences + .getString(themeKey, getString(R.string.default_theme_value)); + final String autoDeviceThemeKey = getString(R.string.auto_device_theme_key); + if (startThemeKey.equals(autoDeviceThemeKey)) { + applyThemeChange(startThemeKey, themeKey, autoDeviceThemeKey); + } else { + if (startThemeKey.equals(R.string.light_theme_key)) { + removePreference(getString(R.string.light_theme_key)); + } else if (startThemeKey.equals(R.string.dark_theme_key)) { + removePreference(getString(R.string.dark_theme_key)); + } else { + removePreference(getString(R.string.black_theme_key)); + } + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java new file mode 100644 index 000000000..94936f6ca --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java @@ -0,0 +1,14 @@ +package org.schabi.newpipe.settings; + +import android.os.Bundle; + +public class ResetSettingsFragment extends BasePreferenceFragment { + + private AppearanceSettingsFragment appearanceSettings; + @Override + public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { + addPreferencesFromResourceRegistry(); + + appearanceSettings.resetToDefault(); + } +} diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 51abe14fb..de883420c 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -222,6 +222,8 @@ prefer_original_audio prefer_descriptive_audio last_resize_mode + + reset_pref_screen_key debug_pref_screen_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5bbffaff..f83938139 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -151,6 +151,7 @@ History and cache Appearance Debug + Reset All Settings Updates Player notification Configure current playing stream notification diff --git a/app/src/main/res/xml/main_settings.xml b/app/src/main/res/xml/main_settings.xml index 1b1c17e85..a569f391c 100644 --- a/app/src/main/res/xml/main_settings.xml +++ b/app/src/main/res/xml/main_settings.xml @@ -53,4 +53,12 @@ android:key="@string/debug_pref_screen_key" android:title="@string/settings_category_debug_title" app:iconSpaceReserved="false" /> + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2c3425d49..fcaba806a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,3 +1,4 @@ +#Fri Oct 21 13:32:17 AEDT 2022 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionSha256Sum=e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f @@ -5,3 +6,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index 0338fde6c..a0aed9527 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,8 +4,8 @@ include ':app' // We assume, that NewPipe and NewPipe Extractor have the same parent directory. // If this is not the case, please change the path in includeBuild(). -//includeBuild('../NewPipeExtractor') { -// dependencySubstitution { -// substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor') -// } -//} +includeBuild('../NewPipeExtractor') { + dependencySubstitution { + substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor') + } +} From 3e40fe3ea9917e2861c6f8989d2cdc8fbea737b9 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Tue, 25 Oct 2022 13:18:31 +1100 Subject: [PATCH 02/17] Added reset button but slightly working as intended. --- .../settings/AppearanceSettingsFragment.java | 18 ------------------ .../settings/ResetSettingsFragment.java | 13 +++++++++++-- .../settings/SettingsResourceRegistry.java | 1 + app/src/main/res/xml/reset_settings.xml | 4 ++++ 4 files changed, 16 insertions(+), 20 deletions(-) create mode 100644 app/src/main/res/xml/reset_settings.xml diff --git a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java index c8fa3e392..ef0e8670c 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java @@ -80,22 +80,4 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment { ActivityCompat.recreate(getActivity()); } } - - public void resetToDefault() { - final String themeKey = getString(R.string.theme_key); - final String startThemeKey = defaultPreferences - .getString(themeKey, getString(R.string.default_theme_value)); - final String autoDeviceThemeKey = getString(R.string.auto_device_theme_key); - if (startThemeKey.equals(autoDeviceThemeKey)) { - applyThemeChange(startThemeKey, themeKey, autoDeviceThemeKey); - } else { - if (startThemeKey.equals(R.string.light_theme_key)) { - removePreference(getString(R.string.light_theme_key)); - } else if (startThemeKey.equals(R.string.dark_theme_key)) { - removePreference(getString(R.string.dark_theme_key)); - } else { - removePreference(getString(R.string.black_theme_key)); - } - } - } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java index 94936f6ca..aa7f528c6 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java @@ -2,13 +2,22 @@ package org.schabi.newpipe.settings; import android.os.Bundle; +import androidx.core.app.ActivityCompat; + +import org.schabi.newpipe.R; +import org.schabi.newpipe.util.Constants; +import org.schabi.newpipe.util.ThemeHelper; + public class ResetSettingsFragment extends BasePreferenceFragment { - private AppearanceSettingsFragment appearanceSettings; @Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResourceRegistry(); - appearanceSettings.resetToDefault(); + // reset appearance to light theme + defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply(); + defaultPreferences.edit().putString(getString(R.string.theme_key), + getString(R.string.light_theme_key)).apply(); + ThemeHelper.setDayNightMode(requireContext(), "light_theme"); } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java index b3d0741bb..20d6555a5 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java @@ -41,6 +41,7 @@ public final class SettingsResourceRegistry { add(UpdateSettingsFragment.class, R.xml.update_settings); add(VideoAudioSettingsFragment.class, R.xml.video_audio_settings); add(ExoPlayerSettingsFragment.class, R.xml.exoplayer_settings); + add(ResetSettingsFragment.class, R.xml.main_settings); } private SettingRegistryEntry add( diff --git a/app/src/main/res/xml/reset_settings.xml b/app/src/main/res/xml/reset_settings.xml new file mode 100644 index 000000000..624ed13ae --- /dev/null +++ b/app/src/main/res/xml/reset_settings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 93cef624c835f9e1f5505bf67db32310e72b6ad5 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Wed, 26 Oct 2022 17:09:53 +1100 Subject: [PATCH 03/17] Added reset button but working as intended for theme. --- .../settings/DebugSettingsFragment.java | 13 +++++++++++ .../settings/ResetSettingsFragment.java | 23 ------------------- .../settings/SettingsResourceRegistry.java | 2 -- app/src/main/res/values/settings_keys.xml | 2 +- app/src/main/res/xml/debug_settings.xml | 5 ++++ app/src/main/res/xml/main_settings.xml | 8 ------- app/src/main/res/xml/reset_settings.xml | 4 ---- 7 files changed, 19 insertions(+), 38 deletions(-) delete mode 100644 app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java delete mode 100644 app/src/main/res/xml/reset_settings.xml diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 0f4c9765e..690220da7 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -10,7 +10,9 @@ import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.ErrorUtil; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.local.feed.notifications.NotificationWorker; +import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.PicassoHelper; +import org.schabi.newpipe.util.ThemeHelper; import java.util.Optional; @@ -35,6 +37,8 @@ public class DebugSettingsFragment extends BasePreferenceFragment { findPreference(getString(R.string.show_error_snackbar_key)); final Preference createErrorNotificationPreference = findPreference(getString(R.string.create_error_notification_key)); + final Preference resetSettings = + findPreference(getString(R.string.reset_settings)); assert allowHeapDumpingPreference != null; assert showMemoryLeaksPreference != null; @@ -86,6 +90,15 @@ public class DebugSettingsFragment extends BasePreferenceFragment { new ErrorInfo(new RuntimeException(DUMMY), UserAction.UI_ERROR, DUMMY)); return true; }); + + // reset appearance to light theme + resetSettings.setOnPreferenceClickListener(preference -> { + defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply(); + defaultPreferences.edit().putString(getString(R.string.theme_key), + getString(R.string.light_theme_key)).apply(); + ThemeHelper.setDayNightMode(requireContext(), "light_theme"); + return true; + }); } /** diff --git a/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java deleted file mode 100644 index aa7f528c6..000000000 --- a/app/src/main/java/org/schabi/newpipe/settings/ResetSettingsFragment.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.schabi.newpipe.settings; - -import android.os.Bundle; - -import androidx.core.app.ActivityCompat; - -import org.schabi.newpipe.R; -import org.schabi.newpipe.util.Constants; -import org.schabi.newpipe.util.ThemeHelper; - -public class ResetSettingsFragment extends BasePreferenceFragment { - - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - addPreferencesFromResourceRegistry(); - - // reset appearance to light theme - defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply(); - defaultPreferences.edit().putString(getString(R.string.theme_key), - getString(R.string.light_theme_key)).apply(); - ThemeHelper.setDayNightMode(requireContext(), "light_theme"); - } -} diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java index 20d6555a5..2fe4f42ed 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java @@ -30,7 +30,6 @@ public final class SettingsResourceRegistry { private SettingsResourceRegistry() { add(MainSettingsFragment.class, R.xml.main_settings).setSearchable(false); - add(AppearanceSettingsFragment.class, R.xml.appearance_settings); add(ContentSettingsFragment.class, R.xml.content_settings); add(DebugSettingsFragment.class, R.xml.debug_settings).setSearchable(false); @@ -41,7 +40,6 @@ public final class SettingsResourceRegistry { add(UpdateSettingsFragment.class, R.xml.update_settings); add(VideoAudioSettingsFragment.class, R.xml.video_audio_settings); add(ExoPlayerSettingsFragment.class, R.xml.exoplayer_settings); - add(ResetSettingsFragment.class, R.xml.main_settings); } private SettingRegistryEntry add( diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index de883420c..42d434900 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -223,7 +223,7 @@ prefer_descriptive_audio last_resize_mode - reset_pref_screen_key + reset_settings debug_pref_screen_key diff --git a/app/src/main/res/xml/debug_settings.xml b/app/src/main/res/xml/debug_settings.xml index 84bb281f3..66836f138 100644 --- a/app/src/main/res/xml/debug_settings.xml +++ b/app/src/main/res/xml/debug_settings.xml @@ -71,4 +71,9 @@ android:title="@string/create_error_notification" app:singleLineTitle="false" app:iconSpaceReserved="false" /> + diff --git a/app/src/main/res/xml/main_settings.xml b/app/src/main/res/xml/main_settings.xml index a569f391c..1b1c17e85 100644 --- a/app/src/main/res/xml/main_settings.xml +++ b/app/src/main/res/xml/main_settings.xml @@ -53,12 +53,4 @@ android:key="@string/debug_pref_screen_key" android:title="@string/settings_category_debug_title" app:iconSpaceReserved="false" /> - diff --git a/app/src/main/res/xml/reset_settings.xml b/app/src/main/res/xml/reset_settings.xml deleted file mode 100644 index 624ed13ae..000000000 --- a/app/src/main/res/xml/reset_settings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 41f5ba4f2b3f4f45284a6b966fcfdcb7f2f553d2 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Wed, 26 Oct 2022 19:13:41 +1100 Subject: [PATCH 04/17] Cleaned up xml files. --- app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/xml/debug_settings.xml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 42d434900..ea283e62c 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -222,6 +222,7 @@ prefer_original_audio prefer_descriptive_audio last_resize_mode + reset_settings diff --git a/app/src/main/res/xml/debug_settings.xml b/app/src/main/res/xml/debug_settings.xml index 66836f138..511bcd19a 100644 --- a/app/src/main/res/xml/debug_settings.xml +++ b/app/src/main/res/xml/debug_settings.xml @@ -72,7 +72,6 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> From e1524cb76a38a58d6634881d1f46039469955493 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 08:58:11 +1100 Subject: [PATCH 05/17] Added alert dialogue and restarts the app when resetting settings. --- .../settings/DebugSettingsFragment.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 690220da7..56c88f730 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.settings; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; @@ -10,9 +12,8 @@ import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.ErrorUtil; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.local.feed.notifications.NotificationWorker; -import org.schabi.newpipe.util.Constants; +import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PicassoHelper; -import org.schabi.newpipe.util.ThemeHelper; import java.util.Optional; @@ -91,12 +92,30 @@ public class DebugSettingsFragment extends BasePreferenceFragment { return true; }); - // reset appearance to light theme + // Resets all settings by deleting shared preference and restarting the app + // A dialogue will pop up to confirm if user intends to reset all settings resetSettings.setOnPreferenceClickListener(preference -> { - defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply(); - defaultPreferences.edit().putString(getString(R.string.theme_key), - getString(R.string.light_theme_key)).apply(); - ThemeHelper.setDayNightMode(requireContext(), "light_theme"); + final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setMessage("Resetting all settings will discard " + + "all of your preferred settings and restarts the app. " + + "Are you sure you want to do this?"); + builder.setCancelable(true); + builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialogInterface, final int i) { + NavigationHelper.restartApp(getActivity()); + } + }); + builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialogInterface, final int i) { + } + }); + final AlertDialog alertDialog = builder.create(); + alertDialog.show(); +// SharedPreferences sharedPreferences = +// PreferenceManager.getDefaultSharedPreferences(requireContext()); +// sharedPreferences = null; return true; }); } From 9ba69cc07348184248ea67749537a1694cd1d482 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 09:19:04 +1100 Subject: [PATCH 06/17] Changed alert dialogue. --- .../java/org/schabi/newpipe/settings/DebugSettingsFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 56c88f730..88addd73e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -98,7 +98,7 @@ public class DebugSettingsFragment extends BasePreferenceFragment { final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage("Resetting all settings will discard " + "all of your preferred settings and restarts the app. " - + "Are you sure you want to do this?"); + + "Are you sure you want to proceed?"); builder.setCancelable(true); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override From 768defdab3239eb3b6a7ac99196d0ed35b1bd954 Mon Sep 17 00:00:00 2001 From: Zhidong Piao Date: Sat, 29 Oct 2022 09:38:00 +1100 Subject: [PATCH 07/17] clear shared preference xmls --- .../newpipe/settings/DebugSettingsFragment.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 88addd73e..5c5f6a039 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -3,9 +3,11 @@ package org.schabi.newpipe.settings; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import androidx.preference.Preference; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.R; import org.schabi.newpipe.error.ErrorInfo; @@ -94,6 +96,7 @@ public class DebugSettingsFragment extends BasePreferenceFragment { // Resets all settings by deleting shared preference and restarting the app // A dialogue will pop up to confirm if user intends to reset all settings + assert resetSettings != null; resetSettings.setOnPreferenceClickListener(preference -> { final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage("Resetting all settings will discard " @@ -113,9 +116,13 @@ public class DebugSettingsFragment extends BasePreferenceFragment { }); final AlertDialog alertDialog = builder.create(); alertDialog.show(); -// SharedPreferences sharedPreferences = -// PreferenceManager.getDefaultSharedPreferences(requireContext()); -// sharedPreferences = null; + + // delete all shared preferences xml files. + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()); + sharedPreferences.edit().clear().apply(); + + return true; }); } From 4332f062cf4d13b3a8db22e7bc894c71434b181c Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 09:52:22 +1100 Subject: [PATCH 08/17] Added delete xml method inside the yes dialogue. --- .../settings/DebugSettingsFragment.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 5c5f6a039..5952fbe5b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -1,7 +1,6 @@ package org.schabi.newpipe.settings; import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; @@ -98,31 +97,27 @@ public class DebugSettingsFragment extends BasePreferenceFragment { // A dialogue will pop up to confirm if user intends to reset all settings assert resetSettings != null; resetSettings.setOnPreferenceClickListener(preference -> { + // Show Alert Dialogue final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage("Resetting all settings will discard " + "all of your preferred settings and restarts the app. " + "Are you sure you want to proceed?"); builder.setCancelable(true); - builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialogInterface, final int i) { - NavigationHelper.restartApp(getActivity()); + builder.setPositiveButton("Yes", (dialogInterface, i) -> { + // Deletes all shared preferences xml files. + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()); + sharedPreferences.edit().clear().apply(); + // Restarts the app + if (getActivity() == null) { + return; } + NavigationHelper.restartApp(getActivity()); }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialogInterface, final int i) { - } + builder.setNegativeButton("Cancel", (dialogInterface, i) -> { }); final AlertDialog alertDialog = builder.create(); alertDialog.show(); - - // delete all shared preferences xml files. - final SharedPreferences sharedPreferences = - PreferenceManager.getDefaultSharedPreferences(requireContext()); - sharedPreferences.edit().clear().apply(); - - return true; }); } From ab25fa9ac18ac065fbca4bc0d8c58d61908366eb Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 10:24:11 +1100 Subject: [PATCH 09/17] Revert changes made to dev. --- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fcaba806a..28d3f9e02 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,3 @@ -#Fri Oct 21 13:32:17 AEDT 2022 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionSha256Sum=e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f @@ -7,3 +6,4 @@ networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index a0aed9527..0338fde6c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,8 +4,8 @@ include ':app' // We assume, that NewPipe and NewPipe Extractor have the same parent directory. // If this is not the case, please change the path in includeBuild(). -includeBuild('../NewPipeExtractor') { - dependencySubstitution { - substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor') - } -} +//includeBuild('../NewPipeExtractor') { +// dependencySubstitution { +// substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor') +// } +//} From ae52f18561684b392c2d4444dc5c33e587c304c8 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 10:26:11 +1100 Subject: [PATCH 10/17] Revert changes made to dev. --- .../org/schabi/newpipe/settings/SettingsResourceRegistry.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java index 2fe4f42ed..b3d0741bb 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java @@ -30,6 +30,7 @@ public final class SettingsResourceRegistry { private SettingsResourceRegistry() { add(MainSettingsFragment.class, R.xml.main_settings).setSearchable(false); + add(AppearanceSettingsFragment.class, R.xml.appearance_settings); add(ContentSettingsFragment.class, R.xml.content_settings); add(DebugSettingsFragment.class, R.xml.debug_settings).setSearchable(false); From 4b16bd3be15ff44c1d7e1591cb753f7d9cd5c72a Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 10:29:16 +1100 Subject: [PATCH 11/17] Revert changes made to dev. --- app/src/main/res/values/settings_keys.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index ea283e62c..51abe14fb 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -223,9 +223,6 @@ prefer_descriptive_audio last_resize_mode - - reset_settings - debug_pref_screen_key allow_heap_dumping_key From f63adf23738b9dd0a8abedd9a3d292e267f2fbcd Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 10:30:41 +1100 Subject: [PATCH 12/17] Revert committed file change of settings key. --- app/src/main/res/values/settings_keys.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 51abe14fb..ea283e62c 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -223,6 +223,9 @@ prefer_descriptive_audio last_resize_mode + + reset_settings + debug_pref_screen_key allow_heap_dumping_key From e2e390c0bc65d692abefff8d8a8893edd793d3f5 Mon Sep 17 00:00:00 2001 From: Vincent Tanumihardja Date: Sat, 29 Oct 2022 11:33:10 +1100 Subject: [PATCH 13/17] Added strings to strings.xml to allow translation. --- .../schabi/newpipe/settings/DebugSettingsFragment.java | 8 +++----- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 5952fbe5b..f2a4e1190 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -99,11 +99,9 @@ public class DebugSettingsFragment extends BasePreferenceFragment { resetSettings.setOnPreferenceClickListener(preference -> { // Show Alert Dialogue final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setMessage("Resetting all settings will discard " - + "all of your preferred settings and restarts the app. " - + "Are you sure you want to proceed?"); + builder.setMessage(R.string.reset_all_settings); builder.setCancelable(true); - builder.setPositiveButton("Yes", (dialogInterface, i) -> { + builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> { // Deletes all shared preferences xml files. final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()); @@ -114,7 +112,7 @@ public class DebugSettingsFragment extends BasePreferenceFragment { } NavigationHelper.restartApp(getActivity()); }); - builder.setNegativeButton("Cancel", (dialogInterface, i) -> { + builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { }); final AlertDialog alertDialog = builder.create(); alertDialog.show(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f83938139..9c843784e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -595,6 +595,8 @@ Download finished %s downloads finished + + Resetting all settings will discard all of your preferred settings and restarts the app. Are you sure you want to proceed? Generate unique name Overwrite From 9bd8e7dbe24825a3b7f1a87ed9efe7add7fba066 Mon Sep 17 00:00:00 2001 From: vincetzr <110076924+vincetzr@users.noreply.github.com> Date: Sat, 29 Oct 2022 21:21:26 +1100 Subject: [PATCH 14/17] Update app/src/main/res/xml/debug_settings.xml Ensuring title to be fully displayed on small devices. Co-authored-by: Tobi --- app/src/main/res/xml/debug_settings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/xml/debug_settings.xml b/app/src/main/res/xml/debug_settings.xml index 511bcd19a..1c66dbdb3 100644 --- a/app/src/main/res/xml/debug_settings.xml +++ b/app/src/main/res/xml/debug_settings.xml @@ -74,5 +74,6 @@ From f91686cf4508182d06df24d498b8960599f08dff Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Sep 2023 17:21:59 +0200 Subject: [PATCH 15/17] Create new settings category: Backup and restore Following settings have been move to the new category: - import database (from ContenttSettings) - export database (from ContenttSettings) - reset settings (from DebugSettings) --- .../BackupRestoreSettingsFragment.java | 271 ++++++++++++++++++ .../settings/ContentSettingsFragment.java | 217 -------------- .../settings/DebugSettingsFragment.java | 32 --- .../newpipe/settings/NewPipeSettings.java | 1 + .../settings/SettingsResourceRegistry.java | 1 + app/src/main/res/values/settings_keys.xml | 1 - app/src/main/res/values/strings.xml | 1 + .../main/res/xml/backup_restore_settings.xml | 24 ++ app/src/main/res/xml/content_settings.xml | 14 - app/src/main/res/xml/debug_settings.xml | 5 - app/src/main/res/xml/main_settings.xml | 6 + 11 files changed, 304 insertions(+), 269 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java create mode 100644 app/src/main/res/xml/backup_restore_settings.xml diff --git a/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java new file mode 100644 index 000000000..bc24fbe81 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/BackupRestoreSettingsFragment.java @@ -0,0 +1,271 @@ +package org.schabi.newpipe.settings; + +import static org.schabi.newpipe.extractor.utils.Utils.isBlank; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Bundle; +import android.widget.Toast; + +import androidx.activity.result.ActivityResult; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.preference.Preference; +import androidx.preference.PreferenceManager; + +import org.schabi.newpipe.NewPipeDatabase; +import org.schabi.newpipe.R; +import org.schabi.newpipe.error.ErrorUtil; +import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard; +import org.schabi.newpipe.streams.io.StoredFileHelper; +import org.schabi.newpipe.util.NavigationHelper; +import org.schabi.newpipe.util.ZipHelper; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.Objects; + +public class BackupRestoreSettingsFragment extends BasePreferenceFragment { + + private static final String ZIP_MIME_TYPE = "application/zip"; + + private final SimpleDateFormat exportDateFormat = + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); + private ContentSettingsManager manager; + private String importExportDataPathKey; + private final ActivityResultLauncher requestImportPathLauncher = + registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), + this::requestImportPathResult); + private final ActivityResultLauncher requestExportPathLauncher = + registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), + this::requestExportPathResult); + + + @Override + public void onCreatePreferences(@Nullable final Bundle savedInstanceState, + @Nullable final String rootKey) { + final File homeDir = ContextCompat.getDataDir(requireContext()); + Objects.requireNonNull(homeDir); + manager = new ContentSettingsManager(new NewPipeFileLocator(homeDir)); + manager.deleteSettingsFile(); + + importExportDataPathKey = getString(R.string.import_export_data_path); + + + addPreferencesFromResourceRegistry(); + + final Preference importDataPreference = requirePreference(R.string.import_data); + importDataPreference.setOnPreferenceClickListener((Preference p) -> { + NoFileManagerSafeGuard.launchSafe( + requestImportPathLauncher, + StoredFileHelper.getPicker(requireContext(), + ZIP_MIME_TYPE, getImportExportDataUri()), + TAG, + getContext() + ); + + return true; + }); + + final Preference exportDataPreference = requirePreference(R.string.export_data); + exportDataPreference.setOnPreferenceClickListener((final Preference p) -> { + NoFileManagerSafeGuard.launchSafe( + requestExportPathLauncher, + StoredFileHelper.getNewPicker(requireContext(), + "NewPipeData-" + exportDateFormat.format(new Date()) + ".zip", + ZIP_MIME_TYPE, getImportExportDataUri()), + TAG, + getContext() + ); + + return true; + }); + + final Preference resetSettings = findPreference(getString(R.string.reset_settings)); + // Resets all settings by deleting shared preference and restarting the app + // A dialogue will pop up to confirm if user intends to reset all settings + assert resetSettings != null; + resetSettings.setOnPreferenceClickListener(preference -> { + // Show Alert Dialogue + final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setMessage(R.string.reset_all_settings); + builder.setCancelable(true); + builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> { + // Deletes all shared preferences xml files. + final SharedPreferences sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()); + sharedPreferences.edit().clear().apply(); + // Restarts the app + if (getActivity() == null) { + return; + } + NavigationHelper.restartApp(getActivity()); + }); + builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + }); + final AlertDialog alertDialog = builder.create(); + alertDialog.show(); + return true; + }); + } + + private void requestExportPathResult(final ActivityResult result) { + assureCorrectAppLanguage(requireContext()); + if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { + // will be saved only on success + final Uri lastExportDataUri = result.getData().getData(); + + final StoredFileHelper file = new StoredFileHelper( + requireContext(), result.getData().getData(), ZIP_MIME_TYPE); + + exportDatabase(file, lastExportDataUri); + } + } + + private void requestImportPathResult(final ActivityResult result) { + assureCorrectAppLanguage(requireContext()); + if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { + // will be saved only on success + final Uri lastImportDataUri = result.getData().getData(); + + final StoredFileHelper file = new StoredFileHelper( + requireContext(), result.getData().getData(), ZIP_MIME_TYPE); + + new androidx.appcompat.app.AlertDialog.Builder(requireActivity()) + .setMessage(R.string.override_current_data) + .setPositiveButton(R.string.ok, (d, id) -> + importDatabase(file, lastImportDataUri)) + .setNegativeButton(R.string.cancel, (d, id) -> + d.cancel()) + .show(); + } + } + + private void exportDatabase(final StoredFileHelper file, final Uri exportDataUri) { + try { + //checkpoint before export + NewPipeDatabase.checkpoint(); + + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(requireContext()); + manager.exportDatabase(preferences, file); + + saveLastImportExportDataUri(exportDataUri); // save export path only on success + Toast.makeText(requireContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT) + .show(); + } catch (final Exception e) { + ErrorUtil.showUiErrorSnackbar(this, "Exporting database", e); + } + } + + private void importDatabase(final StoredFileHelper file, final Uri importDataUri) { + // check if file is supported + if (!ZipHelper.isValidZipFile(file)) { + Toast.makeText(requireContext(), R.string.no_valid_zip_file, Toast.LENGTH_SHORT) + .show(); + return; + } + + try { + if (!manager.ensureDbDirectoryExists()) { + throw new IOException("Could not create databases dir"); + } + + if (!manager.extractDb(file)) { + Toast.makeText(requireContext(), R.string.could_not_import_all_files, + Toast.LENGTH_LONG) + .show(); + } + + // if settings file exist, ask if it should be imported. + if (manager.extractSettings(file)) { + new androidx.appcompat.app.AlertDialog.Builder(requireContext()) + .setTitle(R.string.import_settings) + .setNegativeButton(R.string.cancel, (dialog, which) -> { + dialog.dismiss(); + finishImport(importDataUri); + }) + .setPositiveButton(R.string.ok, (dialog, which) -> { + dialog.dismiss(); + final Context context = requireContext(); + final SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(context); + manager.loadSharedPreferences(prefs); + cleanImport(context, prefs); + finishImport(importDataUri); + }) + .show(); + } else { + finishImport(importDataUri); + } + } catch (final Exception e) { + ErrorUtil.showUiErrorSnackbar(this, "Importing database", e); + } + } + + /** + * Remove settings that are not supposed to be imported on different devices + * and reset them to default values. + * @param context the context used for the import + * @param prefs the preferences used while running the import + */ + private void cleanImport(@NonNull final Context context, + @NonNull final SharedPreferences prefs) { + // Check if media tunnelling needs to be disabled automatically, + // if it was disabled automatically in the imported preferences. + final String tunnelingKey = context.getString(R.string.disable_media_tunneling_key); + final String automaticTunnelingKey = + context.getString(R.string.disabled_media_tunneling_automatically_key); + // R.string.disable_media_tunneling_key should always be true + // if R.string.disabled_media_tunneling_automatically_key equals 1, + // but we double check here just to be sure and to avoid regressions + // caused by possible later modification of the media tunneling functionality. + // R.string.disabled_media_tunneling_automatically_key == 0: + // automatic value overridden by user in settings + // R.string.disabled_media_tunneling_automatically_key == -1: not set + final boolean wasMediaTunnelingDisabledAutomatically = + prefs.getInt(automaticTunnelingKey, -1) == 1 + && prefs.getBoolean(tunnelingKey, false); + if (wasMediaTunnelingDisabledAutomatically) { + prefs.edit() + .putInt(automaticTunnelingKey, -1) + .putBoolean(tunnelingKey, false) + .apply(); + NewPipeSettings.setMediaTunneling(context); + } + } + + /** + * Save import path and restart system. + * + * @param importDataUri The import path to save + */ + private void finishImport(final Uri importDataUri) { + // save import path only on success + saveLastImportExportDataUri(importDataUri); + // restart app to properly load db + NavigationHelper.restartApp(requireActivity()); + } + + private Uri getImportExportDataUri() { + final String path = defaultPreferences.getString(importExportDataPathKey, null); + return isBlank(path) ? null : Uri.parse(path); + } + + private void saveLastImportExportDataUri(final Uri importExportDataUri) { + final SharedPreferences.Editor editor = defaultPreferences.edit() + .putString(importExportDataPathKey, importExportDataUri.toString()); + editor.apply(); + } +} 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 ee34f01dd..ec3b1b2d7 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -1,104 +1,34 @@ package org.schabi.newpipe.settings; -import static org.schabi.newpipe.extractor.utils.Utils.isBlank; -import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; - -import android.app.Activity; import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.widget.Toast; -import androidx.activity.result.ActivityResult; -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; import androidx.preference.Preference; -import androidx.preference.PreferenceManager; import org.schabi.newpipe.DownloaderImpl; -import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; -import org.schabi.newpipe.error.ErrorUtil; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.Localization; -import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard; -import org.schabi.newpipe.streams.io.StoredFileHelper; -import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PicassoHelper; -import org.schabi.newpipe.util.ZipHelper; -import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.Objects; public class ContentSettingsFragment extends BasePreferenceFragment { - private static final String ZIP_MIME_TYPE = "application/zip"; - - private final SimpleDateFormat exportDateFormat = - new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); - - private ContentSettingsManager manager; - - private String importExportDataPathKey; private String youtubeRestrictedModeEnabledKey; private Localization initialSelectedLocalization; private ContentCountry initialSelectedContentCountry; private String initialLanguage; - private final ActivityResultLauncher requestImportPathLauncher = - registerForActivityResult(new StartActivityForResult(), this::requestImportPathResult); - private final ActivityResultLauncher requestExportPathLauncher = - registerForActivityResult(new StartActivityForResult(), this::requestExportPathResult); @Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - final File homeDir = ContextCompat.getDataDir(requireContext()); - Objects.requireNonNull(homeDir); - manager = new ContentSettingsManager(new NewPipeFileLocator(homeDir)); - manager.deleteSettingsFile(); - - importExportDataPathKey = getString(R.string.import_export_data_path); youtubeRestrictedModeEnabledKey = getString(R.string.youtube_restricted_mode_enabled); addPreferencesFromResourceRegistry(); - final Preference importDataPreference = requirePreference(R.string.import_data); - importDataPreference.setOnPreferenceClickListener((Preference p) -> { - NoFileManagerSafeGuard.launchSafe( - requestImportPathLauncher, - StoredFileHelper.getPicker(requireContext(), - ZIP_MIME_TYPE, getImportExportDataUri()), - TAG, - getContext() - ); - - return true; - }); - - final Preference exportDataPreference = requirePreference(R.string.export_data); - exportDataPreference.setOnPreferenceClickListener((final Preference p) -> { - NoFileManagerSafeGuard.launchSafe( - requestExportPathLauncher, - StoredFileHelper.getNewPicker(requireContext(), - "NewPipeData-" + exportDateFormat.format(new Date()) + ".zip", - ZIP_MIME_TYPE, getImportExportDataUri()), - TAG, - getContext() - ); - - return true; - }); - initialSelectedLocalization = org.schabi.newpipe.util.Localization .getPreferredLocalization(requireContext()); initialSelectedContentCountry = org.schabi.newpipe.util.Localization @@ -154,151 +84,4 @@ public class ContentSettingsFragment extends BasePreferenceFragment { NewPipe.setupLocalization(selectedLocalization, selectedContentCountry); } } - - private void requestExportPathResult(final ActivityResult result) { - assureCorrectAppLanguage(getContext()); - if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { - // will be saved only on success - final Uri lastExportDataUri = result.getData().getData(); - - final StoredFileHelper file = - new StoredFileHelper(getContext(), result.getData().getData(), ZIP_MIME_TYPE); - - exportDatabase(file, lastExportDataUri); - } - } - - private void requestImportPathResult(final ActivityResult result) { - assureCorrectAppLanguage(getContext()); - if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { - // will be saved only on success - final Uri lastImportDataUri = result.getData().getData(); - - final StoredFileHelper file = - new StoredFileHelper(getContext(), result.getData().getData(), ZIP_MIME_TYPE); - - new AlertDialog.Builder(requireActivity()) - .setMessage(R.string.override_current_data) - .setPositiveButton(R.string.ok, (d, id) -> - importDatabase(file, lastImportDataUri)) - .setNegativeButton(R.string.cancel, (d, id) -> - d.cancel()) - .show(); - } - } - - private void exportDatabase(final StoredFileHelper file, final Uri exportDataUri) { - try { - //checkpoint before export - NewPipeDatabase.checkpoint(); - - final SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(requireContext()); - manager.exportDatabase(preferences, file); - - saveLastImportExportDataUri(exportDataUri); // save export path only on success - Toast.makeText(getContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT).show(); - } catch (final Exception e) { - ErrorUtil.showUiErrorSnackbar(this, "Exporting database", e); - } - } - - private void importDatabase(final StoredFileHelper file, final Uri importDataUri) { - // check if file is supported - if (!ZipHelper.isValidZipFile(file)) { - Toast.makeText(getContext(), R.string.no_valid_zip_file, Toast.LENGTH_SHORT) - .show(); - return; - } - - try { - if (!manager.ensureDbDirectoryExists()) { - throw new IOException("Could not create databases dir"); - } - - if (!manager.extractDb(file)) { - Toast.makeText(getContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG) - .show(); - } - - // if settings file exist, ask if it should be imported. - if (manager.extractSettings(file)) { - new AlertDialog.Builder(requireContext()) - .setTitle(R.string.import_settings) - .setNegativeButton(R.string.cancel, (dialog, which) -> { - dialog.dismiss(); - finishImport(importDataUri); - }) - .setPositiveButton(R.string.ok, (dialog, which) -> { - dialog.dismiss(); - final Context context = requireContext(); - final SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(context); - manager.loadSharedPreferences(prefs); - cleanImport(context, prefs); - finishImport(importDataUri); - }) - .show(); - } else { - finishImport(importDataUri); - } - } catch (final Exception e) { - ErrorUtil.showUiErrorSnackbar(this, "Importing database", e); - } - } - - /** - * Remove settings that are not supposed to be imported on different devices - * and reset them to default values. - * @param context the context used for the import - * @param prefs the preferences used while running the import - */ - private void cleanImport(@NonNull final Context context, - @NonNull final SharedPreferences prefs) { - // Check if media tunnelling needs to be disabled automatically, - // if it was disabled automatically in the imported preferences. - final String tunnelingKey = context.getString(R.string.disable_media_tunneling_key); - final String automaticTunnelingKey = - context.getString(R.string.disabled_media_tunneling_automatically_key); - // R.string.disable_media_tunneling_key should always be true - // if R.string.disabled_media_tunneling_automatically_key equals 1, - // but we double check here just to be sure and to avoid regressions - // caused by possible later modification of the media tunneling functionality. - // R.string.disabled_media_tunneling_automatically_key == 0: - // automatic value overridden by user in settings - // R.string.disabled_media_tunneling_automatically_key == -1: not set - final boolean wasMediaTunnelingDisabledAutomatically = - prefs.getInt(automaticTunnelingKey, -1) == 1 - && prefs.getBoolean(tunnelingKey, false); - if (wasMediaTunnelingDisabledAutomatically) { - prefs.edit() - .putInt(automaticTunnelingKey, -1) - .putBoolean(tunnelingKey, false) - .apply(); - NewPipeSettings.setMediaTunneling(context); - } - } - - /** - * Save import path and restart system. - * - * @param importDataUri The import path to save - */ - private void finishImport(final Uri importDataUri) { - // save import path only on success - saveLastImportExportDataUri(importDataUri); - // restart app to properly load db - NavigationHelper.restartApp(requireActivity()); - } - - private Uri getImportExportDataUri() { - final String path = defaultPreferences.getString(importExportDataPathKey, null); - return isBlank(path) ? null : Uri.parse(path); - } - - private void saveLastImportExportDataUri(final Uri importExportDataUri) { - final SharedPreferences.Editor editor = defaultPreferences.edit() - .putString(importExportDataPathKey, importExportDataUri.toString()); - editor.apply(); - } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index f2a4e1190..0f4c9765e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -1,19 +1,15 @@ package org.schabi.newpipe.settings; -import android.app.AlertDialog; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import androidx.preference.Preference; -import androidx.preference.PreferenceManager; import org.schabi.newpipe.R; import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.ErrorUtil; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.local.feed.notifications.NotificationWorker; -import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PicassoHelper; import java.util.Optional; @@ -39,8 +35,6 @@ public class DebugSettingsFragment extends BasePreferenceFragment { findPreference(getString(R.string.show_error_snackbar_key)); final Preference createErrorNotificationPreference = findPreference(getString(R.string.create_error_notification_key)); - final Preference resetSettings = - findPreference(getString(R.string.reset_settings)); assert allowHeapDumpingPreference != null; assert showMemoryLeaksPreference != null; @@ -92,32 +86,6 @@ public class DebugSettingsFragment extends BasePreferenceFragment { new ErrorInfo(new RuntimeException(DUMMY), UserAction.UI_ERROR, DUMMY)); return true; }); - - // Resets all settings by deleting shared preference and restarting the app - // A dialogue will pop up to confirm if user intends to reset all settings - assert resetSettings != null; - resetSettings.setOnPreferenceClickListener(preference -> { - // Show Alert Dialogue - final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setMessage(R.string.reset_all_settings); - builder.setCancelable(true); - builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> { - // Deletes all shared preferences xml files. - final SharedPreferences sharedPreferences = - PreferenceManager.getDefaultSharedPreferences(requireContext()); - sharedPreferences.edit().clear().apply(); - // Restarts the app - if (getActivity() == null) { - return; - } - NavigationHelper.restartApp(getActivity()); - }); - builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { - }); - final AlertDialog alertDialog = builder.create(); - alertDialog.show(); - return true; - }); } /** diff --git a/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java b/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java index b85b95eb0..f280324cf 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java +++ b/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java @@ -63,6 +63,7 @@ public final class NewPipeSettings { PreferenceManager.setDefaultValues(context, R.xml.player_notification_settings, true); PreferenceManager.setDefaultValues(context, R.xml.update_settings, true); PreferenceManager.setDefaultValues(context, R.xml.debug_settings, true); + PreferenceManager.setDefaultValues(context, R.xml.backup_restore_settings, true); saveDefaultVideoDownloadDirectory(context); saveDefaultAudioDownloadDirectory(context); diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java index b3d0741bb..06e0a7c1e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsResourceRegistry.java @@ -41,6 +41,7 @@ public final class SettingsResourceRegistry { add(UpdateSettingsFragment.class, R.xml.update_settings); add(VideoAudioSettingsFragment.class, R.xml.video_audio_settings); add(ExoPlayerSettingsFragment.class, R.xml.exoplayer_settings); + add(BackupRestoreSettingsFragment.class, R.xml.backup_restore_settings); } private SettingRegistryEntry add( diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index ea283e62c..30efca080 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -223,7 +223,6 @@ prefer_descriptive_audio last_resize_mode - reset_settings diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9c843784e..314eaa9bd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -155,6 +155,7 @@ Updates Player notification Configure current playing stream notification + Backup and restore Playing in background Playing in popup mode Content diff --git a/app/src/main/res/xml/backup_restore_settings.xml b/app/src/main/res/xml/backup_restore_settings.xml new file mode 100644 index 000000000..b8fee0aa6 --- /dev/null +++ b/app/src/main/res/xml/backup_restore_settings.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index 73a849af7..dac5dccc1 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -124,20 +124,6 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> - - - - - diff --git a/app/src/main/res/xml/main_settings.xml b/app/src/main/res/xml/main_settings.xml index 1b1c17e85..5f96989f9 100644 --- a/app/src/main/res/xml/main_settings.xml +++ b/app/src/main/res/xml/main_settings.xml @@ -47,6 +47,12 @@ android:title="@string/settings_category_updates_title" app:iconSpaceReserved="false" /> + + Date: Sun, 17 Sep 2023 17:31:45 +0200 Subject: [PATCH 16/17] Remove strange change --- gradle/wrapper/gradle-wrapper.properties | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 28d3f9e02..2c3425d49 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -5,5 +5,3 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists From f259e2dc7d150619990558e7cfeceb311f1f6d8d Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Sep 2023 17:35:52 +0200 Subject: [PATCH 17/17] Add summary to reset preference --- app/src/main/res/values/strings.xml | 5 +++-- app/src/main/res/xml/backup_restore_settings.xml | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 314eaa9bd..1dbffa4ae 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -151,7 +151,6 @@ History and cache Appearance Debug - Reset All Settings Updates Player notification Configure current playing stream notification @@ -596,8 +595,10 @@ Download finished %s downloads finished + Reset settings + Reset all settings to their default values - Resetting all settings will discard all of your preferred settings and restarts the app. Are you sure you want to proceed? + Resetting all settings will discard all of your preferred settings and restarts the app.\n\nAre you sure you want to proceed? Generate unique name Overwrite diff --git a/app/src/main/res/xml/backup_restore_settings.xml b/app/src/main/res/xml/backup_restore_settings.xml index b8fee0aa6..ef6a3cde3 100644 --- a/app/src/main/res/xml/backup_restore_settings.xml +++ b/app/src/main/res/xml/backup_restore_settings.xml @@ -18,7 +18,8 @@ \ No newline at end of file