mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Refactoring virtual group
This commit is contained in:
@@ -104,7 +104,6 @@ class GroupActivity : LockingActivity(),
|
|||||||
private var mDatabase: Database? = null
|
private var mDatabase: Database? = null
|
||||||
|
|
||||||
private var mListNodesFragment: ListNodesFragment? = null
|
private var mListNodesFragment: ListNodesFragment? = null
|
||||||
private var mCurrentGroupIsASearch: Boolean = false
|
|
||||||
private var mRequestStartupSearch = true
|
private var mRequestStartupSearch = true
|
||||||
|
|
||||||
private var actionNodeMode: ActionMode? = null
|
private var actionNodeMode: ActionMode? = null
|
||||||
@@ -171,7 +170,7 @@ class GroupActivity : LockingActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCurrentGroup = retrieveCurrentGroup(intent, savedInstanceState)
|
mCurrentGroup = retrieveCurrentGroup(intent, savedInstanceState)
|
||||||
mCurrentGroupIsASearch = Intent.ACTION_SEARCH == intent.action
|
val currentGroupIsASearch = mCurrentGroup?.isVirtual == true
|
||||||
|
|
||||||
Log.i(TAG, "Started creating tree")
|
Log.i(TAG, "Started creating tree")
|
||||||
if (mCurrentGroup == null) {
|
if (mCurrentGroup == null) {
|
||||||
@@ -180,13 +179,13 @@ class GroupActivity : LockingActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fragmentTag = LIST_NODES_FRAGMENT_TAG
|
var fragmentTag = LIST_NODES_FRAGMENT_TAG
|
||||||
if (mCurrentGroupIsASearch)
|
if (currentGroupIsASearch)
|
||||||
fragmentTag = SEARCH_FRAGMENT_TAG
|
fragmentTag = SEARCH_FRAGMENT_TAG
|
||||||
|
|
||||||
// Initialize the fragment with the list
|
// Initialize the fragment with the list
|
||||||
mListNodesFragment = supportFragmentManager.findFragmentByTag(fragmentTag) as ListNodesFragment?
|
mListNodesFragment = supportFragmentManager.findFragmentByTag(fragmentTag) as ListNodesFragment?
|
||||||
if (mListNodesFragment == null)
|
if (mListNodesFragment == null)
|
||||||
mListNodesFragment = ListNodesFragment.newInstance(mCurrentGroup, mReadOnly, mCurrentGroupIsASearch)
|
mListNodesFragment = ListNodesFragment.newInstance(mCurrentGroup, mReadOnly, currentGroupIsASearch)
|
||||||
|
|
||||||
// Attach fragment to content view
|
// Attach fragment to content view
|
||||||
supportFragmentManager.beginTransaction().replace(
|
supportFragmentManager.beginTransaction().replace(
|
||||||
@@ -374,13 +373,10 @@ class GroupActivity : LockingActivity(),
|
|||||||
manageSearchInfoIntent(intentNotNull)
|
manageSearchInfoIntent(intentNotNull)
|
||||||
Log.d(TAG, "setNewIntent: $intentNotNull")
|
Log.d(TAG, "setNewIntent: $intentNotNull")
|
||||||
setIntent(intentNotNull)
|
setIntent(intentNotNull)
|
||||||
mCurrentGroupIsASearch = if (Intent.ACTION_SEARCH == intentNotNull.action) {
|
if (Intent.ACTION_SEARCH == intentNotNull.action) {
|
||||||
// only one instance of search in backstack
|
// only one instance of search in backstack
|
||||||
deletePreviousSearchGroup()
|
deletePreviousSearchGroup()
|
||||||
openGroup(retrieveCurrentGroup(intentNotNull, null), true)
|
openGroup(retrieveCurrentGroup(intentNotNull, null), true)
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,7 +443,6 @@ class GroupActivity : LockingActivity(),
|
|||||||
|
|
||||||
mListNodesFragment = newListNodeFragment
|
mListNodesFragment = newListNodeFragment
|
||||||
mCurrentGroup = group
|
mCurrentGroup = group
|
||||||
mCurrentGroupIsASearch = isASearch
|
|
||||||
assignGroupViewElements()
|
assignGroupViewElements()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,7 +460,7 @@ class GroupActivity : LockingActivity(),
|
|||||||
|
|
||||||
private fun refreshSearchGroup() {
|
private fun refreshSearchGroup() {
|
||||||
deletePreviousSearchGroup()
|
deletePreviousSearchGroup()
|
||||||
if (mCurrentGroupIsASearch)
|
if (mCurrentGroup?.isVirtual == true)
|
||||||
openGroup(retrieveCurrentGroup(intent, null), true)
|
openGroup(retrieveCurrentGroup(intent, null), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,19 +513,15 @@ class GroupActivity : LockingActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mCurrentGroupIsASearch) {
|
|
||||||
searchTitleView?.visibility = View.VISIBLE
|
|
||||||
} else {
|
|
||||||
searchTitleView?.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign icon
|
if (mCurrentGroup?.isVirtual == true) {
|
||||||
if (mCurrentGroupIsASearch) {
|
searchTitleView?.visibility = View.VISIBLE
|
||||||
if (toolbar != null) {
|
if (toolbar != null) {
|
||||||
toolbar?.navigationIcon = null
|
toolbar?.navigationIcon = null
|
||||||
}
|
}
|
||||||
iconView?.visibility = View.GONE
|
iconView?.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
|
searchTitleView?.visibility = View.GONE
|
||||||
// Assign the group icon depending of IconPack or custom icon
|
// Assign the group icon depending of IconPack or custom icon
|
||||||
iconView?.visibility = View.VISIBLE
|
iconView?.visibility = View.VISIBLE
|
||||||
mCurrentGroup?.let { currentGroup ->
|
mCurrentGroup?.let { currentGroup ->
|
||||||
@@ -554,8 +545,8 @@ class GroupActivity : LockingActivity(),
|
|||||||
// Show button if allowed
|
// Show button if allowed
|
||||||
addNodeButtonView?.apply {
|
addNodeButtonView?.apply {
|
||||||
// To enable add button
|
// To enable add button
|
||||||
val addGroupEnabled = !mReadOnly && !mCurrentGroupIsASearch
|
val addGroupEnabled = !mReadOnly && mCurrentGroup?.isVirtual != true
|
||||||
var addEntryEnabled = !mReadOnly && !mCurrentGroupIsASearch
|
var addEntryEnabled = !mReadOnly && mCurrentGroup?.isVirtual != true
|
||||||
mCurrentGroup?.let {
|
mCurrentGroup?.let {
|
||||||
if (!it.allowAddEntryIfIsRoot())
|
if (!it.allowAddEntryIfIsRoot())
|
||||||
addEntryEnabled = it != mRootGroup && addEntryEnabled
|
addEntryEnabled = it != mRootGroup && addEntryEnabled
|
||||||
@@ -563,7 +554,7 @@ class GroupActivity : LockingActivity(),
|
|||||||
enableAddGroup(addGroupEnabled)
|
enableAddGroup(addGroupEnabled)
|
||||||
enableAddEntry(addEntryEnabled)
|
enableAddEntry(addEntryEnabled)
|
||||||
|
|
||||||
if (mCurrentGroupIsASearch)
|
if (mCurrentGroup?.isVirtual == true)
|
||||||
hideButton()
|
hideButton()
|
||||||
else if (actionNodeMode == null)
|
else if (actionNodeMode == null)
|
||||||
showButton()
|
showButton()
|
||||||
@@ -1191,7 +1182,6 @@ class GroupActivity : LockingActivity(),
|
|||||||
mCurrentGroup = mListNodesFragment?.mainGroup
|
mCurrentGroup = mListNodesFragment?.mainGroup
|
||||||
// Remove search in intent
|
// Remove search in intent
|
||||||
deletePreviousSearchGroup()
|
deletePreviousSearchGroup()
|
||||||
mCurrentGroupIsASearch = false
|
|
||||||
if (Intent.ACTION_SEARCH == intent.action) {
|
if (Intent.ACTION_SEARCH == intent.action) {
|
||||||
intent.action = Intent.ACTION_DEFAULT
|
intent.action = Intent.ACTION_DEFAULT
|
||||||
intent.removeExtra(SearchManager.QUERY)
|
intent.removeExtra(SearchManager.QUERY)
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
|
|||||||
var groupKDBX: GroupKDBX? = null
|
var groupKDBX: GroupKDBX? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
// Virtual group is used to defined a detached database group
|
||||||
|
var isVirtual = false
|
||||||
|
|
||||||
fun updateWith(group: Group) {
|
fun updateWith(group: Group) {
|
||||||
group.groupKDB?.let {
|
group.groupKDB?.let {
|
||||||
this.groupKDB?.updateWith(it)
|
this.groupKDB?.updateWith(it)
|
||||||
@@ -77,6 +80,7 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
|
|||||||
constructor(parcel: Parcel) {
|
constructor(parcel: Parcel) {
|
||||||
groupKDB = parcel.readParcelable(GroupKDB::class.java.classLoader)
|
groupKDB = parcel.readParcelable(GroupKDB::class.java.classLoader)
|
||||||
groupKDBX = parcel.readParcelable(GroupKDBX::class.java.classLoader)
|
groupKDBX = parcel.readParcelable(GroupKDBX::class.java.classLoader)
|
||||||
|
isVirtual = parcel.readByte().toInt() != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ChildFilter {
|
enum class ChildFilter {
|
||||||
@@ -110,6 +114,7 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
|
|||||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||||
dest.writeParcelable(groupKDB, flags)
|
dest.writeParcelable(groupKDB, flags)
|
||||||
dest.writeParcelable(groupKDBX, flags)
|
dest.writeParcelable(groupKDBX, flags)
|
||||||
|
dest.writeByte((if (isVirtual) 1 else 0).toByte())
|
||||||
}
|
}
|
||||||
|
|
||||||
override val nodeId: NodeId<*>?
|
override val nodeId: NodeId<*>?
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class SearchHelper {
|
|||||||
max: Int): Group? {
|
max: Int): Group? {
|
||||||
|
|
||||||
val searchGroup = database.createGroup()
|
val searchGroup = database.createGroup()
|
||||||
|
searchGroup?.isVirtual = true
|
||||||
searchGroup?.title = "\"" + searchQuery + "\""
|
searchGroup?.title = "\"" + searchQuery + "\""
|
||||||
|
|
||||||
// Search all entries
|
// Search all entries
|
||||||
|
|||||||
Reference in New Issue
Block a user