Remove HeaderItem as a DataItem type

This commit is contained in:
Abandoned Cart 2023-04-16 20:49:37 -04:00 committed by Billy Laws
parent 1841727c56
commit b82452f8f8
2 changed files with 8 additions and 19 deletions

View File

@ -215,14 +215,14 @@ class MainActivity : AppCompatActivity() {
if (appSettings.searchLocation.isEmpty()) documentPicker.launch(null)
}
private fun getDataItems() = mutableListOf<DataItem>().apply {
private fun getDataItems() = mutableListOf<AppViewItem>().apply {
if (appSettings.groupByFormat) {
appEntries?.let { entries ->
val formats = formatFilter?.let { listOf(it) } ?: formatOrder
for (format in formats) {
entries[format]?.let {
for (entry in sortGameList(it)) {
add(AppItem(entry))
sortGameList(it).forEach { entry ->
add(AppItem(entry).toViewItem())
}
}
}
@ -237,8 +237,8 @@ class MainActivity : AppCompatActivity() {
}
}
}
for (entry in sortGameList(gameList.toList())) {
add(AppItem(entry))
sortGameList(gameList.toList()).forEach { entry ->
add(AppItem(entry).toViewItem())
}
}
}
@ -297,11 +297,7 @@ class MainActivity : AppCompatActivity() {
binding.textTitle.text = null
binding.textTitle.visibility = View.GONE
val items = getDataItems()
adapter.setItems(items.map {
when (it) {
is AppItem -> it.toViewItem()
}
})
adapter.setItems(items)
if (items.isEmpty()) {
binding.textTitle.visibility = View.VISIBLE
binding.textTitle.text = getString(R.string.no_rom)

View File

@ -31,7 +31,6 @@ open class GenericAdapter : RecyclerView.Adapter<GenericViewHolder<ViewBinding>>
}
private val asyncListDiffer = AsyncListDiffer(this, DIFFER)
private val headerItems = mutableListOf<GenericListItem<out ViewBinding>>()
val allItems = mutableListOf<GenericListItem<out ViewBinding>>()
val currentItems : List<GenericListItem<in ViewBinding>> get() = asyncListDiffer.currentList
@ -56,12 +55,6 @@ open class GenericAdapter : RecyclerView.Adapter<GenericViewHolder<ViewBinding>>
override fun getItemViewType(position : Int) = viewTypesMapping.getOrPut(currentItems[position].getViewBindingFactory()) { viewTypesMapping.size }
fun setHeaderItems(items : List<GenericListItem<*>>) {
headerItems.clear()
headerItems.addAll(items)
filter.filter(currentSearchTerm)
}
fun setItems(items : List<GenericListItem<*>>) {
allItems.clear()
allItems.addAll(items)
@ -128,8 +121,8 @@ open class GenericAdapter : RecyclerView.Adapter<GenericViewHolder<ViewBinding>>
filterData
}) {
FilterResults().apply {
values = headerItems + this@with
count = headerItems.size + size
values = this@with
count = size
}
}
}