Added reset button but slightly working as intended.

This commit is contained in:
Vincent Tanumihardja 2022-10-25 13:18:31 +11:00 committed by TobiGr
parent 5d101e7b88
commit aa1847189b
4 changed files with 16 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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