feat: Add recursive number of entries #874 #1327

This commit is contained in:
J-Jamet 2023-09-08 20:32:19 +02:00
parent 8ce63cb5c5
commit d244eef62e
3 changed files with 16 additions and 2 deletions

View file

@ -117,7 +117,7 @@ class BreadcrumbAdapter(val context: Context)
PreferencesUtil.showExpiredEntries(context) PreferencesUtil.showExpiredEntries(context)
) )
) )
text = group.numberOfChildEntries.toString() text = group.recursiveNumberOfChildEntries.toString()
visibility = View.VISIBLE visibility = View.VISIBLE
} else { } else {
visibility = View.GONE visibility = View.GONE

View file

@ -197,6 +197,7 @@ class NodesAdapter (
&& oldItem.containsAttachment() == newItem.containsAttachment() && oldItem.containsAttachment() == newItem.containsAttachment()
} else if (oldItem is Group && newItem is Group) { } else if (oldItem is Group && newItem is Group) {
typeContentTheSame = oldItem.numberOfChildEntries == newItem.numberOfChildEntries typeContentTheSame = oldItem.numberOfChildEntries == newItem.numberOfChildEntries
&& oldItem.recursiveNumberOfChildEntries == newItem.recursiveNumberOfChildEntries
&& oldItem.notes == newItem.notes && oldItem.notes == newItem.notes
} }
return typeContentTheSame return typeContentTheSame
@ -472,7 +473,7 @@ class NodesAdapter (
if (mShowNumberEntries) { if (mShowNumberEntries) {
holder.numberChildren?.apply { holder.numberChildren?.apply {
text = (subNode as Group) text = (subNode as Group)
.numberOfChildEntries .recursiveNumberOfChildEntries
.toString() .toString()
setTextSize(mTextSizeUnit, mNumberChildrenTextDefaultDimension, mPrefSizeMultiplier) setTextSize(mTextSizeUnit, mNumberChildrenTextDefaultDimension, mPrefSizeMultiplier)
visibility = View.VISIBLE visibility = View.VISIBLE

View file

@ -46,6 +46,7 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
var isVirtual = false var isVirtual = false
var numberOfChildEntries: Int = 0 var numberOfChildEntries: Int = 0
var recursiveNumberOfChildEntries: Int = 0
/** /**
* Use this constructor to copy a Group * Use this constructor to copy a Group
@ -332,6 +333,18 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
fun refreshNumberOfChildEntries(filters: Array<ChildFilter> = emptyArray()) { fun refreshNumberOfChildEntries(filters: Array<ChildFilter> = emptyArray()) {
this.numberOfChildEntries = getFilteredChildEntries(filters).size this.numberOfChildEntries = getFilteredChildEntries(filters).size
this.recursiveNumberOfChildEntries = getFilteredChildEntriesInGroups(filters)
}
/**
* @return the cumulative number of entries in the current group and its children
*/
private fun getFilteredChildEntriesInGroups(filters: Array<ChildFilter>): Int {
var counter = 0
getChildGroups().forEach { childGroup ->
counter += childGroup.getFilteredChildEntriesInGroups(filters)
}
return getFilteredChildEntries(filters).size + counter
} }
/** /**