mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Refactor group elements
This commit is contained in:
@@ -114,9 +114,9 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
|
||||
// Manage group
|
||||
private var mSearchState: SearchState? = null
|
||||
private var mCurrentGroupState: GroupState? = null
|
||||
private var mRootGroup: Group? = null
|
||||
private var mCurrentGroup: Group? = null
|
||||
private var mMainGroupState: GroupState? = null // Group in the tree, not a search
|
||||
private var mRootGroup: Group? = null // Root group in the tree
|
||||
private var mCurrentGroup: Group? = null // Group currently visible (search or main group)
|
||||
private var mPreviousGroupsIds = mutableListOf<GroupState>()
|
||||
private var mOldGroupToUpdate: Group? = null
|
||||
|
||||
@@ -128,7 +128,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
searchState.searchParameters.searchQuery = query
|
||||
mGroupViewModel.loadSearchGroup(mDatabase,
|
||||
searchState.searchParameters,
|
||||
mCurrentGroupState?.groupId,
|
||||
mMainGroupState?.groupId,
|
||||
searchState.firstVisibleItem)
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
searchState.searchParameters = searchParameters
|
||||
mGroupViewModel.loadSearchGroup(mDatabase,
|
||||
searchState.searchParameters,
|
||||
mCurrentGroupState?.groupId,
|
||||
mMainGroupState?.groupId,
|
||||
searchState.firstVisibleItem)
|
||||
}
|
||||
}
|
||||
@@ -315,7 +315,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
if (!currentGroup.isVirtual) {
|
||||
mRecyclingBinIsCurrentGroup = it.isRecycleBin
|
||||
// Save group state
|
||||
mCurrentGroupState = GroupState(currentGroup.nodeId, it.showFromPosition)
|
||||
mMainGroupState = GroupState(currentGroup.nodeId, it.showFromPosition)
|
||||
// Update last access time.
|
||||
currentGroup.touch(modified = false, touchParents = false)
|
||||
} else {
|
||||
@@ -328,7 +328,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
|
||||
mGroupViewModel.firstPositionVisible.observe(this) { firstPositionVisible ->
|
||||
mSearchState?.firstVisibleItem = firstPositionVisible
|
||||
mCurrentGroupState?.firstVisibleItem = firstPositionVisible
|
||||
mMainGroupState?.firstVisibleItem = firstPositionVisible
|
||||
}
|
||||
|
||||
mGroupEditViewModel.requestIconSelection.observe(this) { iconImage ->
|
||||
@@ -448,13 +448,13 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
|
||||
private fun loadGroup() {
|
||||
val searchState = mSearchState
|
||||
val currentGroupState = mCurrentGroupState
|
||||
val currentGroupState = mMainGroupState
|
||||
when {
|
||||
searchState != null -> {
|
||||
finishNodeAction()
|
||||
mGroupViewModel.loadSearchGroup(mDatabase,
|
||||
searchState.searchParameters,
|
||||
mCurrentGroupState?.groupId,
|
||||
mMainGroupState?.groupId,
|
||||
searchState.firstVisibleItem
|
||||
)
|
||||
}
|
||||
@@ -597,7 +597,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
private fun manageIntent(intent: Intent?) {
|
||||
intent?.let {
|
||||
if (intent.extras?.containsKey(GROUP_STATE_KEY) == true) {
|
||||
mCurrentGroupState = intent.getParcelableExtra(GROUP_STATE_KEY)
|
||||
mMainGroupState = intent.getParcelableExtra(GROUP_STATE_KEY)
|
||||
intent.removeExtra(GROUP_STATE_KEY)
|
||||
}
|
||||
// To transform KEY_SEARCH_INFO in ACTION_SEARCH
|
||||
@@ -635,7 +635,9 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
val group = mCurrentGroup
|
||||
// Assign title
|
||||
if (group?.isVirtual == true) {
|
||||
searchFiltersView?.setNumbers(SearchHelper.showNumberOfSearchResults(group.numberOfChildEntries))
|
||||
searchFiltersView?.setNumbers(group.numberOfChildEntries)
|
||||
// TODO current group title
|
||||
// searchFiltersView?.setCurrentGroupText("Title with a large text")
|
||||
toolbarBreadcrumb?.navigationIcon = null
|
||||
} else {
|
||||
// Add breadcrumb
|
||||
@@ -685,7 +687,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
val group = node as Group
|
||||
// Save the last not virtual group and it's position
|
||||
if (mCurrentGroup?.isVirtual == false) {
|
||||
mCurrentGroupState?.let {
|
||||
mMainGroupState?.let {
|
||||
mPreviousGroupsIds.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.search.SearchHelper
|
||||
import com.kunzisoft.keepass.database.search.SearchParameters
|
||||
|
||||
class SearchFiltersView @JvmOverloads constructor(context: Context,
|
||||
@@ -163,8 +164,12 @@ class SearchFiltersView @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
fun setNumbers(stringNumbers: String) {
|
||||
searchNumbers.text = stringNumbers
|
||||
fun setNumbers(numbers: Int) {
|
||||
searchNumbers.text = SearchHelper.showNumberOfSearchResults(numbers)
|
||||
}
|
||||
|
||||
fun setCurrentGroupText(text: String) {
|
||||
searchCurrentGroup.text = if (text.length > 8) text.substring(0, 8) + "…" else text
|
||||
}
|
||||
|
||||
override fun setVisibility(visibility: Int) {
|
||||
|
||||
Reference in New Issue
Block a user