Refactor GroupActivity remove V3 and V4

This commit is contained in:
J-Jamet
2018-02-22 17:26:49 +01:00
parent f0b5b1bcb5
commit 31426268ea
6 changed files with 47 additions and 164 deletions

View File

@@ -23,7 +23,8 @@
android:theme="@style/KeepassDXStyle.Light"
tools:replace="android:theme">
<!-- TODO backup API Key -->
<meta-data android:name="com.google.android.backup.api_key"
<meta-data
android:name="com.google.android.backup.api_key"
android:value="" />
<!-- Folder picker -->
@@ -52,14 +53,17 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.keepassdroid.fileselect.FileSelectActivity"
<activity
android:name="com.keepassdroid.fileselect.FileSelectActivity"
android:launchMode="singleInstance"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden" />
<activity android:name="com.keepassdroid.activities.AboutActivity"
<activity
android:name="com.keepassdroid.activities.AboutActivity"
android:launchMode="singleInstance"
android:label="@string/menu_about" />
<activity android:name="com.keepassdroid.password.PasswordActivity"
<activity
android:name="com.keepassdroid.password.PasswordActivity"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustResize">
<intent-filter>
@@ -90,19 +94,12 @@
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.kdbx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.kdbx" />
</intent-filter>
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/octet-stream" />
</intent-filter>
</activity>
<activity android:name="com.keepassdroid.activities.GroupActivityV3" android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.default_searchable"
android:value="com.keepassdroid.search.SearchResults" />
</activity>
<activity android:name="com.keepassdroid.activities.GroupActivityV4" android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.default_searchable"
<activity
android:name="com.keepassdroid.activities.GroupActivity"
android:configChanges="orientation|keyboardHidden">
<meta-data
android:name="android.app.default_searchable"
android:value="com.keepassdroid.search.SearchResults"
android:exported="false"/>
</activity>
@@ -114,12 +111,16 @@
android:name="com.keepassdroid.activities.EntryEditActivity"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden" />
<activity android:name="com.keepassdroid.search.SearchResultsActivity" android:launchMode="standard">
<activity
android:name="com.keepassdroid.search.SearchResultsActivity"
android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity android:name="com.keepassdroid.settings.SettingsActivity" />

View File

@@ -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);
Intent intent = new Intent(act, GroupActivity.class);
if ( group != null ) {
PwGroupV3 g = (PwGroupV3) group;
i.putExtra(KEY_ENTRY, g.groupId);
intent.putExtra(KEY_ENTRY, group.getId());
}
} 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;
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");
@@ -138,9 +105,12 @@ public abstract class GroupActivity extends ListNodesActivity
return;
}
isRoot = mCurrentGroup == root;
addGroupEnabled = !readOnly;
addEntryEnabled = !readOnly;
setupButtons();
isRoot = (mCurrentGroup == root);
if ( !mCurrentGroup.allowAddEntryIfIsRoot() )
addEntryEnabled = !isRoot && addEntryEnabled;
// Construct main view
ListNodesWithAddButtonView rootView = new ListNodesWithAddButtonView(this);

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -120,6 +120,10 @@ public abstract class PwGroup extends PwNode {
public abstract void setLastModificationTime(Date date);
public boolean allowAddEntryIfIsRoot() {
return false;
}
public void touch(boolean modified, boolean touchParents) {
Date now = new Date();
setLastAccessTime(now);

View File

@@ -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