diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt index c73aaf0a3..e6bf3a2a2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt @@ -106,6 +106,8 @@ class GroupActivity : LockingActivity(), private var mIconColor: Int = 0 + private var showExpiredEntries = true + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -191,6 +193,8 @@ class GroupActivity : LockingActivity(), } }) + showExpiredEntries = PreferencesUtil.showExpiredEntries(this) + mDatabase?.let { database -> // Search suggestion mSearchSuggestionAdapter = SearchEntryCursorAdapter(this, database) @@ -448,7 +452,9 @@ class GroupActivity : LockingActivity(), private fun refreshNumberOfChildren() { numberChildrenView?.apply { if (PreferencesUtil.showNumberEntries(context)) { - text = mCurrentGroup?.getChildEntries(true)?.size?.toString() ?: "" + text = mCurrentGroup?.getChildEntries(true) + ?.filter { !it.isCurrentlyExpires or showExpiredEntries} + ?.size?.toString() ?: "" visibility = View.VISIBLE } else { visibility = View.GONE diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/NodeAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/NodeAdapter.kt index 8af26d21e..62ea7415b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/NodeAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/NodeAdapter.kt @@ -66,6 +66,7 @@ class NodeAdapter private var recycleBinBottomSort: Boolean = true private var showUserNames: Boolean = true private var showNumberEntries: Boolean = true + private var showExpiredEntries: Boolean = true private var actionNodesList = LinkedList() private var nodeClickCallback: NodeClickCallback? = null @@ -127,6 +128,7 @@ class NodeAdapter this.recycleBinBottomSort = PreferencesUtil.getRecycleBinBottomSort(context) this.showUserNames = PreferencesUtil.showUsernamesListEntries(context) this.showNumberEntries = PreferencesUtil.showNumberEntries(context) + this.showExpiredEntries = PreferencesUtil.showExpiredEntries(context) // Reinit textSize for all view type calculateViewTypeTextSize.forEachIndexed { index, _ -> calculateViewTypeTextSize[index] = true } @@ -139,7 +141,7 @@ class NodeAdapter this.nodeSortedList.clear() assignPreferences() try { - this.nodeSortedList.addAll(group.getChildren()) + this.nodeSortedList.addAll(group.getChildren().filter { !it.isCurrentlyExpires or showExpiredEntries}) } catch (e: Exception) { Log.e(TAG, "Can't add node elements to the list", e) Toast.makeText(context, "Can't add node elements to the list : " + e.message, Toast.LENGTH_LONG).show() @@ -338,7 +340,10 @@ class NodeAdapter if (subNode.type == Type.GROUP) { if (showNumberEntries) { holder.numberChildren?.apply { - text = (subNode as Group).getChildEntries(true).size.toString() + text = (subNode as Group) + .getChildEntries(true) + .filter { !it.isCurrentlyExpires or showExpiredEntries} + .size.toString() setTextSize(textSizeUnit, numberChildrenTextSize) visibility = View.VISIBLE } @@ -348,6 +353,7 @@ class NodeAdapter } } + override fun getItemCount(): Int { return nodeSortedList.size() } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt index c5097fc1e..b15c479aa 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt @@ -57,6 +57,12 @@ object PreferencesUtil { context.resources.getBoolean(R.bool.list_groups_show_number_entries_default)) } + fun showExpiredEntries(context: Context): Boolean { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + return ! prefs.getBoolean(context.getString(R.string.hide_expired_entries_key), + context.resources.getBoolean(R.bool.hide_expired_entries_default)) + } + /** * Retrieve the text size in % (1 for 100%) */