Added OnPreferenceChangeListener
This commit is contained in:
parent
c7e81eb66b
commit
5ac835ce0f
|
@ -30,16 +30,19 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.luca0n.joguitos.pluck.util.UiUtil;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
UiUtil.setTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null)
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
getFragmentManager()
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
|
|
|
@ -24,15 +24,32 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
package com.luca0n.joguitos.pluck.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.luca0n.joguitos.pluck.R;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
import com.luca0n.joguitos.pluck.R;
|
||||
import com.luca0n.joguitos.pluck.util.UiUtil;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey){
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
// Listen for theme preference changes
|
||||
ListPreference preferenceTheme = (ListPreference) findPreference(getString(R.string.pref_ui_theme));
|
||||
preferenceTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener(){
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue){
|
||||
getActivity().recreate();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ public class UiUtil {
|
|||
public static void setTheme(Context context){
|
||||
SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
|
||||
|
||||
|
||||
String light = context.getString(R.string.pref_ui_theme_entryValues_light),
|
||||
dark = context.getString(R.string.pref_ui_theme_entryValues_dark),
|
||||
themeKey = context.getString(R.string.pref_ui_theme),
|
||||
|
|
|
@ -28,4 +28,8 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
<string name="pref_network_tor">pref_network_tor</string>
|
||||
<string name="pref_network_server">pref_network_server</string>
|
||||
<string name="pref_network_server_default">https://opentdb.com/api.php</string>
|
||||
<string name="pref_ui_theme">pref_ui_theme</string>
|
||||
<string name="pref_ui_theme_entryValues_light">pref_ui_theme_entryValues_light</string>
|
||||
<string name="pref_ui_theme_entryValues_dark">pref_ui_theme_entryValues_dark</string>
|
||||
<string name="pref_ui_theme_default">pref_ui_theme_entryValues_light</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue