Misc improvements to GenericAdapter

- Allow removing one item from the list
- Keep track of one selected position. This is useful for single choice lists using radio buttons
- Max number of displayed entries. An expand button will be displayed at the bottom when going past the limit, and the entries to display when collapsed is configurable
This commit is contained in:
lynxnb 2022-02-23 18:19:49 +01:00
parent c5797fdff6
commit 67881d2215

View File

@ -36,6 +36,7 @@ class GenericAdapter : RecyclerView.Adapter<GenericViewHolder<ViewBinding>>(), F
val currentItems : List<GenericListItem<in ViewBinding>> get() = asyncListDiffer.currentList
var currentSearchTerm = ""
var selectedPosition : Int? = null
private val viewTypesMapping = mutableMapOf<ViewBindingFactory, Int>()
@ -68,6 +69,11 @@ class GenericAdapter : RecyclerView.Adapter<GenericViewHolder<ViewBinding>>(), F
filter.filter(currentSearchTerm)
}
fun removeItemAt(position : Int) {
allItems.removeAt(position)
filter.filter(currentSearchTerm)
}
fun setOnFilterPublishedListener(listener : OnFilterPublishedListener) {
onFilterPublishedListener = listener
}