File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
java/com/d4rk/androidtutorials/java/ui/screens/onboarding Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 33import android .content .Context ;
44import android .content .SharedPreferences ;
55
6+ import androidx .appcompat .app .AppCompatDelegate ;
67import androidx .lifecycle .ViewModel ;
78import androidx .preference .PreferenceManager ;
89
@@ -24,6 +25,20 @@ public class OnboardingViewModel extends ViewModel {
2425 public OnboardingViewModel (@ ApplicationContext Context context ) {
2526 this .context = context ;
2627 this .prefs = PreferenceManager .getDefaultSharedPreferences (context );
28+
29+ // Ensure defaults are persisted so skipping onboarding still sets them
30+ String themeKey = context .getString (R .string .key_theme );
31+ String [] themeValues = context .getResources ().getStringArray (R .array .preference_theme_values );
32+ if (!prefs .contains (themeKey )) {
33+ prefs .edit ().putString (themeKey , themeValues [0 ]).apply ();
34+ AppCompatDelegate .setDefaultNightMode (AppCompatDelegate .MODE_NIGHT_FOLLOW_SYSTEM );
35+ }
36+
37+ String tabKey = context .getString (R .string .key_default_tab );
38+ String [] tabValues = context .getResources ().getStringArray (R .array .preference_default_tab_values );
39+ if (!prefs .contains (tabKey )) {
40+ prefs .edit ().putString (tabKey , tabValues [0 ]).apply ();
41+ }
2742 }
2843
2944 public void setTheme (String value ) {
Original file line number Diff line number Diff line change 5151 android : id =" @+id/ad_placeholder"
5252 android : layout_width =" match_parent"
5353 android : layout_height =" match_parent"
54- android : background =" @android:color/darker_gray " />
54+ android : background =" ?attr/colorSurfaceContainer " />
5555
5656 <com .d4rk.androidtutorials.java.ads.views.NativeAdBannerView
5757 android : id =" @+id/ad_view"
You can’t perform that action at this time.
0 commit comments