mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Add contextual bar to paste and add move entry
This commit is contained in:
1 parent
5286a60142
commit
9424feefce
13 files changed
+346
-28
No files matched your search
@@ -37,6 +37,7 @@ import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -56,6 +57,7 @@ import com.kunzisoft.keepass.database.PwIcon;
|
||||
import com.kunzisoft.keepass.database.PwIconStandard;
|
||||
import com.kunzisoft.keepass.database.PwNode;
|
||||
import com.kunzisoft.keepass.database.action.AddGroupRunnable;
|
||||
import com.kunzisoft.keepass.database.action.CopyEntryRunnable;
|
||||
import com.kunzisoft.keepass.database.action.DeleteEntryRunnable;
|
||||
import com.kunzisoft.keepass.database.action.DeleteGroupRunnable;
|
||||
import com.kunzisoft.keepass.database.action.UpdateGroupRunnable;
|
||||
@@ -257,6 +259,65 @@ public class GroupActivity extends ListNodesActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCopyMenuClick(PwNode node) {
|
||||
startActionMode(new ActionMode.Callback() {
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
|
||||
actionMode.setTitle(R.string.where);
|
||||
actionMode.getMenuInflater().inflate(R.menu.node_paste_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
|
||||
actionMode.finish();
|
||||
switch (menuItem.getItemId()) {
|
||||
|
||||
case R.id.menu_paste:
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
break;
|
||||
case ENTRY:
|
||||
copyNode((PwEntry) node, mCurrentGroup);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode actionMode) {
|
||||
|
||||
}
|
||||
});
|
||||
// TODO COPY
|
||||
return false;
|
||||
}
|
||||
|
||||
private void copyNode(PwEntry entryToCopy, PwGroup newParent) {
|
||||
CopyEntryRunnable task = new CopyEntryRunnable(this, App.getDB(), entryToCopy, newParent,
|
||||
new AfterAddNode(new Handler()));
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMoveMenuClick(PwNode node) {
|
||||
// TODO MOVE
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDeleteMenuClick(PwNode node) {
|
||||
switch (node.getType()) {
|
||||
@@ -270,6 +331,29 @@ public class GroupActivity extends ListNodesActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
private void deleteGroup(PwGroup group) {
|
||||
//TODO Verify trash recycle bin
|
||||
DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group,
|
||||
new AfterDeleteNode(new Handler(), group));
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
private void deleteEntry(PwEntry entry) {
|
||||
DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry,
|
||||
new AfterDeleteNode(new Handler(), entry));
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
@@ -420,31 +504,6 @@ public class GroupActivity extends ListNodesActivity
|
||||
addNodeButtonView.hideButton();
|
||||
}
|
||||
|
||||
private void deleteEntry(PwEntry entry) {
|
||||
Handler handler = new Handler();
|
||||
DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry,
|
||||
new AfterDeleteNode(handler, entry));
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
private void deleteGroup(PwGroup group) {
|
||||
//TODO Verify trash recycle bin
|
||||
Handler handler = new Handler();
|
||||
DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group,
|
||||
new AfterDeleteNode(handler, group));
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
|
||||
@@ -237,6 +237,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
public interface NodeMenuListener {
|
||||
boolean onOpenMenuClick(PwNode node);
|
||||
boolean onEditMenuClick(PwNode node);
|
||||
boolean onCopyMenuClick(PwNode node);
|
||||
boolean onMoveMenuClick(PwNode node);
|
||||
boolean onDeleteMenuClick(PwNode node);
|
||||
}
|
||||
|
||||
@@ -264,7 +266,9 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
|
||||
private static final int MENU_OPEN = Menu.FIRST;
|
||||
private static final int MENU_EDIT = MENU_OPEN + 1;
|
||||
private static final int MENU_DELETE = MENU_EDIT + 1;
|
||||
private static final int MENU_COPY = MENU_EDIT + 1;
|
||||
private static final int MENU_MOVE = MENU_COPY + 1;
|
||||
private static final int MENU_DELETE = MENU_MOVE + 1;
|
||||
|
||||
private PwNode node;
|
||||
private NodeMenuListener menuListener;
|
||||
@@ -282,6 +286,12 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
// Edition
|
||||
clearMenu = contextMenu.add(Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
// Copy
|
||||
clearMenu = contextMenu.add(Menu.NONE, MENU_COPY, Menu.NONE, R.string.menu_copy);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
// Move
|
||||
clearMenu = contextMenu.add(Menu.NONE, MENU_MOVE, Menu.NONE, R.string.menu_move);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
// Deletion
|
||||
clearMenu = contextMenu.add(Menu.NONE, MENU_DELETE, Menu.NONE, R.string.menu_delete);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
@@ -298,6 +308,10 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
return menuListener.onOpenMenuClick(node);
|
||||
case MENU_EDIT:
|
||||
return menuListener.onEditMenuClick(node);
|
||||
case MENU_COPY:
|
||||
return menuListener.onCopyMenuClick(node);
|
||||
case MENU_MOVE:
|
||||
return menuListener.onMoveMenuClick(node);
|
||||
case MENU_DELETE:
|
||||
return menuListener.onDeleteMenuClick(node);
|
||||
default:
|
||||
|
||||
@@ -51,6 +51,9 @@ import java.io.OutputStream;
|
||||
import java.io.SyncFailedException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class Database {
|
||||
@@ -659,6 +662,42 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable PwEntry copyEntry(PwEntry entryToCopy, PwGroup newParent) {
|
||||
try {
|
||||
// TODO encapsulate
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
case V3:
|
||||
PwEntryV3 entryV3Copied = ((PwEntryV3) entryToCopy).clone();
|
||||
entryV3Copied.setUUID(UUID.randomUUID());
|
||||
entryV3Copied.setParent((PwGroupV3) newParent);
|
||||
return entryV3Copied;
|
||||
case V4:
|
||||
PwEntryV4 entryV4Copied = ((PwEntryV4) entryToCopy).clone();
|
||||
entryV4Copied.setUUID(UUID.randomUUID());
|
||||
entryV4Copied.setParent((PwGroupV4) newParent);
|
||||
return entryV4Copied;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwEntry can't be updated", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO copy group
|
||||
public void copyGroup(PwGroup groupToCopy, PwGroup newParent) {
|
||||
|
||||
}
|
||||
|
||||
// TODO move entry
|
||||
public void moveEntry(PwEntry entryToMove, PwGroup newParent) {
|
||||
|
||||
}
|
||||
|
||||
// TODO move group
|
||||
public void moveGroup(PwGroup groupToMove, PwGroup newParent) {
|
||||
|
||||
}
|
||||
|
||||
public void deleteEntry(PwEntry entry) {
|
||||
try {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2018 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 3 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.kunzisoft.keepass.database.action;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class CopyEntryRunnable extends RunnableOnFinish {
|
||||
|
||||
private static final String TAG = CopyEntryRunnable.class.getName();
|
||||
|
||||
private Database mDb;
|
||||
private PwEntry mEntryToCopy;
|
||||
private PwEntry mEntryCopied;
|
||||
private PwGroup mNewParent;
|
||||
private Context mContext;
|
||||
private boolean mDontSave;
|
||||
|
||||
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
|
||||
this(context, db, oldE, newParent, afterAddNode, false);
|
||||
}
|
||||
|
||||
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||
super(afterAddNode);
|
||||
|
||||
this.mDb = db;
|
||||
this.mEntryToCopy = oldE;
|
||||
this.mNewParent = newParent;
|
||||
this.mContext = context;
|
||||
this.mDontSave = dontSave;
|
||||
|
||||
this.mFinish = new AfterCopy(afterAddNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Update entry with new values
|
||||
mEntryCopied = mDb.copyEntry(mEntryToCopy, mNewParent);
|
||||
mDb.addEntryTo(mEntryCopied, mNewParent);
|
||||
|
||||
if (mEntryCopied != null) {
|
||||
mEntryCopied.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
SaveDBRunnable save = new SaveDBRunnable(mContext, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
} else {
|
||||
Log.e(TAG, "Unable to create a copy of the entry");
|
||||
}
|
||||
}
|
||||
|
||||
private class AfterCopy extends OnFinishRunnable {
|
||||
|
||||
AfterCopy(OnFinishRunnable finish) {
|
||||
super(finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( !mSuccess ) {
|
||||
// If we fail to save, try to delete the copy
|
||||
try {
|
||||
mDb.deleteEntry(mEntryCopied);
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Unable to delete the copied entry");
|
||||
}
|
||||
}
|
||||
// TODO Better callback
|
||||
AfterActionNodeOnFinish afterAddNode =
|
||||
(AfterActionNodeOnFinish) super.mOnFinish;
|
||||
afterAddNode.mSuccess = mSuccess;
|
||||
afterAddNode.mMessage = mMessage;
|
||||
afterAddNode.run(null, mEntryCopied);
|
||||
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user