Skip to content

Commit 0d65ada

Browse files
SUPERCILEXsamtstern
authored andcommitted
Fix dark mode bugs in sample (#959)
1 parent 486584b commit 0d65ada

File tree

5 files changed

+20
-71
lines changed

5 files changed

+20
-71
lines changed

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.support.annotation.StyleRes;
2424
import android.support.design.widget.Snackbar;
2525
import android.support.v7.app.AppCompatActivity;
26+
import android.support.v7.app.AppCompatDelegate;
2627
import android.view.View;
2728
import android.widget.Button;
2829
import android.widget.CheckBox;
@@ -193,6 +194,10 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
193194
if (isGoogleMisconfigured() || isFacebookMisconfigured() || isTwitterMisconfigured()) {
194195
showSnackbar(R.string.configuration_required);
195196
}
197+
198+
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
199+
mUseDarkTheme.setChecked(true);
200+
}
196201
}
197202

198203
@OnClick(R.id.sign_in)
@@ -281,22 +286,26 @@ private void setFacebookScopesEnabled(boolean enabled) {
281286
mFacebookScopePhotos.setEnabled(enabled);
282287
}
283288

289+
@OnClick({R.id.default_theme, R.id.purple_theme, R.id.green_theme, R.id.dark_theme})
290+
public void toggleDarkTheme() {
291+
int mode = mUseDarkTheme.isChecked() ?
292+
AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_AUTO;
293+
AppCompatDelegate.setDefaultNightMode(mode);
294+
getDelegate().setLocalNightMode(mode);
295+
}
296+
284297
@MainThread
285298
@StyleRes
286299
private int getSelectedTheme() {
287-
if (mUseDefaultTheme.isChecked()) {
288-
return AuthUI.getDefaultTheme();
300+
if (mUseGreenTheme.isChecked()) {
301+
return R.style.GreenTheme;
289302
}
290303

291304
if (mUsePurpleTheme.isChecked()) {
292305
return R.style.PurpleTheme;
293306
}
294307

295-
if (mUseDarkTheme.isChecked()) {
296-
return R.style.DarkTheme;
297-
}
298-
299-
return R.style.GreenTheme;
308+
return AuthUI.getDefaultTheme();
300309
}
301310

302311
@MainThread
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<color name="colorPrimary">#016AA8</color>
3+
<color name="colorPrimaryDark">#01579B</color>
4+
</resources>

app/src/main/res/values-v21/styles.xml

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/src/main/res/values/colors.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
<color name="colorPrimaryDark">#0288D1</color>
44
<color name="colorAccent">#FFA000</color>
55

6-
<!-- Text -->
7-
<color name="text_default_material_dark_primary">#ffffffff</color>
8-
<color name="text_default_material_light_primary">#de000000</color>
9-
<color name="text_default_material_dark_secondary">#b3ffffff</color>
10-
<color name="text_default_material_light_secondary">#8a000000</color>
11-
126
<color name="material_deep_purple_50">#EDE7F6</color>
137
<color name="material_deep_purple_500">#673AB7</color>
148
<color name="material_deep_purple_700">#512DA8</color>
@@ -20,15 +14,9 @@
2014

2115
<color name="material_gray_300">#E0E0E0</color>
2216
<color name="material_gray_500">#9e9e9e</color>
23-
<color name="material_gray_850">#ff303030</color>
24-
<color name="material_gray_900">#ff212121</color>
2517

2618
<color name="material_lime_a700">#AEEA00</color>
27-
28-
<color name="material_purple_50">#F3E5F5</color>
2919
<color name="material_purple_a700">#AA00FF</color>
30-
3120
<color name="material_red_a200">#FF5252</color>
3221

33-
<color name="material_deep_teal_a200">#ff80cbc4</color>
3422
</resources>

app/src/main/res/values/styles.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@
2121
<item name="android:windowBackground">@color/material_green_50</item>
2222
</style>
2323

24-
<style name="DarkTheme">
25-
<item name="colorPrimary">@color/material_gray_900</item>
26-
<item name="colorPrimaryDark">@android:color/black</item>
27-
<item name="colorAccent">@android:color/black</item>
28-
<item name="android:colorBackground">@color/material_gray_850</item>
29-
<item name="android:colorForeground">@android:color/white</item>
30-
<item name="android:textColor">@color/text_default_material_dark_primary</item>
31-
<item name="android:textColorPrimary">@color/text_default_material_dark_primary</item>
32-
<item name="android:textColorPrimaryInverse">@color/text_default_material_light_primary</item>
33-
<item name="android:textColorSecondary">@color/text_default_material_dark_secondary</item>
34-
<item name="android:textColorSecondaryInverse">@color/text_default_material_light_secondary</item>
35-
<item name="android:windowBackground">@color/material_gray_850</item>
36-
</style>
37-
3824
<style name="WarnButton" parent="Widget.AppCompat.Button.Colored">
3925
<item name="colorButtonNormal">@color/material_red_a200</item>
4026
<item name="android:textColor">@android:color/white</item>

0 commit comments

Comments
 (0)