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

Commit a47801a

Browse files
jainkuniyakunall17
authored andcommitted
Restore theme after closing/reopening the app.
Fix:#505
1 parent f330a95 commit a47801a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,15 @@ public void setMessageContentEditParams(int seconds, boolean param) {
598598
}
599599
}
600600
}
601+
602+
/**
603+
* Update preferred theme
604+
* @param b true if night theme is preferred
605+
*/
606+
public void makeNightThemeDefault(boolean nightTheme) {
607+
SharedPreferences.Editor editor = getSettings().edit();
608+
609+
editor.putBoolean(Constants.NIGHT_THEME, nightTheme);
610+
editor.apply();
611+
}
601612
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ protected void onCreate(Bundle savedInstanceState) {
354354
mMutedTopics = MutedTopics.get();
355355
}
356356

357+
boolean isCurrentThemeNight = (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES);
358+
359+
//apply preferred theme
360+
if (app.getSettings().getBoolean(Constants.NIGHT_THEME, false) && !isCurrentThemeNight) {
361+
setNightMode(AppCompatDelegate.MODE_NIGHT_YES);
362+
}
363+
357364
this.logged_in = true;
358365
notifications = new Notifications(this);
359366
notifications.register();
@@ -386,7 +393,7 @@ public void onClick(View v) {
386393
sendBtn = (ImageView) findViewById(R.id.send_btn);
387394
addFileBtn = (ImageView) findViewById(R.id.add_btn);
388395
appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
389-
boolean isCurrentThemeNight = (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES);
396+
390397
etSearchPeople = (EditText) findViewById(R.id.people_drawer_search);
391398
ivSearchPeopleCancel = (ImageView) findViewById(R.id.iv_people__search_cancel_button);
392399
onTextChangeOfPeopleSearchEditText();
@@ -2358,12 +2365,11 @@ public void onClick(
23582365
case -1:
23592366
case AppCompatDelegate.MODE_NIGHT_NO:
23602367
setNightMode(AppCompatDelegate.MODE_NIGHT_YES);
2361-
break;
2362-
case AppCompatDelegate.MODE_NIGHT_YES:
2363-
setNightMode(AppCompatDelegate.MODE_NIGHT_NO);
2368+
app.makeNightThemeDefault(true);
23642369
break;
23652370
default:
23662371
setNightMode(AppCompatDelegate.MODE_NIGHT_NO);
2372+
app.makeNightThemeDefault(false);
23672373
break;
23682374
}
23692375
break;

app/src/main/java/com/zulip/android/util/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ public class Constants {
2727
//if two continuous messages are from same sender and time difference is less than this then hide it
2828
public static long HIDE_TIMESTAMP_THRESHOLD = 60 * 1000;// 1 minute
2929
public static String ACTION_MESSAGE_PUSH_NOTIFICATION = "ACTION_MESSAGE_PUSH_NOTIFICATION";
30+
public static String NIGHT_THEME = "NIGHT_THEME";
3031
}

0 commit comments

Comments
 (0)