Fix two minor issues in themes

- Neatly map configured themes to styles
- Make the dark NoActionBar themes inherit from Dark/AMOLED
This commit is contained in:
Alexander Bakker 2020-07-11 18:42:44 +02:00
parent 0eb9a25687
commit 2aa88a2921
7 changed files with 59 additions and 65 deletions

View file

@ -13,14 +13,16 @@ import com.beemdevelopment.aegis.AegisApplication;
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.Theme;
import com.beemdevelopment.aegis.ThemeMap;
import com.beemdevelopment.aegis.vault.VaultManagerException;
import java.util.Locale;
import java.util.Map;
public abstract class AegisActivity extends AppCompatActivity implements AegisApplication.LockListener {
private boolean _resumed;
private AegisApplication _app;
private Theme _currentTheme;
private Theme _configuredTheme;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -28,7 +30,7 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
// set the theme and locale before creating the activity
Preferences prefs = getPreferences();
setPreferredTheme(prefs.getCurrentTheme());
onSetTheme();
setLocale(prefs.getLocale());
super.onCreate(savedInstanceState);
@ -84,9 +86,26 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
return _app.getPreferences();
}
protected void setPreferredTheme(Theme theme) {
/**
* Called when the activity is expected to set its theme.
*/
protected void onSetTheme() {
setTheme(ThemeMap.DEFAULT);
}
/**
* Sets the theme of the activity. The actual style that is set is picked from the
* given map, based on the theme configured by the user.
*/
protected void setTheme(Map<Theme, Integer> themeMap) {
int theme = themeMap.get(getConfiguredTheme());
setTheme(theme);
}
protected Theme getConfiguredTheme() {
Theme theme = getPreferences().getCurrentTheme();
if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
// set the theme based on the system theme
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
@ -98,19 +117,7 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
}
}
_currentTheme = theme;
switch (theme) {
case LIGHT:
setTheme(R.style.AppTheme);
break;
case DARK:
setTheme(R.style.AppTheme_Dark);
break;
case AMOLED:
setTheme(R.style.AppTheme_TrueBlack);
break;
}
return theme;
}
protected void setLocale(Locale locale) {
@ -146,8 +153,4 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
private boolean isOrphan() {
return !(this instanceof MainActivity) && !(this instanceof AuthActivity) && _app.isVaultLocked();
}
protected Theme getCurrentTheme() {
return _currentTheme;
}
}