mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Search in fragment
This commit is contained in:
1 parent
379263a6d3
commit
f037561a67
6 files changed
+177
-148
No files matched your search
@@ -112,18 +112,11 @@ public class GroupActivity extends LockingActivity
|
||||
private ExpandableLayout toolbarPasteExpandableLayout;
|
||||
private Toolbar toolbarPaste;
|
||||
private ImageView iconView;
|
||||
private View readOnlyView;
|
||||
private AddNodeButtonView addNodeButtonView;
|
||||
private TextView groupNameView;
|
||||
private View notFoundView;
|
||||
private View listContainer;
|
||||
|
||||
private Database database;
|
||||
|
||||
private boolean addGroupEnabled = false;
|
||||
private boolean addEntryEnabled = false;
|
||||
private boolean isRoot = false;
|
||||
|
||||
private ListNodesFragment listNodesFragment;
|
||||
private boolean currentGroupIsASearch;
|
||||
|
||||
@@ -219,54 +212,18 @@ public class GroupActivity extends LockingActivity
|
||||
|
||||
// Initialize views
|
||||
iconView = findViewById(R.id.icon);
|
||||
readOnlyView = findViewById(R.id.read_only);
|
||||
addNodeButtonView = findViewById(R.id.add_node_button);
|
||||
toolbar = findViewById(R.id.toolbar);
|
||||
groupNameView = findViewById(R.id.group_name);
|
||||
toolbarPasteExpandableLayout = findViewById(R.id.expandable_toolbar_paste_layout);
|
||||
toolbarPaste = findViewById(R.id.toolbar_paste);
|
||||
notFoundView = findViewById(R.id.not_found_container);
|
||||
listContainer = findViewById(R.id.nodes_list_fragment_container);
|
||||
|
||||
invalidateOptionsMenu();
|
||||
|
||||
rootGroup = database.getPwDatabase().getRootGroup();
|
||||
mCurrentGroup = retrieveCurrentGroup(getIntent(), savedInstanceState);
|
||||
currentGroupIsASearch = Intent.ACTION_SEARCH.equals(getIntent().getAction());
|
||||
|
||||
Log.i(TAG, "Started creating tree");
|
||||
if ( mCurrentGroup == null ) {
|
||||
Log.w(TAG, "Group was null");
|
||||
return;
|
||||
}
|
||||
|
||||
addNodeButtonView.enableAddGroup(addGroupEnabled);
|
||||
addNodeButtonView.enableAddEntry(addEntryEnabled);
|
||||
|
||||
toolbar.setTitle("");
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
toolbarPaste.inflateMenu(R.menu.node_paste_menu);
|
||||
toolbarPaste.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
|
||||
toolbarPaste.setNavigationOnClickListener(view -> {
|
||||
toolbarPasteExpandableLayout.collapse();
|
||||
nodeToCopy = null;
|
||||
nodeToMove = null;
|
||||
});
|
||||
|
||||
// Initialize thr fragment with list
|
||||
listNodesFragment = (ListNodesFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(LIST_NODES_FRAGMENT_TAG);
|
||||
if (listNodesFragment == null)
|
||||
listNodesFragment = ListNodesFragment.newInstance(mCurrentGroup, readOnly);
|
||||
|
||||
// Attach fragment to content view
|
||||
getSupportFragmentManager().beginTransaction().replace(
|
||||
R.id.nodes_list_fragment_container,
|
||||
listNodesFragment,
|
||||
LIST_NODES_FRAGMENT_TAG)
|
||||
.commit();
|
||||
// Get arg from intent or instance state
|
||||
readOnly = ReadOnlyHelper.retrieveReadOnlyFromInstanceStateOrIntent(savedInstanceState, getIntent());
|
||||
|
||||
// Retrieve elements after an orientation change
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey(OLD_GROUP_TO_UPDATE_KEY))
|
||||
oldGroupToUpdate = savedInstanceState.getParcelable(OLD_GROUP_TO_UPDATE_KEY);
|
||||
@@ -281,23 +238,55 @@ public class GroupActivity extends LockingActivity
|
||||
}
|
||||
}
|
||||
|
||||
rootGroup = database.getPwDatabase().getRootGroup();
|
||||
mCurrentGroup = retrieveCurrentGroup(getIntent(), savedInstanceState);
|
||||
currentGroupIsASearch = Intent.ACTION_SEARCH.equals(getIntent().getAction());
|
||||
|
||||
Log.i(TAG, "Started creating tree");
|
||||
if ( mCurrentGroup == null ) {
|
||||
Log.w(TAG, "Group was null");
|
||||
return;
|
||||
}
|
||||
|
||||
toolbar.setTitle("");
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
toolbarPaste.inflateMenu(R.menu.node_paste_menu);
|
||||
toolbarPaste.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
|
||||
toolbarPaste.setNavigationOnClickListener(view -> {
|
||||
toolbarPasteExpandableLayout.collapse();
|
||||
nodeToCopy = null;
|
||||
nodeToMove = null;
|
||||
});
|
||||
|
||||
// Initialize the fragment with the list
|
||||
listNodesFragment = (ListNodesFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(LIST_NODES_FRAGMENT_TAG);
|
||||
if (listNodesFragment == null)
|
||||
listNodesFragment = ListNodesFragment.newInstance(mCurrentGroup, readOnly, currentGroupIsASearch);
|
||||
|
||||
// Attach fragment to content view
|
||||
getSupportFragmentManager().beginTransaction().replace(
|
||||
R.id.nodes_list_fragment_container,
|
||||
listNodesFragment,
|
||||
LIST_NODES_FRAGMENT_TAG)
|
||||
.commit();
|
||||
|
||||
// Add listeners to the add buttons
|
||||
addNodeButtonView.setAddGroupClickListener(v -> GroupEditDialogFragment.build()
|
||||
.show(getSupportFragmentManager(),
|
||||
GroupEditDialogFragment.TAG_CREATE_GROUP));
|
||||
addNodeButtonView.setAddEntryClickListener(v ->
|
||||
EntryEditActivity.launch(GroupActivity.this, mCurrentGroup));
|
||||
|
||||
Log.i(TAG, "Finished creating tree");
|
||||
|
||||
if (isRoot) {
|
||||
showWarnings();
|
||||
}
|
||||
|
||||
// To init autofill
|
||||
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
autofillHelper = new AutofillHelper();
|
||||
autofillHelper.retrieveAssistStructure(getIntent());
|
||||
}
|
||||
|
||||
Log.i(TAG, "Finished creating tree");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -305,13 +294,15 @@ public class GroupActivity extends LockingActivity
|
||||
setIntent(intent);
|
||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
// only one instance of search in backstack
|
||||
openANewGroup(retrieveCurrentGroup(intent, null), !currentGroupIsASearch);
|
||||
openANewGroup(retrieveCurrentGroup(intent, null), !currentGroupIsASearch, true);
|
||||
currentGroupIsASearch = true;
|
||||
} else {
|
||||
currentGroupIsASearch = false;
|
||||
}
|
||||
currentGroupIsASearch = Intent.ACTION_SEARCH.equals(getIntent().getAction());
|
||||
}
|
||||
|
||||
private void openANewGroup(PwGroup group, boolean addToBackStack) {
|
||||
ListNodesFragment newListNodeFragment = ListNodesFragment.newInstance(group, readOnly);
|
||||
private void openANewGroup(PwGroup group, boolean addToBackStack, boolean isASearch) {
|
||||
ListNodesFragment newListNodeFragment = ListNodesFragment.newInstance(group, readOnly, isASearch);
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left,
|
||||
R.anim.slide_in_left, R.anim.slide_out_right)
|
||||
@@ -334,6 +325,7 @@ public class GroupActivity extends LockingActivity
|
||||
outState.putParcelable(NODE_TO_COPY_KEY, nodeToCopy);
|
||||
if (nodeToMove != null)
|
||||
outState.putParcelable(NODE_TO_MOVE_KEY, nodeToMove);
|
||||
ReadOnlyHelper.onSaveInstanceState(outState, readOnly);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@@ -364,14 +356,6 @@ public class GroupActivity extends LockingActivity
|
||||
currentGroup = database.getPwDatabase().getGroupByGroupId(pwGroupId);
|
||||
}
|
||||
|
||||
if (currentGroup != null) {
|
||||
addGroupEnabled = !readOnly;
|
||||
addEntryEnabled = !readOnly;
|
||||
isRoot = (currentGroup == rootGroup);
|
||||
if (!currentGroup.allowAddEntryIfIsRoot())
|
||||
addEntryEnabled = !isRoot && addEntryEnabled;
|
||||
}
|
||||
|
||||
return currentGroup;
|
||||
}
|
||||
}
|
||||
@@ -393,13 +377,6 @@ public class GroupActivity extends LockingActivity
|
||||
}
|
||||
}
|
||||
|
||||
// Assign read only text
|
||||
if (readOnly) {
|
||||
readOnlyView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
readOnlyView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// Assign icon
|
||||
if (currentGroupIsASearch) {
|
||||
if (toolbar != null) {
|
||||
@@ -430,22 +407,24 @@ public class GroupActivity extends LockingActivity
|
||||
}
|
||||
}
|
||||
|
||||
// To show the " no search entry found "
|
||||
if (currentGroupIsASearch &&
|
||||
(mCurrentGroup == null || mCurrentGroup.numbersOfChildEntries() < 1 )) {
|
||||
listContainer.setVisibility(View.GONE);
|
||||
notFoundView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
listContainer.setVisibility(View.VISIBLE);
|
||||
notFoundView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// Show button if allowed
|
||||
if (currentGroupIsASearch)
|
||||
addNodeButtonView.setVisibility(View.GONE);
|
||||
else {
|
||||
addNodeButtonView.setVisibility(View.VISIBLE);
|
||||
if (addNodeButtonView != null)
|
||||
if (addNodeButtonView != null) {
|
||||
|
||||
// To enable add button
|
||||
boolean addGroupEnabled = !readOnly && !currentGroupIsASearch;
|
||||
boolean addEntryEnabled = !readOnly && !currentGroupIsASearch;
|
||||
if (mCurrentGroup != null) {
|
||||
boolean isRoot = (mCurrentGroup == rootGroup);
|
||||
if (!mCurrentGroup.allowAddEntryIfIsRoot())
|
||||
addEntryEnabled = !isRoot && addEntryEnabled;
|
||||
if (isRoot) {
|
||||
showWarnings();
|
||||
}
|
||||
}
|
||||
addNodeButtonView.enableAddGroup(addGroupEnabled);
|
||||
addNodeButtonView.enableAddEntry(addEntryEnabled);
|
||||
|
||||
if (addNodeButtonView.isEnable())
|
||||
addNodeButtonView.showButton();
|
||||
}
|
||||
}
|
||||
@@ -687,7 +666,7 @@ public class GroupActivity extends LockingActivity
|
||||
if (listNodesFragment != null
|
||||
&& listNodesFragment.isEmpty()) {
|
||||
if (!PreferencesUtil.isEducationNewNodePerformed(this)
|
||||
&& addNodeButtonView.isVisible()) {
|
||||
&& addNodeButtonView.isEnable()) {
|
||||
|
||||
TapTargetView.showFor(this,
|
||||
TapTarget.forView(findViewById(R.id.add_button),
|
||||
@@ -1089,7 +1068,7 @@ public class GroupActivity extends LockingActivity
|
||||
if (checkTimeIsAllowedOrFinish(this)) {
|
||||
startRecordTime(this);
|
||||
// Open a new group and add the current one in the backstack
|
||||
openANewGroup(group, true);
|
||||
openANewGroup(group, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,25 +34,30 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
private static final String TAG = ListNodesFragment.class.getName();
|
||||
|
||||
private static final String GROUP_KEY = "GROUP_KEY";
|
||||
private static final String IS_SEARCH = "IS_SEARCH";
|
||||
|
||||
private NodeAdapter.NodeClickCallback nodeClickCallback;
|
||||
private NodeAdapter.NodeMenuListener nodeMenuListener;
|
||||
private OnScrollListener onScrollListener;
|
||||
|
||||
private RecyclerView listView;
|
||||
protected PwGroup mCurrentGroup;
|
||||
protected NodeAdapter mAdapter;
|
||||
private PwGroup currentGroup;
|
||||
private NodeAdapter mAdapter;
|
||||
|
||||
private View notFoundView;
|
||||
private boolean isASearchResult;
|
||||
|
||||
// Preferences for sorting
|
||||
private SharedPreferences prefs;
|
||||
|
||||
private boolean readOnly;
|
||||
|
||||
public static ListNodesFragment newInstance(PwGroup group, boolean readOnly) {
|
||||
public static ListNodesFragment newInstance(PwGroup group, boolean readOnly, boolean isASearch) {
|
||||
Bundle bundle = new Bundle();
|
||||
if (group != null) {
|
||||
bundle.putParcelable(GROUP_KEY, group);
|
||||
}
|
||||
bundle.putBoolean(IS_SEARCH, isASearch);
|
||||
ReadOnlyHelper.putReadOnlyInBundle(bundle, readOnly);
|
||||
ListNodesFragment listNodesFragment = new ListNodesFragment();
|
||||
listNodesFragment.setArguments(bundle);
|
||||
@@ -99,11 +104,17 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
if (getArguments() != null) {
|
||||
// Contains all the group in element
|
||||
if (getArguments().containsKey(GROUP_KEY)) {
|
||||
mCurrentGroup = getArguments().getParcelable(GROUP_KEY);
|
||||
currentGroup = getArguments().getParcelable(GROUP_KEY);
|
||||
}
|
||||
|
||||
if (getArguments().containsKey(IS_SEARCH)) {
|
||||
isASearchResult = getArguments().getBoolean(IS_SEARCH);
|
||||
}
|
||||
}
|
||||
|
||||
mAdapter = new NodeAdapter(getContextThemed(), getActivity().getMenuInflater(), readOnly);
|
||||
mAdapter = new NodeAdapter(getContextThemed(), getActivity().getMenuInflater());
|
||||
mAdapter.setReadOnly(readOnly);
|
||||
mAdapter.setIsASearchResult(isASearchResult);
|
||||
mAdapter.setOnNodeClickListener(nodeClickCallback);
|
||||
|
||||
if (nodeMenuListener != null) {
|
||||
@@ -129,6 +140,7 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
View rootView = inflater.cloneInContext(getContextThemed())
|
||||
.inflate(R.layout.list_nodes_fragment, container, false);
|
||||
listView = rootView.findViewById(R.id.nodes_list);
|
||||
notFoundView = rootView.findViewById(R.id.not_found_container);
|
||||
|
||||
if (onScrollListener != null) {
|
||||
listView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@@ -148,11 +160,20 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
super.onResume();
|
||||
|
||||
rebuildList();
|
||||
|
||||
if (isASearchResult && mAdapter.isEmpty()) {
|
||||
// To show the " no search entry found "
|
||||
listView.setVisibility(View.GONE);
|
||||
notFoundView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
listView.setVisibility(View.VISIBLE);
|
||||
notFoundView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void rebuildList() {
|
||||
// Add elements to the list
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
mAdapter.rebuildList(currentGroup);
|
||||
assignListToNodeAdapter(listView);
|
||||
}
|
||||
|
||||
@@ -174,7 +195,7 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
|
||||
// Tell the adapter to refresh it's list
|
||||
mAdapter.notifyChangeSort(sortNodeEnum, ascending, groupsBefore);
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
mAdapter.rebuildList(currentGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,7 +253,7 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
mAdapter.addNode(newNode);
|
||||
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||
//mAdapter.updateLastNodeRegister(newNode);
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
mAdapter.rebuildList(currentGroup);
|
||||
}
|
||||
} else {
|
||||
Log.e(this.getClass().getName(), "New node can be retrieve in Activity Result");
|
||||
@@ -259,7 +280,7 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
}
|
||||
|
||||
public PwGroup getMainGroup() {
|
||||
return mCurrentGroup;
|
||||
return currentGroup;
|
||||
}
|
||||
|
||||
public interface OnScrollListener {
|
||||
|
||||
@@ -62,6 +62,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
private NodeMenuListener nodeMenuListener;
|
||||
private boolean activateContextMenu;
|
||||
private boolean readOnly;
|
||||
private boolean isASearchResult;
|
||||
|
||||
private int iconGroupColor;
|
||||
private int iconEntryColor;
|
||||
@@ -70,13 +71,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
* Create node list adapter with contextMenu or not
|
||||
* @param context Context to use
|
||||
*/
|
||||
public NodeAdapter(final Context context, MenuInflater menuInflater, boolean readOnly) {
|
||||
public NodeAdapter(final Context context, MenuInflater menuInflater) {
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.menuInflater = menuInflater;
|
||||
this.context = context;
|
||||
assignPreferences();
|
||||
this.activateContextMenu = false;
|
||||
this.readOnly = readOnly;
|
||||
this.readOnly = false;
|
||||
this.isASearchResult = false;
|
||||
|
||||
this.nodeSortedList = new SortedList<>(PwNode.class, new SortedListAdapterCallback<PwNode>(this) {
|
||||
@Override public int compare(PwNode item1, PwNode item2) {
|
||||
@@ -103,6 +105,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
taTextColor.recycle();
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly) {
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public void setIsASearchResult(boolean isASearchResult) {
|
||||
this.isASearchResult = isASearchResult;
|
||||
}
|
||||
|
||||
public void setActivateContextMenu(boolean activate) {
|
||||
this.activateContextMenu = activate;
|
||||
}
|
||||
@@ -136,6 +146,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the adapter contains or not any element
|
||||
* @return true if the list is empty
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return nodeSortedList.size() <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a node to the list
|
||||
* @param node Node to add
|
||||
@@ -301,29 +319,44 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
|
||||
menuInflater.inflate(R.menu.node_menu, contextMenu);
|
||||
|
||||
// Opening
|
||||
MenuItem menuItem = contextMenu.findItem(R.id.menu_open);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
|
||||
// Edition
|
||||
if (readOnly || node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||
contextMenu.removeItem(R.id.menu_edit);
|
||||
contextMenu.removeItem(R.id.menu_copy);
|
||||
contextMenu.removeItem(R.id.menu_move);
|
||||
contextMenu.removeItem(R.id.menu_delete);
|
||||
} else {
|
||||
// Edition
|
||||
menuItem = contextMenu.findItem(R.id.menu_edit);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
// Copy (not for group)
|
||||
if (node.getType().equals(PwNode.Type.ENTRY)) {
|
||||
menuItem = contextMenu.findItem(R.id.menu_copy);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
} else {
|
||||
// TODO COPY For Group
|
||||
contextMenu.removeItem(R.id.menu_copy);
|
||||
}
|
||||
// Move
|
||||
}
|
||||
|
||||
// Copy (not for group)
|
||||
if (readOnly
|
||||
|| isASearchResult
|
||||
|| node.equals(App.getDB().getPwDatabase().getRecycleBin())
|
||||
|| node.getType().equals(PwNode.Type.GROUP)) {
|
||||
// TODO COPY For Group
|
||||
contextMenu.removeItem(R.id.menu_copy);
|
||||
} else {
|
||||
menuItem = contextMenu.findItem(R.id.menu_copy);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
}
|
||||
|
||||
// Move
|
||||
if (readOnly
|
||||
|| isASearchResult
|
||||
|| node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||
contextMenu.removeItem(R.id.menu_move);
|
||||
} else {
|
||||
menuItem = contextMenu.findItem(R.id.menu_move);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
// Deletion
|
||||
}
|
||||
|
||||
// Deletion
|
||||
if (readOnly || node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||
contextMenu.removeItem(R.id.menu_delete);
|
||||
} else {
|
||||
menuItem = contextMenu.findItem(R.id.menu_delete);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class AddNodeButtonView extends RelativeLayout {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
public boolean isEnable() {
|
||||
return getVisibility() == VISIBLE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user