mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 06:49:12 +00:00
Merge pull request #1497 from michaelschattgen/feature/assign-groups
Add ability to easily assign groups
This commit is contained in:
commit
9ef3315a70
4 changed files with 139 additions and 0 deletions
|
@ -24,6 +24,7 @@ import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -42,6 +43,7 @@ import androidx.core.view.WindowInsetsCompat;
|
||||||
import com.beemdevelopment.aegis.Preferences;
|
import com.beemdevelopment.aegis.Preferences;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.SortCategory;
|
import com.beemdevelopment.aegis.SortCategory;
|
||||||
|
import com.beemdevelopment.aegis.helpers.DropdownHelper;
|
||||||
import com.beemdevelopment.aegis.helpers.FabScrollHelper;
|
import com.beemdevelopment.aegis.helpers.FabScrollHelper;
|
||||||
import com.beemdevelopment.aegis.helpers.PermissionHelper;
|
import com.beemdevelopment.aegis.helpers.PermissionHelper;
|
||||||
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
||||||
|
@ -67,6 +69,8 @@ import com.google.android.material.chip.ChipGroup;
|
||||||
import com.google.android.material.color.MaterialColors;
|
import com.google.android.material.color.MaterialColors;
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -79,6 +83,7 @@ import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MainActivity extends AegisActivity implements EntryListView.Listener {
|
public class MainActivity extends AegisActivity implements EntryListView.Listener {
|
||||||
|
@ -489,6 +494,76 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
assignIconsResultLauncher.launch(assignIconIntent);
|
assignIconsResultLauncher.launch(assignIconIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startAssignGroupsDialog() {
|
||||||
|
View view = LayoutInflater.from(this).inflate(R.layout.dialog_select_group, null);
|
||||||
|
TextInputLayout groupSelectionLayout = view.findViewById(R.id.group_selection_layout);
|
||||||
|
AutoCompleteTextView groupsSelection = view.findViewById(R.id.group_selection_dropdown);
|
||||||
|
TextInputLayout newGroupLayout = view.findViewById(R.id.text_group_name_layout);
|
||||||
|
TextInputEditText newGroupText = view.findViewById(R.id.text_group_name);
|
||||||
|
|
||||||
|
Collection<VaultGroup> groups = _vaultManager.getVault().getUsedGroups();
|
||||||
|
List<VaultGroupModel> groupModels = new ArrayList<>();
|
||||||
|
groupModels.add(new VaultGroupModel(getString(R.string.new_group)));
|
||||||
|
groupModels.addAll(groups.stream().map(VaultGroupModel::new).collect(Collectors.toList()));
|
||||||
|
DropdownHelper.fillDropdown(this, groupsSelection, groupModels);
|
||||||
|
|
||||||
|
AtomicReference<VaultGroupModel> groupModelRef = new AtomicReference<>();
|
||||||
|
groupsSelection.setOnItemClickListener((parent, view1, position, id) -> {
|
||||||
|
VaultGroupModel groupModel = (VaultGroupModel) parent.getItemAtPosition(position);
|
||||||
|
groupModelRef.set(groupModel);
|
||||||
|
|
||||||
|
if (groupModel.isPlaceholder()) {
|
||||||
|
newGroupLayout.setVisibility(View.VISIBLE);
|
||||||
|
newGroupText.requestFocus();
|
||||||
|
} else {
|
||||||
|
newGroupLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
groupSelectionLayout.setError(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
AlertDialog dialog = new MaterialAlertDialogBuilder(this)
|
||||||
|
.setTitle(R.string.assign_groups)
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
dialog.setOnShowListener(d -> {
|
||||||
|
Button btnPos = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
btnPos.setOnClickListener(v -> {
|
||||||
|
VaultGroupModel groupModel = groupModelRef.get();
|
||||||
|
if (groupModel == null) {
|
||||||
|
groupSelectionLayout.setError(getString(R.string.error_required_field));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupModel.isPlaceholder()) {
|
||||||
|
String newGroupName = newGroupText.getText().toString().trim();
|
||||||
|
if (newGroupName.isEmpty()) {
|
||||||
|
newGroupLayout.setError(getString(R.string.error_required_field));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VaultGroup group = new VaultGroup(newGroupName);
|
||||||
|
_vaultManager.getVault().addGroup(group);
|
||||||
|
groupModel = new VaultGroupModel(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (VaultEntry selectedEntry : _selectedEntries) {
|
||||||
|
selectedEntry.addGroup(groupModel.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
|
saveAndBackupVault();
|
||||||
|
_actionMode.finish();
|
||||||
|
setGroups(_vaultManager.getVault().getUsedGroups());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Dialogs.showSecureDialog(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
private void startIntroActivity() {
|
private void startIntroActivity() {
|
||||||
if (!_isDoingIntro) {
|
if (!_isDoingIntro) {
|
||||||
Intent intro = new Intent(this, IntroActivity.class);
|
Intent intro = new Intent(this, IntroActivity.class);
|
||||||
|
@ -1356,6 +1431,8 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
} else if (itemId == R.id.action_assign_icons) {
|
} else if (itemId == R.id.action_assign_icons) {
|
||||||
startAssignIconsActivity(_selectedEntries);
|
startAssignIconsActivity(_selectedEntries);
|
||||||
mode.finish();
|
mode.finish();
|
||||||
|
} else if (itemId == R.id.action_assign_groups) {
|
||||||
|
startAssignGroupsDialog();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
52
app/src/main/res/layout/dialog_select_group.xml
Normal file
52
app/src/main/res/layout/dialog_select_group.xml
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="10dp"
|
||||||
|
android:paddingTop="10dp">
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="25dp"
|
||||||
|
android:layout_marginEnd="25dp"
|
||||||
|
android:text="@string/assign_groups_dialog_summary" />
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/group_selection_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="25dp"
|
||||||
|
android:layout_marginEnd="25dp"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:hint="@string/assign_groups_dialog_dropdown"
|
||||||
|
style="?attr/dropdownStyle">
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/group_selection_dropdown"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="none" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/text_group_name_layout"
|
||||||
|
android:hint="@string/group_name_hint"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="25dp"
|
||||||
|
android:layout_marginEnd="25dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/text_group_name"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="textCapSentences"/>
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
|
@ -33,6 +33,12 @@
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="100"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_assign_groups"
|
||||||
|
android:title="@string/assign_groups"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_share_qr"
|
android:id="@+id/action_share_qr"
|
||||||
android:title="@string/action_transfer"
|
android:title="@string/action_transfer"
|
||||||
|
|
|
@ -211,6 +211,9 @@
|
||||||
<string name="edit">Edit</string>
|
<string name="edit">Edit</string>
|
||||||
<string name="select_all">Select all</string>
|
<string name="select_all">Select all</string>
|
||||||
<string name="assign_icons">Assign icons</string>
|
<string name="assign_icons">Assign icons</string>
|
||||||
|
<string name="assign_groups">Assign to group</string>
|
||||||
|
<string name="assign_groups_dialog_summary">Select a group you wish to assign the selected entries to.</string>
|
||||||
|
<string name="assign_groups_dialog_dropdown">Select group</string>
|
||||||
<string name="favorite" comment="Verb">Favorite</string>
|
<string name="favorite" comment="Verb">Favorite</string>
|
||||||
<string name="unfavorite" comment="Verb">Unfavorite</string>
|
<string name="unfavorite" comment="Verb">Unfavorite</string>
|
||||||
<string name="error_all_caps">ERROR</string>
|
<string name="error_all_caps">ERROR</string>
|
||||||
|
@ -254,6 +257,7 @@
|
||||||
<string name="copied">Copied</string>
|
<string name="copied">Copied</string>
|
||||||
<string name="errors_copied">Errors copied to the clipboard</string>
|
<string name="errors_copied">Errors copied to the clipboard</string>
|
||||||
<string name="version_copied">Version copied to the clipboard</string>
|
<string name="version_copied">Version copied to the clipboard</string>
|
||||||
|
<string name="error_required_field">This field is required</string>
|
||||||
<string name="error_occurred">An error occurred</string>
|
<string name="error_occurred">An error occurred</string>
|
||||||
<string name="decryption_error">An error occurred while trying to unlock the vault</string>
|
<string name="decryption_error">An error occurred while trying to unlock the vault</string>
|
||||||
<string name="decryption_corrupt_error">An error occurred while trying to unlock the vault. Your vault file might be corrupt.</string>
|
<string name="decryption_corrupt_error">An error occurred while trying to unlock the vault. Your vault file might be corrupt.</string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue