Support for viewing groups in the group list.

This commit is contained in:
Brian Pellin
2010-06-03 00:39:53 -05:00
parent f7066bdd94
commit 82c2c473be
15 changed files with 120 additions and 68 deletions

View File

@@ -34,6 +34,12 @@
<!-- whenever the user invokes search while in this Activity. -->
<meta-data android:name="android.app.default_searchable"
android:value="com.keepassdroid.search.SearchResults" />
</activity>
<activity android:name="com.keepassdroid.GroupActivityV4" android:configChanges="orientation|keyboardHidden">
<!-- This metadata entry causes .app.SearchQueryResults to be the default context -->
<!-- whenever the user invokes search while in this Activity. -->
<meta-data android:name="android.app.default_searchable"
android:value="com.keepassdroid.search.SearchResults" />
</activity>
<activity android:name="com.keepassdroid.EntryActivity"></activity>
<activity android:name="com.keepassdroid.LockingActivity"></activity>

View File

@@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
@@ -47,7 +48,6 @@ import com.keepassdroid.database.exception.Kdb4Exception;
import com.keepassdroid.database.exception.PwDbOutputException;
import com.keepassdroid.database.load.Importer;
import com.keepassdroid.database.load.ImporterFactory;
import com.keepassdroid.database.load.ImporterV3;
import com.keepassdroid.database.save.PwDbOutput;
import com.keepassdroid.search.SearchDbHelper;
@@ -112,14 +112,17 @@ public class Database {
Importer imp = ImporterFactory.createImporter(bis, debug);
/*
ImporterV3 Importer;
Importer = (ImporterV3) imp; // Remove me when V4 support is in
*/
bis.reset(); // Return to the start
pm = Importer.openDatabase(bis, password, keyfile, status);
pm = imp.openDatabase(bis, password, keyfile, status);
if ( pm != null ) {
root = pm.rootGroup;
populateGlobals(null);
}
@@ -192,7 +195,6 @@ public class Database {
Vector<? extends PwGroup> rootChildGroups = pm.getGrpRoots();
for (int i = 0; i < rootChildGroups.size(); i++ ){
PwGroup cur = rootChildGroups.elementAt(i);
root = cur.getParent();
groups.put(cur.getId(), new WeakReference<PwGroup>(cur));
populateGlobals(cur);
}
@@ -200,16 +202,16 @@ public class Database {
return;
}
Vector<PwGroup> childGroups = currentGroup.childGroups;
Vector<PwEntry> childEntries = currentGroup.childEntries;
List<PwGroup> childGroups = currentGroup.childGroups;
List<PwEntry> childEntries = currentGroup.childEntries;
for (int i = 0; i < childEntries.size(); i++ ) {
PwEntry cur = childEntries.elementAt(i);
PwEntry cur = childEntries.get(i);
entries.put(cur.getUUID(), new WeakReference<PwEntry>(cur));
}
for (int i = 0; i < childGroups.size(); i++ ) {
PwGroup cur = childGroups.elementAt(i);
PwGroup cur = childGroups.get(i);
groups.put(cur.getId(), new WeakReference<PwGroup>(cur));
populateGlobals(cur);
}

View File

@@ -44,6 +44,7 @@ import com.keepassdroid.database.PwDatabaseV4;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.PwGroupId;
import com.keepassdroid.database.PwGroupV3;
import com.keepassdroid.database.PwGroupV4;
import com.keepassdroid.database.edit.AddGroup;
public abstract class GroupActivity extends GroupBaseActivity {
@@ -57,16 +58,22 @@ public abstract class GroupActivity extends GroupBaseActivity {
public static void Launch(Activity act, PwGroup group, int mode) {
Intent i;
PwDatabase pm = App.getDB().pm;
if ( pm instanceof PwDatabaseV3 ) {
// Need to use PwDatabase since group may be null
PwDatabase db = App.getDB().pm;
if ( db instanceof PwDatabaseV3 ) {
i = new Intent(act, GroupActivityV3.class);
if ( group != null ) {
PwGroupV3 g = (PwGroupV3) group;
i.putExtra(KEY_ENTRY, g.groupId);
}
} else if ( pm instanceof PwDatabaseV4 ) {
throw new RuntimeException("Not yet implemented.");
} else if ( db instanceof PwDatabaseV4 ) {
i = new Intent(act, GroupActivityV4.class);
if ( group != null ) {
PwGroupV4 g = (PwGroupV4) group;
i.putExtra(KEY_ENTRY, g.uuid.toString());
}
} else {
assert(true); // Should never be reached
throw new RuntimeException("Should never be reached.");
@@ -78,7 +85,6 @@ public abstract class GroupActivity extends GroupBaseActivity {
}
protected abstract PwGroupId retrieveGroupId(Intent i);
protected abstract PwGroup getGroup();
@Override
protected void onCreate(Bundle savedInstanceState) {

View File

@@ -1,18 +1,30 @@
/*
* Copyright 2010 Brian Pellin.
*
* This file is part of KeePassDroid.
*
* KeePassDroid 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.
*
* KeePassDroid 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 KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid;
import android.content.Intent;
import com.keepassdroid.database.PwGroupIdV3;
import com.keepassdroid.database.PwGroupV3;
public class GroupActivityV3 extends GroupActivity {
@Override
protected PwGroupV3 getGroup() {
return (PwGroupV3) mGroup;
}
@Override
protected PwGroupIdV3 retrieveGroupId(Intent i) {
int id = i.getIntExtra(KEY_ENTRY, -1);

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2010 Brian Pellin.
*
* This file is part of KeePassDroid.
*
* KeePassDroid 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.
*
* KeePassDroid 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 KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid;
import java.util.UUID;
import android.content.Intent;
import com.keepassdroid.database.PwGroupId;
import com.keepassdroid.database.PwGroupIdV4;
public class GroupActivityV4 extends GroupActivity {
@Override
protected PwGroupId retrieveGroupId(Intent i) {
String uuid = i.getStringExtra(KEY_ENTRY);
if ( uuid == null || uuid.length() == 0 ) {
return null;
}
return new PwGroupIdV4(UUID.fromString(uuid));
}
}

View File

@@ -26,9 +26,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwEntryV3;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.PwGroupV3;
import com.keepassdroid.view.PwEntryView;
import com.keepassdroid.view.PwGroupView;
@@ -64,7 +62,7 @@ public class PwListAdapter extends BaseAdapter {
filteredEntries = new Vector<PwEntry>();
for (int i = 0; i < mGroup.childEntries.size(); i++) {
PwEntryV3 entry = (PwEntryV3) mGroup.childEntries.elementAt(i);
PwEntry entry = mGroup.childEntries.get(i);
if ( ! entry.isMetaStream() ) {
filteredEntries.add(entry);
}
@@ -100,26 +98,18 @@ public class PwListAdapter extends BaseAdapter {
private View createGroupView(int position, View convertView) {
PwGroupView gv;
//if (convertView == null || ! (convertView instanceof PwGroupView)) {
PwGroupV3 group = (PwGroupV3) mGroup.childGroups.elementAt(position);
gv = PwGroupView.getInstance(mAct, group);
/*
} else {
gv = (PwGroupView) convertView;
gv.setGroup((PwGroupV3) mGroup.childGroups.elementAt(position));
}
*/
PwGroup group = mGroup.childGroups.get(position);
gv = PwGroupView.getInstance(mAct, group);
return gv;
}
private PwEntryView createEntryView(int position, View convertView) {
PwEntryView ev;
// if (convertView == null || ! (convertView instanceof PwEntryView) ) {
ev = PwEntryView.getInstance(mAct, filteredEntries.elementAt(position), position);
// } else {
// ev = (PwEntryView) convertView;
// ev.setEntry(filteredEntries.elementAt(position));
// }
ev = PwEntryView.getInstance(mAct, filteredEntries.elementAt(position), position);
return ev;
}

View File

@@ -39,6 +39,7 @@ public abstract class PwDatabase {
public byte masterKey[] = new byte[32];
public byte[] finalKey;
public String name = "KeePass database";
public PwGroup rootGroup;
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, int numRounds) throws IOException {

View File

@@ -61,8 +61,6 @@ public class PwDatabaseV3 extends PwDatabase {
// Debugging entries
public PwDbHeaderV3 dbHeader;
// root group
public PwGroupV3 rootGroup;
public int getAlgorithm() {
return algorithm;
@@ -159,15 +157,17 @@ public class PwDatabaseV3 extends PwDatabase {
{
// I'm in root
if (currentGroup == null) {
rootGroup = new PwGroupV3();
PwGroupV3 root = new PwGroupV3();
rootGroup = root;
Vector<PwGroup> rootChildGroups = getGrpRoots();
rootGroup.setGroups(rootChildGroups);
rootGroup.childEntries = new Vector<PwEntry>();
rootGroup.level = -1;
root.setGroups(rootChildGroups);
root.childEntries = new Vector<PwEntry>();
root.level = -1;
for (int i=0; i<rootChildGroups.size(); i++) {
PwGroupV3 grp = (PwGroupV3) rootChildGroups.elementAt(i);
grp.parent = rootGroup;
grp.parent = root;
constructTree(grp);
}
return;

View File

@@ -20,7 +20,6 @@
package com.keepassdroid.database;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@@ -31,7 +30,6 @@ import java.util.Map;
import java.util.UUID;
import java.util.Vector;
import com.keepassdroid.database.exception.InconsistentDBException;
import com.keepassdroid.database.exception.InvalidKeyFileException;
@@ -80,9 +78,6 @@ public class PwDatabaseV4 extends PwDatabase {
public static final UUID UUID_ZERO = new UUID(0,0);
//private Vector<PwGroupV4> groups = new Vector<PwGroupV4>();
public PwGroupV4 rootGroup;
@Override
public byte[] getMasterKey(String key, String keyFileName)
throws InvalidKeyFileException, IOException {
@@ -118,15 +113,12 @@ public class PwDatabaseV4 extends PwDatabase {
@Override
public Vector<PwGroup> getGroups() {
Vector<PwGroup> list = new Vector<PwGroup>();
rootGroup.buildChildGroupsRecursive(list);
PwGroupV4 root = (PwGroupV4) rootGroup;
root.buildChildGroupsRecursive(list);
return list;
}
public void parseDB(InputStream in) throws InconsistentDBException {
//TODO Implement Me
}
@Override
public Vector<PwGroup> getGrpRoots() {
return rootGroup.childGroups;
@@ -135,7 +127,8 @@ public class PwDatabaseV4 extends PwDatabase {
@Override
public Vector<PwEntry> getEntries() {
Vector<PwEntry> list = new Vector<PwEntry>();
rootGroup.buildChildEntriesRecursive(list);
PwGroupV4 root = (PwGroupV4) rootGroup;
root.buildChildEntriesRecursive(list);
return list;
}

View File

@@ -73,4 +73,8 @@ public abstract class PwEntry implements Cloneable {
public abstract String getDisplayTitle();
public boolean isMetaStream() {
return false;
}
}

View File

@@ -223,7 +223,8 @@ public class PwEntryV3 extends PwEntry {
System.arraycopy( buf, offset, binaryData, 0, len );
}
// Determine if this is a MetaStream entrie
// Determine if this is a MetaStream entry
@Override
public boolean isMetaStream() {
if ( binaryData == null ) return false;
if ( additional == null || additional.length() == 0 ) return false;

View File

@@ -19,9 +19,7 @@
*/
package com.keepassdroid.database;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
@@ -46,10 +44,6 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
private boolean expires = false;
private long usageCount = 0;
public List<PwGroupV4> listGroups = new ArrayList<PwGroupV4>();
public List<PwEntryV4> listEntries = new ArrayList<PwEntryV4>();
public PwGroupV4() {
}
@@ -61,7 +55,7 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
public void AddGroup(PwGroupV4 subGroup, boolean takeOwnership, boolean updateLocationChanged) {
if ( subGroup == null ) throw new RuntimeException("subGroup");
listGroups.add(subGroup);
childGroups.add(subGroup);
if ( takeOwnership ) subGroup.parent = this;
@@ -76,7 +70,7 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
public void AddEntry(PwEntryV4 pe, boolean takeOwnership, boolean updateLocationChanged) {
assert(pe != null);
listEntries.add(pe);
childEntries.add(pe);
if ( takeOwnership ) pe.parent = this;

View File

@@ -86,7 +86,7 @@ public abstract class AddEntry extends RunnableOnFinish {
}
} else {
// Remove from group
mEntry.getParent().childEntries.removeElement(mEntry);
mEntry.getParent().childEntries.remove(mEntry);
// Remove from manager
mDb.pm.getEntries().removeElement(mEntry);

View File

@@ -42,7 +42,8 @@ public class ImporterFactory {
if ( PwDbHeaderV3.matchesHeader(sig1, sig2) ) {
return new ImporterV3(debug);
} else if ( PwDbHeaderV4.matchesHeader(sig1, sig2) ) {
throw new Kdb4Exception();
return new ImporterV4();
//throw new Kdb4Exception();
//return new ImporterV4();
}

View File

@@ -464,7 +464,7 @@ public class ImporterV4 extends Importer {
if ( ctxGroups.size() != 0 ) throw new IOException("Group list should be empty.");
db.rootGroup = new PwGroupV4();
ctxGroups.push(db.rootGroup);
ctxGroups.push((PwGroupV4)db.rootGroup);
ctxGroup = ctxGroups.peek();
return SwitchContext(ctx, KdbContext.Group, xpp);