mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-27 01:06:14 +00:00
Abstract the key profile list away from MainActivity
This commit is contained in:
parent
461f321626
commit
f952ee7df9
2 changed files with 24 additions and 12 deletions
|
@ -28,13 +28,29 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
|||
private Handler _uiHandler;
|
||||
private static Listener _listener;
|
||||
|
||||
public KeyProfileAdapter(ArrayList<KeyProfile> keyProfiles, Listener listener) {
|
||||
_keyProfiles = keyProfiles;
|
||||
public KeyProfileAdapter(Listener listener) {
|
||||
_keyProfiles = new ArrayList<>();
|
||||
_holders = new ArrayList<>();
|
||||
_uiHandler = new Handler();
|
||||
_listener = listener;
|
||||
}
|
||||
|
||||
public void addKey(KeyProfile profile) {
|
||||
_keyProfiles.add(profile);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addKeys(List<KeyProfile> profiles) {
|
||||
_keyProfiles.addAll(profiles);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void removeKey(KeyProfile profile) {
|
||||
int position = _keyProfiles.indexOf(profile);
|
||||
_keyProfiles.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemDismiss(int position) {
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@ public class MainActivity extends AppCompatActivity implements KeyProfileAdapter
|
|||
private static final int CODE_PREFERENCES = 5;
|
||||
|
||||
private KeyProfileAdapter _keyProfileAdapter;
|
||||
private ArrayList<KeyProfile> _keyProfiles;
|
||||
private DatabaseManager _db;
|
||||
|
||||
private boolean _nightMode = false;
|
||||
|
@ -113,8 +112,7 @@ public class MainActivity extends AppCompatActivity implements KeyProfileAdapter
|
|||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
|
||||
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
||||
|
||||
_keyProfiles = new ArrayList<>();
|
||||
_keyProfileAdapter = new KeyProfileAdapter(_keyProfiles, this);
|
||||
_keyProfileAdapter = new KeyProfileAdapter(this);
|
||||
if (_db.isDecrypted()) {
|
||||
loadKeyProfiles();
|
||||
}
|
||||
|
@ -282,8 +280,7 @@ public class MainActivity extends AppCompatActivity implements KeyProfileAdapter
|
|||
return;
|
||||
}
|
||||
|
||||
_keyProfiles.add(profile);
|
||||
_keyProfileAdapter.notifyDataSetChanged();
|
||||
_keyProfileAdapter.addKey(profile);
|
||||
}
|
||||
|
||||
private void onDoIntroResult(int resultCode, Intent data) {
|
||||
|
@ -400,9 +397,7 @@ public class MainActivity extends AppCompatActivity implements KeyProfileAdapter
|
|||
Toast.makeText(this, "An error occurred while trying to delete an entry", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
int position = _keyProfiles.indexOf(profile);
|
||||
_keyProfiles.remove(profile);
|
||||
_keyProfileAdapter.notifyItemRemoved(position);
|
||||
_keyProfileAdapter.removeKey(profile);
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show();
|
||||
|
@ -501,9 +496,10 @@ public class MainActivity extends AppCompatActivity implements KeyProfileAdapter
|
|||
private void loadKeyProfiles() {
|
||||
updateLockIcon();
|
||||
|
||||
List<KeyProfile> profiles = new ArrayList<>();
|
||||
try {
|
||||
for (DatabaseEntry entry : _db.getKeys()) {
|
||||
_keyProfiles.add(new KeyProfile(entry));
|
||||
profiles.add(new KeyProfile(entry));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -511,7 +507,7 @@ public class MainActivity extends AppCompatActivity implements KeyProfileAdapter
|
|||
return;
|
||||
}
|
||||
|
||||
_keyProfileAdapter.notifyDataSetChanged();
|
||||
_keyProfileAdapter.addKeys(profiles);
|
||||
}
|
||||
|
||||
private void updateLockIcon() {
|
||||
|
|
Loading…
Add table
Reference in a new issue