mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-04 07:42:30 -08:00
fix: Breadcrumbs clicked in ViewModel #2541
This commit is contained in:
3 files changed
+67
-36
No files matched your search
@@ -227,7 +227,6 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
}
|
||||
|
||||
private fun addSearch() {
|
||||
finishNodeAction()
|
||||
mGroupViewModel.assignSearchParameters(searchFiltersView?.searchParameters)
|
||||
}
|
||||
|
||||
@@ -473,6 +472,16 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
}
|
||||
}
|
||||
}
|
||||
launch {
|
||||
mGroupViewModel.requestShowGroup.collect { group ->
|
||||
launchDialogToShowGroupInfo(group)
|
||||
}
|
||||
}
|
||||
launch {
|
||||
mGroupViewModel.requestUpdateGroup.collect { group ->
|
||||
launchDialogForGroupUpdate(group)
|
||||
}
|
||||
}
|
||||
launch {
|
||||
mGroupViewModel.requestCopyNodes.collect {
|
||||
removeSearch()
|
||||
@@ -689,33 +698,11 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
|
||||
mBreadcrumbAdapter?.apply {
|
||||
// Open group on breadcrumb click
|
||||
onItemClickListener = { node, _ ->
|
||||
// If last item & not a virtual root group
|
||||
val currentGroup = mGroupViewModel.mainGroup
|
||||
if (currentGroup != null && node.nodeId == currentGroup.nodeId
|
||||
&& (currentGroup.nodeId != database.rootGroup?.nodeId
|
||||
|| !database.rootGroupIsVirtual)
|
||||
) {
|
||||
finishNodeAction()
|
||||
launchDialogToShowGroupInfo(currentGroup)
|
||||
} else {
|
||||
if (mGroupViewModel.nodeActionSelectionMode) {
|
||||
finishNodeAction()
|
||||
}
|
||||
openNode(database, node)
|
||||
}
|
||||
onItemClickListener = { node ->
|
||||
mGroupViewModel.onBreadcrumbClicked(node)
|
||||
}
|
||||
onLongItemClickListener = { node, position ->
|
||||
val currentGroup = mGroupViewModel.mainGroup
|
||||
if (currentGroup != null && node.nodeId == currentGroup.nodeId
|
||||
&& (currentGroup.nodeId != database.rootGroup?.nodeId
|
||||
|| !database.rootGroupIsVirtual)
|
||||
) {
|
||||
finishNodeAction()
|
||||
launchDialogForGroupUpdate(currentGroup)
|
||||
} else {
|
||||
onItemClickListener?.invoke(node, position)
|
||||
}
|
||||
onLongItemClickListener = { node ->
|
||||
mGroupViewModel.onBreadcrumbLongClicked(node)
|
||||
}
|
||||
}
|
||||
breadcrumbListView?.apply {
|
||||
|
||||
@@ -47,8 +47,8 @@ class BreadcrumbAdapter(val context: Context)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
private var mNodeBreadcrumb: MutableList<SortedGroupInfo> = mutableListOf()
|
||||
var onItemClickListener: ((item: SortedGroupInfo, position: Int)->Unit)? = null
|
||||
var onLongItemClickListener: ((item: SortedGroupInfo, position: Int)->Unit)? = null
|
||||
var onItemClickListener: ((item: SortedGroupInfo)->Unit)? = null
|
||||
var onLongItemClickListener: ((item: SortedGroupInfo)->Unit)? = null
|
||||
|
||||
private var mShowNumberEntries = false
|
||||
private var mShowTags = false
|
||||
@@ -101,10 +101,10 @@ class BreadcrumbAdapter(val context: Context)
|
||||
|
||||
holder.itemView.apply {
|
||||
setOnClickListener {
|
||||
onItemClickListener?.invoke(node, position)
|
||||
onItemClickListener?.invoke(node)
|
||||
}
|
||||
setOnLongClickListener {
|
||||
onLongItemClickListener?.invoke(node, position)
|
||||
onLongItemClickListener?.invoke(node)
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -140,11 +140,10 @@ class BreadcrumbAdapter(val context: Context)
|
||||
tagsAdapter.onItemClickListener =
|
||||
object : TagsAdapter.OnItemClickListener {
|
||||
override fun onItemClick(item: Tag) {
|
||||
onItemClickListener?.invoke(node, position)
|
||||
onItemClickListener?.invoke(node)
|
||||
}
|
||||
|
||||
override fun onItemLongClick(item: Tag): Boolean {
|
||||
onLongItemClickListener?.invoke(node, position)
|
||||
onLongItemClickListener?.invoke(node)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,12 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
private val _removeSearch = MutableSharedFlow<Unit>(replay = 0)
|
||||
val removeSearch: SharedFlow<Unit> = _removeSearch.asSharedFlow()
|
||||
|
||||
private val _requestShowGroup = MutableSharedFlow<GroupInfo>(replay = 0)
|
||||
val requestShowGroup: SharedFlow<GroupInfo> = _requestShowGroup.asSharedFlow()
|
||||
|
||||
private val _requestUpdateGroup = MutableSharedFlow<GroupInfo>(replay = 0)
|
||||
val requestUpdateGroup: SharedFlow<GroupInfo> = _requestUpdateGroup.asSharedFlow()
|
||||
|
||||
private val _showKeyboard = MutableSharedFlow<Boolean>(replay = 0)
|
||||
val showKeyboard: SharedFlow<Boolean> = _showKeyboard.asSharedFlow()
|
||||
|
||||
@@ -185,7 +191,7 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
} else loadMainGroup(mDatabase)
|
||||
}
|
||||
|
||||
fun loadMainGroup(
|
||||
private fun loadMainGroup(
|
||||
database: ContextualDatabase?,
|
||||
groupState: GroupState? = mMainGroupState
|
||||
) {
|
||||
@@ -258,7 +264,7 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
loadMainGroup(database, GroupState(groupId, firstVisibleItem = 0))
|
||||
}
|
||||
|
||||
fun loadSearch(
|
||||
private fun loadSearch(
|
||||
database: ContextualDatabase?,
|
||||
searchState: SearchState? = mSearchState,
|
||||
) {
|
||||
@@ -355,6 +361,7 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
}
|
||||
|
||||
fun assignSearchParameters(searchParameters: SearchParameters?) {
|
||||
finishNodeAction()
|
||||
if (mSearchState == null) {
|
||||
mSearchState = SearchState(
|
||||
searchParameters ?: mDefaultSearchParameters,
|
||||
@@ -368,6 +375,44 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
mMainGroupState?.firstVisibleItem = position
|
||||
}
|
||||
|
||||
/*
|
||||
* Breadcrumbs
|
||||
*/
|
||||
|
||||
fun onBreadcrumbClicked(node: SortedNodeInfo) {
|
||||
viewModelScope.launch {
|
||||
// If last item & not a virtual root group
|
||||
val currentGroup = mainGroup
|
||||
if (currentGroup != null && node.nodeId == currentGroup.nodeId
|
||||
&& (currentGroup.nodeId != mDatabase?.rootGroup?.nodeId
|
||||
|| mDatabase?.rootGroupIsVirtual != true)
|
||||
) {
|
||||
finishNodeAction()
|
||||
_requestShowGroup.emit(currentGroup)
|
||||
} else {
|
||||
if (nodeActionSelectionMode) {
|
||||
finishNodeAction()
|
||||
}
|
||||
_requestOpenNode.emit(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onBreadcrumbLongClicked(node: SortedNodeInfo) {
|
||||
viewModelScope.launch {
|
||||
val currentGroup = mainGroup
|
||||
if (currentGroup != null && node.nodeId == currentGroup.nodeId
|
||||
&& (currentGroup.nodeId != mDatabase?.rootGroup?.nodeId
|
||||
|| mDatabase?.rootGroupIsVirtual != true)
|
||||
) {
|
||||
finishNodeAction()
|
||||
_requestUpdateGroup.emit(currentGroup)
|
||||
} else {
|
||||
onBreadcrumbClicked(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user