Better index implementation

This commit is contained in:
J-Jamet
2019-05-10 00:39:31 +02:00
parent 6be2148951
commit e75a2502d1
10 changed files with 33 additions and 73 deletions

View File

@@ -26,17 +26,8 @@ import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;
import android.view.*;
import android.widget.*;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
@@ -56,7 +47,6 @@ import com.kunzisoft.keepass.timeout.TimeoutHelper;
import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.Util;
import com.kunzisoft.keepass.view.EntryEditCustomField;
import org.jetbrains.annotations.NotNull;
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.KEY_ICON_STANDARD;
@@ -185,7 +175,8 @@ public class EntryEditActivity extends LockingHideActivity
} else {
mEntry = database.getEntryById(keyEntry);
mIsNew = false;
fillData();
if (mEntry != null)
fillData();
}
// Close the activity if entry to edit or parent to add entry can't be retrieve
@@ -525,6 +516,7 @@ public class EntryEditActivity extends LockingHideActivity
if (mEntry.allowExtraFields()) {
LinearLayout container = findViewById(R.id.entry_edit_advanced_container);
// TODO Close here but why ?
mEntry.getFields().doActionToAllCustomProtectedField((key, value) -> {
EntryEditCustomField entryEditCustomField = new EntryEditCustomField(EntryEditActivity.this);
entryEditCustomField.setData(key, value);

View File

@@ -168,14 +168,15 @@ class Database {
get() = pwDatabaseV4 != null
val isRecycleBinEnabled: Boolean
get() = if (pwDatabaseV4 != null) {
pwDatabaseV4!!.isRecycleBinEnabled
} else false
get() = pwDatabaseV4?.isRecycleBinEnabled ?: false
val recycleBin: GroupVersioned?
get() = if (pwDatabaseV4 != null) {
GroupVersioned(pwDatabaseV4!!.recycleBin!!)
} else null
get() {
pwDatabaseV4?.recycleBin?.let {
return GroupVersioned(it)
}
return null
}
constructor()
@@ -278,14 +279,14 @@ class Database {
when {
// Header of database V3
PwDbHeaderV3.matchesHeader(sig1, sig2) -> setDatabaseV3(ImporterV3()
.openDatabaseAndBuildIndex(bufferedInputStream,
.openDatabase(bufferedInputStream,
password,
keyFileInputStream,
progressTaskUpdater))
// Header of database V4
PwDbHeaderV4.matchesHeader(sig1, sig2) -> setDatabaseV4(ImporterV4(ctx.filesDir)
.openDatabaseAndBuildIndex(bufferedInputStream,
.openDatabase(bufferedInputStream,
password,
keyFileInputStream,
progressTaskUpdater))
@@ -544,11 +545,9 @@ class Database {
pwDatabaseV3?.getGroupById(id)?.let {
return GroupVersioned(it)
}
pwDatabaseV4?.getGroupById(id)?.let {
return GroupVersioned(it)
}
return null
}

View File

@@ -37,16 +37,12 @@ class EntryVersioned : NodeVersioned, PwEntryInterface<GroupVersioned> {
constructor(entry: PwEntryV3) {
this.pwEntryV4 = null
if (this.pwEntryV3 == null)
this.pwEntryV3 = PwEntryV3()
this.pwEntryV3?.updateWith(entry)
this.pwEntryV3 = entry
}
constructor(entry: PwEntryV4) {
this.pwEntryV3 = null
if (this.pwEntryV4 == null)
this.pwEntryV4 = PwEntryV4()
this.pwEntryV4?.updateWith(entry)
this.pwEntryV4 = entry
}
constructor(parcel: Parcel) {

View File

@@ -34,16 +34,12 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
constructor(group: PwGroupV3) {
this.pwGroupV4 = null
if (this.pwGroupV3 == null)
this.pwGroupV3 = PwGroupV3()
this.pwGroupV3?.updateWith(group)
this.pwGroupV3 = group
}
constructor(group: PwGroupV4) {
this.pwGroupV3 = null
if (this.pwGroupV4 == null)
this.pwGroupV4 = PwGroupV4()
this.pwGroupV4?.updateWith(group)
this.pwGroupV4 = group
}
constructor(parcel: Parcel) {

View File

@@ -229,8 +229,6 @@ public abstract class PwDatabase<Group extends PwGroup<?, Group, Entry>, Entry e
* -------------------------------------
*/
public abstract void populateNodesIndexes();
public abstract PwNodeId newGroupId();
public abstract PwNodeId newEntryId();
@@ -315,7 +313,7 @@ public abstract class PwDatabase<Group extends PwGroup<?, Group, Entry>, Entry e
* -------------------------------------
*/
protected void addGroupTo(Group newGroup, @Nullable Group parent) {
public void addGroupTo(Group newGroup, @Nullable Group parent) {
// Add tree to parent tree
if (parent != null)
parent.addChildGroup(newGroup);
@@ -323,7 +321,7 @@ public abstract class PwDatabase<Group extends PwGroup<?, Group, Entry>, Entry e
addGroupIndex(newGroup);
}
protected void removeGroupFrom(Group groupToRemove, Group parent) {
public void removeGroupFrom(Group groupToRemove, Group parent) {
// Remove tree from parent tree
if (parent != null) {
parent.removeChildGroup(groupToRemove);
@@ -331,7 +329,7 @@ public abstract class PwDatabase<Group extends PwGroup<?, Group, Entry>, Entry e
removeGroupIndex(groupToRemove);
}
protected void addEntryTo(Entry newEntry, @Nullable Group parent) {
public void addEntryTo(Entry newEntry, @Nullable Group parent) {
// Add entry to parent
if (parent != null)
parent.addChildEntry(newEntry);
@@ -339,7 +337,7 @@ public abstract class PwDatabase<Group extends PwGroup<?, Group, Entry>, Entry e
addEntryIndex(newEntry);
}
protected void removeEntryFrom(Entry entryToRemove, Group parent) {
public void removeEntryFrom(Entry entryToRemove, Group parent) {
// Remove entry for parent
if (parent != null) {
parent.removeChildEntry(entryToRemove);

View File

@@ -111,8 +111,7 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
}
}
@Override
public void populateNodesIndexes() {
public void constructTreeFromIndex() {
constructTreeFromIndex(getRootGroup());
}

View File

@@ -470,25 +470,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return null;
}
@Override
public void populateNodesIndexes() {
getRootGroup().doForEachChildAndForIt(
new NodeHandler<PwEntryV4>() {
@Override
public boolean operate(PwEntryV4 entry) {
addEntryIndex(entry);
return true;
}
},
new NodeHandler<PwGroupV4>() {
@Override
public boolean operate(PwGroupV4 group) {
addGroupIndex(group);
return true;
}
});
}
@Override
public PwNodeIdUUID newGroupId() {
PwNodeIdUUID newId;
@@ -656,15 +637,15 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
}
@Override
protected void removeEntryFrom(PwEntryV4 entryToRemove, PwGroupV4 parent) {
public void removeEntryFrom(PwEntryV4 entryToRemove, PwGroupV4 parent) {
super.removeEntryFrom(entryToRemove, parent);
deletedObjects.add(new PwDeletedObject((UUID) entryToRemove.getNodeId().getId()));
deletedObjects.add(new PwDeletedObject(entryToRemove.getNodeId().getId()));
}
@Override
public void undoDeleteEntryFrom(PwEntryV4 entry, PwGroupV4 origParent) {
super.undoDeleteEntryFrom(entry, origParent);
deletedObjects.remove(new PwDeletedObject((UUID) entry.getNodeId().getId()));
deletedObjects.remove(new PwDeletedObject(entry.getNodeId().getId()));
}
public PwGroupV4 getRecycleBin() { // TODO delete recycle bin preference

View File

@@ -41,11 +41,4 @@ public abstract class Importer<PwDb extends PwDatabase> {
public abstract PwDb openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater)
throws IOException, InvalidDBException;
public PwDb openDatabaseAndBuildIndex(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater)
throws IOException, InvalidDBException {
PwDb database = openDatabase(inStream, password, keyInputStream, updater);
database.populateNodesIndexes();
return database;
}
}

View File

@@ -228,7 +228,9 @@ public class ImporterV3 extends Importer<PwDatabaseV3> {
}
pos += 2 + 4 + fieldSize;
}
databaseToOpen.constructTreeFromIndex();
return databaseToOpen;
}

View File

@@ -525,6 +525,7 @@ public class ImporterV4 extends Importer<PwDatabaseV4> {
case Group:
if ( name.equalsIgnoreCase(PwDatabaseV4XML.ElemUuid) ) {
ctxGroup.setNodeId(new PwNodeIdUUID(ReadUuid(xpp)));
mDatabase.addGroupIndex(ctxGroup);
} else if ( name.equalsIgnoreCase(PwDatabaseV4XML.ElemName) ) {
ctxGroup.setTitle(ReadString(xpp));
} else if ( name.equalsIgnoreCase(PwDatabaseV4XML.ElemNotes) ) {
@@ -587,6 +588,7 @@ public class ImporterV4 extends Importer<PwDatabaseV4> {
case Entry:
if ( name.equalsIgnoreCase(PwDatabaseV4XML.ElemUuid) ) {
ctxEntry.setNodeId(new PwNodeIdUUID(ReadUuid(xpp)));
mDatabase.addEntryIndex(ctxEntry);
} else if ( name.equalsIgnoreCase(PwDatabaseV4XML.ElemIcon) ) {
ctxEntry.setIconStandard(mDatabase.getIconFactory().getIcon((int)ReadUInt(xpp, 0)));
} else if ( name.equalsIgnoreCase(PwDatabaseV4XML.ElemCustomIconID) ) {
@@ -789,6 +791,7 @@ public class ImporterV4 extends Importer<PwDatabaseV4> {
} else if ( ctx == KdbContext.Group && name.equalsIgnoreCase(PwDatabaseV4XML.ElemGroup) ) {
if ( ctxGroup.getNodeId() == null || ctxGroup.getNodeId().getId().equals(PwDatabase.UUID_ZERO) ) {
ctxGroup.setNodeId(new PwNodeIdUUID());
mDatabase.addGroupIndex(ctxGroup);
}
ctxGroups.pop();
@@ -817,6 +820,7 @@ public class ImporterV4 extends Importer<PwDatabaseV4> {
} else if ( ctx == KdbContext.Entry && name.equalsIgnoreCase(PwDatabaseV4XML.ElemEntry) ) {
if ( ctxEntry.getNodeId() == null || ctxEntry.getNodeId().getId().equals(PwDatabase.UUID_ZERO) ) {
ctxEntry.setNodeId(new PwNodeIdUUID());
mDatabase.addEntryIndex(ctxEntry);
}
if ( entryInHistory ) {