mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Added Support for System Wide Dark Theme (#3460)
* Added Support for System Wide Dark Theme * changed methods to private * Moved Strings to strings.xml * Used Dagger to reduce code repetition * Changes made as per review suggestions * Minor Changes * Fixes as per suggestions * Minor Fixes as per suggestion * made the variables static * removed irrelevant code
This commit is contained in:
parent
65ec071493
commit
1584ffe0e2
9 changed files with 139 additions and 42 deletions
|
|
@ -8,6 +8,7 @@ import javax.inject.Named;
|
|||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerAppCompatActivity;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.utils.SystemThemeUtils;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public abstract class BaseActivity extends CommonsDaggerAppCompatActivity {
|
||||
|
|
@ -15,20 +16,23 @@ public abstract class BaseActivity extends CommonsDaggerAppCompatActivity {
|
|||
@Named("default_preferences")
|
||||
public JsonKvStore defaultKvStore;
|
||||
|
||||
@Inject
|
||||
SystemThemeUtils systemThemeUtils;
|
||||
|
||||
protected CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
protected boolean wasPreviouslyDarkTheme;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
wasPreviouslyDarkTheme = defaultKvStore.getBoolean("theme", false);
|
||||
wasPreviouslyDarkTheme = systemThemeUtils.isDeviceInNightMode();
|
||||
setTheme(wasPreviouslyDarkTheme ? R.style.DarkAppTheme : R.style.LightAppTheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Restart activity if theme is changed
|
||||
if (wasPreviouslyDarkTheme != defaultKvStore.getBoolean("theme", false)) {
|
||||
if (wasPreviouslyDarkTheme != systemThemeUtils.isDeviceInNightMode()) {
|
||||
recreate();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue