mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Serializable for Pw, solve bug of entry refresh
This commit is contained in:
@@ -35,8 +35,8 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.widget.Toolbar;
|
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.text.method.PasswordTransformationMethod;
|
import android.text.method.PasswordTransformationMethod;
|
||||||
@@ -49,21 +49,21 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.keepassdroid.database.Database;
|
|
||||||
import com.keepassdroid.tasks.UIToastTask;
|
|
||||||
import com.kunzisoft.keepass.KeePass;
|
|
||||||
import com.kunzisoft.keepass.R;
|
|
||||||
import com.keepassdroid.app.App;
|
import com.keepassdroid.app.App;
|
||||||
import com.keepassdroid.compat.ActivityCompat;
|
import com.keepassdroid.compat.ActivityCompat;
|
||||||
|
import com.keepassdroid.database.Database;
|
||||||
import com.keepassdroid.database.PwDatabase;
|
import com.keepassdroid.database.PwDatabase;
|
||||||
import com.keepassdroid.database.PwEntry;
|
import com.keepassdroid.database.PwEntry;
|
||||||
import com.keepassdroid.database.PwEntryV4;
|
import com.keepassdroid.database.PwEntryV4;
|
||||||
import com.keepassdroid.database.exception.SamsungClipboardException;
|
import com.keepassdroid.database.exception.SamsungClipboardException;
|
||||||
import com.keepassdroid.intents.Intents;
|
import com.keepassdroid.intents.Intents;
|
||||||
|
import com.keepassdroid.tasks.UIToastTask;
|
||||||
import com.keepassdroid.utils.EmptyUtils;
|
import com.keepassdroid.utils.EmptyUtils;
|
||||||
import com.keepassdroid.utils.MenuUtil;
|
import com.keepassdroid.utils.MenuUtil;
|
||||||
import com.keepassdroid.utils.Types;
|
import com.keepassdroid.utils.Types;
|
||||||
import com.keepassdroid.utils.Util;
|
import com.keepassdroid.utils.Util;
|
||||||
|
import com.kunzisoft.keepass.KeePass;
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -90,7 +90,7 @@ public class EntryActivity extends LockCloseHideActivity {
|
|||||||
|
|
||||||
i.putExtra(KEY_ENTRY, Types.UUIDtoBytes(pw.getUUID()));
|
i.putExtra(KEY_ENTRY, Types.UUIDtoBytes(pw.getUUID()));
|
||||||
|
|
||||||
act.startActivityForResult(i,0);
|
act.startActivityForResult(i, EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PwEntry mEntry;
|
protected PwEntry mEntry;
|
||||||
@@ -124,6 +124,7 @@ public class EntryActivity extends LockCloseHideActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
//TODO in Prefs
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
mShowPassword = ! prefs.getBoolean(getString(R.string.maskpass_key), getResources().getBoolean(R.bool.maskpass_default));
|
mShowPassword = ! prefs.getBoolean(getString(R.string.maskpass_key), getResources().getBoolean(R.bool.maskpass_default));
|
||||||
|
|
||||||
@@ -298,13 +299,14 @@ public class EntryActivity extends LockCloseHideActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if ( resultCode == KeePass.EXIT_REFRESH || resultCode == KeePass.EXIT_REFRESH_TITLE ) {
|
switch (requestCode) {
|
||||||
fillData(true);
|
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
|
||||||
if ( resultCode == KeePass.EXIT_REFRESH_TITLE ) {
|
// TODO CHANGE Fill function to include data
|
||||||
Intent ret = new Intent();
|
fillData(true);
|
||||||
setResult(KeePass.EXIT_REFRESH, ret);
|
// Transit data in previous Activity
|
||||||
}
|
setResult(resultCode, data);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -66,9 +66,17 @@ import java.util.UUID;
|
|||||||
public abstract class EntryEditActivity extends LockCloseHideActivity
|
public abstract class EntryEditActivity extends LockCloseHideActivity
|
||||||
implements IconPickerDialogFragment.IconPickerListener,
|
implements IconPickerDialogFragment.IconPickerListener,
|
||||||
GeneratePasswordDialogFragment.GeneratePasswordListener {
|
GeneratePasswordDialogFragment.GeneratePasswordListener {
|
||||||
|
|
||||||
|
// Keys for current Activity
|
||||||
public static final String KEY_ENTRY = "entry";
|
public static final String KEY_ENTRY = "entry";
|
||||||
public static final String KEY_PARENT = "parent";
|
public static final String KEY_PARENT = "parent";
|
||||||
|
|
||||||
|
// Keys for callback
|
||||||
|
public static final int ADD_ENTRY_RESULT_CODE = 31;
|
||||||
|
public static final int UPDATE_ENTRY_RESULT_CODE = 32;
|
||||||
|
public static final int ADD_OR_UPDATE_ENTRY_REQUEST_CODE = 7129;
|
||||||
|
public static final String ADD_OR_UPDATE_ENTRY_KEY = "ADD_OR_UPDATE_ENTRY_KEY";
|
||||||
|
|
||||||
protected PwEntry mEntry;
|
protected PwEntry mEntry;
|
||||||
protected boolean mIsNew;
|
protected boolean mIsNew;
|
||||||
protected int mSelectedIconID = -1;
|
protected int mSelectedIconID = -1;
|
||||||
@@ -87,7 +95,7 @@ public abstract class EntryEditActivity extends LockCloseHideActivity
|
|||||||
|
|
||||||
i.putExtra(KEY_ENTRY, Types.UUIDtoBytes(pw.getUUID()));
|
i.putExtra(KEY_ENTRY, Types.UUIDtoBytes(pw.getUUID()));
|
||||||
|
|
||||||
act.startActivityForResult(i, 0);
|
act.startActivityForResult(i, ADD_OR_UPDATE_ENTRY_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Launch(Activity act, PwGroup pw) {
|
public static void Launch(Activity act, PwGroup pw) {
|
||||||
@@ -104,7 +112,7 @@ public abstract class EntryEditActivity extends LockCloseHideActivity
|
|||||||
throw new RuntimeException("Not yet implemented.");
|
throw new RuntimeException("Not yet implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
act.startActivityForResult(i, 0);
|
act.startActivityForResult(i, ADD_OR_UPDATE_ENTRY_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract PwGroupId getParentGroupId(Intent i, String key);
|
protected abstract PwGroupId getParentGroupId(Intent i, String key);
|
||||||
@@ -179,20 +187,19 @@ public abstract class EntryEditActivity extends LockCloseHideActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
PwEntry newEntry = populateNewEntry();
|
PwEntry newEntry = populateNewEntry();
|
||||||
|
|
||||||
if ( newEntry.getTitle().equals(mEntry.getTitle()) ) {
|
|
||||||
setResult(KeePass.EXIT_REFRESH);
|
|
||||||
} else {
|
|
||||||
setResult(KeePass.EXIT_REFRESH_TITLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
RunnableOnFinish task;
|
RunnableOnFinish task;
|
||||||
OnFinish onFinish = act.new AfterSave(new Handler());
|
OnFinish onFinish = act.new AfterSave(new Handler());
|
||||||
|
|
||||||
|
Intent intentEntry = new Intent();
|
||||||
if ( mIsNew ) {
|
if ( mIsNew ) {
|
||||||
task = AddEntry.getInstance(EntryEditActivity.this, App.getDB(), newEntry, onFinish);
|
task = new AddEntry(act, App.getDB(), newEntry, onFinish);
|
||||||
|
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, newEntry);
|
||||||
|
setResult(ADD_ENTRY_RESULT_CODE, intentEntry);
|
||||||
} else {
|
} else {
|
||||||
task = new UpdateEntry(EntryEditActivity.this, App.getDB(), mEntry, newEntry, onFinish);
|
task = new UpdateEntry(act, App.getDB(), mEntry, newEntry, onFinish);
|
||||||
|
intentEntry.putExtra(ADD_OR_UPDATE_ENTRY_KEY, mEntry);
|
||||||
|
setResult(UPDATE_ENTRY_RESULT_CODE, intentEntry);
|
||||||
}
|
}
|
||||||
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
|
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
|
||||||
pt.run();
|
pt.run();
|
||||||
|
|||||||
@@ -240,7 +240,24 @@ public abstract class GroupActivity extends GroupBaseActivity
|
|||||||
pt.run();
|
pt.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
switch (requestCode) {
|
||||||
|
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
|
||||||
|
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
|
||||||
|
resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||||
|
PwNode newNode = (PwNode) data.getSerializableExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY);
|
||||||
|
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
||||||
|
mAdapter.addNode(newNode);
|
||||||
|
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE)
|
||||||
|
mAdapter.updateNode(newNode);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ public abstract class GroupBaseActivity extends LockCloseListActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
refreshIfDirty();
|
refreshIfDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.support.v7.util.SortedList;
|
import android.support.v7.util.SortedList;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.util.SortedListAdapterCallback;
|
import android.support.v7.widget.util.SortedListAdapterCallback;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -58,6 +59,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
|||||||
nodeSortedList.add(node);
|
nodeSortedList.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateNode(PwNode node) {
|
||||||
|
try {
|
||||||
|
nodeSortedList.updateItemAt(nodeSortedList.indexOf(node), node);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
Log.e(NodeAdapter.class.getName(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void removeNode(PwNode node) {
|
public void removeNode(PwNode node) {
|
||||||
nodeSortedList.remove(node);
|
nodeSortedList.remove(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.keepassdroid.database;
|
package com.keepassdroid.database;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -32,7 +33,7 @@ import com.keepassdroid.utils.Types;
|
|||||||
* @author bpellin
|
* @author bpellin
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PwDate implements Cloneable {
|
public class PwDate implements Cloneable, Serializable {
|
||||||
|
|
||||||
private static final int DATE_SIZE = 5;
|
private static final int DATE_SIZE = 5;
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.keepassdroid.database;
|
package com.keepassdroid.database;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -62,7 +63,7 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
|
|||||||
public String tags = "";
|
public String tags = "";
|
||||||
public Map<String, String> customData = new HashMap<String, String>();
|
public Map<String, String> customData = new HashMap<String, String>();
|
||||||
|
|
||||||
public class AutoType implements Cloneable {
|
public class AutoType implements Cloneable, Serializable {
|
||||||
private static final long OBF_OPT_NONE = 0;
|
private static final long OBF_OPT_NONE = 0;
|
||||||
|
|
||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.keepassdroid.database;
|
package com.keepassdroid.database;
|
||||||
|
|
||||||
public abstract class PwGroupId {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public abstract class PwGroupId implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.keepassdroid.database;
|
package com.keepassdroid.database;
|
||||||
|
|
||||||
public abstract class PwIcon {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public abstract class PwIcon implements Serializable {
|
||||||
|
|
||||||
public boolean isMetaStreamIcon() {
|
public boolean isMetaStreamIcon() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ package com.keepassdroid.database;
|
|||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class who manage Groups and Entries
|
* Abstract class who manage Groups and Entries
|
||||||
*/
|
*/
|
||||||
public abstract class PwNode implements Comparable<PwNode> {
|
public abstract class PwNode implements Comparable<PwNode>, Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of Node
|
* Get the type of Node
|
||||||
|
|||||||
@@ -31,11 +31,7 @@ public class AddEntry extends RunnableOnFinish {
|
|||||||
private PwEntry mEntry;
|
private PwEntry mEntry;
|
||||||
private Context ctx;
|
private Context ctx;
|
||||||
|
|
||||||
public static AddEntry getInstance(Context ctx, Database db, PwEntry entry, OnFinish finish) {
|
public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) {
|
||||||
return new AddEntry(ctx, db, entry, finish);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) {
|
|
||||||
super(finish);
|
super(finish);
|
||||||
|
|
||||||
mDb = db;
|
mDb = db;
|
||||||
@@ -56,7 +52,7 @@ public class AddEntry extends RunnableOnFinish {
|
|||||||
|
|
||||||
private class AfterAdd extends OnFinish {
|
private class AfterAdd extends OnFinish {
|
||||||
|
|
||||||
public AfterAdd(OnFinish finish) {
|
AfterAdd(OnFinish finish) {
|
||||||
super(finish);
|
super(finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class UpdateEntry extends RunnableOnFinish {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if ( mSuccess ) {
|
if ( mSuccess ) {
|
||||||
// Mark group dirty if title or icon changes
|
// Mark group dirty if title or icon changes
|
||||||
|
// TODO CHange if not equal... Why only title and Icon ?
|
||||||
if ( ! mBackup.getTitle().equals(mNewE.getTitle()) || ! mBackup.getIcon().equals(mNewE.getIcon()) ) {
|
if ( ! mBackup.getTitle().equals(mNewE.getTitle()) || ! mBackup.getIcon().equals(mNewE.getIcon()) ) {
|
||||||
PwGroup parent = mBackup.getParent();
|
PwGroup parent = mBackup.getParent();
|
||||||
if ( parent != null ) {
|
if ( parent != null ) {
|
||||||
|
|||||||
@@ -19,7 +19,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.keepassdroid.database.security;
|
package com.keepassdroid.database.security;
|
||||||
|
|
||||||
public class ProtectedString {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class ProtectedString implements Serializable {
|
||||||
|
|
||||||
private String string;
|
private String string;
|
||||||
private boolean protect;
|
private boolean protect;
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ public class KeePass extends Activity {
|
|||||||
|
|
||||||
public static final int EXIT_NORMAL = 0;
|
public static final int EXIT_NORMAL = 0;
|
||||||
public static final int EXIT_LOCK = 1;
|
public static final int EXIT_LOCK = 1;
|
||||||
public static final int EXIT_REFRESH = 2;
|
|
||||||
public static final int EXIT_REFRESH_TITLE = 3;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|||||||
Reference in New Issue
Block a user