Added reset button but working as intended for theme.

This commit is contained in:
Vincent Tanumihardja 2022-10-26 17:09:53 +11:00 committed by TobiGr
parent aa1847189b
commit 58517d1d27
7 changed files with 19 additions and 38 deletions

View File

@ -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;
});
}
/**

View File

@ -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");
}
}

View File

@ -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(

View File

@ -223,7 +223,7 @@
<string name="prefer_descriptive_audio_key">prefer_descriptive_audio</string>
<string name="last_resize_mode">last_resize_mode</string>
<!-- RESET ONLY -->
<string name="reset_pref_screen_key">reset_pref_screen_key</string>
<string name="reset_settings">reset_settings</string>
<!-- DEBUG ONLY -->
<string name="debug_pref_screen_key">debug_pref_screen_key</string>

View File

@ -71,4 +71,9 @@
android:title="@string/create_error_notification"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />
<Preference
android:icon="@drawable/ic_replay"
android:key="@string/reset_settings"
android:title="@string/settings_category_reset_title"
app:iconSpaceReserved="false" />
</PreferenceScreen>

View File

@ -53,12 +53,4 @@
android:key="@string/debug_pref_screen_key"
android:title="@string/settings_category_debug_title"
app:iconSpaceReserved="false" />
<PreferenceScreen
android:fragment="org.schabi.newpipe.settings.ResetSettingsFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_replay"
android:key="@string/reset_pref_screen_key"
android:title="@string/settings_category_reset_title"
app:iconSpaceReserved="false" />
</PreferenceScreen>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
</PreferenceScreen>