Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the dark mode override 'stick' (#1104) #1105

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import edu.usf.cutr.open311client.models.Open311Option;

import static com.google.android.gms.location.LocationServices.getFusedLocationProviderClient;
import static org.onebusaway.android.util.UIUtils.setAppTheme;

public class Application extends MultiDexApplication {

Expand Down Expand Up @@ -436,6 +437,7 @@ private void initOba() {
}

checkArrivalStylePreferenceDefault();
checkDarkMode();

// Get the current app version.
PackageManager pm = getPackageManager();
Expand Down Expand Up @@ -481,6 +483,15 @@ private void checkArrivalStylePreferenceDefault() {
}
}

private void checkDarkMode() {
String appThemePrefKey = getResources()
.getString(R.string.preference_key_app_theme);
String appThemePref = mPrefs.getString(appThemePrefKey, null);
if (appThemePref != null) {
setAppTheme(appThemePref);
}
}

private void initObaRegion() {
// Read the region preference, look it up in the DB, then set the region.
long id = mPrefs.getLong(getString(R.string.preference_key_region), -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.onebusaway.android.util.PermissionUtils.RESTORE_BACKUP_PERMISSION_REQUEST;
import static org.onebusaway.android.util.PermissionUtils.SAVE_BACKUP_PERMISSION_REQUEST;
import static org.onebusaway.android.util.PermissionUtils.STORAGE_PERMISSIONS;
import static org.onebusaway.android.util.UIUtils.setAppTheme;

import android.annotation.SuppressLint;
import android.app.Activity;
Expand Down Expand Up @@ -666,16 +667,4 @@ public void onRegionTaskFinished(boolean currentRegionChanged) {
NavHelp.goHome(this, false);
}
}

private void setAppTheme(String themeValue) {
if (themeValue.equalsIgnoreCase(Application.get().getString(R.string.preferences_app_theme_option_system_default))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
if (themeValue.equalsIgnoreCase(Application.get().getString(R.string.preferences_app_theme_option_dark))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
if (themeValue.equalsIgnoreCase(Application.get().getString(R.string.preferences_app_theme_option_light))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.core.content.pm.ShortcutInfoCompat;
Expand Down Expand Up @@ -2010,4 +2011,16 @@ public static void openBatteryIgnoreIntent(Activity activity) {
intent.setData(Uri.parse("package:" + activity.getPackageName()));
activity.startActivity(intent);
}

public static void setAppTheme(String themeValue) {
if (themeValue.equalsIgnoreCase(Application.get().getString(R.string.preferences_app_theme_option_system_default))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
if (themeValue.equalsIgnoreCase(Application.get().getString(R.string.preferences_app_theme_option_dark))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
if (themeValue.equalsIgnoreCase(Application.get().getString(R.string.preferences_app_theme_option_light))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
}