mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 06:22:49 +00:00
Clean up the bottom sheet code a little
This commit is contained in:
parent
ad823d05cd
commit
9286196811
5 changed files with 22 additions and 32 deletions
|
@ -13,7 +13,6 @@ import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.KeyInfo;
|
import me.impy.aegis.crypto.KeyInfo;
|
||||||
import me.impy.aegis.crypto.otp.OTP;
|
|
||||||
|
|
||||||
public class AddProfileActivity extends AppCompatActivity {
|
public class AddProfileActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,12 @@ import java.lang.reflect.UndeclaredThrowableException;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.CryptoUtils;
|
|
||||||
import me.impy.aegis.crypto.KeyStoreHandle;
|
import me.impy.aegis.crypto.KeyStoreHandle;
|
||||||
import me.impy.aegis.crypto.MasterKey;
|
import me.impy.aegis.crypto.MasterKey;
|
||||||
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
||||||
import me.impy.aegis.crypto.slots.PasswordSlot;
|
import me.impy.aegis.crypto.slots.PasswordSlot;
|
||||||
import me.impy.aegis.crypto.slots.Slot;
|
import me.impy.aegis.crypto.slots.Slot;
|
||||||
import me.impy.aegis.crypto.slots.SlotCollection;
|
import me.impy.aegis.crypto.slots.SlotCollection;
|
||||||
import me.impy.aegis.crypto.slots.SlotIntegrityException;
|
|
||||||
import me.impy.aegis.finger.FingerprintUiHelper;
|
import me.impy.aegis.finger.FingerprintUiHelper;
|
||||||
import me.impy.aegis.helpers.AuthHelper;
|
import me.impy.aegis.helpers.AuthHelper;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ import javax.crypto.Cipher;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.CryptResult;
|
import me.impy.aegis.crypto.CryptResult;
|
||||||
import me.impy.aegis.crypto.CryptoUtils;
|
|
||||||
import me.impy.aegis.crypto.MasterKey;
|
import me.impy.aegis.crypto.MasterKey;
|
||||||
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
||||||
import me.impy.aegis.crypto.slots.PasswordSlot;
|
import me.impy.aegis.crypto.slots.PasswordSlot;
|
||||||
|
|
|
@ -151,12 +151,16 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
_itemClickListener.onItemClick(getAdapterPosition(), view);
|
if (_itemClickListener != null) {
|
||||||
|
_itemClickListener.onItemClick(getAdapterPosition(), view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View view) {
|
public boolean onLongClick(View view) {
|
||||||
_longItemClickListener.onLongItemClick(getAdapterPosition(), view);
|
if (_longItemClickListener != null) {
|
||||||
|
_longItemClickListener.onLongItemClick(getAdapterPosition(), view);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private DatabaseManager _db;
|
private DatabaseManager _db;
|
||||||
|
|
||||||
private boolean _nightMode = false;
|
private boolean _nightMode = false;
|
||||||
private int _clickedItemPosition = -1;
|
|
||||||
|
|
||||||
private Menu _menu;
|
private Menu _menu;
|
||||||
|
|
||||||
|
@ -111,13 +110,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
||||||
|
|
||||||
_keyProfileAdapter = new KeyProfileAdapter(_keyProfiles);
|
_keyProfileAdapter = new KeyProfileAdapter(_keyProfiles);
|
||||||
_keyProfileAdapter.setOnItemClickListener((position, v) -> {
|
_keyProfileAdapter.setOnItemClickListener((position, v) -> createBottomSheet(position).show());
|
||||||
_clickedItemPosition = position;
|
|
||||||
InitializeBottomSheet().show();
|
|
||||||
});
|
|
||||||
_keyProfileAdapter.setOnLongItemClickListener((position, v) -> {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_keyProfileAdapter);
|
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_keyProfileAdapter);
|
||||||
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
||||||
|
@ -272,34 +265,30 @@ public class MainActivity extends AppCompatActivity {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BottomSheetDialog InitializeBottomSheet()
|
private BottomSheetDialog createBottomSheet(int position) {
|
||||||
{
|
View bottomSheetView = getLayoutInflater().inflate(R.layout.bottom_sheet_edit_profile, null);
|
||||||
View bottomSheetView = getLayoutInflater ().inflate (R.layout.bottom_sheet_edit_profile, null);
|
LinearLayout copyLayout = (LinearLayout) bottomSheetView.findViewById(R.id.copy_button);
|
||||||
LinearLayout copyLayout = (LinearLayout)bottomSheetView.findViewById(R.id.copy_button);
|
LinearLayout deleteLayout = (LinearLayout) bottomSheetView.findViewById(R.id.delete_button);
|
||||||
LinearLayout deleteLayout = (LinearLayout)bottomSheetView.findViewById(R.id.delete_button);
|
LinearLayout editLayout = (LinearLayout) bottomSheetView.findViewById(R.id.edit_button);
|
||||||
LinearLayout editLayout = (LinearLayout)bottomSheetView.findViewById(R.id.edit_button);
|
|
||||||
bottomSheetView.findViewById(R.id.edit_button);
|
bottomSheetView.findViewById(R.id.edit_button);
|
||||||
BottomSheetDialog bottomDialog = new BottomSheetDialog(this);
|
BottomSheetDialog bottomDialog = new BottomSheetDialog(this);
|
||||||
bottomDialog.setContentView(bottomSheetView);
|
bottomDialog.setContentView(bottomSheetView);
|
||||||
bottomDialog.setCancelable (true);
|
bottomDialog.setCancelable(true);
|
||||||
bottomDialog.getWindow ().setLayout (LinearLayout.LayoutParams.MATCH_PARENT,
|
bottomDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
bottomDialog.show();
|
bottomDialog.show();
|
||||||
|
|
||||||
copyLayout.setOnClickListener(view -> {
|
copyLayout.setOnClickListener(view -> {
|
||||||
bottomDialog.dismiss();
|
bottomDialog.dismiss();
|
||||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
ClipData clip = ClipData.newPlainText("text/plain", _keyProfiles.get(_clickedItemPosition).getCode());
|
ClipData clip = ClipData.newPlainText("text/plain", _keyProfiles.get(position).getCode());
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
|
Toast.makeText(this.getApplicationContext(), "Code copied to the clipboard", Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(this.getApplicationContext(), "Code successfully copied to the clipboard", Toast.LENGTH_SHORT).show();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
deleteLayout.setOnClickListener(view -> {
|
deleteLayout.setOnClickListener(view -> {
|
||||||
bottomDialog.dismiss();
|
bottomDialog.dismiss();
|
||||||
|
deleteProfile(position);
|
||||||
KeyProfile keyProfile = _keyProfiles.get(_clickedItemPosition);
|
|
||||||
deleteProfile(keyProfile);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
editLayout.setOnClickListener(view -> {
|
editLayout.setOnClickListener(view -> {
|
||||||
|
@ -310,8 +299,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return bottomDialog;
|
return bottomDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteProfile(KeyProfile profile)
|
private void deleteProfile(int position)
|
||||||
{
|
{
|
||||||
|
KeyProfile profile = _keyProfiles.get(position);
|
||||||
new AlertDialog.Builder(MainActivity.this)
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
.setTitle("Delete entry")
|
.setTitle("Delete entry")
|
||||||
.setMessage("Are you sure you want to delete this profile?")
|
.setMessage("Are you sure you want to delete this profile?")
|
||||||
|
@ -323,8 +313,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
Toast.makeText(this, "An error occurred while trying to delete an entry", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "An error occurred while trying to delete an entry", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_keyProfiles.remove(_clickedItemPosition);
|
_keyProfiles.remove(position);
|
||||||
_keyProfileAdapter.notifyItemRemoved(_clickedItemPosition);
|
_keyProfileAdapter.notifyItemRemoved(position);
|
||||||
})
|
})
|
||||||
.setNegativeButton(android.R.string.no, null)
|
.setNegativeButton(android.R.string.no, null)
|
||||||
.show();
|
.show();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue