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(