Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit b2cd8e1

Browse files
jainkuniyakunall17
authored andcommitted
Added 3 options in menu (day/night/auto theme).
1 parent 5a95547 commit b2cd8e1

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,8 +2259,13 @@ public boolean onCreateOptionsMenu(Menu menu) {
22592259
getMenuInflater().inflate(R.menu.options, menu);
22602260
prepareSearchView(menu);
22612261
this.menu = menu;
2262-
menu.findItem(R.id.autoTheme).setChecked(app.getSettings()
2263-
.getBoolean(Constants.AUTO_NIGHT_THEME, false));
2262+
if (app.getSettings().getBoolean(Constants.AUTO_NIGHT_THEME, false)) {
2263+
menu.findItem(R.id.autoTheme).setChecked(true);
2264+
} else if (app.getSettings().getBoolean(Constants.NIGHT_THEME, false)) {
2265+
menu.findItem(R.id.nightTheme).setChecked(true);
2266+
} else {
2267+
menu.findItem(R.id.dayTheme).setChecked(true);
2268+
}
22642269
return true;
22652270
}
22662271

@@ -2363,17 +2368,22 @@ public void onClick(
23632368
case R.id.private_msg:
23642369
drawerLayout.openDrawer(GravityCompat.END);
23652370
break;
2366-
case R.id.daynight:
2367-
switch (AppCompatDelegate.getDefaultNightMode()) {
2368-
case -1:
2369-
case AppCompatDelegate.MODE_NIGHT_NO:
2370-
setNightMode(AppCompatDelegate.MODE_NIGHT_YES);
2371-
app.makeNightThemeDefault(true);
2372-
break;
2373-
default:
2374-
setNightMode(AppCompatDelegate.MODE_NIGHT_NO);
2375-
app.makeNightThemeDefault(false);
2376-
break;
2371+
case R.id.dayTheme:
2372+
item.setChecked(!item.isChecked());
2373+
if (item.isChecked() &&
2374+
AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO) {
2375+
setNightMode(AppCompatDelegate.MODE_NIGHT_NO);
2376+
app.makeNightThemeDefault(false);
2377+
app.setAutoNightTheme(false);
2378+
}
2379+
break;
2380+
case R.id.nightTheme:
2381+
item.setChecked(!item.isChecked());
2382+
if (item.isChecked() &&
2383+
AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) {
2384+
setNightMode(AppCompatDelegate.MODE_NIGHT_YES);
2385+
app.makeNightThemeDefault(true);
2386+
app.setAutoNightTheme(false);
23772387
}
23782388
break;
23792389
case R.id.autoTheme:

app/src/main/res/menu/options.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@
3838
android:id="@+id/theme"
3939
android:title="@string/theme">
4040
<menu>
41-
<item
42-
android:id="@+id/daynight"
43-
android:title="@string/switch_theme" />
44-
<item
45-
android:id="@+id/autoTheme"
46-
android:checkable="true"
47-
android:title="@string/autoTheme"
48-
app:actionViewClass="android.widget.CheckBox" />
41+
<group
42+
android:id="@+id/group"
43+
android:checkableBehavior="single">
44+
<item
45+
android:id="@+id/dayTheme"
46+
android:title="@string/dayTheme" />
47+
<item
48+
android:id="@+id/nightTheme"
49+
android:title="@string/nightTheme" />
50+
<item
51+
android:id="@+id/autoTheme"
52+
android:title="@string/autoTheme" />
53+
</group>
4954
</menu>
5055
</item>
5156

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
<string name="use_https">Use HTTPS</string>
8585
<string name="use_http">Use HTTP</string>
8686
<string name="empty_list">Sorry, no messages here.</string>
87-
<string name="switch_theme">Switch day/night theme</string>
8887
<string name="reply_stream">Reply to stream</string>
8988
<string name="reply_sender">Reply to sender</string>
9089
<string name="narrow_stream">Narrow to this stream</string>
@@ -175,13 +174,14 @@
175174
<string name="logout_title">Are you sure you want to logout?</string>
176175
<string name="autoTheme">Auto Night Theme</string>
177176
<string name="theme">Theme</string>
178-
<string name="terms">Terms of Service</string>
177+
<string name="terms">Terms Of Service</string>
178+
<string name="nightTheme">Night Theme</string>
179+
<string name="dayTheme">Day Theme</string>
179180
<!--Placeholder strings-->
180181
<string name="placeholder_my_stream">MyStream</string>
181182
<string name="placeholder_short_stream">Short stream</string>
182183
<string name="placeholder_topic">Topic</string>
183184
<string name="placeholder_message_here">Message here</string>
184185
<string name="placeholder_sender_name">Sender name</string>
185186
<string name="placeholder_social">Social</string>
186-
187187
</resources>

0 commit comments

Comments
 (0)