mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix sort for natural database
This commit is contained in:
@@ -35,12 +35,12 @@ class SortDialogFragment : DialogFragment() {
|
||||
|
||||
private var mListener: SortSelectionListener? = null
|
||||
|
||||
private var mSortNodeEnum: SortNodeEnum? = null
|
||||
private var mSortNodeEnum: SortNodeEnum = SortNodeEnum.DB
|
||||
@IdRes
|
||||
private var mCheckedId: Int = 0
|
||||
private var mGroupsBefore: Boolean = false
|
||||
private var mAscending: Boolean = false
|
||||
private var mRecycleBinBottom: Boolean = false
|
||||
private var mGroupsBefore: Boolean = true
|
||||
private var mAscending: Boolean = true
|
||||
private var mRecycleBinBottom: Boolean = true
|
||||
|
||||
override fun onAttach(context: Context?) {
|
||||
super.onAttach(context)
|
||||
@@ -50,18 +50,13 @@ class SortDialogFragment : DialogFragment() {
|
||||
throw ClassCastException(context!!.toString()
|
||||
+ " must implement " + SortSelectionListener::class.java.name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
activity?.let { activity ->
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
|
||||
mSortNodeEnum = SortNodeEnum.TITLE
|
||||
mAscending = true
|
||||
mGroupsBefore = true
|
||||
var recycleBinAllowed = false
|
||||
mRecycleBinBottom = true
|
||||
|
||||
arguments?.apply {
|
||||
if (containsKey(SORT_NODE_ENUM_BUNDLE_KEY))
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
package com.kunzisoft.keepass.database
|
||||
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.Type
|
||||
import java.util.*
|
||||
@@ -31,7 +33,7 @@ enum class SortNodeEnum {
|
||||
return when (this) {
|
||||
DB -> NodeNaturalComparator(ascending, groupsBefore)
|
||||
TITLE -> NodeTitleComparator(ascending, groupsBefore)
|
||||
USERNAME -> NodeCreationComparator(ascending, groupsBefore) // TODO Sort
|
||||
USERNAME -> NodeUsernameComparator(ascending, groupsBefore)
|
||||
CREATION_TIME -> NodeCreationComparator(ascending, groupsBefore)
|
||||
LAST_MODIFY_TIME -> NodeLastModificationComparator(ascending, groupsBefore)
|
||||
LAST_ACCESS_TIME -> NodeLastAccessComparator(ascending, groupsBefore)
|
||||
@@ -94,7 +96,7 @@ enum class SortNodeEnum {
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of Node by Title, Groups first, Entries second
|
||||
* Comparator of Node by Title
|
||||
*/
|
||||
class NodeTitleComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
@@ -104,7 +106,23 @@ enum class SortNodeEnum {
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of node by creation, Groups first, Entries second
|
||||
* Comparator of Node by Username, Groups by title
|
||||
*/
|
||||
class NodeUsernameComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
override fun compareBySpecificOrder(object1: NodeVersioned, object2: NodeVersioned): Int {
|
||||
if (object1.type == Type.ENTRY && object2.type == Type.ENTRY) {
|
||||
// To get username if it's a ref
|
||||
return (object1 as EntryVersioned).getEntryInfo(Database.getInstance()).username
|
||||
.compareTo((object2 as EntryVersioned).getEntryInfo(Database.getInstance()).username,
|
||||
ignoreCase = true)
|
||||
}
|
||||
return NodeTitleComparator(ascending, groupsBefore).compare(object1, object2)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of node by creation
|
||||
*/
|
||||
class NodeCreationComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
@@ -115,7 +133,7 @@ enum class SortNodeEnum {
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of node by last modification, Groups first, Entries second
|
||||
* Comparator of node by last modification
|
||||
*/
|
||||
class NodeLastModificationComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
@@ -126,7 +144,7 @@ enum class SortNodeEnum {
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparator of node by last access, Groups first, Entries second
|
||||
* Comparator of node by last access
|
||||
*/
|
||||
class NodeLastAccessComparator(ascending: Boolean, groupsBefore: Boolean) : NodeComparator(ascending, groupsBefore) {
|
||||
|
||||
|
||||
@@ -338,11 +338,24 @@ class EntryVersioned : NodeVersioned, PwEntryInterface<GroupVersioned> {
|
||||
return entryInfo
|
||||
}
|
||||
|
||||
/*
|
||||
------------
|
||||
Class methods
|
||||
------------
|
||||
*/
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as EntryVersioned
|
||||
|
||||
if (pwEntryV3 != other.pwEntryV3) return false
|
||||
if (pwEntryV4 != other.pwEntryV4) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = pwEntryV3?.hashCode() ?: 0
|
||||
result = 31 * result + (pwEntryV4?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<EntryVersioned> {
|
||||
override fun createFromParcel(parcel: Parcel): EntryVersioned {
|
||||
|
||||
@@ -130,7 +130,7 @@ object PreferencesUtil {
|
||||
fun getListSort(context: Context): SortNodeEnum {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
prefs.getString(context.getString(R.string.sort_node_key),
|
||||
SortNodeEnum.TITLE.name)?.let {
|
||||
SortNodeEnum.DB.name)?.let {
|
||||
return SortNodeEnum.valueOf(it)
|
||||
}
|
||||
return SortNodeEnum.DB
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<RadioButton android:id="@+id/sort_selection_username"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sort_username"
|
||||
android:visibility="gone"/>
|
||||
android:text="@string/sort_username"/>
|
||||
<RadioButton android:id="@+id/sort_selection_creation_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user