mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Refactor GroupActivity remove V3 and V4
This commit is contained in:
1 parent
f0b5b1bcb5
commit
31426268ea
6 files changed
+47
-164
No files matched your search
@@ -35,14 +35,9 @@ import android.widget.ImageView;
|
||||
import com.keepassdroid.adapters.NodeAdapter;
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.database.Database;
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
import com.keepassdroid.database.PwDatabaseV3;
|
||||
import com.keepassdroid.database.PwDatabaseV4;
|
||||
import com.keepassdroid.database.PwEntry;
|
||||
import com.keepassdroid.database.PwGroup;
|
||||
import com.keepassdroid.database.PwGroupId;
|
||||
import com.keepassdroid.database.PwGroupV3;
|
||||
import com.keepassdroid.database.PwGroupV4;
|
||||
import com.keepassdroid.database.PwNode;
|
||||
import com.keepassdroid.database.edit.AddGroup;
|
||||
import com.keepassdroid.database.edit.DeleteEntry;
|
||||
@@ -55,7 +50,7 @@ import com.keepassdroid.view.ListNodesWithAddButtonView;
|
||||
import com.kunzisoft.keepass.KeePass;
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
public abstract class GroupActivity extends ListNodesActivity
|
||||
public class GroupActivity extends ListNodesActivity
|
||||
implements GroupEditDialogFragment.EditGroupListener, IconPickerDialogFragment.IconPickerListener {
|
||||
|
||||
protected boolean addGroupEnabled = false;
|
||||
@@ -75,37 +70,11 @@ public abstract class GroupActivity extends ListNodesActivity
|
||||
}
|
||||
|
||||
public static void Launch(Activity act, PwGroup group) {
|
||||
Intent i;
|
||||
|
||||
// Need to use PwDatabase since tree 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 ( db instanceof PwDatabaseV4 ) {
|
||||
i = new Intent(act, GroupActivityV4.class);
|
||||
|
||||
if ( group != null ) {
|
||||
PwGroupV4 g = (PwGroupV4) group;
|
||||
i.putExtra(KEY_ENTRY, g.uuid.toString());
|
||||
}
|
||||
} else {
|
||||
// Reached if db is null
|
||||
Log.d(TAG, "Tried to launch with null db");
|
||||
return;
|
||||
}
|
||||
|
||||
act.startActivityForResult(i,0);
|
||||
}
|
||||
|
||||
protected abstract PwGroupId retrieveGroupId(Intent i);
|
||||
|
||||
protected void setupButtons() {
|
||||
addGroupEnabled = !readOnly;
|
||||
Intent intent = new Intent(act, GroupActivity.class);
|
||||
if ( group != null ) {
|
||||
intent.putExtra(KEY_ENTRY, group.getId());
|
||||
}
|
||||
act.startActivityForResult(intent,0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,17 +88,15 @@ public abstract class GroupActivity extends ListNodesActivity
|
||||
setResult(KeePass.EXIT_NORMAL);
|
||||
|
||||
Log.w(TAG, "Creating tree view");
|
||||
Intent intent = getIntent();
|
||||
|
||||
PwGroupId id = retrieveGroupId(intent);
|
||||
PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(KEY_ENTRY);
|
||||
|
||||
Database db = App.getDB();
|
||||
readOnly = db.readOnly;
|
||||
PwGroup root = db.pm.rootGroup;
|
||||
if ( id == null ) {
|
||||
if ( pwGroupId == null ) {
|
||||
mCurrentGroup = root;
|
||||
} else {
|
||||
mCurrentGroup = db.pm.groups.get(id);
|
||||
mCurrentGroup = db.pm.groups.get(pwGroupId);
|
||||
}
|
||||
|
||||
Log.w(TAG, "Retrieved tree");
|
||||
@@ -137,10 +104,13 @@ public abstract class GroupActivity extends ListNodesActivity
|
||||
Log.w(TAG, "Group was null");
|
||||
return;
|
||||
}
|
||||
|
||||
isRoot = mCurrentGroup == root;
|
||||
|
||||
setupButtons();
|
||||
|
||||
addGroupEnabled = !readOnly;
|
||||
addEntryEnabled = !readOnly;
|
||||
|
||||
isRoot = (mCurrentGroup == root);
|
||||
if ( !mCurrentGroup.allowAddEntryIfIsRoot() )
|
||||
addEntryEnabled = !isRoot && addEntryEnabled;
|
||||
|
||||
// Construct main view
|
||||
ListNodesWithAddButtonView rootView = new ListNodesWithAddButtonView(this);
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, 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 2 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.keepassdroid.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.keepassdroid.database.PwGroupIdV3;
|
||||
|
||||
public class GroupActivityV3 extends GroupActivity {
|
||||
|
||||
@Override
|
||||
protected PwGroupIdV3 retrieveGroupId(Intent i) {
|
||||
int id = i.getIntExtra(KEY_ENTRY, -1);
|
||||
|
||||
if ( id == -1 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PwGroupIdV3(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupButtons() {
|
||||
super.setupButtons();
|
||||
addEntryEnabled = !isRoot && !readOnly;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, 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 2 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.keepassdroid.activities;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupButtons() {
|
||||
super.setupButtons();
|
||||
addEntryEnabled = !readOnly;
|
||||
}
|
||||
}
|
||||
@@ -119,6 +119,10 @@ public abstract class PwGroup extends PwNode {
|
||||
public abstract void setLastAccessTime(Date date);
|
||||
|
||||
public abstract void setLastModificationTime(Date date);
|
||||
|
||||
public boolean allowAddEntryIfIsRoot() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void touch(boolean modified, boolean touchParents) {
|
||||
Date now = new Date();
|
||||
|
||||
@@ -19,11 +19,6 @@
|
||||
*/
|
||||
package com.keepassdroid.database;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -213,7 +208,11 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
|
||||
@Override
|
||||
public void setParent(PwGroup prt) {
|
||||
parent = (PwGroupV4) prt;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowAddEntryIfIsRoot() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user