Refactor for list of nodes, solve bug of add button

This commit is contained in:
J-Jamet
2018-02-16 16:33:25 +01:00
parent 79750c5320
commit 5c4d2e607a
12 changed files with 151 additions and 198 deletions

View File

@@ -30,6 +30,7 @@ import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import com.keepassdroid.adapters.NodeAdapter;
import com.keepassdroid.app.App;
@@ -50,13 +51,11 @@ import com.keepassdroid.dialog.ReadOnlyDialog;
import com.keepassdroid.fragments.GroupEditDialogFragment;
import com.keepassdroid.fragments.IconPickerDialogFragment;
import com.keepassdroid.tasks.ProgressTask;
import com.keepassdroid.view.GroupAddEntryView;
import com.keepassdroid.view.GroupRootView;
import com.keepassdroid.view.GroupViewOnlyView;
import com.keepassdroid.view.ListNodesWithAddButtonView;
import com.kunzisoft.keepass.KeePass;
import com.kunzisoft.keepass.R;
public abstract class GroupActivity extends GroupBaseActivity
public abstract class GroupActivity extends ListNodesActivity
implements GroupEditDialogFragment.EditGroupListener, IconPickerDialogFragment.IconPickerListener {
protected boolean addGroupEnabled = false;
@@ -143,17 +142,11 @@ public abstract class GroupActivity extends GroupBaseActivity
setupButtons();
if ( addGroupEnabled && addEntryEnabled ) {
setContentView(new GroupAddEntryView(this));
} else if ( addGroupEnabled ) {
setContentView(new GroupRootView(this));
} else if ( addEntryEnabled ) {
setContentView(new GroupAddEntryView(this));
View addGroup = findViewById(R.id.add_group);
addGroup.setVisibility(View.GONE);
} else {
setContentView(new GroupViewOnlyView(this));
}
// Construct main view
ListNodesWithAddButtonView rootView = new ListNodesWithAddButtonView(this);
rootView.enableAddGroup(addGroupEnabled);
rootView.enableAddEntry(addEntryEnabled);
setContentView(rootView);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("");
@@ -162,8 +155,6 @@ public abstract class GroupActivity extends GroupBaseActivity
if ( mCurrentGroup.getParent() != null )
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
Log.w(TAG, "Set view");
if ( addGroupEnabled ) {
// Add Group button
View addGroup = findViewById(R.id.add_group);
@@ -247,6 +238,13 @@ public abstract class GroupActivity extends GroupBaseActivity
}
}
protected void setGroupIcon() {
if (mCurrentGroup != null) {
ImageView iv = (ImageView) findViewById(R.id.icon);
App.getDB().drawFactory.assignDrawableTo(iv, getResources(), mCurrentGroup.getIcon());
}
}
private void deleteEntry(PwEntry entry) {
Handler handler = new Handler();
DeleteEntry task = new DeleteEntry(this, App.getDB(), entry,

View File

@@ -38,7 +38,6 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.keepassdroid.adapters.NodeAdapter;
@@ -55,11 +54,10 @@ import com.keepassdroid.search.SearchResultsActivity;
import com.keepassdroid.tasks.UIToastTask;
import com.keepassdroid.utils.MenuUtil;
import com.keepassdroid.view.AssignPasswordHelper;
import com.keepassdroid.view.GroupViewOnlyView;
import com.kunzisoft.keepass.KeePass;
import com.kunzisoft.keepass.R;
public abstract class GroupBaseActivity extends LockCloseListActivity
public abstract class ListNodesActivity extends LockCloseListActivity
implements AssignMasterKeyDialogFragment.AssignPasswordDialogListener,
NodeAdapter.OnNodeClickCallback {
protected RecyclerView mList;
@@ -85,7 +83,7 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
ActivityCompat.invalidateOptionsMenu(this);
setContentView(new GroupViewOnlyView(this));
setContentView(R.layout.list_nodes);
setResult(KeePass.EXIT_NORMAL);
styleScrollBars();
@@ -113,11 +111,9 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
}
}
protected void setGroupIcon() {
if (mCurrentGroup != null) {
ImageView iv = (ImageView) findViewById(R.id.icon);
App.getDB().drawFactory.assignDrawableTo(iv, getResources(), mCurrentGroup.getIcon());
}
private void ensureCorrectListView(){
mList = (RecyclerView) findViewById(R.id.nodes_list);
mList.setLayoutManager(new LinearLayoutManager(this));
}
protected void setNodeAdapter(NodeAdapter adapter) {
@@ -126,11 +122,6 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
mList.setAdapter(adapter);
}
private void ensureCorrectListView(){
mList = (RecyclerView) findViewById(R.id.group_list);
mList.setLayoutManager(new LinearLayoutManager(this));
}
@Override
public void onNodeClick(PwNode node) {
mAdapter.registerANodeToUpdate(node);
@@ -266,49 +257,6 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
dialog.show(getSupportFragmentManager(), "passwordDialog");
}
public class AfterAddNode extends AfterAddNodeOnFinish {
public AfterAddNode(Handler handler) {
super(handler);
}
public void run(PwNode pwNode) {
super.run();
if (mSuccess) {
mAdapter.addNode(pwNode);
} else {
displayMessage(GroupBaseActivity.this);
}
}
}
public class AfterDeleteNode extends OnFinish {
private PwNode pwNode;
public AfterDeleteNode(Handler handler, PwNode pwNode) {
super(handler);
this.pwNode = pwNode;
}
@Override
public void run() {
if ( mSuccess) {
mAdapter.removeNode(pwNode);
PwGroup parent = pwNode.getParent();
PwGroup recycleBin = App.getDB().pm.getRecycleBin();
// Add trash if it doesn't exists
if (parent.equals(recycleBin)
&& mCurrentGroup.getParent() == null
&& !mCurrentGroup.equals(recycleBin)) {
mAdapter.addNode(parent);
}
} else {
mHandler.post(new UIToastTask(GroupBaseActivity.this, "Unrecoverable error: " + mMessage));
App.setShutdown();
finish();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -347,4 +295,47 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
super.startActivityForResult(intent, requestCode, options);
}
}
class AfterAddNode extends AfterAddNodeOnFinish {
AfterAddNode(Handler handler) {
super(handler);
}
public void run(PwNode pwNode) {
super.run();
if (mSuccess) {
mAdapter.addNode(pwNode);
} else {
displayMessage(ListNodesActivity.this);
}
}
}
class AfterDeleteNode extends OnFinish {
private PwNode pwNode;
AfterDeleteNode(Handler handler, PwNode pwNode) {
super(handler);
this.pwNode = pwNode;
}
@Override
public void run() {
if ( mSuccess) {
mAdapter.removeNode(pwNode);
PwGroup parent = pwNode.getParent();
PwGroup recycleBin = App.getDB().pm.getRecycleBin();
// Add trash if it doesn't exists
if (parent.equals(recycleBin)
&& mCurrentGroup.getParent() == null
&& !mCurrentGroup.equals(recycleBin)) {
mAdapter.addNode(parent);
}
} else {
mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage));
App.setShutdown();
finish();
}
}
}
}

View File

@@ -159,10 +159,10 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
BasicViewHolder basicViewHolder;
View view;
if (viewType == PwNode.Type.GROUP.ordinal()) {
view = inflater.inflate(R.layout.list_entries_group, parent, false);
view = inflater.inflate(R.layout.list_nodes_group, parent, false);
basicViewHolder = new GroupViewHolder(view);
} else {
view = inflater.inflate(R.layout.list_entries_entry, parent, false);
view = inflater.inflate(R.layout.list_nodes_entry, parent, false);
basicViewHolder = new EntryViewHolder(view);
}
return basicViewHolder;

View File

@@ -28,7 +28,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import com.keepassdroid.activities.GroupBaseActivity;
import com.keepassdroid.activities.ListNodesActivity;
import com.keepassdroid.adapters.NodeAdapter;
import com.keepassdroid.app.App;
import com.keepassdroid.database.Database;
@@ -36,7 +36,7 @@ import com.keepassdroid.utils.MenuUtil;
import com.kunzisoft.keepass.KeePass;
import com.kunzisoft.keepass.R;
public class SearchResultsActivity extends GroupBaseActivity {
public class SearchResultsActivity extends ListNodesActivity {
private Database mDb;
@@ -69,7 +69,7 @@ public class SearchResultsActivity extends GroupBaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
listView = findViewById(R.id.group_list);
listView = findViewById(R.id.nodes_list);
notFoundView = findViewById(R.id.not_found_container);
performSearch(getSearchStr(getIntent()));

View File

@@ -1,43 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid.view;
import android.content.Context;
import android.util.AttributeSet;
public class GroupRootView extends GroupAddEntryView {
public GroupRootView(Context context) {
this(context, null);
}
public GroupRootView(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context);
}
@Override
protected void inflate(Context context) {
super.inflate(context);
addEntryActivated = false;
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid.view;
import android.content.Context;
import android.util.AttributeSet;
public class GroupViewOnlyView extends GroupAddEntryView {
public GroupViewOnlyView(Context context) {
this(context, null);
}
public GroupViewOnlyView(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context);
}
@Override
protected void inflate(Context context) {
super.inflate(context);
// Hide the buttons
addButton.setVisibility(GONE);
}
}

View File

@@ -33,39 +33,39 @@ import android.widget.RelativeLayout;
import com.kunzisoft.keepass.R;
public class GroupAddEntryView extends RelativeLayout {
public class ListNodesWithAddButtonView extends RelativeLayout {
protected View addButton;
protected View addEntry;
protected boolean addEntryActivated;
protected View addGroup;
protected boolean addGroupActivated;
private View addEntry;
private boolean addEntryActivated;
private View addGroup;
private boolean addGroupActivated;
private boolean entryEnable;
private boolean groupEnable;
private boolean animInProgress;
private AddButtonAnimation viewButtonMenuAnimation;
private ViewMenuAnimation viewMenuAnimationAddEntry;
private ViewMenuAnimation viewMenuAnimationAddGroup;
public GroupAddEntryView(Context context) {
public ListNodesWithAddButtonView(Context context) {
this(context, null);
}
public GroupAddEntryView(Context context, AttributeSet attrs) {
public ListNodesWithAddButtonView(Context context, AttributeSet attrs) {
super(context, attrs);
inflate(context);
}
protected void inflate(Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.group_add_entry, this);
assert inflater != null;
inflater.inflate(R.layout.list_nodes_with_add_button, this);
addEntryActivated = true;
addGroupActivated = true;
addEntryActivated = true;
addButton = findViewById(R.id.add_button);
View addButton = findViewById(R.id.add_button);
addEntry = findViewById(R.id.add_entry);
addGroup = findViewById(R.id.add_group);
@@ -76,7 +76,9 @@ public class GroupAddEntryView extends RelativeLayout {
addButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!animInProgress) {
if (!animInProgress
&& (addEntry.getVisibility() != VISIBLE
|| addGroup.getVisibility() != VISIBLE)) {
startGlobalAnimation();
}
}
@@ -97,12 +99,30 @@ public class GroupAddEntryView extends RelativeLayout {
return super.dispatchTouchEvent(ev);
}
/**
* Enable or not the possibility to add an entry by pressing a button
* @param enable true to enable
*/
public void enableAddEntry(boolean enable) {
this.entryEnable = enable;
this.addEntry.setVisibility(GONE);
}
/**
* Enable or not the possibility to add a group by pressing a button
* @param enable true to enable
*/
public void enableAddGroup(boolean enable) {
this.groupEnable = enable;
this.addGroup.setVisibility(GONE);
}
private void startGlobalAnimation() {
viewButtonMenuAnimation.startAnimation();
if (addEntryActivated) {
if (entryEnable && addEntryActivated) {
viewMenuAnimationAddEntry.startAnimation();
}
if (addGroupActivated) {
if (groupEnable && addGroupActivated) {
viewMenuAnimationAddGroup.startAnimation();
}
}
@@ -182,7 +202,7 @@ public class GroupAddEntryView extends RelativeLayout {
@Override
public void onAnimationEnd(Animation animation) {
if(view.getVisibility() == VISIBLE)
view.setVisibility(GONE);
view.setVisibility(INVISIBLE);
else
view.setVisibility(VISIBLE);
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
This file is part of KeePass DX.
KeePass DX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
KeePass DX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_default" />
<android.support.v7.widget.RecyclerView android:id="@+id/nodes_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar" />
</RelativeLayout>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
This file is part of KeePass DX.
KeePass DX is free software: you can redistribute it and/or modify
@@ -18,9 +18,9 @@
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
-->
<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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
@@ -43,7 +43,7 @@
android:layout_below="@+id/toolbar" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView android:id="@+id/group_list"
<android.support.v7.widget.RecyclerView android:id="@+id/nodes_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar" />
@@ -56,7 +56,7 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
style="@style/KeepassDXStyle.Fab" />
style="@style/KeepassDXStyle.Fab" />
<TextView android:id="@+id/add_entry"
android:layout_marginRight="12dp"
@@ -67,21 +67,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_entry"
android:visibility="invisible"
android:visibility="invisible"
style="@style/KeepassDXStyle.FabMenu"
tools:ignore="UnusedAttribute" />
<TextView android:id="@+id/add_group"
android:layout_marginBottom="24dp"
<TextView android:id="@+id/add_group"
android:layout_marginBottom="24dp"
android:layout_marginRight="12dp"
android:layout_marginEnd="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"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_group"
android:visibility="invisible"
style="@style/KeepassDXStyle.FabMenu"
style="@style/KeepassDXStyle.FabMenu"
tools:ignore="UnusedAttribute" />
</RelativeLayout>

View File

@@ -47,7 +47,7 @@
android:layout_height="wrap_content"
android:text="@string/no_results"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView android:id="@+id/group_list"
<android.support.v7.widget.RecyclerView android:id="@+id/nodes_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"