mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Best update and nodeId type implementation
This commit is contained in:
@@ -142,6 +142,7 @@ class NodeAdapter
|
||||
Log.e(TAG, "Can't add node elements to the list", e)
|
||||
Toast.makeText(context, "Can't add node elements to the list : " + e.message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun contains(node: NodeVersioned): Boolean {
|
||||
|
||||
@@ -33,22 +33,17 @@ class UpdateEntryRunnable constructor(
|
||||
finishRunnable: AfterActionNodeFinishRunnable?)
|
||||
: ActionNodeDatabaseRunnable(context, database, finishRunnable, save) {
|
||||
|
||||
// Keep backup of original values in case save fails
|
||||
private var mBackupEntryHistory: EntryVersioned = EntryVersioned(mOldEntry)
|
||||
|
||||
override fun nodeAction() {
|
||||
// Update entry with new values
|
||||
mOldEntry.updateWith(mNewEntry)
|
||||
mNewEntry.touch(modified = true, touchParents = true)
|
||||
|
||||
// Create an entry history (an entry history don't have history)
|
||||
mOldEntry.addEntryToHistory(EntryVersioned(mBackupEntryHistory, copyHistory = false))
|
||||
mNewEntry.addEntryToHistory(EntryVersioned(mOldEntry, copyHistory = false))
|
||||
|
||||
database.removeOldestHistory(mOldEntry)
|
||||
database.removeOldestHistory(mNewEntry)
|
||||
|
||||
// Only change data un index
|
||||
// TODO
|
||||
database.updateEntry(mOldEntry)
|
||||
database.updateEntry(mNewEntry)
|
||||
}
|
||||
|
||||
override fun nodeFinish(result: Result): ActionNodeValues {
|
||||
|
||||
@@ -38,12 +38,10 @@ class UpdateGroupRunnable constructor(
|
||||
|
||||
override fun nodeAction() {
|
||||
// Update group with new values
|
||||
mOldGroup.updateWith(mNewGroup)
|
||||
mOldGroup.touch(modified = true, touchParents = true)
|
||||
mNewGroup.touch(modified = true, touchParents = true)
|
||||
|
||||
// Only change data un index
|
||||
// TODO
|
||||
database.updateGroup(mOldGroup)
|
||||
database.updateGroup(mNewGroup)
|
||||
}
|
||||
|
||||
override fun nodeFinish(result: Result): ActionNodeValues {
|
||||
|
||||
@@ -2,12 +2,11 @@ package com.kunzisoft.keepass.database.cursor
|
||||
|
||||
import android.database.MatrixCursor
|
||||
import android.provider.BaseColumns
|
||||
import com.kunzisoft.keepass.database.element.PwEntry
|
||||
import com.kunzisoft.keepass.database.element.PwIconFactory
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId
|
||||
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
abstract class EntryCursor<PwEntryV : PwEntry<*, *>> : MatrixCursor(arrayOf(
|
||||
abstract class EntryCursor<EntryId, PwEntryV : PwEntry<*, EntryId, *, *>> : MatrixCursor(arrayOf(
|
||||
_ID,
|
||||
COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS,
|
||||
COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS,
|
||||
@@ -25,10 +24,10 @@ abstract class EntryCursor<PwEntryV : PwEntry<*, *>> : MatrixCursor(arrayOf(
|
||||
|
||||
abstract fun addEntry(entry: PwEntryV)
|
||||
|
||||
abstract fun getPwNodeId(): PwNodeId<EntryId>
|
||||
|
||||
open fun populateEntry(pwEntry: PwEntryV, iconFactory: PwIconFactory) {
|
||||
pwEntry.nodeId = PwNodeIdUUID(
|
||||
UUID(getLong(getColumnIndex(COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
|
||||
getLong(getColumnIndex(COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS))))
|
||||
pwEntry.nodeId = getPwNodeId()
|
||||
pwEntry.title = getString(getColumnIndex(COLUMN_INDEX_TITLE))
|
||||
|
||||
val iconStandard = iconFactory.getIcon(getInt(getColumnIndex(COLUMN_INDEX_ICON_STANDARD)))
|
||||
@@ -53,5 +52,4 @@ abstract class EntryCursor<PwEntryV : PwEntry<*, *>> : MatrixCursor(arrayOf(
|
||||
const val COLUMN_INDEX_URL = "URL"
|
||||
const val COLUMN_INDEX_NOTES = "notes"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kunzisoft.keepass.database.cursor
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwEntry
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId
|
||||
import com.kunzisoft.keepass.database.element.PwNodeIdUUID
|
||||
import java.util.*
|
||||
|
||||
abstract class EntryCursorUUID<EntryV: PwEntry<*, UUID, *, *>>: EntryCursor<UUID, EntryV>() {
|
||||
|
||||
override fun getPwNodeId(): PwNodeId<UUID> {
|
||||
return PwNodeIdUUID(
|
||||
UUID(getLong(getColumnIndex(COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
|
||||
getLong(getColumnIndex(COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS))))
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.kunzisoft.keepass.database.cursor
|
||||
import com.kunzisoft.keepass.database.element.PwDatabase
|
||||
import com.kunzisoft.keepass.database.element.PwEntryV3
|
||||
|
||||
class EntryCursorV3 : EntryCursor<PwEntryV3>() {
|
||||
class EntryCursorV3 : EntryCursorUUID<PwEntryV3>() {
|
||||
|
||||
override fun addEntry(entry: PwEntryV3) {
|
||||
addRow(arrayOf(
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.kunzisoft.keepass.database.element.PwIconFactory
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class EntryCursorV4 : EntryCursor<PwEntryV4>() {
|
||||
class EntryCursorV4 : EntryCursorUUID<PwEntryV4>() {
|
||||
|
||||
private val extraFieldCursor: ExtraFieldCursor = ExtraFieldCursor()
|
||||
|
||||
|
||||
@@ -30,8 +30,9 @@ import java.util.*
|
||||
|
||||
abstract class PwDatabase<
|
||||
GroupId,
|
||||
Group : PwGroup<GroupId, Group, Entry>,
|
||||
Entry : PwEntry<Group, Entry>
|
||||
EntryId,
|
||||
Group : PwGroup<GroupId, EntryId, Group, Entry>,
|
||||
Entry : PwEntry<GroupId, EntryId, Group, Entry>
|
||||
> {
|
||||
|
||||
// Algorithm used to encrypt the database
|
||||
@@ -51,7 +52,7 @@ abstract class PwDatabase<
|
||||
var changeDuplicateId = false
|
||||
|
||||
private var groupIndexes = LinkedHashMap<PwNodeId<GroupId>, Group>()
|
||||
private var entryIndexes = LinkedHashMap<PwNodeId<UUID>, Entry>()
|
||||
private var entryIndexes = LinkedHashMap<PwNodeId<EntryId>, Entry>()
|
||||
|
||||
abstract val version: String
|
||||
|
||||
@@ -193,7 +194,7 @@ abstract class PwDatabase<
|
||||
|
||||
abstract fun newGroupId(): PwNodeId<GroupId>
|
||||
|
||||
abstract fun newEntryId(): PwNodeId<UUID>
|
||||
abstract fun newEntryId(): PwNodeId<EntryId>
|
||||
|
||||
abstract fun createGroup(): Group
|
||||
|
||||
@@ -274,7 +275,7 @@ abstract class PwDatabase<
|
||||
}
|
||||
}
|
||||
|
||||
fun isEntryIdUsed(id: PwNodeId<UUID>): Boolean {
|
||||
fun isEntryIdUsed(id: PwNodeId<EntryId>): Boolean {
|
||||
return entryIndexes.containsKey(id)
|
||||
}
|
||||
|
||||
@@ -282,7 +283,7 @@ abstract class PwDatabase<
|
||||
return entryIndexes.values
|
||||
}
|
||||
|
||||
fun getEntryById(id: PwNodeId<UUID>): Entry? {
|
||||
fun getEntryById(id: PwNodeId<EntryId>): Entry? {
|
||||
return this.entryIndexes[id]
|
||||
}
|
||||
|
||||
@@ -340,6 +341,7 @@ abstract class PwDatabase<
|
||||
}
|
||||
|
||||
fun updateGroup(group: Group) {
|
||||
getGroupById(group.nodeId)?.parent?.updateChildGroup(group)
|
||||
updateGroupIndex(group)
|
||||
}
|
||||
|
||||
@@ -357,6 +359,7 @@ abstract class PwDatabase<
|
||||
}
|
||||
|
||||
fun updateEntry(entry: Entry) {
|
||||
getEntryById(entry.nodeId)?.parent?.updateChildEntry(entry)
|
||||
updateEntryIndex(entry)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,10 @@ import java.io.InputStream
|
||||
import java.security.DigestOutputStream
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class PwDatabaseV3 : PwDatabase<Int, PwGroupV3, PwEntryV3>() {
|
||||
class PwDatabaseV3 : PwDatabase<Int, UUID, PwGroupV3, PwEntryV3>() {
|
||||
|
||||
private var numKeyEncRounds: Int = 0
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ import javax.xml.parsers.DocumentBuilderFactory
|
||||
import javax.xml.parsers.ParserConfigurationException
|
||||
|
||||
|
||||
class PwDatabaseV4 : PwDatabase<UUID, PwGroupV4, PwEntryV4> {
|
||||
class PwDatabaseV4 : PwDatabase<UUID, UUID, PwGroupV4, PwEntryV4> {
|
||||
|
||||
var hmacKey: ByteArray? = null
|
||||
private set
|
||||
|
||||
@@ -5,10 +5,12 @@ import java.util.*
|
||||
|
||||
abstract class PwEntry
|
||||
<
|
||||
ParentGroup: PwGroupInterface<ParentGroup, Entry>,
|
||||
Entry: PwEntryInterface<ParentGroup>
|
||||
GroupId,
|
||||
EntryId,
|
||||
ParentGroup: PwGroup<GroupId, EntryId, ParentGroup, Entry>,
|
||||
Entry: PwEntry<GroupId, EntryId, ParentGroup, Entry>
|
||||
>
|
||||
: PwNode<UUID, ParentGroup, Entry>, PwEntryInterface<ParentGroup> {
|
||||
: PwNode<EntryId, ParentGroup, Entry>, PwEntryInterface<ParentGroup> {
|
||||
|
||||
constructor() : super()
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ import java.util.UUID
|
||||
* @author Dominik Reichl <dominik.reichl></dominik.reichl>@t-online.de>
|
||||
* @author Jeremy Jamet <jeremy.jamet></jeremy.jamet>@kunzisoft.com>
|
||||
*/
|
||||
class PwEntryV3 : PwEntry<PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
class PwEntryV3 : PwEntry<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
|
||||
/** A string describing what is in pBinaryData */
|
||||
var binaryDesc = ""
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.utils.MemoryUtil
|
||||
import java.util.*
|
||||
|
||||
class PwEntryV4 : PwEntry<PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
class PwEntryV4 : PwEntry<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
|
||||
// To decode each field not parcelable
|
||||
@Transient
|
||||
|
||||
@@ -4,11 +4,12 @@ import android.os.Parcel
|
||||
|
||||
abstract class PwGroup
|
||||
<
|
||||
Id,
|
||||
Group: PwGroupInterface<Group, Entry>,
|
||||
Entry: PwEntryInterface<Group>
|
||||
GroupId,
|
||||
EntryId,
|
||||
Group: PwGroup<GroupId, EntryId, Group, Entry>,
|
||||
Entry: PwEntry<GroupId, EntryId, Group, Entry>
|
||||
>
|
||||
: PwNode<Id, Group, Entry>, PwGroupInterface<Group, Entry> {
|
||||
: PwNode<GroupId, Group, Entry>, PwGroupInterface<Group, Entry> {
|
||||
|
||||
private var titleGroup = ""
|
||||
@Transient
|
||||
@@ -27,7 +28,7 @@ abstract class PwGroup
|
||||
dest.writeString(titleGroup)
|
||||
}
|
||||
|
||||
protected fun updateWith(source: PwGroup<Id, Group, Entry>) {
|
||||
protected fun updateWith(source: PwGroup<GroupId, EntryId, Group, Entry>) {
|
||||
super.updateWith(source)
|
||||
titleGroup = source.titleGroup
|
||||
childGroups.clear()
|
||||
|
||||
@@ -22,8 +22,9 @@ package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import java.util.*
|
||||
|
||||
class PwGroupV3 : PwGroup<Int, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
class PwGroupV3 : PwGroup<Int, UUID, PwGroupV3, PwEntryV3>, PwNodeV3Interface {
|
||||
|
||||
var level = 0 // short
|
||||
/** Used by KeePass internally, don't use */
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.os.Parcelable
|
||||
import java.util.HashMap
|
||||
import java.util.UUID
|
||||
|
||||
class PwGroupV4 : PwGroup<UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
class PwGroupV4 : PwGroup<UUID, UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
|
||||
|
||||
// TODO Encapsulate
|
||||
override var icon: PwIcon
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
||||
import java.io.InputStream
|
||||
|
||||
abstract class Importer<PwDb : PwDatabase<*, *, *>> {
|
||||
abstract class Importer<PwDb : PwDatabase<*, *, *, *>> {
|
||||
|
||||
/**
|
||||
* Load a versioned database file, return contents in a new PwDatabase.
|
||||
|
||||
Reference in New Issue
Block a user