mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 14:59:14 +00:00
Merge pull request #1005 from alexbakker/predictive-back
Add support for predictive back gesture
This commit is contained in:
commit
41eba76b05
15 changed files with 395 additions and 212 deletions
|
@ -131,6 +131,7 @@ dependencies {
|
||||||
annotationProcessor "com.github.bumptech.glide:compiler:${glideVersion}"
|
annotationProcessor "com.github.bumptech.glide:compiler:${glideVersion}"
|
||||||
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
implementation 'androidx.activity:activity:1.6.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.5.1'
|
implementation 'androidx.appcompat:appcompat:1.5.1'
|
||||||
implementation "androidx.biometric:biometric:1.1.0"
|
implementation "androidx.biometric:biometric:1.1.0"
|
||||||
implementation "androidx.camera:camera-camera2:$cameraxVersion"
|
implementation "androidx.camera:camera-camera2:$cameraxVersion"
|
||||||
|
|
|
@ -20,12 +20,13 @@
|
||||||
android:fullBackupContent="@xml/backup_rules_old"
|
android:fullBackupContent="@xml/backup_rules_old"
|
||||||
android:dataExtractionRules="@xml/backup_rules"
|
android:dataExtractionRules="@xml/backup_rules"
|
||||||
android:backupAgent=".AegisBackupAgent"
|
android:backupAgent=".AegisBackupAgent"
|
||||||
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:icon="@mipmap/${iconName}"
|
android:icon="@mipmap/${iconName}"
|
||||||
android:label="Aegis"
|
android:label="Aegis"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.Aegis.Launch"
|
android:theme="@style/Theme.Aegis.Launch"
|
||||||
tools:replace="android:theme"
|
tools:replace="android:theme"
|
||||||
tools:targetApi="s">
|
tools:targetApi="tiramisu">
|
||||||
<activity android:name=".ui.TransferEntriesActivity"
|
<activity android:name=".ui.TransferEntriesActivity"
|
||||||
android:label="@string/title_activity_transfer" />
|
android:label="@string/title_activity_transfer" />
|
||||||
<activity
|
<activity
|
||||||
|
|
|
@ -4,6 +4,9 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
|
import androidx.documentfile.provider.DocumentFile;
|
||||||
|
|
||||||
public class SafHelper {
|
public class SafHelper {
|
||||||
private SafHelper() {
|
private SafHelper() {
|
||||||
|
@ -24,4 +27,21 @@ public class SafHelper {
|
||||||
|
|
||||||
return uri.getLastPathSegment();
|
return uri.getLastPathSegment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getMimeType(Context context, Uri uri) {
|
||||||
|
DocumentFile file = DocumentFile.fromSingleUri(context, uri);
|
||||||
|
if (file != null) {
|
||||||
|
String fileType = file.getType();
|
||||||
|
if (fileType != null) {
|
||||||
|
return fileType;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ext = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
|
||||||
|
if (ext != null) {
|
||||||
|
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.beemdevelopment.aegis.helpers;
|
||||||
|
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
|
||||||
|
public final class SimpleTextWatcher implements TextWatcher {
|
||||||
|
private final Listener _listener;
|
||||||
|
|
||||||
|
public SimpleTextWatcher(Listener listener) {
|
||||||
|
_listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
if (_listener != null) {
|
||||||
|
_listener.afterTextChanged(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Listener {
|
||||||
|
void afterTextChanged(Editable s);
|
||||||
|
}
|
||||||
|
}
|
|
@ -160,7 +160,7 @@ public class AboutActivity extends AegisActivity {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
onBackPressed();
|
finish();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.widget.PopupWindow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.biometric.BiometricPrompt;
|
import androidx.biometric.BiometricPrompt;
|
||||||
|
@ -76,6 +77,8 @@ public class AuthActivity extends AegisActivity {
|
||||||
Button decryptButton = findViewById(R.id.button_decrypt);
|
Button decryptButton = findViewById(R.id.button_decrypt);
|
||||||
TextView biometricsButton = findViewById(R.id.button_biometrics);
|
TextView biometricsButton = findViewById(R.id.button_biometrics);
|
||||||
|
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, new BackPressHandler());
|
||||||
|
|
||||||
_textPassword.setOnEditorActionListener((v, actionId, event) -> {
|
_textPassword.setOnEditorActionListener((v, actionId, event) -> {
|
||||||
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
|
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
|
||||||
decryptButton.performClick();
|
decryptButton.performClick();
|
||||||
|
@ -102,7 +105,9 @@ public class AuthActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_vaultManager.getVaultFileError() != null) {
|
if (_vaultManager.getVaultFileError() != null) {
|
||||||
Dialogs.showErrorDialog(this, R.string.vault_load_error, _vaultManager.getVaultFileError(), (dialog, which) -> onBackPressed());
|
Dialogs.showErrorDialog(this, R.string.vault_load_error, _vaultManager.getVaultFileError(), (dialog, which) -> {
|
||||||
|
getOnBackPressedDispatcher().onBackPressed();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,11 +184,6 @@ public class AuthActivity extends AegisActivity {
|
||||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
finishAffinity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -301,6 +301,19 @@ public class AuthActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class BackPressHandler extends OnBackPressedCallback {
|
||||||
|
public BackPressHandler() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
// This breaks predictive back gestures, but it doesn't make sense
|
||||||
|
// to go back to MainActivity when cancelling auth
|
||||||
|
finishAffinity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class PasswordDerivationListener implements PasswordSlotDecryptTask.Callback {
|
private class PasswordDerivationListener implements PasswordSlotDecryptTask.Callback {
|
||||||
@Override
|
@Override
|
||||||
public void onTaskFinished(PasswordSlotDecryptTask.Result result) {
|
public void onTaskFinished(PasswordSlotDecryptTask.Result result) {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -16,18 +15,17 @@ import android.view.ViewGroup;
|
||||||
import android.view.animation.AccelerateInterpolator;
|
import android.view.animation.AccelerateInterpolator;
|
||||||
import android.view.animation.AlphaAnimation;
|
import android.view.animation.AlphaAnimation;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.webkit.MimeTypeMap;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.documentfile.provider.DocumentFile;
|
|
||||||
|
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
import com.avito.android.krop.KropView;
|
import com.avito.android.krop.KropView;
|
||||||
|
@ -38,6 +36,8 @@ import com.beemdevelopment.aegis.encoding.Hex;
|
||||||
import com.beemdevelopment.aegis.helpers.DropdownHelper;
|
import com.beemdevelopment.aegis.helpers.DropdownHelper;
|
||||||
import com.beemdevelopment.aegis.helpers.EditTextHelper;
|
import com.beemdevelopment.aegis.helpers.EditTextHelper;
|
||||||
import com.beemdevelopment.aegis.helpers.IconViewHelper;
|
import com.beemdevelopment.aegis.helpers.IconViewHelper;
|
||||||
|
import com.beemdevelopment.aegis.helpers.SafHelper;
|
||||||
|
import com.beemdevelopment.aegis.helpers.SimpleTextWatcher;
|
||||||
import com.beemdevelopment.aegis.helpers.TextDrawableHelper;
|
import com.beemdevelopment.aegis.helpers.TextDrawableHelper;
|
||||||
import com.beemdevelopment.aegis.icons.IconPack;
|
import com.beemdevelopment.aegis.icons.IconPack;
|
||||||
import com.beemdevelopment.aegis.icons.IconType;
|
import com.beemdevelopment.aegis.icons.IconType;
|
||||||
|
@ -93,7 +93,6 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
// keep track of icon changes separately as the generated jpeg's are not deterministic
|
// keep track of icon changes separately as the generated jpeg's are not deterministic
|
||||||
private boolean _hasChangedIcon = false;
|
private boolean _hasChangedIcon = false;
|
||||||
private IconPack.Icon _selectedIcon;
|
private IconPack.Icon _selectedIcon;
|
||||||
private boolean _isEditingIcon;
|
|
||||||
private CircleImageView _iconView;
|
private CircleImageView _iconView;
|
||||||
private ImageView _saveImageButton;
|
private ImageView _saveImageButton;
|
||||||
|
|
||||||
|
@ -120,6 +119,9 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
private RelativeLayout _advancedSettingsHeader;
|
private RelativeLayout _advancedSettingsHeader;
|
||||||
private RelativeLayout _advancedSettings;
|
private RelativeLayout _advancedSettings;
|
||||||
|
|
||||||
|
private BackPressHandler _backPressHandler;
|
||||||
|
private IconBackPressHandler _iconBackPressHandler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -132,8 +134,15 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
_groups = _vaultManager.getVault().getGroups();
|
_groups = _vaultManager.getVault().getGroups();
|
||||||
|
|
||||||
ActionBar bar = getSupportActionBar();
|
ActionBar bar = getSupportActionBar();
|
||||||
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
if (bar != null) {
|
||||||
bar.setDisplayHomeAsUpEnabled(true);
|
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
||||||
|
bar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
_backPressHandler = new BackPressHandler();
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, _backPressHandler);
|
||||||
|
_iconBackPressHandler = new IconBackPressHandler();
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, _iconBackPressHandler);
|
||||||
|
|
||||||
// retrieve info from the calling activity
|
// retrieve info from the calling activity
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
|
@ -254,9 +263,21 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
String group = _origEntry.getGroup();
|
String group = _origEntry.getGroup();
|
||||||
setGroup(group);
|
setGroup(group);
|
||||||
|
|
||||||
// update the icon if the text changed
|
// Update the icon if the issuer or name has changed
|
||||||
_textIssuer.addTextChangedListener(_iconChangeListener);
|
_textIssuer.addTextChangedListener(_nameChangeListener);
|
||||||
_textName.addTextChangedListener(_iconChangeListener);
|
_textName.addTextChangedListener(_nameChangeListener);
|
||||||
|
|
||||||
|
// Register listeners to trigger validation
|
||||||
|
_textIssuer.addTextChangedListener(_validationListener);
|
||||||
|
_textName.addTextChangedListener(_validationListener);
|
||||||
|
_textNote.addTextChangedListener(_validationListener);
|
||||||
|
_textSecret.addTextChangedListener(_validationListener);
|
||||||
|
_dropdownType.addTextChangedListener(_validationListener);
|
||||||
|
_dropdownGroup.addTextChangedListener(_validationListener);
|
||||||
|
_dropdownAlgo.addTextChangedListener(_validationListener);
|
||||||
|
_textPeriodCounter.addTextChangedListener(_validationListener);
|
||||||
|
_textDigits.addTextChangedListener(_validationListener);
|
||||||
|
_textPin.addTextChangedListener(_validationListener);
|
||||||
|
|
||||||
// show/hide period and counter fields on type change
|
// show/hide period and counter fields on type change
|
||||||
_dropdownType.setOnItemClickListener((parent, view, position, id) -> {
|
_dropdownType.setOnItemClickListener((parent, view, position, id) -> {
|
||||||
|
@ -403,30 +424,26 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
_dropdownGroupList.add(res.getString(R.string.new_group));
|
_dropdownGroupList.add(res.getString(R.string.new_group));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private boolean hasUnsavedChanges(VaultEntry newEntry) {
|
||||||
public void onBackPressed() {
|
return _hasChangedIcon || !_origEntry.equals(newEntry);
|
||||||
if (_isEditingIcon) {
|
}
|
||||||
stopEditingIcon(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private void discardAndFinish() {
|
||||||
AtomicReference<String> msg = new AtomicReference<>();
|
AtomicReference<String> msg = new AtomicReference<>();
|
||||||
AtomicReference<VaultEntry> entry = new AtomicReference<>();
|
AtomicReference<VaultEntry> entry = new AtomicReference<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
entry.set(parseEntry());
|
entry.set(parseEntry());
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
msg.set(e.getMessage());
|
msg.set(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// close the activity if the entry has not been changed
|
if (!hasUnsavedChanges(entry.get())) {
|
||||||
if (!_hasChangedIcon && _origEntry.equals(entry.get())) {
|
finish();
|
||||||
super.onBackPressed();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ask for confirmation if the entry has been changed
|
// ask for confirmation if the entry has been changed
|
||||||
Dialogs.showDiscardDialog(this,
|
Dialogs.showDiscardDialog(EditEntryActivity.this,
|
||||||
(dialog, which) -> {
|
(dialog, which) -> {
|
||||||
// if the entry couldn't be parsed, we show an error dialog
|
// if the entry couldn't be parsed, we show an error dialog
|
||||||
if (msg.get() != null) {
|
if (msg.get() != null) {
|
||||||
|
@ -436,7 +453,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
|
|
||||||
addAndFinish(entry.get());
|
addAndFinish(entry.get());
|
||||||
},
|
},
|
||||||
(dialog, which) -> super.onBackPressed()
|
(dialog, which) -> finish()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +461,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
onBackPressed();
|
discardAndFinish();
|
||||||
break;
|
break;
|
||||||
case R.id.action_save:
|
case R.id.action_save:
|
||||||
onSave();
|
onSave();
|
||||||
|
@ -558,7 +575,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
stopEditingIcon(true);
|
stopEditingIcon(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
_isEditingIcon = true;
|
_iconBackPressHandler.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopEditingIcon(boolean save) {
|
private void stopEditingIcon(boolean save) {
|
||||||
|
@ -570,7 +587,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
|
|
||||||
_hasCustomIcon = _hasCustomIcon || save;
|
_hasCustomIcon = _hasCustomIcon || save;
|
||||||
_hasChangedIcon = save;
|
_hasChangedIcon = save;
|
||||||
_isEditingIcon = false;
|
_iconBackPressHandler.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -620,7 +637,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, final int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, final int resultCode, Intent data) {
|
||||||
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
|
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
|
||||||
String fileType = getMimeType(data.getData());
|
String fileType = SafHelper.getMimeType(this, data.getData());
|
||||||
if (fileType != null && fileType.equals(IconType.SVG.toMimeType())) {
|
if (fileType != null && fileType.equals(IconType.SVG.toMimeType())) {
|
||||||
ImportFileTask.Params params = new ImportFileTask.Params(data.getData(), "icon", null);
|
ImportFileTask.Params params = new ImportFileTask.Params(data.getData(), "icon", null);
|
||||||
ImportFileTask task = new ImportFileTask(this, result -> {
|
ImportFileTask task = new ImportFileTask(this, result -> {
|
||||||
|
@ -640,23 +657,6 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMimeType(Uri uri) {
|
|
||||||
DocumentFile file = DocumentFile.fromSingleUri(this, uri);
|
|
||||||
if (file != null) {
|
|
||||||
String fileType = file.getType();
|
|
||||||
if (fileType != null) {
|
|
||||||
return fileType;
|
|
||||||
}
|
|
||||||
|
|
||||||
String ext = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
|
|
||||||
if (ext != null) {
|
|
||||||
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int parsePeriod() throws ParseException {
|
private int parsePeriod() throws ParseException {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(_textPeriodCounter.getText().toString());
|
return Integer.parseInt(_textPeriodCounter.getText().toString());
|
||||||
|
@ -792,7 +792,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onSave() {
|
private boolean onSave() {
|
||||||
if (_isEditingIcon) {
|
if (_iconBackPressHandler.isEnabled()) {
|
||||||
stopEditingIcon(true);
|
stopEditingIcon(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,23 +819,50 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final TextWatcher _iconChangeListener = new TextWatcher() {
|
private final TextWatcher _validationListener = new SimpleTextWatcher((s) -> {
|
||||||
@Override
|
updateBackPressHandlerState();
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
});
|
||||||
|
|
||||||
|
private final TextWatcher _nameChangeListener = new SimpleTextWatcher((s) -> {
|
||||||
|
if (!_hasCustomIcon) {
|
||||||
|
TextDrawable drawable = TextDrawableHelper.generate(_textIssuer.getText().toString(), _textName.getText().toString(), _iconView);
|
||||||
|
_iconView.setImageDrawable(drawable);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
private void updateBackPressHandlerState() {
|
||||||
|
VaultEntry entry = null;
|
||||||
|
try {
|
||||||
|
entry = parseEntry();
|
||||||
|
} catch (ParseException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean backEnabled = hasUnsavedChanges(entry);
|
||||||
|
_backPressHandler.setEnabled(backEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class BackPressHandler extends OnBackPressedCallback {
|
||||||
|
public BackPressHandler() {
|
||||||
|
super(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void handleOnBackPressed() {
|
||||||
|
discardAndFinish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class IconBackPressHandler extends OnBackPressedCallback {
|
||||||
|
public IconBackPressHandler() {
|
||||||
|
super(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void handleOnBackPressed() {
|
||||||
if (!_hasCustomIcon) {
|
stopEditingIcon(false);
|
||||||
TextDrawable drawable = TextDrawableHelper.generate(_textIssuer.getText().toString(), _textName.getText().toString(), _iconView);
|
|
||||||
_iconView.setImageDrawable(drawable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
private static class ParseException extends Exception {
|
private static class ParseException extends Exception {
|
||||||
public ParseException(String message) {
|
public ParseException(String message) {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.beemdevelopment.aegis.ui;
|
package com.beemdevelopment.aegis.ui;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
@ -12,16 +14,19 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||||
import com.beemdevelopment.aegis.ui.views.GroupAdapter;
|
import com.beemdevelopment.aegis.ui.views.GroupAdapter;
|
||||||
|
import com.beemdevelopment.aegis.vault.VaultEntry;
|
||||||
|
|
||||||
import java.text.Collator;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.TreeSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class GroupManagerActivity extends AegisActivity implements GroupAdapter.Listener {
|
public class GroupManagerActivity extends AegisActivity implements GroupAdapter.Listener {
|
||||||
private GroupAdapter _adapter;
|
private GroupAdapter _adapter;
|
||||||
private TreeSet<String> _groups;
|
private HashSet<String> _removedGroups;
|
||||||
private RecyclerView _slotsView;
|
private RecyclerView _slotsView;
|
||||||
private View _emptyStateView;
|
private View _emptyStateView;
|
||||||
|
private BackPressHandler _backPressHandler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -31,17 +36,20 @@ public class GroupManagerActivity extends AegisActivity implements GroupAdapter.
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_groups);
|
setContentView(R.layout.activity_groups);
|
||||||
setSupportActionBar(findViewById(R.id.toolbar));
|
setSupportActionBar(findViewById(R.id.toolbar));
|
||||||
|
|
||||||
Intent intent = getIntent();
|
|
||||||
_groups = new TreeSet<>(Collator.getInstance());
|
|
||||||
_groups.addAll(intent.getStringArrayListExtra("groups"));
|
|
||||||
|
|
||||||
if (getSupportActionBar() != null) {
|
if (getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||||
}
|
}
|
||||||
|
_backPressHandler = new BackPressHandler();
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, _backPressHandler);
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
List<String> groups = savedInstanceState.getStringArrayList("removedGroups");
|
||||||
|
_removedGroups = new HashSet<>(Objects.requireNonNull(groups));
|
||||||
|
} else {
|
||||||
|
_removedGroups = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
// set up the recycler view
|
|
||||||
_adapter = new GroupAdapter(this);
|
_adapter = new GroupAdapter(this);
|
||||||
_slotsView= findViewById(R.id.list_slots);
|
_slotsView= findViewById(R.id.list_slots);
|
||||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||||
|
@ -49,7 +57,7 @@ public class GroupManagerActivity extends AegisActivity implements GroupAdapter.
|
||||||
_slotsView.setAdapter(_adapter);
|
_slotsView.setAdapter(_adapter);
|
||||||
_slotsView.setNestedScrollingEnabled(false);
|
_slotsView.setNestedScrollingEnabled(false);
|
||||||
|
|
||||||
for (String group : _groups) {
|
for (String group : _vaultManager.getVault().getGroups()) {
|
||||||
_adapter.addGroup(group);
|
_adapter.addGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +65,74 @@ public class GroupManagerActivity extends AegisActivity implements GroupAdapter.
|
||||||
updateEmptyState();
|
updateEmptyState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putStringArrayList("removedGroups", new ArrayList<>(_removedGroups));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoveGroup(String group) {
|
||||||
|
Dialogs.showSecureDialog(new AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.remove_group)
|
||||||
|
.setMessage(R.string.remove_group_description)
|
||||||
|
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
|
||||||
|
_removedGroups.add(group);
|
||||||
|
_adapter.removeGroup(group);
|
||||||
|
_backPressHandler.setEnabled(true);
|
||||||
|
updateEmptyState();
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.no, null)
|
||||||
|
.create());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveAndFinish() {
|
||||||
|
if (!_removedGroups.isEmpty()) {
|
||||||
|
for (VaultEntry entry : _vaultManager.getVault().getEntries()) {
|
||||||
|
if (_removedGroups.contains(entry.getGroup())) {
|
||||||
|
entry.setGroup(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveAndBackupVault();
|
||||||
|
}
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void discardAndFinish() {
|
||||||
|
if (_removedGroups.isEmpty()) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialogs.showDiscardDialog(this,
|
||||||
|
(dialog, which) -> saveAndFinish(),
|
||||||
|
(dialog, which) -> finish());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.menu_groups, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
discardAndFinish();
|
||||||
|
break;
|
||||||
|
case R.id.action_save:
|
||||||
|
saveAndFinish();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateEmptyState() {
|
private void updateEmptyState() {
|
||||||
if (_adapter.getItemCount() > 0) {
|
if (_adapter.getItemCount() > 0) {
|
||||||
_slotsView.setVisibility(View.VISIBLE);
|
_slotsView.setVisibility(View.VISIBLE);
|
||||||
|
@ -67,38 +143,14 @@ public class GroupManagerActivity extends AegisActivity implements GroupAdapter.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class BackPressHandler extends OnBackPressedCallback {
|
||||||
public void onRemoveGroup(String group) {
|
public BackPressHandler() {
|
||||||
Dialogs.showSecureDialog(new AlertDialog.Builder(this)
|
super(false);
|
||||||
.setTitle(R.string.remove_group)
|
|
||||||
.setMessage(R.string.remove_group_description)
|
|
||||||
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
|
|
||||||
_groups.remove(group);
|
|
||||||
_adapter.removeGroup(group);
|
|
||||||
updateEmptyState();
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, null)
|
|
||||||
.create());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
|
||||||
onBackPressed();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public void handleOnBackPressed() {
|
||||||
|
discardAndFinish();
|
||||||
@Override
|
}
|
||||||
public void onBackPressed() {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.putExtra("groups", new ArrayList<>(_groups));
|
|
||||||
setResult(RESULT_OK, intent);
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,7 +236,7 @@ public class ImportEntriesActivity extends AegisActivity {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
onBackPressed();
|
finish();
|
||||||
break;
|
break;
|
||||||
case R.id.toggle_checkboxes:
|
case R.id.toggle_checkboxes:
|
||||||
_adapter.toggleCheckboxes();
|
_adapter.toggleCheckboxes();
|
||||||
|
|
|
@ -29,6 +29,7 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.view.ActionMode;
|
import androidx.appcompat.view.ActionMode;
|
||||||
|
@ -47,11 +48,11 @@ import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||||
import com.beemdevelopment.aegis.ui.fragments.preferences.BackupsPreferencesFragment;
|
import com.beemdevelopment.aegis.ui.fragments.preferences.BackupsPreferencesFragment;
|
||||||
import com.beemdevelopment.aegis.ui.fragments.preferences.PreferencesFragment;
|
import com.beemdevelopment.aegis.ui.fragments.preferences.PreferencesFragment;
|
||||||
import com.beemdevelopment.aegis.ui.tasks.QrDecodeTask;
|
import com.beemdevelopment.aegis.ui.tasks.QrDecodeTask;
|
||||||
import com.beemdevelopment.aegis.ui.views.EntryHolder;
|
|
||||||
import com.beemdevelopment.aegis.ui.views.EntryListView;
|
import com.beemdevelopment.aegis.ui.views.EntryListView;
|
||||||
import com.beemdevelopment.aegis.vault.VaultEntry;
|
import com.beemdevelopment.aegis.vault.VaultEntry;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -81,12 +82,10 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
private boolean _isDoingIntro;
|
private boolean _isDoingIntro;
|
||||||
private boolean _isAuthenticating;
|
private boolean _isAuthenticating;
|
||||||
|
|
||||||
private String _submittedSearchSubtitle;
|
private String _submittedSearchQuery;
|
||||||
private String _searchQueryInputText;
|
private String _pendingSearchQuery;
|
||||||
private String _activeSearchFilter;
|
|
||||||
|
|
||||||
private List<VaultEntry> _selectedEntries;
|
private List<VaultEntry> _selectedEntries;
|
||||||
private ActionMode _actionMode;
|
|
||||||
|
|
||||||
private Menu _menu;
|
private Menu _menu;
|
||||||
private SearchView _searchView;
|
private SearchView _searchView;
|
||||||
|
@ -96,8 +95,13 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
|
|
||||||
private FabScrollHelper _fabScrollHelper;
|
private FabScrollHelper _fabScrollHelper;
|
||||||
|
|
||||||
|
private ActionMode _actionMode;
|
||||||
private ActionMode.Callback _actionModeCallbacks = new ActionModeCallbacks();
|
private ActionMode.Callback _actionModeCallbacks = new ActionModeCallbacks();
|
||||||
|
|
||||||
|
private LockBackPressHandler _lockBackPressHandler;
|
||||||
|
private SearchViewBackPressHandler _searchViewBackPressHandler;
|
||||||
|
private ActionModeBackPressHandler _actionModeBackPressHandler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -110,13 +114,19 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
_isRecreated = true;
|
_isRecreated = true;
|
||||||
_searchQueryInputText = savedInstanceState.getString("searchQueryInputText");
|
_pendingSearchQuery = savedInstanceState.getString("pendingSearchQuery");
|
||||||
_activeSearchFilter = savedInstanceState.getString("activeSearchFilter");
|
_submittedSearchQuery = savedInstanceState.getString("submittedSearchQuery");
|
||||||
_submittedSearchSubtitle = savedInstanceState.getString("submittedSearchSubtitle");
|
|
||||||
_isDoingIntro = savedInstanceState.getBoolean("isDoingIntro");
|
_isDoingIntro = savedInstanceState.getBoolean("isDoingIntro");
|
||||||
_isAuthenticating = savedInstanceState.getBoolean("isAuthenticating");
|
_isAuthenticating = savedInstanceState.getBoolean("isAuthenticating");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lockBackPressHandler = new LockBackPressHandler();
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, _lockBackPressHandler);
|
||||||
|
_searchViewBackPressHandler = new SearchViewBackPressHandler();
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, _searchViewBackPressHandler);
|
||||||
|
_actionModeBackPressHandler = new ActionModeBackPressHandler();
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, _actionModeBackPressHandler);
|
||||||
|
|
||||||
_entryListView = (EntryListView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
|
_entryListView = (EntryListView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
|
||||||
_entryListView.setListener(this);
|
_entryListView.setListener(this);
|
||||||
_entryListView.setCodeGroupSize(_prefs.getCodeGroupSize());
|
_entryListView.setCodeGroupSize(_prefs.getCodeGroupSize());
|
||||||
|
@ -178,9 +188,8 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle instance) {
|
protected void onSaveInstanceState(@NonNull Bundle instance) {
|
||||||
super.onSaveInstanceState(instance);
|
super.onSaveInstanceState(instance);
|
||||||
instance.putString("activeSearchFilter", _activeSearchFilter);
|
instance.putString("pendingSearchQuery", _pendingSearchQuery);
|
||||||
instance.putString("submittedSearchSubtitle", _submittedSearchSubtitle);
|
instance.putString("submittedSearchQuery", _submittedSearchQuery);
|
||||||
instance.putString("searchQueryInputText", _searchQueryInputText);
|
|
||||||
instance.putBoolean("isDoingIntro", _isDoingIntro);
|
instance.putBoolean("isDoingIntro", _isDoingIntro);
|
||||||
instance.putBoolean("isAuthenticating", _isAuthenticating);
|
instance.putBoolean("isAuthenticating", _isAuthenticating);
|
||||||
}
|
}
|
||||||
|
@ -619,33 +628,16 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
checkTimeSyncSetting();
|
checkTimeSyncSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lockBackPressHandler.setEnabled(
|
||||||
|
_vaultManager.isAutoLockEnabled(Preferences.AUTO_LOCK_ON_BACK_BUTTON)
|
||||||
|
);
|
||||||
|
|
||||||
handleIncomingIntent();
|
handleIncomingIntent();
|
||||||
updateLockIcon();
|
updateLockIcon();
|
||||||
doShortcutActions();
|
doShortcutActions();
|
||||||
updateErrorBar();
|
updateErrorBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
if (!_searchView.isIconified() || _submittedSearchSubtitle != null) {
|
|
||||||
_submittedSearchSubtitle = null;
|
|
||||||
_entryListView.setSearchFilter(null);
|
|
||||||
_activeSearchFilter = null;
|
|
||||||
|
|
||||||
collapseSearchView();
|
|
||||||
setTitle(R.string.app_name);
|
|
||||||
getSupportActionBar().setSubtitle(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_vaultManager.isAutoLockEnabled(Preferences.AUTO_LOCK_ON_BACK_BUTTON)) {
|
|
||||||
_vaultManager.lock(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onBackPressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteEntries(List<VaultEntry> entries) {
|
private void deleteEntries(List<VaultEntry> entries) {
|
||||||
for (VaultEntry entry: entries) {
|
for (VaultEntry entry: entries) {
|
||||||
VaultEntry oldEntry = _vaultManager.getVault().removeEntry(entry);
|
VaultEntry oldEntry = _vaultManager.getVault().removeEntry(entry);
|
||||||
|
@ -669,56 +661,63 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
|
|
||||||
_searchView = (SearchView) searchViewMenuItem.getActionView();
|
_searchView = (SearchView) searchViewMenuItem.getActionView();
|
||||||
_searchView.setMaxWidth(Integer.MAX_VALUE);
|
_searchView.setMaxWidth(Integer.MAX_VALUE);
|
||||||
|
_searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
|
||||||
|
boolean enabled = _submittedSearchQuery != null || hasFocus;
|
||||||
|
_searchViewBackPressHandler.setEnabled(enabled);
|
||||||
|
});
|
||||||
|
_searchView.setOnCloseListener(() -> {
|
||||||
|
boolean enabled = _submittedSearchQuery != null;
|
||||||
|
_searchViewBackPressHandler.setEnabled(enabled);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
_searchView.setQueryHint(getString(R.string.search));
|
_searchView.setQueryHint(getString(R.string.search));
|
||||||
if (_prefs.getFocusSearchEnabled() && !_isRecreated) {
|
|
||||||
_searchView.setIconified(false);
|
|
||||||
_searchView.setFocusable(true);
|
|
||||||
_searchView.requestFocus();
|
|
||||||
_searchView.requestFocusFromTouch();
|
|
||||||
}
|
|
||||||
|
|
||||||
_searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
_searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String s) {
|
public boolean onQueryTextSubmit(String s) {
|
||||||
setTitle(getString(R.string.search));
|
setTitle(getString(R.string.search));
|
||||||
getSupportActionBar().setSubtitle(s);
|
getSupportActionBar().setSubtitle(s);
|
||||||
_searchQueryInputText = null;
|
_entryListView.setSearchFilter(s);
|
||||||
_submittedSearchSubtitle = s;
|
_pendingSearchQuery = null;
|
||||||
|
_submittedSearchQuery = s;
|
||||||
collapseSearchView();
|
collapseSearchView();
|
||||||
|
_searchViewBackPressHandler.setEnabled(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String s) {
|
public boolean onQueryTextChange(String s) {
|
||||||
if (_submittedSearchSubtitle == null) {
|
if (_submittedSearchQuery == null) {
|
||||||
_entryListView.setSearchFilter(s);
|
_entryListView.setSearchFilter(s);
|
||||||
_activeSearchFilter = s;
|
|
||||||
_searchQueryInputText = s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_pendingSearchQuery = Strings.isNullOrEmpty(s) && !_searchView.isIconified() ? null : s;
|
||||||
|
if (_pendingSearchQuery != null) {
|
||||||
|
_entryListView.setSearchFilter(_pendingSearchQuery);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_searchView.setOnSearchClickListener(v -> {
|
_searchView.setOnSearchClickListener(v -> {
|
||||||
if (_submittedSearchSubtitle != null) {
|
String query = _submittedSearchQuery != null ? _submittedSearchQuery : _pendingSearchQuery;
|
||||||
_entryListView.setSearchFilter(null);
|
_searchView.setQuery(query, false);
|
||||||
_activeSearchFilter = null;
|
|
||||||
_submittedSearchSubtitle = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (_submittedSearchSubtitle != null) {
|
if (_pendingSearchQuery != null) {
|
||||||
getSupportActionBar().setSubtitle(_submittedSearchSubtitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_activeSearchFilter != null) {
|
|
||||||
_entryListView.setSearchFilter(_activeSearchFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_searchQueryInputText != null) {
|
|
||||||
_searchView.setQuery(_searchQueryInputText, false);
|
|
||||||
_searchView.setIconified(false);
|
_searchView.setIconified(false);
|
||||||
|
_searchView.setQuery(_pendingSearchQuery, false);
|
||||||
|
_searchViewBackPressHandler.setEnabled(true);
|
||||||
|
} else if (_submittedSearchQuery != null) {
|
||||||
|
setTitle(getString(R.string.search));
|
||||||
|
getSupportActionBar().setSubtitle(_submittedSearchQuery);
|
||||||
|
_entryListView.setSearchFilter(_submittedSearchQuery);
|
||||||
|
_searchViewBackPressHandler.setEnabled(true);
|
||||||
|
} else if (_prefs.getFocusSearchEnabled() && !_isRecreated) {
|
||||||
|
_searchView.setIconified(false);
|
||||||
|
_searchView.setFocusable(true);
|
||||||
|
_searchView.requestFocus();
|
||||||
|
_searchView.requestFocusFromTouch();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -897,7 +896,12 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
|
|
||||||
_selectedEntries.add(entry);
|
_selectedEntries.add(entry);
|
||||||
_entryListView.setActionModeState(true, entry);
|
_entryListView.setActionModeState(true, entry);
|
||||||
|
startActionMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startActionMode() {
|
||||||
_actionMode = startSupportActionMode(_actionModeCallbacks);
|
_actionMode = startSupportActionMode(_actionModeCallbacks);
|
||||||
|
_actionModeBackPressHandler.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -975,6 +979,51 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SearchViewBackPressHandler extends OnBackPressedCallback {
|
||||||
|
public SearchViewBackPressHandler() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
if (!_searchView.isIconified() || _submittedSearchQuery != null) {
|
||||||
|
_submittedSearchQuery = null;
|
||||||
|
_pendingSearchQuery = null;
|
||||||
|
_entryListView.setSearchFilter(null);
|
||||||
|
|
||||||
|
collapseSearchView();
|
||||||
|
setTitle(R.string.app_name);
|
||||||
|
getSupportActionBar().setSubtitle(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LockBackPressHandler extends OnBackPressedCallback {
|
||||||
|
public LockBackPressHandler() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
if (_vaultManager.isAutoLockEnabled(Preferences.AUTO_LOCK_ON_BACK_BUTTON)) {
|
||||||
|
_vaultManager.lock(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ActionModeBackPressHandler extends OnBackPressedCallback {
|
||||||
|
public ActionModeBackPressHandler() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
if (_actionMode != null) {
|
||||||
|
_actionMode.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ActionModeCallbacks implements ActionMode.Callback {
|
private class ActionModeCallbacks implements ActionMode.Callback {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
|
@ -1044,6 +1093,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
_entryListView.setActionModeState(false, null);
|
_entryListView.setActionModeState(false, null);
|
||||||
|
_actionModeBackPressHandler.setEnabled(false);
|
||||||
_selectedEntries.clear();
|
_selectedEntries.clear();
|
||||||
_actionMode = null;
|
_actionMode = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package com.beemdevelopment.aegis.ui;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
|
@ -23,6 +25,8 @@ public class PreferencesActivity extends AegisActivity implements
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_preferences);
|
setContentView(R.layout.activity_preferences);
|
||||||
setSupportActionBar(findViewById(R.id.toolbar));
|
setSupportActionBar(findViewById(R.id.toolbar));
|
||||||
|
getSupportFragmentManager()
|
||||||
|
.registerFragmentLifecycleCallbacks(new FragmentResumeListener(), true);
|
||||||
|
|
||||||
if (getSupportActionBar() != null) {
|
if (getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
@ -33,7 +37,7 @@ public class PreferencesActivity extends AegisActivity implements
|
||||||
_fragment = new MainPreferencesFragment();
|
_fragment = new MainPreferencesFragment();
|
||||||
_fragment.setArguments(getIntent().getExtras());
|
_fragment.setArguments(getIntent().getExtras());
|
||||||
|
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.replace(R.id.content, _fragment)
|
.replace(R.id.content, _fragment)
|
||||||
.commit();
|
.commit();
|
||||||
|
|
||||||
|
@ -48,13 +52,7 @@ public class PreferencesActivity extends AegisActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
protected void onRestoreInstanceState(@NonNull final Bundle inState) {
|
||||||
super.onBackPressed();
|
|
||||||
setTitle(R.string.action_settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onRestoreInstanceState(final Bundle inState) {
|
|
||||||
if (_fragment instanceof PreferencesFragment) {
|
if (_fragment instanceof PreferencesFragment) {
|
||||||
// pass the stored result intent back to the fragment
|
// pass the stored result intent back to the fragment
|
||||||
if (inState.containsKey("result")) {
|
if (inState.containsKey("result")) {
|
||||||
|
@ -65,7 +63,7 @@ public class PreferencesActivity extends AegisActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(final Bundle outState) {
|
protected void onSaveInstanceState(@NonNull final Bundle outState) {
|
||||||
if (_fragment instanceof PreferencesFragment) {
|
if (_fragment instanceof PreferencesFragment) {
|
||||||
// save the result intent of the fragment
|
// save the result intent of the fragment
|
||||||
// this is done so we don't lose anything if the fragment calls recreate on this activity
|
// this is done so we don't lose anything if the fragment calls recreate on this activity
|
||||||
|
@ -77,7 +75,7 @@ public class PreferencesActivity extends AegisActivity implements
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
onBackPressed();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +84,7 @@ public class PreferencesActivity extends AegisActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
|
public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat caller, Preference pref) {
|
||||||
_fragment = getSupportFragmentManager().getFragmentFactory().instantiate(getClassLoader(), pref.getFragment());
|
_fragment = getSupportFragmentManager().getFragmentFactory().instantiate(getClassLoader(), pref.getFragment());
|
||||||
_fragment.setArguments(pref.getExtras());
|
_fragment.setArguments(pref.getExtras());
|
||||||
_fragment.setTargetFragment(caller, 0);
|
_fragment.setTargetFragment(caller, 0);
|
||||||
|
@ -117,4 +115,13 @@ public class PreferencesActivity extends AegisActivity implements
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class FragmentResumeListener extends FragmentManager.FragmentLifecycleCallbacks {
|
||||||
|
@Override
|
||||||
|
public void onFragmentStarted(@NonNull FragmentManager fm, @NonNull Fragment f) {
|
||||||
|
if (f instanceof MainPreferencesFragment) {
|
||||||
|
setTitle(R.string.action_settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class TransferEntriesActivity extends AegisActivity {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
onBackPressed();
|
finish();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.beemdevelopment.aegis.ui.fragments.preferences;
|
package com.beemdevelopment.aegis.ui.fragments.preferences;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -13,10 +12,8 @@ import com.beemdevelopment.aegis.Theme;
|
||||||
import com.beemdevelopment.aegis.ViewMode;
|
import com.beemdevelopment.aegis.ViewMode;
|
||||||
import com.beemdevelopment.aegis.ui.GroupManagerActivity;
|
import com.beemdevelopment.aegis.ui.GroupManagerActivity;
|
||||||
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||||
import com.beemdevelopment.aegis.vault.VaultEntry;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class AppearancePreferencesFragment extends PreferencesFragment {
|
public class AppearancePreferencesFragment extends PreferencesFragment {
|
||||||
private Preference _groupsPreference;
|
private Preference _groupsPreference;
|
||||||
|
@ -30,8 +27,7 @@ public class AppearancePreferencesFragment extends PreferencesFragment {
|
||||||
_groupsPreference = requirePreference("pref_groups");
|
_groupsPreference = requirePreference("pref_groups");
|
||||||
_groupsPreference.setOnPreferenceClickListener(preference -> {
|
_groupsPreference.setOnPreferenceClickListener(preference -> {
|
||||||
Intent intent = new Intent(requireActivity(), GroupManagerActivity.class);
|
Intent intent = new Intent(requireActivity(), GroupManagerActivity.class);
|
||||||
intent.putExtra("groups", new ArrayList<>(_vaultManager.getVault().getGroups()));
|
startActivity(intent);
|
||||||
startActivityForResult(intent, CODE_GROUPS);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -114,29 +110,4 @@ public class AppearancePreferencesFragment extends PreferencesFragment {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
|
|
||||||
if (data != null && requestCode == CODE_GROUPS) {
|
|
||||||
onGroupManagerResult(resultCode, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onGroupManagerResult(int resultCode, Intent data) {
|
|
||||||
if (resultCode != Activity.RESULT_OK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashSet<String> groups = new HashSet<>(data.getStringArrayListExtra("groups"));
|
|
||||||
|
|
||||||
for (VaultEntry entry : _vaultManager.getVault().getEntries()) {
|
|
||||||
if (!groups.contains(entry.getGroup())) {
|
|
||||||
entry.setGroup(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
saveAndBackupVault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
|
import androidx.activity.OnBackPressedCallback;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
@ -34,6 +35,7 @@ public abstract class IntroBaseActivity extends AegisActivity implements IntroAc
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_intro);
|
setContentView(R.layout.activity_intro);
|
||||||
|
getOnBackPressedDispatcher().addCallback(this, new BackPressHandler());
|
||||||
|
|
||||||
_slides = new ArrayList<>();
|
_slides = new ArrayList<>();
|
||||||
_state = new Bundle();
|
_state = new Bundle();
|
||||||
|
@ -163,11 +165,6 @@ public abstract class IntroBaseActivity extends AegisActivity implements IntroAc
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
goToPreviousSlide();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void onDonePressed();
|
protected abstract void onDonePressed();
|
||||||
|
|
||||||
public void addSlide(Class<? extends SlideFragment> type) {
|
public void addSlide(Class<? extends SlideFragment> type) {
|
||||||
|
@ -186,6 +183,17 @@ public abstract class IntroBaseActivity extends AegisActivity implements IntroAc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class BackPressHandler extends OnBackPressedCallback {
|
||||||
|
public BackPressHandler() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleOnBackPressed() {
|
||||||
|
goToPreviousSlide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ScreenSlidePagerAdapter extends FragmentStateAdapter {
|
private class ScreenSlidePagerAdapter extends FragmentStateAdapter {
|
||||||
public ScreenSlidePagerAdapter(FragmentManager fm) {
|
public ScreenSlidePagerAdapter(FragmentManager fm) {
|
||||||
super(fm, getLifecycle());
|
super(fm, getLifecycle());
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:context="com.beemdevelopment.aegis.ui.SlotManagerActivity">
|
tools:context="com.beemdevelopment.aegis.ui.GroupManagerActivity">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_save"
|
android:id="@+id/action_save"
|
||||||
app:showAsAction="ifRoom"
|
app:showAsAction="ifRoom"
|
Loading…
Add table
Reference in a new issue