mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
#55 Fix listener to add node (dispatch event must to be refactored)
This commit is contained in:
@@ -61,18 +61,19 @@ import com.keepassdroid.dialogs.IconPickerDialogFragment;
|
|||||||
import com.keepassdroid.password.PasswordActivity;
|
import com.keepassdroid.password.PasswordActivity;
|
||||||
import com.keepassdroid.search.SearchResultsActivity;
|
import com.keepassdroid.search.SearchResultsActivity;
|
||||||
import com.keepassdroid.tasks.ProgressTask;
|
import com.keepassdroid.tasks.ProgressTask;
|
||||||
import com.keepassdroid.view.ListNodesWithAddButtonView;
|
import com.keepassdroid.view.AddNodeView;
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
public class GroupActivity extends ListNodesActivity
|
public class GroupActivity extends ListNodesActivity
|
||||||
implements GroupEditDialogFragment.EditGroupListener, IconPickerDialogFragment.IconPickerListener {
|
implements GroupEditDialogFragment.EditGroupListener, IconPickerDialogFragment.IconPickerListener {
|
||||||
|
|
||||||
|
private AddNodeView addNodeView;
|
||||||
|
|
||||||
protected boolean addGroupEnabled = false;
|
protected boolean addGroupEnabled = false;
|
||||||
protected boolean addEntryEnabled = false;
|
protected boolean addEntryEnabled = false;
|
||||||
protected boolean isRoot = false;
|
protected boolean isRoot = false;
|
||||||
protected boolean readOnly = false;
|
protected boolean readOnly = false;
|
||||||
protected EditGroupDialogAction editGroupDialogAction = EditGroupDialogAction.NONE;
|
protected EditGroupDialogAction editGroupDialogAction = EditGroupDialogAction.NONE;
|
||||||
private ListNodesWithAddButtonView rootView;
|
|
||||||
|
|
||||||
private AutofillHelper autofillHelper;
|
private AutofillHelper autofillHelper;
|
||||||
|
|
||||||
@@ -124,31 +125,30 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Construct main view
|
// Construct main view
|
||||||
rootView = new ListNodesWithAddButtonView(this);
|
setContentView(getLayoutInflater().inflate(R.layout.list_nodes_with_add_button, null));
|
||||||
rootView.enableAddGroup(addGroupEnabled);
|
|
||||||
rootView.enableAddEntry(addEntryEnabled);
|
|
||||||
setContentView(rootView);
|
|
||||||
|
|
||||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
addNodeView = findViewById(R.id.add_node_button);
|
||||||
|
addNodeView.enableAddGroup(addGroupEnabled);
|
||||||
|
addNodeView.enableAddEntry(addEntryEnabled);
|
||||||
|
// Hide when scroll
|
||||||
|
RecyclerView recyclerView = findViewById(R.id.nodes_list);
|
||||||
|
recyclerView.addOnScrollListener(addNodeView.hideButtonOnScrollListener());
|
||||||
|
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
toolbar.setTitle("");
|
toolbar.setTitle("");
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
if ( mCurrentGroup.getParent() != null )
|
if ( mCurrentGroup.getParent() != null )
|
||||||
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
|
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
|
||||||
|
|
||||||
rootView.setAddGroupClickListener(new View.OnClickListener() {
|
addNodeView.setAddGroupClickListener(v -> {
|
||||||
public void onClick(View v) {
|
editGroupDialogAction = EditGroupDialogAction.CREATION;
|
||||||
editGroupDialogAction = EditGroupDialogAction.CREATION;
|
GroupEditDialogFragment groupEditDialogFragment = new GroupEditDialogFragment();
|
||||||
GroupEditDialogFragment groupEditDialogFragment = new GroupEditDialogFragment();
|
groupEditDialogFragment.show(getSupportFragmentManager(),
|
||||||
groupEditDialogFragment.show(getSupportFragmentManager(),
|
GroupEditDialogFragment.TAG_CREATE_GROUP);
|
||||||
GroupEditDialogFragment.TAG_CREATE_GROUP);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
rootView.setAddEntryClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
EntryEditActivity.Launch(GroupActivity.this, mCurrentGroup);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
addNodeView.setAddEntryClickListener(v ->
|
||||||
|
EntryEditActivity.Launch(GroupActivity.this, mCurrentGroup));
|
||||||
|
|
||||||
setGroupTitle();
|
setGroupTitle();
|
||||||
setGroupIcon();
|
setGroupIcon();
|
||||||
@@ -276,7 +276,14 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
// Show button on resume
|
// Show button on resume
|
||||||
rootView.showButton();
|
addNodeView.showButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
// Hide button
|
||||||
|
addNodeView.hideButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -291,9 +298,8 @@ public class GroupActivity extends ListNodesActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
||||||
super.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
|
super.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
|
||||||
|
|
||||||
// Show button if hide after sort
|
// Show button if hide after sort
|
||||||
rootView.showButton();
|
addNodeView.showButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setGroupIcon() {
|
protected void setGroupIcon() {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package com.keepassdroid.view;
|
package com.keepassdroid.view;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v4.view.ViewPropertyAnimatorListener;
|
import android.support.v4.view.ViewPropertyAnimatorListener;
|
||||||
@@ -36,7 +35,7 @@ import android.widget.RelativeLayout;
|
|||||||
|
|
||||||
import com.kunzisoft.keepass.R;
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
public class ListNodesWithAddButtonView extends RelativeLayout {
|
public class AddNodeView extends RelativeLayout {
|
||||||
|
|
||||||
private enum State {
|
private enum State {
|
||||||
OPEN, CLOSE
|
OPEN, CLOSE
|
||||||
@@ -58,11 +57,11 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
private ViewMenuAnimation viewMenuAnimationAddGroup;
|
private ViewMenuAnimation viewMenuAnimationAddGroup;
|
||||||
private long animationDuration;
|
private long animationDuration;
|
||||||
|
|
||||||
public ListNodesWithAddButtonView(Context context) {
|
public AddNodeView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListNodesWithAddButtonView(Context context, AttributeSet attrs) {
|
public AddNodeView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
inflate(context);
|
inflate(context);
|
||||||
}
|
}
|
||||||
@@ -70,12 +69,12 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
protected void inflate(Context context) {
|
protected void inflate(Context context) {
|
||||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
assert inflater != null;
|
assert inflater != null;
|
||||||
inflater.inflate(R.layout.list_nodes_with_add_button, this);
|
inflater.inflate(R.layout.add_node_button, this);
|
||||||
|
|
||||||
addEntryEnable = true;
|
addEntryEnable = true;
|
||||||
addGroupEnable = true;
|
addGroupEnable = true;
|
||||||
|
|
||||||
addButton = (FloatingActionButton) findViewById(R.id.add_button);
|
addButton = findViewById(R.id.add_button);
|
||||||
addEntry = findViewById(R.id.add_entry);
|
addEntry = findViewById(R.id.add_entry);
|
||||||
addGroup = findViewById(R.id.add_group);
|
addGroup = findViewById(R.id.add_group);
|
||||||
|
|
||||||
@@ -88,12 +87,9 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
allowAction = true;
|
allowAction = true;
|
||||||
state = State.CLOSE;
|
state = State.CLOSE;
|
||||||
|
|
||||||
onAddButtonClickListener = new OnClickListener() {
|
onAddButtonClickListener = v -> {
|
||||||
@Override
|
if (allowAction) {
|
||||||
public void onClick(View v) {
|
startGlobalAnimation();
|
||||||
if (allowAction && state.equals(State.CLOSE)) {
|
|
||||||
startGlobalAnimation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
addButton.setOnClickListener(onAddButtonClickListener);
|
addButton.setOnClickListener(onAddButtonClickListener);
|
||||||
@@ -111,10 +107,10 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
addButton.setOnClickListener(onAddButtonClickListener);
|
addButton.setOnClickListener(onAddButtonClickListener);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Hide when scroll
|
public RecyclerView.OnScrollListener hideButtonOnScrollListener() {
|
||||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.nodes_list);
|
return new RecyclerView.OnScrollListener() {
|
||||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||||
super.onScrolled(recyclerView, dx, dy);
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
@@ -126,8 +122,8 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showButton() {
|
public void showButton() {
|
||||||
addButton.show(onAddButtonVisibilityChangedListener);
|
addButton.show(onAddButtonVisibilityChangedListener);
|
||||||
@@ -139,6 +135,8 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||||
|
/*
|
||||||
|
TODO Dispatch event to close
|
||||||
Rect viewRectG = new Rect();
|
Rect viewRectG = new Rect();
|
||||||
getGlobalVisibleRect(viewRectG);
|
getGlobalVisibleRect(viewRectG);
|
||||||
if (viewRectG.contains((int) ev.getRawX(), (int) ev.getRawY())) {
|
if (viewRectG.contains((int) ev.getRawX(), (int) ev.getRawY())) {
|
||||||
@@ -146,6 +144,7 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
startGlobalAnimation();
|
startGlobalAnimation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return super.dispatchTouchEvent(ev);
|
return super.dispatchTouchEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,12 +170,18 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
|
|||||||
|
|
||||||
public void setAddGroupClickListener(OnClickListener onClickListener) {
|
public void setAddGroupClickListener(OnClickListener onClickListener) {
|
||||||
if (addGroupEnable)
|
if (addGroupEnable)
|
||||||
addGroup.setOnClickListener(onClickListener);
|
addGroup.setOnClickListener(view -> {
|
||||||
|
onClickListener.onClick(view);
|
||||||
|
startGlobalAnimation();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddEntryClickListener(OnClickListener onClickListener) {
|
public void setAddEntryClickListener(OnClickListener onClickListener) {
|
||||||
if (addEntryEnable)
|
if (addEntryEnable)
|
||||||
addEntry.setOnClickListener(onClickListener);
|
addEntry.setOnClickListener(view -> {
|
||||||
|
onClickListener.onClick(view);
|
||||||
|
startGlobalAnimation();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startGlobalAnimation() {
|
private void startGlobalAnimation() {
|
||||||
43
app/src/main/res/layout/add_node_button.xml
Normal file
43
app/src/main/res/layout/add_node_button.xml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<android.support.design.widget.FloatingActionButton
|
||||||
|
android:id="@+id/add_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_add_white_24dp"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
app:useCompatPadding="true"
|
||||||
|
style="@style/KeepassDXStyle.Fab" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/add_entry"
|
||||||
|
android:layout_margin="12dp"
|
||||||
|
android:layout_above="@+id/add_button"
|
||||||
|
android:layout_alignRight="@+id/add_button"
|
||||||
|
android:layout_alignEnd="@+id/add_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/add_entry"
|
||||||
|
style="@style/KeepassDXStyle.FabMenu"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:ignore="UnusedAttribute" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/add_group"
|
||||||
|
android:layout_margin="12dp"
|
||||||
|
android:layout_above="@+id/add_entry"
|
||||||
|
android:layout_alignRight="@+id/add_button"
|
||||||
|
android:layout_alignEnd="@+id/add_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/add_group"
|
||||||
|
style="@style/KeepassDXStyle.FabMenu"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:ignore="UnusedAttribute" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -72,38 +72,11 @@
|
|||||||
android:layout_below="@+id/toolbar" />
|
android:layout_below="@+id/toolbar" />
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
||||||
<android.support.design.widget.FloatingActionButton
|
<com.keepassdroid.view.AddNodeView
|
||||||
android:id="@+id/add_button"
|
android:id="@+id/add_node_button"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_add_white_24dp"
|
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
app:useCompatPadding="true"
|
|
||||||
style="@style/KeepassDXStyle.Fab" />
|
|
||||||
|
|
||||||
<TextView android:id="@+id/add_entry"
|
|
||||||
android:layout_margin="12dp"
|
|
||||||
android:layout_above="@+id/add_button"
|
|
||||||
android:layout_alignRight="@+id/add_button"
|
|
||||||
android:layout_alignEnd="@+id/add_button"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:text="@string/add_entry"
|
|
||||||
style="@style/KeepassDXStyle.FabMenu"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:ignore="UnusedAttribute" />
|
|
||||||
|
|
||||||
<TextView android:id="@+id/add_group"
|
|
||||||
android:layout_margin="12dp"
|
|
||||||
android:layout_above="@+id/add_entry"
|
|
||||||
android:layout_alignRight="@+id/add_button"
|
|
||||||
android:layout_alignEnd="@+id/add_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/add_group"
|
|
||||||
style="@style/KeepassDXStyle.FabMenu"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:ignore="UnusedAttribute" />
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
Reference in New Issue
Block a user