mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Solve bugs of recycle bin and entry view after callback
This commit is contained in:
1 parent
f295aac206
commit
23df28cb25
10 files changed
+88
-55
No files matched your search
@@ -78,9 +78,15 @@ public abstract class EntryEditActivity extends LockCloseHideActivity
|
||||
public static final String ADD_OR_UPDATE_ENTRY_KEY = "ADD_OR_UPDATE_ENTRY_KEY";
|
||||
|
||||
protected PwEntry mEntry;
|
||||
protected PwEntry mCallbackNewEntry;
|
||||
protected boolean mIsNew;
|
||||
protected int mSelectedIconID = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Launch EntryEditActivity to update an existing entry
|
||||
* @param act from activity
|
||||
* @param pw Entry to update
|
||||
*/
|
||||
public static void Launch(Activity act, PwEntry pw) {
|
||||
Intent i;
|
||||
if (pw instanceof PwEntryV3) {
|
||||
@@ -97,7 +103,12 @@ public abstract class EntryEditActivity extends LockCloseHideActivity
|
||||
|
||||
act.startActivityForResult(i, ADD_OR_UPDATE_ENTRY_REQUEST_CODE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Launch EntryEditActivity to add a new entry
|
||||
* @param act from activity
|
||||
* @param pw Group who will contains new entry
|
||||
*/
|
||||
public static void Launch(Activity act, PwGroup pw) {
|
||||
Intent i;
|
||||
if (pw instanceof PwGroupV3) {
|
||||
@@ -180,26 +191,19 @@ public abstract class EntryEditActivity extends LockCloseHideActivity
|
||||
save.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
EntryEditActivity act = EntryEditActivity.this;
|
||||
|
||||
if (!validateBeforeSaving()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PwEntry newEntry = populateNewEntry();
|
||||
|
||||
RunnableOnFinish task;
|
||||
mCallbackNewEntry = populateNewEntry();
|
||||
|
||||
OnFinish onFinish = new AfterSave();
|
||||
|
||||
Intent intentEntry = new Intent();
|
||||
EntryEditActivity act = EntryEditActivity.this;
|
||||
RunnableOnFinish task;
|
||||
if ( mIsNew ) {
|
||||
task = new AddEntry(act, App.getDB(), newEntry, onFinish);
|
||||
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, newEntry);
|
||||
setResult(ADD_ENTRY_RESULT_CODE, intentEntry);
|
||||
task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish);
|
||||
} else {
|
||||
task = new UpdateEntry(act, App.getDB(), mEntry, newEntry, onFinish);
|
||||
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, newEntry);
|
||||
setResult(UPDATE_ENTRY_RESULT_CODE, intentEntry);
|
||||
task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
|
||||
}
|
||||
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
|
||||
pt.run();
|
||||
@@ -320,7 +324,22 @@ public abstract class EntryEditActivity extends LockCloseHideActivity
|
||||
// Do nothing here
|
||||
}
|
||||
|
||||
private final class AfterSave extends OnFinish {
|
||||
@Override
|
||||
public void finish() {
|
||||
// Assign entry callback as a result in all case
|
||||
Intent intentEntry = new Intent();
|
||||
if ( mIsNew ) {
|
||||
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, mCallbackNewEntry);
|
||||
setResult(ADD_ENTRY_RESULT_CODE, intentEntry);
|
||||
} else {
|
||||
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, mCallbackNewEntry);
|
||||
setResult(UPDATE_ENTRY_RESULT_CODE, intentEntry);
|
||||
}
|
||||
|
||||
super.finish();
|
||||
}
|
||||
|
||||
private final class AfterSave extends OnFinish {
|
||||
|
||||
AfterSave() {
|
||||
super(new Handler());
|
||||
|
||||
@@ -125,18 +125,18 @@ public abstract class GroupActivity extends GroupBaseActivity
|
||||
readOnly = db.readOnly;
|
||||
PwGroup root = db.pm.rootGroup;
|
||||
if ( id == null ) {
|
||||
mGroup = root;
|
||||
mCurrentGroup = root;
|
||||
} else {
|
||||
mGroup = db.pm.groups.get(id);
|
||||
mCurrentGroup = db.pm.groups.get(id);
|
||||
}
|
||||
|
||||
Log.w(TAG, "Retrieved tree");
|
||||
if ( mGroup == null ) {
|
||||
if ( mCurrentGroup == null ) {
|
||||
Log.w(TAG, "Group was null");
|
||||
return;
|
||||
}
|
||||
|
||||
isRoot = mGroup == root;
|
||||
isRoot = mCurrentGroup == root;
|
||||
|
||||
setupButtons();
|
||||
|
||||
@@ -156,7 +156,7 @@ public abstract class GroupActivity extends GroupBaseActivity
|
||||
toolbar.setTitle("");
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
if ( mGroup.getParent() != null )
|
||||
if ( mCurrentGroup.getParent() != null )
|
||||
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
|
||||
|
||||
Log.w(TAG, "Set view");
|
||||
@@ -179,7 +179,7 @@ public abstract class GroupActivity extends GroupBaseActivity
|
||||
addEntry.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
EntryEditActivity.Launch(GroupActivity.this, mGroup);
|
||||
EntryEditActivity.Launch(GroupActivity.this, mCurrentGroup);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public abstract class GroupActivity extends GroupBaseActivity
|
||||
setGroupTitle();
|
||||
setGroupIcon();
|
||||
|
||||
NodeAdapter nodeAdapter = new NodeAdapter(this, mGroup);
|
||||
NodeAdapter nodeAdapter = new NodeAdapter(this, mCurrentGroup);
|
||||
nodeAdapter.setOnNodeClickListener(this);
|
||||
nodeAdapter.setNodeMenuListener(new NodeAdapter.NodeMenuListener() {
|
||||
@Override
|
||||
@@ -233,6 +233,7 @@ public abstract class GroupActivity extends GroupBaseActivity
|
||||
}
|
||||
|
||||
private void deleteGroup(PwGroup group) {
|
||||
//TODO Verify trash recycle bin
|
||||
Handler handler = new Handler();
|
||||
DeleteGroup task = new DeleteGroup(this, App.getDB(), group,
|
||||
new AfterDeleteNode(handler, group));
|
||||
@@ -272,7 +273,7 @@ public abstract class GroupActivity extends GroupBaseActivity
|
||||
String GroupName = bundle.getString(GroupEditDialogFragment.KEY_NAME);
|
||||
int GroupIconID = bundle.getInt(GroupEditDialogFragment.KEY_ICON_ID);
|
||||
Handler handler = new Handler();
|
||||
AddGroup task = new AddGroup(this, App.getDB(), GroupName, GroupIconID, mGroup,
|
||||
AddGroup task = new AddGroup(this, App.getDB(), GroupName, GroupIconID, mCurrentGroup,
|
||||
new AfterAddNode(handler), false);
|
||||
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
|
||||
pt.run();
|
||||
|
||||
@@ -69,7 +69,7 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
|
||||
|
||||
private SharedPreferences prefs;
|
||||
|
||||
protected PwGroup mGroup;
|
||||
protected PwGroup mCurrentGroup;
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
@@ -79,8 +79,8 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
|
||||
|
||||
public void refreshIfDirty() {
|
||||
Database db = App.getDB();
|
||||
if ( db.dirty.contains(mGroup) ) {
|
||||
db.dirty.remove(mGroup);
|
||||
if ( db.dirty.contains(mCurrentGroup) ) {
|
||||
db.dirty.remove(mCurrentGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
|
||||
}
|
||||
|
||||
protected void setGroupTitle() {
|
||||
if ( mGroup != null ) {
|
||||
String name = mGroup.getName();
|
||||
if ( mCurrentGroup != null ) {
|
||||
String name = mCurrentGroup.getName();
|
||||
TextView tv = (TextView) findViewById(R.id.group_name);
|
||||
if ( name != null && name.length() > 0 ) {
|
||||
if ( tv != null ) {
|
||||
@@ -129,9 +129,9 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
|
||||
}
|
||||
|
||||
protected void setGroupIcon() {
|
||||
if (mGroup != null) {
|
||||
if (mCurrentGroup != null) {
|
||||
ImageView iv = (ImageView) findViewById(R.id.icon);
|
||||
App.getDB().drawFactory.assignDrawableTo(iv, getResources(), mGroup.getIcon());
|
||||
App.getDB().drawFactory.assignDrawableTo(iv, getResources(), mCurrentGroup.getIcon());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,11 +258,11 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
|
||||
Database db = App.getDB();
|
||||
db.markAllGroupsAsDirty();
|
||||
// We'll manually refresh this tree so we can remove it
|
||||
db.dirty.remove(mGroup);
|
||||
db.dirty.remove(mCurrentGroup);
|
||||
|
||||
// Tell the adapter to refresh it's list
|
||||
mAdapter.notifyChangeSort();
|
||||
mAdapter.rebuildList(mGroup);
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -317,6 +317,11 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
|
||||
if ( mSuccess) {
|
||||
refreshIfDirty();
|
||||
mAdapter.removeNode(pwNode);
|
||||
PwGroup parent = pwNode.getParent();
|
||||
PwGroup recycleBin = App.getDB().pm.getRecycleBin();
|
||||
if (parent.equals(recycleBin) && !mCurrentGroup.equals(recycleBin)) {
|
||||
mAdapter.addNode(parent);
|
||||
}
|
||||
} else {
|
||||
mHandler.post(new UIToastTask(GroupBaseActivity.this, "Unrecoverable error: " + mMessage));
|
||||
App.setShutdown();
|
||||
|
||||
@@ -230,7 +230,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
|
||||
MenuItem clearMenu = contextMenu.add(Menu.NONE, MENU_OPEN, Menu.NONE, R.string.menu_open);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
if (!App.getDB().readOnly) {
|
||||
if (!App.getDB().readOnly && !node.equals(App.getDB().pm.getRecycleBin())) {
|
||||
clearMenu = contextMenu.add(Menu.NONE, MENU_DELETE, Menu.NONE, R.string.menu_delete);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
}
|
||||
|
||||
@@ -335,6 +335,11 @@ public abstract class PwDatabase {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define if an Entry must be delete or recycle
|
||||
* @param entry Entry to remove
|
||||
* @return true if entry can be recycle, false elsewhere
|
||||
*/
|
||||
public boolean canRecycle(PwEntry entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
|
||||
public PwEntry clone(boolean deepStrings) {
|
||||
return (PwEntry) clone();
|
||||
}
|
||||
@@ -101,12 +101,10 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
public abstract String getPassword(boolean decodeRef, PwDatabase db);
|
||||
public abstract String getUrl(boolean decodeRef, PwDatabase db);
|
||||
public abstract String getNotes(boolean decodeRef, PwDatabase db);
|
||||
public abstract Date getCreationTime();
|
||||
public abstract Date getLastModificationTime();
|
||||
public abstract Date getLastAccessTime();
|
||||
public abstract Date getExpiryTime();
|
||||
public abstract boolean expires();
|
||||
public abstract PwGroup getParent();
|
||||
|
||||
public abstract void setTitle(String title, PwDatabase db);
|
||||
public abstract void setUsername(String user, PwDatabase db);
|
||||
@@ -165,8 +163,6 @@ public abstract class PwEntry extends PwNode implements Cloneable {
|
||||
|
||||
public void touchLocation() { }
|
||||
|
||||
public abstract void setParent(PwGroup parent);
|
||||
|
||||
public boolean isSearchingEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -89,9 +89,6 @@ public abstract class PwGroup extends PwNode {
|
||||
return childGroups.size() + childEntries.size();
|
||||
}
|
||||
|
||||
public abstract PwGroup getParent();
|
||||
public abstract void setParent(PwGroup parent);
|
||||
|
||||
public boolean isContainedIn(PwGroup container) {
|
||||
PwGroup cur = this;
|
||||
while (cur != null) {
|
||||
@@ -102,7 +99,7 @@ public abstract class PwGroup extends PwNode {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public abstract PwGroupId getId();
|
||||
public abstract void setId(PwGroupId id);
|
||||
|
||||
|
||||
@@ -62,7 +62,14 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initNewGroup(String nm, PwGroupId newId) {
|
||||
super.initNewGroup(nm, newId);
|
||||
|
||||
lastAccess = lastMod = creation = parentGroupLastMod = new Date();
|
||||
}
|
||||
|
||||
public void AddGroup(PwGroupV4 subGroup, boolean takeOwnership) {
|
||||
AddGroup(subGroup, takeOwnership, false);
|
||||
}
|
||||
@@ -166,7 +173,6 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
|
||||
public void setCreationTime(Date date) {
|
||||
creation = date;
|
||||
|
||||
}
|
||||
|
||||
public void setExpiryTime(Date date) {
|
||||
@@ -214,13 +220,6 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initNewGroup(String nm, PwGroupId newId) {
|
||||
super.initNewGroup(nm, newId);
|
||||
|
||||
lastAccess = lastMod = creation = parentGroupLastMod = new Date();
|
||||
}
|
||||
|
||||
public boolean isSearchEnabled() {
|
||||
PwGroupV4 group = this;
|
||||
while (group != null) {
|
||||
|
||||
@@ -56,6 +56,17 @@ public abstract class PwNode implements Serializable {
|
||||
*/
|
||||
public abstract Date getCreationTime();
|
||||
|
||||
/**
|
||||
* Retrieve the parent node
|
||||
* @return PwGroup parent as group
|
||||
*/
|
||||
public abstract PwGroup getParent();
|
||||
|
||||
/**
|
||||
* Assign a parent to this node
|
||||
*/
|
||||
public abstract void setParent(PwGroup parent);
|
||||
|
||||
/**
|
||||
* If the content (type, title, icon) is visually the same
|
||||
* @param o Node to compare
|
||||
|
||||
@@ -97,9 +97,9 @@ public class SearchResultsActivity extends GroupBaseActivity {
|
||||
}
|
||||
|
||||
private void performSearch(String query) {
|
||||
mGroup = mDb.Search(query.trim());
|
||||
mCurrentGroup = mDb.Search(query.trim());
|
||||
|
||||
if ( mGroup == null || mGroup.numbersOfChildEntries() < 1 ) {
|
||||
if ( mCurrentGroup == null || mCurrentGroup.numbersOfChildEntries() < 1 ) {
|
||||
listView.setVisibility(View.GONE);
|
||||
notFoundView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
@@ -109,7 +109,7 @@ public class SearchResultsActivity extends GroupBaseActivity {
|
||||
|
||||
setGroupTitle();
|
||||
|
||||
setNodeAdapter(new NodeAdapter(this, mGroup));
|
||||
setNodeAdapter(new NodeAdapter(this, mCurrentGroup));
|
||||
}
|
||||
|
||||
private String getSearchStr(Intent queryIntent) {
|
||||
|
||||
Reference in new issue
Block a user