mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 05:52:52 +00:00
Rework theming a bit to partially fix dark mode on dialogs
Dark mode is still not great, but at least it's a little less broken now
This commit is contained in:
parent
3c2f62de26
commit
7be5d08a60
15 changed files with 79 additions and 132 deletions
|
@ -8,6 +8,7 @@ import me.impy.aegis.AegisApplication;
|
|||
|
||||
public abstract class AegisActivity extends AppCompatActivity {
|
||||
private AegisApplication _app;
|
||||
private boolean _darkMode;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -18,13 +19,17 @@ public abstract class AegisActivity extends AppCompatActivity {
|
|||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
||||
|
||||
// set the theme
|
||||
boolean darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);
|
||||
setPreferredTheme(darkMode);
|
||||
_darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);
|
||||
setPreferredTheme(_darkMode);
|
||||
}
|
||||
|
||||
protected AegisApplication getApp() {
|
||||
return _app;
|
||||
}
|
||||
|
||||
protected boolean isDark() {
|
||||
return _darkMode;
|
||||
}
|
||||
|
||||
protected abstract void setPreferredTheme(boolean darkMode);
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
|
|||
if (darkMode) {
|
||||
setTheme(R.style.AppTheme_Dark);
|
||||
} else {
|
||||
setTheme(R.style.AppTheme_Default);
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import android.view.animation.AlphaAnimation;
|
|||
import android.view.animation.Animation;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Spinner;
|
||||
|
@ -54,8 +53,6 @@ public class EditProfileActivity extends AegisActivity {
|
|||
private RelativeLayout _advancedSettingsHeader;
|
||||
private RelativeLayout _advancedSettings;
|
||||
|
||||
int _dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -122,12 +119,12 @@ public class EditProfileActivity extends AegisActivity {
|
|||
});
|
||||
|
||||
_advancedSettingsHeader.setOnClickListener(v -> {
|
||||
OpenAdvancedSettings();
|
||||
openAdvancedSettings();
|
||||
});
|
||||
|
||||
// Automatically open advanced settings since 'Secret' is required.
|
||||
if(_isNew){
|
||||
OpenAdvancedSettings();
|
||||
openAdvancedSettings();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,15 +155,13 @@ public class EditProfileActivity extends AegisActivity {
|
|||
@Override
|
||||
protected void setPreferredTheme(boolean darkMode) {
|
||||
if (darkMode) {
|
||||
_dialogStyle = android.R.style.Theme_Material_Dialog_NoActionBar;
|
||||
setTheme(R.style.AppTheme_Dark_TransparentActionBar);
|
||||
} else {
|
||||
_dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar;
|
||||
setTheme(R.style.AppTheme_Default_TransparentActionBar);
|
||||
setTheme(R.style.AppTheme_TransparentActionBar);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenAdvancedSettings() {
|
||||
private void openAdvancedSettings() {
|
||||
Animation fadeOut = new AlphaAnimation(1, 0); // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0)
|
||||
fadeOut.setInterpolator(new AccelerateInterpolator());
|
||||
fadeOut.setDuration(220); // Fadeout duration should be 1000 milli seconds
|
||||
|
@ -219,7 +214,7 @@ public class EditProfileActivity extends AegisActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this, _dialogStyle)
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Discard changes?")
|
||||
.setMessage("Your changes have not been saved")
|
||||
.setPositiveButton(R.string.save, (dialog, which) -> onSave())
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -47,7 +48,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|||
private DatabaseManager _db;
|
||||
private KeyProfileView _keyProfileView;
|
||||
|
||||
private boolean _darkMode = false;
|
||||
private Menu _menu;
|
||||
private FloatingActionsMenu _fabMenu;
|
||||
|
||||
|
@ -59,7 +59,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|||
|
||||
// set up the main view
|
||||
setContentView(R.layout.activity_main);
|
||||
setSupportActionBar(findViewById(R.id.toolbar));
|
||||
|
||||
// set up the key profile view
|
||||
_keyProfileView = (KeyProfileView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
|
||||
|
@ -140,11 +139,10 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|||
@Override
|
||||
protected void setPreferredTheme(boolean darkMode) {
|
||||
if (darkMode) {
|
||||
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
||||
} else if (_darkMode) {
|
||||
setTheme(R.style.AppTheme_Default_NoActionBar);
|
||||
setTheme(R.style.AppTheme_Dark);
|
||||
} else {
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
_darkMode = darkMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -346,7 +344,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|||
super.onResume();
|
||||
|
||||
boolean darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);
|
||||
if (darkMode != _darkMode) {
|
||||
if (darkMode != isDark()) {
|
||||
setPreferredTheme(darkMode);
|
||||
recreate();
|
||||
}
|
||||
|
@ -356,39 +354,34 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|||
}
|
||||
|
||||
private BottomSheetDialog createBottomSheet(final KeyProfile profile) {
|
||||
View bottomSheetView = getLayoutInflater().inflate(R.layout.bottom_sheet_edit_profile, null);
|
||||
LinearLayout copyLayout = bottomSheetView.findViewById(R.id.copy_button);
|
||||
LinearLayout deleteLayout = bottomSheetView.findViewById(R.id.delete_button);
|
||||
LinearLayout editLayout = bottomSheetView.findViewById(R.id.edit_button);
|
||||
bottomSheetView.findViewById(R.id.edit_button);
|
||||
BottomSheetDialog bottomDialog = new BottomSheetDialog(this);
|
||||
bottomDialog.setContentView(bottomSheetView);
|
||||
bottomDialog.setCancelable(true);
|
||||
bottomDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(this);
|
||||
dialog.setContentView(R.layout.bottom_sheet_edit_profile);
|
||||
dialog.setCancelable(true);
|
||||
dialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
bottomDialog.show();
|
||||
dialog.show();
|
||||
|
||||
copyLayout.setOnClickListener(view -> {
|
||||
bottomDialog.dismiss();
|
||||
dialog.findViewById(R.id.copy_button).setOnClickListener(view -> {
|
||||
dialog.dismiss();
|
||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("text/plain", profile.getCode());
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toast.makeText(this.getApplicationContext(), "Code copied to the clipboard", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, "Code copied to the clipboard", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
deleteLayout.setOnClickListener(view -> {
|
||||
bottomDialog.dismiss();
|
||||
Dialogs.showDeleteEntryDialog(this, (dialog, which) -> {
|
||||
dialog.findViewById(R.id.delete_button).setOnClickListener(view -> {
|
||||
dialog.dismiss();
|
||||
Dialogs.showDeleteEntryDialog(this, (d, which) -> {
|
||||
deleteProfile(profile);
|
||||
});
|
||||
});
|
||||
|
||||
editLayout.setOnClickListener(view -> {
|
||||
bottomDialog.dismiss();
|
||||
dialog.findViewById(R.id.edit_button).setOnClickListener(view -> {
|
||||
dialog.dismiss();
|
||||
startEditProfileActivity(CODE_EDIT_KEYINFO, profile, false);
|
||||
});
|
||||
|
||||
return bottomDialog;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void deleteProfile(KeyProfile profile) {
|
||||
|
|
|
@ -21,7 +21,7 @@ public class PreferencesActivity extends AegisActivity {
|
|||
if (darkMode) {
|
||||
setTheme(R.style.AppTheme_Dark);
|
||||
} else {
|
||||
setTheme(R.style.AppTheme_Default);
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,8 @@ public class SlotManagerActivity extends AegisActivity implements SlotAdapter.Li
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// set up the view
|
||||
setContentView(R.layout.activity_slots);
|
||||
setSupportActionBar(findViewById(R.id.toolbar));
|
||||
|
||||
ActionBar bar = getSupportActionBar();
|
||||
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
||||
bar.setDisplayHomeAsUpEnabled(true);
|
||||
|
@ -105,9 +103,9 @@ public class SlotManagerActivity extends AegisActivity implements SlotAdapter.Li
|
|||
@Override
|
||||
protected void setPreferredTheme(boolean darkMode) {
|
||||
if (darkMode) {
|
||||
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
||||
setTheme(R.style.AppTheme_Dark);
|
||||
} else {
|
||||
setTheme(R.style.AppTheme_Default_NoActionBar);
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package me.impy.aegis.ui.dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
|
@ -9,8 +9,8 @@ public class Dialogs {
|
|||
|
||||
}
|
||||
|
||||
public static AlertDialog showDeleteEntryDialog(Context context, DialogInterface.OnClickListener onDelete) {
|
||||
return new AlertDialog.Builder(context)
|
||||
public static AlertDialog showDeleteEntryDialog(Activity activity, DialogInterface.OnClickListener onDelete) {
|
||||
return new AlertDialog.Builder(activity)
|
||||
.setTitle("Delete entry")
|
||||
.setMessage("Are you sure you want to delete this entry?")
|
||||
.setPositiveButton(android.R.string.yes, onDelete)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue