mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-06-05 06:10:18 +00:00
Refactor dark mode to allow multiple themes
This commit is contained in:
parent
9baaf824c6
commit
cf4aecbd3e
7 changed files with 64 additions and 17 deletions
|
@ -43,6 +43,15 @@ public class Preferences {
|
||||||
return _prefs.getInt("pref_tap_to_reveal_time", 30);
|
return _prefs.getInt("pref_tap_to_reveal_time", 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCurrentTheme() {
|
||||||
|
return _prefs.getInt("pref_current_theme", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentTheme(Theme theme) {
|
||||||
|
_prefs.edit().putInt("pref_current_theme", theme.ordinal()).apply();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getTimeout() {
|
public int getTimeout() {
|
||||||
return _prefs.getInt("pref_timeout", -1);
|
return _prefs.getInt("pref_timeout", -1);
|
||||||
|
|
19
app/src/main/java/com/beemdevelopment/aegis/Theme.java
Normal file
19
app/src/main/java/com/beemdevelopment/aegis/Theme.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package com.beemdevelopment.aegis;
|
||||||
|
|
||||||
|
public enum Theme {
|
||||||
|
LIGHT,
|
||||||
|
DARK,
|
||||||
|
AMOLED;
|
||||||
|
|
||||||
|
public static Theme fromInteger(int x) {
|
||||||
|
switch(x) {
|
||||||
|
case 0:
|
||||||
|
return LIGHT;
|
||||||
|
case 1:
|
||||||
|
return DARK;
|
||||||
|
case 2:
|
||||||
|
return AMOLED;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import android.view.WindowManager;
|
||||||
import com.beemdevelopment.aegis.AegisApplication;
|
import com.beemdevelopment.aegis.AegisApplication;
|
||||||
import com.beemdevelopment.aegis.Preferences;
|
import com.beemdevelopment.aegis.Preferences;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
|
import com.beemdevelopment.aegis.Theme;
|
||||||
|
|
||||||
public abstract class AegisActivity extends AppCompatActivity {
|
public abstract class AegisActivity extends AppCompatActivity {
|
||||||
private AegisApplication _app;
|
private AegisApplication _app;
|
||||||
|
@ -22,7 +23,7 @@ public abstract class AegisActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the theme
|
// set the theme
|
||||||
setPreferredTheme(getPreferences().isDarkModeEnabled());
|
setPreferredTheme(Theme.fromInteger(getPreferences().getCurrentTheme()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AegisApplication getApp() {
|
protected AegisApplication getApp() {
|
||||||
|
@ -33,11 +34,19 @@ public abstract class AegisActivity extends AppCompatActivity {
|
||||||
return _app.getPreferences();
|
return _app.getPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPreferredTheme(boolean darkMode) {
|
protected void setPreferredTheme(Theme theme) {
|
||||||
if (darkMode) {
|
switch (theme) {
|
||||||
setTheme(R.style.AppTheme_Dark);
|
case LIGHT:
|
||||||
} else {
|
setTheme(R.style.AppTheme);
|
||||||
setTheme(R.style.AppTheme);
|
break;
|
||||||
|
|
||||||
|
case DARK:
|
||||||
|
setTheme(R.style.AppTheme_Dark);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AMOLED:
|
||||||
|
setTheme(R.style.AppTheme_TrueBlack);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import android.widget.TableRow;
|
||||||
|
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
import com.avito.android.krop.KropView;
|
import com.avito.android.krop.KropView;
|
||||||
|
import com.beemdevelopment.aegis.Theme;
|
||||||
import com.beemdevelopment.aegis.encoding.Base32;
|
import com.beemdevelopment.aegis.encoding.Base32;
|
||||||
import com.beemdevelopment.aegis.encoding.Base32Exception;
|
import com.beemdevelopment.aegis.encoding.Base32Exception;
|
||||||
import com.beemdevelopment.aegis.helpers.EditTextHelper;
|
import com.beemdevelopment.aegis.helpers.EditTextHelper;
|
||||||
|
@ -253,15 +254,6 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setPreferredTheme(boolean darkMode) {
|
|
||||||
if (darkMode) {
|
|
||||||
setTheme(R.style.AppTheme_Dark);
|
|
||||||
} else {
|
|
||||||
setTheme(R.style.AppTheme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openAdvancedSettings() {
|
private void openAdvancedSettings() {
|
||||||
Animation fadeOut = new AlphaAnimation(1, 0);
|
Animation fadeOut = new AlphaAnimation(1, 0);
|
||||||
fadeOut.setInterpolator(new AccelerateInterpolator());
|
fadeOut.setInterpolator(new AccelerateInterpolator());
|
||||||
|
|
|
@ -2,6 +2,9 @@ package com.beemdevelopment.aegis.ui;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.beemdevelopment.aegis.R;
|
||||||
|
import com.beemdevelopment.aegis.Theme;
|
||||||
|
|
||||||
public class PreferencesActivity extends AegisActivity {
|
public class PreferencesActivity extends AegisActivity {
|
||||||
private PreferencesFragment _fragment;
|
private PreferencesFragment _fragment;
|
||||||
|
|
||||||
|
@ -36,4 +39,18 @@ public class PreferencesActivity extends AegisActivity {
|
||||||
outState.putParcelable("result", _fragment.getResult());
|
outState.putParcelable("result", _fragment.getResult());
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setPreferredTheme(Theme theme) {
|
||||||
|
switch (theme) {
|
||||||
|
case LIGHT:
|
||||||
|
setTheme(R.style.AppTheme);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DARK:
|
||||||
|
case AMOLED:
|
||||||
|
setTheme(R.style.AppTheme_Dark);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.beemdevelopment.aegis.Theme;
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
import com.beemdevelopment.aegis.helpers.SquareFinderView;
|
import com.beemdevelopment.aegis.helpers.SquareFinderView;
|
||||||
|
@ -57,7 +58,7 @@ public class ScannerActivity extends AegisActivity implements ZXingScannerView.R
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setPreferredTheme(boolean darkMode) {
|
protected void setPreferredTheme(Theme theme) {
|
||||||
setTheme(R.style.AppTheme_Fullscreen);
|
setTheme(R.style.AppTheme_Fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="Appearance"
|
android:title="Appearance"
|
||||||
app:iconSpaceReserved="false">
|
app:iconSpaceReserved="false">
|
||||||
<androidx.preference.SwitchPreferenceCompat
|
<Preference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="pref_dark_mode"
|
android:key="pref_dark_mode"
|
||||||
android:title="@string/pref_dark_mode_title"
|
android:title="@string/pref_dark_mode_title"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue