mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-20 09:01:33 -08:00
Add natural database sort
This commit is contained in:
1 parent
8536de3555
commit
173dd5b59b
8 files changed
+101
-127
No files matched your search
@@ -1,5 +1,6 @@
|
||||
KeepassDX (2.5.0.0beta20)
|
||||
* Fix nested groups no longer visible in V1 databases
|
||||
* Add natural database sort
|
||||
|
||||
KeepassDX (2.5.0.0beta20)
|
||||
* Fix a major bug that displays an entry history
|
||||
|
||||
@@ -30,7 +30,6 @@ import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.app.App
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||
@@ -138,7 +137,7 @@ class NodeAdapter
|
||||
assignPreferences()
|
||||
// TODO verify sort
|
||||
try {
|
||||
this.nodeSortedList.addAll(group.getChildrenWithoutMetaStream())
|
||||
this.nodeSortedList.addAll(group.getChildren())
|
||||
} catch (e: Exception) {
|
||||
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()
|
||||
|
||||
@@ -31,7 +31,7 @@ enum class SortNodeEnum {
|
||||
|
||||
fun getNodeComparator(ascending: Boolean, groupsBefore: Boolean): Comparator<NodeVersioned> {
|
||||
return when (this) {
|
||||
DB -> NodeCreationComparator(ascending, groupsBefore) // TODO Sort
|
||||
DB -> NodeNaturalComparator(ascending, groupsBefore)
|
||||
TITLE -> NodeTitleComparator(ascending, groupsBefore)
|
||||
USERNAME -> NodeCreationComparator(ascending, groupsBefore) // TODO Sort
|
||||
CREATION_TIME -> NodeCreationComparator(ascending, groupsBefore)
|
||||
@@ -40,7 +40,7 @@ enum class SortNodeEnum {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NodeComparator internal constructor(internal var ascending: Boolean, private var groupsBefore: Boolean) : Comparator<NodeVersioned> {
|
||||
abstract class NodeComparator(internal var ascending: Boolean, private var groupsBefore: Boolean) : Comparator<NodeVersioned> {
|
||||
|
||||
internal fun compareWith(comparatorGroup: Comparator<GroupVersioned>,
|
||||
comparatorEntry: Comparator<EntryVersioned>,
|
||||
@@ -81,10 +81,27 @@ enum class SortNodeEnum {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of node by natural database placement
|
||||
*/
|
||||
class NodeNaturalComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
override fun compare(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
|
||||
return compareWith(
|
||||
GroupNaturalOrderComparator(ascending),
|
||||
EntryNaturalOrderComparator(ascending),
|
||||
object1,
|
||||
object2,
|
||||
object1.creationTime.date
|
||||
?.compareTo(object2.creationTime.date) ?: 0)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Node by Title, Groups first, Entries second
|
||||
*/
|
||||
class NodeTitleComparator internal constructor(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
class NodeTitleComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
override fun compare(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
|
||||
@@ -101,7 +118,7 @@ enum class SortNodeEnum {
|
||||
/**
|
||||
* Comparator of node by creation, Groups first, Entries second
|
||||
*/
|
||||
class NodeCreationComparator internal constructor(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
class NodeCreationComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
override fun compare(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
|
||||
@@ -118,7 +135,7 @@ enum class SortNodeEnum {
|
||||
/**
|
||||
* Comparator of node by last modification, Groups first, Entries second
|
||||
*/
|
||||
class NodeLastModificationComparator internal constructor(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
class NodeLastModificationComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
override fun compare(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
|
||||
@@ -135,7 +152,7 @@ enum class SortNodeEnum {
|
||||
/**
|
||||
* Comparator of node by last access, Groups first, Entries second
|
||||
*/
|
||||
class NodeLastAccessComparator internal constructor(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
class NodeLastAccessComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
override fun compare(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
|
||||
@@ -149,162 +166,119 @@ enum class SortNodeEnum {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AscendingComparator<Node> internal constructor(private val ascending: Boolean) : Comparator<Node> {
|
||||
abstract class AscendingComparator<Node>(private val ascending: Boolean) : Comparator<Node> {
|
||||
|
||||
internal fun compareWithAscending(basicCompareResult: Int): Int {
|
||||
private fun compareWithAscending(specificOrderComp: Int): Int {
|
||||
// If descending, revert
|
||||
return if (!ascending) -basicCompareResult else basicCompareResult
|
||||
|
||||
return if (!ascending) -specificOrderComp else specificOrderComp
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by name
|
||||
*/
|
||||
class GroupNameComparator internal constructor(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
abstract fun compareBySecificOrder(object1: Node, object2: Node): Int
|
||||
|
||||
override fun compare(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
override fun compare(object1: Node, object2: Node): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val groupNameComp = object1.title.compareTo(object2.title, ignoreCase = true)
|
||||
// If same name, can be different
|
||||
return if (groupNameComp == 0) {
|
||||
val specificOrderComp = compareBySecificOrder(object1, object2)
|
||||
return if (specificOrderComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(groupNameComp)
|
||||
} else compareWithAscending(specificOrderComp)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by natural order
|
||||
*/
|
||||
class GroupNaturalOrderComparator(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
return object1.nodePositionInParent.compareTo(object2.nodePositionInParent)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by name
|
||||
*/
|
||||
class GroupCreationComparator internal constructor(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
class GroupNameComparator(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
return object1.title.compareTo(object2.title, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun compare(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val groupCreationComp = object1.creationTime.date
|
||||
/**
|
||||
* Group comparator by name
|
||||
*/
|
||||
class GroupCreationComparator(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
return object1.creationTime.date
|
||||
?.compareTo(object2.creationTime.date) ?: 0
|
||||
// If same creation, can be different
|
||||
return if (groupCreationComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(groupCreationComp)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by last modification
|
||||
*/
|
||||
class GroupLastModificationComparator internal constructor(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
|
||||
override fun compare(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val groupLastModificationComp = object1.lastModificationTime.date
|
||||
class GroupLastModificationComparator(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
return object1.lastModificationTime.date
|
||||
?.compareTo(object2.lastModificationTime.date) ?: 0
|
||||
// If same creation, can be different
|
||||
return if (groupLastModificationComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(groupLastModificationComp)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Group comparator by last access
|
||||
*/
|
||||
class GroupLastAccessComparator internal constructor(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
|
||||
override fun compare(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val groupLastAccessComp = object1.lastAccessTime.date
|
||||
class GroupLastAccessComparator(ascending: Boolean) : AscendingComparator<GroupVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: GroupVersioned, object2: GroupVersioned): Int {
|
||||
return object1.lastAccessTime.date
|
||||
?.compareTo(object2.lastAccessTime.date) ?: 0
|
||||
// If same creation, can be different
|
||||
return if (groupLastAccessComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(groupLastAccessComp)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Name
|
||||
*/
|
||||
class EntryNameComparator internal constructor(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
|
||||
override fun compare(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val entryTitleComp = object1.title.compareTo(object2.title, ignoreCase = true)
|
||||
// If same title, can be different
|
||||
return if (entryTitleComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(entryTitleComp)
|
||||
class EntryNaturalOrderComparator(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
return object1.nodePositionInParent.compareTo(object2.nodePositionInParent)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Name
|
||||
*/
|
||||
class EntryNameComparator(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
return object1.title.compareTo(object2.title, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Creation
|
||||
*/
|
||||
class EntryCreationComparator internal constructor(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
|
||||
override fun compare(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val entryCreationComp = object1.creationTime.date
|
||||
class EntryCreationComparator(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
return object1.creationTime.date
|
||||
?.compareTo(object2.creationTime.date) ?: 0
|
||||
// If same creation, can be different
|
||||
return if (entryCreationComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(entryCreationComp)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Last Modification
|
||||
*/
|
||||
class EntryLastModificationComparator internal constructor(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
|
||||
override fun compare(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val entryLastModificationComp = object1.lastModificationTime.date
|
||||
class EntryLastModificationComparator(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
return object1.lastModificationTime.date
|
||||
?.compareTo(object2.lastModificationTime.date) ?: 0
|
||||
// If same creation, can be different
|
||||
return if (entryLastModificationComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(entryLastModificationComp)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Entry by Last Access
|
||||
*/
|
||||
class EntryLastAccessComparator internal constructor(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
|
||||
override fun compare(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
if (object1 == object2)
|
||||
return 0
|
||||
|
||||
val entryLastAccessComp = object1.lastAccessTime.date
|
||||
class EntryLastAccessComparator(ascending: Boolean) : AscendingComparator<EntryVersioned>(ascending) {
|
||||
override fun compareBySecificOrder(object1: EntryVersioned, object2: EntryVersioned): Int {
|
||||
return object1.lastAccessTime.date
|
||||
?.compareTo(object2.lastAccessTime.date) ?: 0
|
||||
// If same creation, can be different
|
||||
return if (entryLastAccessComp == 0) {
|
||||
object1.hashCode() - object2.hashCode()
|
||||
} else compareWithAscending(entryLastAccessComp)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,12 +195,15 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
|
||||
* Filter MetaStream entries and return children
|
||||
* @return List of direct children (one level below) as PwNode
|
||||
*/
|
||||
fun getChildrenWithoutMetaStream(): List<NodeVersioned> {
|
||||
fun getChildren(withoutMetaStream: Boolean = true): List<NodeVersioned> {
|
||||
val children = ArrayList<NodeVersioned>()
|
||||
children.addAll(getChildGroups())
|
||||
|
||||
pwGroupV3?.let {
|
||||
children.addAll(getChildEntries().filter { !it.isMetaStream })
|
||||
if (withoutMetaStream)
|
||||
children.addAll(getChildEntries().filter { !it.isMetaStream })
|
||||
else
|
||||
children.addAll(getChildEntries())
|
||||
}
|
||||
pwGroupV4?.let {
|
||||
// No MetasStream in V4
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
package com.kunzisoft.keepass.database.element
|
||||
|
||||
interface NodeVersioned: PwNodeInterface<GroupVersioned>
|
||||
interface NodeVersioned: PwNodeInterface<GroupVersioned> {
|
||||
|
||||
val nodePositionInParent: Int
|
||||
get() {
|
||||
parent?.getChildren(false)?.let { children ->
|
||||
for ((i, child) in children.withIndex()) {
|
||||
if (child == this)
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of available Nodes
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
<RadioButton android:id="@+id/sort_selection_db"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sort_db"
|
||||
android:visibility="gone"/>
|
||||
android:text="@string/sort_db"/>
|
||||
<RadioButton android:id="@+id/sort_selection_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -1,9 +1,2 @@
|
||||
* Add lock button always visible
|
||||
* New connection workflow
|
||||
* Code refactored in Kotlin
|
||||
* Better notification implementation
|
||||
* Better views for large screen
|
||||
* Magikeyboard enhancement
|
||||
* Fix Recycle Bin
|
||||
* Fix memory when load database
|
||||
* Fix bugs that displays bad entries and groups (2.5.0.0beta19-20)
|
||||
* Fix nested groups no longer visible in V1 databases
|
||||
* Add natural database sort
|
||||
@@ -1,9 +1,2 @@
|
||||
* Ajout du bouton de lock toujours visible
|
||||
* Nouveau workflow de connexion
|
||||
* Code refactorisé en Kotlin
|
||||
* Meilleure implementation des notifications
|
||||
* Meilleures vues pour les écrans larges
|
||||
* Amélioration du Magikeyboard
|
||||
* Correction de la Corbeille
|
||||
* Correction de la mémoire lors du chargement de base de données
|
||||
* Correction de bugs d'affichage des entrée et groupes (2.5.0.0beta19-20)
|
||||
* Correction des groupes imbriqués plus visible dans les bases V1
|
||||
* Ajout du tri par ordre naturel de la base
|
||||
Reference in new issue
Block a user