#55 Fix listener to add node (dispatch event must to be refactored)

This commit is contained in:
J-Jamet
2018-03-21 16:13:40 +01:00
parent 64448ef218
commit 30f805f5a9
4 changed files with 98 additions and 71 deletions

View File

@@ -61,18 +61,19 @@ import com.keepassdroid.dialogs.IconPickerDialogFragment;
import com.keepassdroid.password.PasswordActivity;
import com.keepassdroid.search.SearchResultsActivity;
import com.keepassdroid.tasks.ProgressTask;
import com.keepassdroid.view.ListNodesWithAddButtonView;
import com.keepassdroid.view.AddNodeView;
import com.kunzisoft.keepass.R;
public class GroupActivity extends ListNodesActivity
implements GroupEditDialogFragment.EditGroupListener, IconPickerDialogFragment.IconPickerListener {
private AddNodeView addNodeView;
protected boolean addGroupEnabled = false;
protected boolean addEntryEnabled = false;
protected boolean isRoot = false;
protected boolean readOnly = false;
protected EditGroupDialogAction editGroupDialogAction = EditGroupDialogAction.NONE;
private ListNodesWithAddButtonView rootView;
private AutofillHelper autofillHelper;
@@ -124,31 +125,30 @@ public class GroupActivity extends ListNodesActivity
}
// Construct main view
rootView = new ListNodesWithAddButtonView(this);
rootView.enableAddGroup(addGroupEnabled);
rootView.enableAddEntry(addEntryEnabled);
setContentView(rootView);
setContentView(getLayoutInflater().inflate(R.layout.list_nodes_with_add_button, null));
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("");
setSupportActionBar(toolbar);
if ( mCurrentGroup.getParent() != null )
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
rootView.setAddGroupClickListener(new View.OnClickListener() {
public void onClick(View v) {
editGroupDialogAction = EditGroupDialogAction.CREATION;
GroupEditDialogFragment groupEditDialogFragment = new GroupEditDialogFragment();
groupEditDialogFragment.show(getSupportFragmentManager(),
GroupEditDialogFragment.TAG_CREATE_GROUP);
}
});
rootView.setAddEntryClickListener(new View.OnClickListener() {
public void onClick(View v) {
EntryEditActivity.Launch(GroupActivity.this, mCurrentGroup);
}
addNodeView.setAddGroupClickListener(v -> {
editGroupDialogAction = EditGroupDialogAction.CREATION;
GroupEditDialogFragment groupEditDialogFragment = new GroupEditDialogFragment();
groupEditDialogFragment.show(getSupportFragmentManager(),
GroupEditDialogFragment.TAG_CREATE_GROUP);
});
addNodeView.setAddEntryClickListener(v ->
EntryEditActivity.Launch(GroupActivity.this, mCurrentGroup));
setGroupTitle();
setGroupIcon();
@@ -276,7 +276,14 @@ public class GroupActivity extends ListNodesActivity
protected void onResume() {
super.onResume();
// Show button on resume
rootView.showButton();
addNodeView.showButton();
}
@Override
protected void onStop() {
super.onStop();
// Hide button
addNodeView.hideButton();
}
@Override
@@ -291,9 +298,8 @@ public class GroupActivity extends ListNodesActivity
@Override
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
super.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
// Show button if hide after sort
rootView.showButton();
addNodeView.showButton();
}
protected void setGroupIcon() {

View File

@@ -20,7 +20,6 @@
package com.keepassdroid.view;
import android.content.Context;
import android.graphics.Rect;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
@@ -36,7 +35,7 @@ import android.widget.RelativeLayout;
import com.kunzisoft.keepass.R;
public class ListNodesWithAddButtonView extends RelativeLayout {
public class AddNodeView extends RelativeLayout {
private enum State {
OPEN, CLOSE
@@ -58,11 +57,11 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
private ViewMenuAnimation viewMenuAnimationAddGroup;
private long animationDuration;
public ListNodesWithAddButtonView(Context context) {
public AddNodeView(Context context) {
this(context, null);
}
public ListNodesWithAddButtonView(Context context, AttributeSet attrs) {
public AddNodeView(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context);
}
@@ -70,12 +69,12 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
protected void inflate(Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
inflater.inflate(R.layout.list_nodes_with_add_button, this);
inflater.inflate(R.layout.add_node_button, this);
addEntryEnable = true;
addGroupEnable = true;
addButton = (FloatingActionButton) findViewById(R.id.add_button);
addButton = findViewById(R.id.add_button);
addEntry = findViewById(R.id.add_entry);
addGroup = findViewById(R.id.add_group);
@@ -88,12 +87,9 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
allowAction = true;
state = State.CLOSE;
onAddButtonClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (allowAction && state.equals(State.CLOSE)) {
startGlobalAnimation();
}
onAddButtonClickListener = v -> {
if (allowAction) {
startGlobalAnimation();
}
};
addButton.setOnClickListener(onAddButtonClickListener);
@@ -111,10 +107,10 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
addButton.setOnClickListener(onAddButtonClickListener);
}
};
}
// Hide when scroll
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.nodes_list);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
public RecyclerView.OnScrollListener hideButtonOnScrollListener() {
return new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
@@ -126,8 +122,8 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
}
}
}
});
}
};
}
public void showButton() {
addButton.show(onAddButtonVisibilityChangedListener);
@@ -139,6 +135,8 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
/*
TODO Dispatch event to close
Rect viewRectG = new Rect();
getGlobalVisibleRect(viewRectG);
if (viewRectG.contains((int) ev.getRawX(), (int) ev.getRawY())) {
@@ -146,6 +144,7 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
startGlobalAnimation();
}
}
*/
return super.dispatchTouchEvent(ev);
}
@@ -171,12 +170,18 @@ public class ListNodesWithAddButtonView extends RelativeLayout {
public void setAddGroupClickListener(OnClickListener onClickListener) {
if (addGroupEnable)
addGroup.setOnClickListener(onClickListener);
addGroup.setOnClickListener(view -> {
onClickListener.onClick(view);
startGlobalAnimation();
});
}
public void setAddEntryClickListener(OnClickListener onClickListener) {
if (addEntryEnable)
addEntry.setOnClickListener(onClickListener);
addEntry.setOnClickListener(view -> {
onClickListener.onClick(view);
startGlobalAnimation();
});
}
private void startGlobalAnimation() {

View 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>

View File

@@ -72,38 +72,11 @@
android:layout_below="@+id/toolbar" />
</android.support.design.widget.CoordinatorLayout>
<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"
<com.keepassdroid.view.AddNodeView
android:id="@+id/add_node_button"
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" />
android:layout_height="wrap_content" />
</RelativeLayout>