mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-24 07:46:07 +00:00
Move the recycler view to its own fragment
This commit is contained in:
parent
0427164529
commit
950c6d0cf3
5 changed files with 121 additions and 51 deletions
|
@ -15,10 +15,9 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileHolder> im
|
||||||
private static Listener _listener;
|
private static Listener _listener;
|
||||||
private boolean _showIssuer;
|
private boolean _showIssuer;
|
||||||
|
|
||||||
public KeyProfileAdapter(Listener listener, boolean showIssuer) {
|
public KeyProfileAdapter(Listener listener) {
|
||||||
_keyProfiles = new ArrayList<>();
|
_keyProfiles = new ArrayList<>();
|
||||||
_listener = listener;
|
_listener = listener;
|
||||||
_showIssuer = showIssuer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShowIssuer(boolean showIssuer) {
|
public void setShowIssuer(boolean showIssuer) {
|
||||||
|
|
87
app/src/main/java/me/impy/aegis/KeyProfileView.java
Normal file
87
app/src/main/java/me/impy/aegis/KeyProfileView.java
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
package me.impy.aegis;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import me.impy.aegis.db.DatabaseEntry;
|
||||||
|
import me.impy.aegis.helpers.SimpleItemTouchHelperCallback;
|
||||||
|
|
||||||
|
public class KeyProfileView extends Fragment implements KeyProfileAdapter.Listener {
|
||||||
|
private KeyProfileAdapter _adapter;
|
||||||
|
private Listener _listener;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
_adapter = new KeyProfileAdapter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_keyprofile_view, container, false);
|
||||||
|
|
||||||
|
// set up the recycler view
|
||||||
|
RecyclerView rvKeyProfiles = view.findViewById(R.id.rvKeyProfiles);
|
||||||
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
|
||||||
|
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
||||||
|
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_adapter);
|
||||||
|
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
||||||
|
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
||||||
|
rvKeyProfiles.setAdapter(_adapter);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListener(Listener listener) {
|
||||||
|
_listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onKeyProfileClick(KeyProfile profile) {
|
||||||
|
_listener.onEntryClick(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongKeyProfileClick(KeyProfile profile) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onKeyProfileMove(KeyProfile profile1, KeyProfile profile2) {
|
||||||
|
_listener.onEntryMove(profile1.getEntry(), profile2.getEntry());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onKeyProfileDrop(KeyProfile profile) {
|
||||||
|
_listener.onEntryDrop(profile.getEntry());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowIssuer(boolean showIssuer) {
|
||||||
|
_adapter.setShowIssuer(showIssuer);
|
||||||
|
_adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addKey(KeyProfile profile) {
|
||||||
|
_adapter.addKey(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeKey(KeyProfile profile) {
|
||||||
|
_adapter.removeKey(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearKeys() {
|
||||||
|
_adapter.clearKeys();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Listener {
|
||||||
|
void onEntryClick(KeyProfile profile);
|
||||||
|
void onEntryMove(DatabaseEntry entry1, DatabaseEntry entry2);
|
||||||
|
void onEntryDrop(DatabaseEntry entry);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,10 +15,7 @@ import android.support.design.widget.BottomSheetDialog;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -26,7 +23,6 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
import java.lang.reflect.UndeclaredThrowableException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -37,10 +33,9 @@ import me.impy.aegis.db.DatabaseEntry;
|
||||||
import me.impy.aegis.db.DatabaseManager;
|
import me.impy.aegis.db.DatabaseManager;
|
||||||
import me.impy.aegis.helpers.PermissionHelper;
|
import me.impy.aegis.helpers.PermissionHelper;
|
||||||
import me.impy.aegis.importers.DatabaseImporter;
|
import me.impy.aegis.importers.DatabaseImporter;
|
||||||
import me.impy.aegis.helpers.SimpleItemTouchHelperCallback;
|
|
||||||
import me.impy.aegis.util.ByteInputStream;
|
import me.impy.aegis.util.ByteInputStream;
|
||||||
|
|
||||||
public class MainActivity extends AegisActivity implements KeyProfileAdapter.Listener {
|
public class MainActivity extends AegisActivity implements KeyProfileView.Listener {
|
||||||
// activity request codes
|
// activity request codes
|
||||||
private static final int CODE_GET_KEYINFO = 0;
|
private static final int CODE_GET_KEYINFO = 0;
|
||||||
private static final int CODE_ADD_KEYINFO = 1;
|
private static final int CODE_ADD_KEYINFO = 1;
|
||||||
|
@ -54,9 +49,9 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
private static final int CODE_PERM_IMPORT = 1;
|
private static final int CODE_PERM_IMPORT = 1;
|
||||||
private static final int CODE_PERM_CAMERA = 2;
|
private static final int CODE_PERM_CAMERA = 2;
|
||||||
|
|
||||||
private KeyProfileAdapter _keyProfileAdapter;
|
|
||||||
private AegisApplication _app;
|
private AegisApplication _app;
|
||||||
private DatabaseManager _db;
|
private DatabaseManager _db;
|
||||||
|
private KeyProfileView _keyProfileView;
|
||||||
|
|
||||||
private boolean _nightMode = false;
|
private boolean _nightMode = false;
|
||||||
private Menu _menu;
|
private Menu _menu;
|
||||||
|
@ -72,6 +67,11 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
// set up the key profile view
|
||||||
|
_keyProfileView = (KeyProfileView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
|
||||||
|
_keyProfileView.setListener(this);
|
||||||
|
_keyProfileView.setShowIssuer(_app.getPreferences().getBoolean("pref_issuer", false));
|
||||||
|
|
||||||
// init the app shortcuts and execute any pending actions
|
// init the app shortcuts and execute any pending actions
|
||||||
initializeAppShortcuts();
|
initializeAppShortcuts();
|
||||||
doShortcutActions();
|
doShortcutActions();
|
||||||
|
@ -81,16 +81,6 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
fab.setEnabled(true);
|
fab.setEnabled(true);
|
||||||
fab.setOnClickListener(view -> onGetKeyInfo());
|
fab.setOnClickListener(view -> onGetKeyInfo());
|
||||||
|
|
||||||
// set up the recycler view for the key profiles
|
|
||||||
_keyProfileAdapter = new KeyProfileAdapter(this, _app.getPreferences().getBoolean("pref_issuer", false));
|
|
||||||
RecyclerView rvKeyProfiles = findViewById(R.id.rvKeyProfiles);
|
|
||||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
|
|
||||||
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
|
||||||
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(_keyProfileAdapter);
|
|
||||||
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
|
|
||||||
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
|
||||||
rvKeyProfiles.setAdapter(_keyProfileAdapter);
|
|
||||||
|
|
||||||
// skip this part if this is the not initial startup and the database has been unlocked
|
// skip this part if this is the not initial startup and the database has been unlocked
|
||||||
if (!_app.isRunning() && _db.isLocked()) {
|
if (!_app.isRunning() && _db.isLocked()) {
|
||||||
if (!_db.fileExists()) {
|
if (!_db.fileExists()) {
|
||||||
|
@ -180,8 +170,7 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
// refresh the entire key profile list if needed
|
// refresh the entire key profile list if needed
|
||||||
if (data.getBooleanExtra("needsRefresh", false)) {
|
if (data.getBooleanExtra("needsRefresh", false)) {
|
||||||
boolean showIssuer = _app.getPreferences().getBoolean("pref_issuer", false);
|
boolean showIssuer = _app.getPreferences().getBoolean("pref_issuer", false);
|
||||||
_keyProfileAdapter.setShowIssuer(showIssuer);
|
_keyProfileView.setShowIssuer(showIssuer);
|
||||||
_keyProfileAdapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform any pending actions
|
// perform any pending actions
|
||||||
|
@ -336,7 +325,7 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_keyProfileAdapter.addKey(profile);
|
_keyProfileView.addKey(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDoIntroResult(int resultCode, Intent data) {
|
private void onDoIntroResult(int resultCode, Intent data) {
|
||||||
|
@ -458,7 +447,7 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
}
|
}
|
||||||
saveDatabase();
|
saveDatabase();
|
||||||
|
|
||||||
_keyProfileAdapter.removeKey(profile);
|
_keyProfileView.removeKey(profile);
|
||||||
})
|
})
|
||||||
.setNegativeButton(android.R.string.no, null)
|
.setNegativeButton(android.R.string.no, null)
|
||||||
.show();
|
.show();
|
||||||
|
@ -485,7 +474,7 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_lock:
|
case R.id.action_lock:
|
||||||
_keyProfileAdapter.clearKeys();
|
_keyProfileView.clearKeys();
|
||||||
try {
|
try {
|
||||||
_db.lock();
|
_db.lock();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -548,7 +537,7 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (DatabaseEntry entry : _db.getKeys()) {
|
for (DatabaseEntry entry : _db.getKeys()) {
|
||||||
_keyProfileAdapter.addKey(new KeyProfile(entry));
|
_keyProfileView.addKey(new KeyProfile(entry));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -566,19 +555,14 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKeyProfileClick(KeyProfile profile) {
|
public void onEntryClick(KeyProfile profile) {
|
||||||
createBottomSheet(profile).show();
|
createBottomSheet(profile).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongKeyProfileClick(KeyProfile profile) {
|
public void onEntryMove(DatabaseEntry entry1, DatabaseEntry entry2) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onKeyProfileMove(KeyProfile profile1, KeyProfile profile2) {
|
|
||||||
try {
|
try {
|
||||||
_db.swapKeys(profile1.getEntry(), profile2.getEntry());
|
_db.swapKeys(entry1, entry2);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new UndeclaredThrowableException(e);
|
throw new UndeclaredThrowableException(e);
|
||||||
|
@ -586,7 +570,7 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKeyProfileDrop(KeyProfile profile) {
|
public void onEntryDrop(DatabaseEntry entry) {
|
||||||
saveDatabase();
|
saveDatabase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,22 +30,11 @@
|
||||||
android:src="@drawable/ic_add_black_24dp"
|
android:src="@drawable/ic_add_black_24dp"
|
||||||
android:tint="@color/background"/>
|
android:tint="@color/background"/>
|
||||||
|
|
||||||
<RelativeLayout
|
<fragment
|
||||||
android:layout_width="match_parent"
|
android:name="me.impy.aegis.KeyProfileView"
|
||||||
|
android:id="@+id/key_profiles"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?attr/background"
|
android:layout_width="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
|
||||||
tools:context="me.impy.aegis.MainActivity"
|
|
||||||
tools:showIn="@layout/activity_main">
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/rvKeyProfiles"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
/>
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
|
||||||
|
|
11
app/src/main/res/layout/fragment_keyprofile_view.xml
Normal file
11
app/src/main/res/layout/fragment_keyprofile_view.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="?attr/background">
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/rvKeyProfiles"/>
|
||||||
|
</LinearLayout>
|
Loading…
Add table
Reference in a new issue