set first theme choice as default

workaround for not knowing how to set default based on os version:
don't set default, and when there's none set use the first in the
list.
This commit is contained in:
Eric House 2021-08-09 21:21:10 -07:00
parent bfd7963ea6
commit cf553a0aed
7 changed files with 28 additions and 5 deletions

View file

@ -159,10 +159,18 @@ public class PrefsDelegate extends DelegateBase
protected void onResume() protected void onResume()
{ {
super.onResume(); super.onResume();
getSharedPreferences().registerOnSharedPreferenceChangeListener(this); SharedPreferences sp = getSharedPreferences();
sp.registerOnSharedPreferenceChangeListener( this );
// It's too early somehow to do this in init() above // It's too early somehow to do this in init() above
findViewById( R.id.prefs_menu ).setOnClickListener(this); findViewById( R.id.prefs_menu ).setOnClickListener(this);
String key = LocUtils.getString( mActivity, R.string.key_theme_which );
if ( null == sp.getString( key, null ) ) {
Resources res = mActivity.getResources();
String[] vals = res.getStringArray( R.array.color_themes );
sp.edit().putString( key, vals[0] ).commit();
}
} }
@Override @Override

View file

@ -1,2 +1,2 @@
values-*/strings.xml values-*/
**/*__gen.png **/*__gen.png

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation"
>
<string-array name="color_themes">
<item>@string/color_use_theme_os</item>
<item>@string/color_use_theme_light</item>
<item>@string/color_use_theme_dark</item>
</string-array>
</resources>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation"
>
<string name="color_use_theme_os">Use Theme from Android Settings</string>
</resources>

View file

@ -386,7 +386,6 @@
<string-array name="color_themes"> <string-array name="color_themes">
<item>@string/color_use_theme_light</item> <item>@string/color_use_theme_light</item>
<item>@string/color_use_theme_dark</item> <item>@string/color_use_theme_dark</item>
<item>@string/color_use_theme_os</item>
</string-array> </string-array>
<!-- Keep in sync with the color_ids_{light,dark} below --> <!-- Keep in sync with the color_ids_{light,dark} below -->

View file

@ -2746,7 +2746,6 @@
<string name="theme_which">Board color theme</string> <string name="theme_which">Board color theme</string>
<string name="color_use_theme_light">Use Light theme</string> <string name="color_use_theme_light">Use Light theme</string>
<string name="color_use_theme_dark">Use Dark theme</string> <string name="color_use_theme_dark">Use Dark theme</string>
<string name="color_use_theme_os">Use Theme from Android Settings</string>
<string name="color_theme_edit_light">Edit Light theme</string> <string name="color_theme_edit_light">Edit Light theme</string>
<string name="color_theme_edit_dark">Edit Dark theme</string> <string name="color_theme_edit_dark">Edit Dark theme</string>

View file

@ -6,12 +6,12 @@
<PreferenceCategory android:title="@string/prefs_themes" <PreferenceCategory android:title="@string/prefs_themes"
> >
<!-- color_use_theme_os only defined for v29+... -->
<org.eehouse.android.xw4.XWListPreference <org.eehouse.android.xw4.XWListPreference
android:key="@string/key_theme_which" android:key="@string/key_theme_which"
android:title="@string/theme_which" android:title="@string/theme_which"
android:entries="@array/color_themes" android:entries="@array/color_themes"
android:entryValues="@array/color_themes" android:entryValues="@array/color_themes"
android:defaultValue="@string/color_use_theme_os"
/> />
<Preference app:title="@string/color_theme_edit_light" <Preference app:title="@string/color_theme_edit_light"