diff --git a/app/src/main/java/emu/skyline/adapter/AppViewItem.kt b/app/src/main/java/emu/skyline/adapter/AppViewItem.kt index eb6d5443..df93385c 100644 --- a/app/src/main/java/emu/skyline/adapter/AppViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/AppViewItem.kt @@ -84,7 +84,8 @@ private typealias InteractionFunction = (appItem : AppItem) -> Unit class AppViewItem(var layoutType : LayoutType, private val item : AppItem, private val missingIcon : Bitmap, private val onClick : InteractionFunction, private val onLongClick : InteractionFunction) : GenericListItem>() { override fun getViewBindingFactory() = LayoutBindingFactory(layoutType) - override fun bind(binding : LayoutBinding<*>, position : Int) { + override fun bind(holder : GenericViewHolder>, position : Int) { + val binding = holder.binding binding.textTitle.text = item.title binding.textSubtitle.text = item.subTitle ?: item.loaderResultString(binding.root.context) diff --git a/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt b/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt index 9dce5633..b73ab638 100644 --- a/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt +++ b/app/src/main/java/emu/skyline/adapter/GenericAdapter.kt @@ -46,7 +46,7 @@ open class GenericAdapter : RecyclerView.Adapter> override fun onBindViewHolder(holder : GenericViewHolder, position : Int) { currentItems[position].apply { adapter = this@GenericAdapter - bind(holder.binding, position) + bind(holder, position) } } diff --git a/app/src/main/java/emu/skyline/adapter/GenericListItem.kt b/app/src/main/java/emu/skyline/adapter/GenericListItem.kt index 2d2522de..81e04984 100644 --- a/app/src/main/java/emu/skyline/adapter/GenericListItem.kt +++ b/app/src/main/java/emu/skyline/adapter/GenericListItem.kt @@ -24,7 +24,7 @@ abstract class GenericListItem { abstract fun getViewBindingFactory() : ViewBindingFactory - abstract fun bind(binding : V, position : Int) + abstract fun bind(holder : GenericViewHolder, position : Int) /** * Used for filtering diff --git a/app/src/main/java/emu/skyline/adapter/GpuDriverViewItem.kt b/app/src/main/java/emu/skyline/adapter/GpuDriverViewItem.kt index f021e6e7..f485854a 100644 --- a/app/src/main/java/emu/skyline/adapter/GpuDriverViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/GpuDriverViewItem.kt @@ -6,6 +6,7 @@ package emu.skyline.adapter import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView import emu.skyline.data.GpuDriverMetadata import emu.skyline.databinding.GpuDriverItemBinding @@ -18,12 +19,15 @@ open class GpuDriverViewItem( var onDelete : ((position : Int, wasChecked : Boolean) -> Unit)? = null, var onClick : (() -> Unit)? = null ) : SelectableGenericListItem() { - private var position = -1 + private var holder : GenericViewHolder? = null + private val adapterPosition get() = holder?.adapterPosition ?: RecyclerView.NO_POSITION override fun getViewBindingFactory() = GpuDriverBindingFactory - override fun bind(binding : GpuDriverItemBinding, position : Int) { - this.position = position + override fun bind(holder : GenericViewHolder, position : Int) { + this.holder = holder + val binding = holder.binding + binding.name.text = driverMetadata.name if (driverMetadata.packageVersion.isNotBlank() || driverMetadata.packageVersion.isNotBlank()) { @@ -38,17 +42,21 @@ open class GpuDriverViewItem( binding.radioButton.isChecked = position == selectableAdapter?.selectedPosition binding.root.setOnClickListener { - selectableAdapter?.selectAndNotify(position) + selectableAdapter?.selectAndNotify(adapterPosition) onClick?.invoke() } onDelete?.let { onDelete -> binding.deleteButton.visibility = ViewGroup.VISIBLE binding.deleteButton.setOnClickListener { - val wasChecked = position == selectableAdapter?.selectedPosition - selectableAdapter?.removeItemAt(position) + val pos = adapterPosition + if (pos == RecyclerView.NO_POSITION) + return@setOnClickListener - onDelete.invoke(position, wasChecked) + val wasChecked = pos == selectableAdapter?.selectedPosition + selectableAdapter?.removeItemAt(pos) + + onDelete.invoke(pos, wasChecked) } } ?: run { binding.deleteButton.visibility = ViewGroup.GONE diff --git a/app/src/main/java/emu/skyline/adapter/HeaderRomFilterItem.kt b/app/src/main/java/emu/skyline/adapter/HeaderRomFilterItem.kt index 91970370..78f74684 100644 --- a/app/src/main/java/emu/skyline/adapter/HeaderRomFilterItem.kt +++ b/app/src/main/java/emu/skyline/adapter/HeaderRomFilterItem.kt @@ -22,7 +22,8 @@ class HeaderRomFilterItem(private val formats : List, selectedFormat override fun getViewBindingFactory() = HeaderRomFilterBindingFactory - override fun bind(binding : HeaderRomFilterBinding, position : Int) { + override fun bind(holder : GenericViewHolder, position : Int) { + val binding = holder.binding binding.chipGroup.removeViews(1, binding.chipGroup.childCount - 1) for (format in formats) { binding.chipGroup.addView(Chip(binding.root.context, null, R.attr.chipChoiceStyle).apply { text = format.name }) diff --git a/app/src/main/java/emu/skyline/adapter/HeaderViewItem.kt b/app/src/main/java/emu/skyline/adapter/HeaderViewItem.kt index b97fc2bb..8a625837 100644 --- a/app/src/main/java/emu/skyline/adapter/HeaderViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/HeaderViewItem.kt @@ -15,8 +15,8 @@ object HeaderBindingFactory : ViewBindingFactory { class HeaderViewItem(private val text : String) : GenericListItem() { override fun getViewBindingFactory() = HeaderBindingFactory - override fun bind(binding : SectionItemBinding, position : Int) { - binding.textTitle.text = text + override fun bind(holder : GenericViewHolder, position : Int) { + holder.binding.textTitle.text = text } override fun toString() = "" diff --git a/app/src/main/java/emu/skyline/adapter/controller/ControllerButtonViewItem.kt b/app/src/main/java/emu/skyline/adapter/controller/ControllerButtonViewItem.kt index 26e50e06..05923042 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerButtonViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerButtonViewItem.kt @@ -6,6 +6,7 @@ package emu.skyline.adapter.controller import emu.skyline.adapter.GenericListItem +import emu.skyline.adapter.GenericViewHolder import emu.skyline.databinding.ControllerItemBinding import emu.skyline.di.getInputManager import emu.skyline.input.ButtonGuestEvent @@ -15,12 +16,13 @@ import emu.skyline.input.ButtonId * This item is used to display a particular [button] mapping for the controller */ class ControllerButtonViewItem(private val controllerId : Int, val button : ButtonId, private val onClick : (item : ControllerButtonViewItem, position : Int) -> Unit) : ControllerViewItem() { - override fun bind(binding : ControllerItemBinding, position : Int) { + override fun bind(holder : GenericViewHolder, position : Int) { + val binding = holder.binding content = button.long?.let { binding.root.context.getString(it) } ?: button.toString() val guestEvent = ButtonGuestEvent(controllerId, button) subContent = binding.root.context.getInputManager().eventMap.filter { it.value is ButtonGuestEvent && it.value == guestEvent }.keys.firstOrNull()?.toString() ?: "" - super.bind(binding, position) + super.bind(holder, position) binding.root.setOnClickListener { onClick.invoke(this, position) } } diff --git a/app/src/main/java/emu/skyline/adapter/controller/ControllerCheckBoxViewItem.kt b/app/src/main/java/emu/skyline/adapter/controller/ControllerCheckBoxViewItem.kt index 6be4d020..9331bb1c 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerCheckBoxViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerCheckBoxViewItem.kt @@ -8,6 +8,7 @@ package emu.skyline.adapter.controller import android.view.ViewGroup import androidx.core.view.isGone import emu.skyline.adapter.GenericListItem +import emu.skyline.adapter.GenericViewHolder import emu.skyline.adapter.ViewBindingFactory import emu.skyline.adapter.inflater import emu.skyline.databinding.ControllerCheckboxItemBinding @@ -19,7 +20,8 @@ object ControllerCheckBoxBindingFactory : ViewBindingFactory { class ControllerCheckBoxViewItem(var title : String, var summary : String, var checked : Boolean, private val onCheckedChange : (item : ControllerCheckBoxViewItem, position : Int) -> Unit) : GenericListItem() { override fun getViewBindingFactory() = ControllerCheckBoxBindingFactory - override fun bind(binding : ControllerCheckboxItemBinding, position : Int) { + override fun bind(holder : GenericViewHolder, position : Int) { + val binding = holder.binding binding.textTitle.isGone = title.isEmpty() binding.textTitle.text = title binding.textSubtitle.isGone = summary.isEmpty() diff --git a/app/src/main/java/emu/skyline/adapter/controller/ControllerGeneralViewItem.kt b/app/src/main/java/emu/skyline/adapter/controller/ControllerGeneralViewItem.kt index 6224f86a..2d929fcc 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerGeneralViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerGeneralViewItem.kt @@ -19,7 +19,8 @@ import emu.skyline.input.JoyConLeftController * @param type The type of controller setting this item is displaying */ class ControllerGeneralViewItem(private val controllerId : Int, val type : GeneralType, private val onClick : (item : ControllerGeneralViewItem, position : Int) -> Unit) : ControllerViewItem() { - override fun bind(binding : ControllerItemBinding, position : Int) { + override fun bind(holder : GenericViewHolder, position : Int) { + val binding = holder.binding val context = binding.root.context val controller = context.getInputManager().controllers[controllerId]!! @@ -38,7 +39,7 @@ class ControllerGeneralViewItem(private val controllerId : Int, val type : Gener GeneralType.SetupGuide -> context.getString(R.string.setup_guide_description) } - super.bind(binding, position) + super.bind(holder, position) binding.root.setOnClickListener { onClick.invoke(this, position) } } diff --git a/app/src/main/java/emu/skyline/adapter/controller/ControllerHeaderItem.kt b/app/src/main/java/emu/skyline/adapter/controller/ControllerHeaderItem.kt index a854d901..f8572642 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerHeaderItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerHeaderItem.kt @@ -2,6 +2,7 @@ package emu.skyline.adapter.controller import android.view.ViewGroup import emu.skyline.adapter.GenericListItem +import emu.skyline.adapter.GenericViewHolder import emu.skyline.adapter.ViewBindingFactory import emu.skyline.adapter.inflater import emu.skyline.databinding.ControllerHeaderBinding @@ -13,8 +14,8 @@ object ControllerHeaderBindingFactory : ViewBindingFactory { class ControllerHeaderItem(private val text : String) : GenericListItem() { override fun getViewBindingFactory() = ControllerHeaderBindingFactory - override fun bind(binding : ControllerHeaderBinding, position : Int) { - binding.root.text = text + override fun bind(holder : GenericViewHolder, position : Int) { + holder.binding.root.text = text } override fun areItemsTheSame(other : GenericListItem) = other is ControllerHeaderItem diff --git a/app/src/main/java/emu/skyline/adapter/controller/ControllerStickViewItem.kt b/app/src/main/java/emu/skyline/adapter/controller/ControllerStickViewItem.kt index d77edd87..b7bce7c2 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerStickViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerStickViewItem.kt @@ -18,7 +18,8 @@ import emu.skyline.input.StickId * This item is used to display all information regarding a [stick] and it's mappings for the controller */ class ControllerStickViewItem(private val controllerId : Int, val stick : StickId, private val onClick : (item : ControllerStickViewItem, position : Int) -> Unit) : ControllerViewItem(stick.toString()) { - override fun bind(binding : ControllerItemBinding, position : Int) { + override fun bind(holder : GenericViewHolder, position : Int) { + val binding = holder.binding val context = binding.root.context val inputManager = context.getInputManager() @@ -39,7 +40,7 @@ class ControllerStickViewItem(private val controllerId : Int, val stick : StickI subContent = "${context.getString(R.string.button)}: $button\n${context.getString(R.string.up)}: $yAxisPlus\n${context.getString(R.string.down)}: $yAxisMinus\n${context.getString(R.string.left)}: $xAxisMinus\n${context.getString(R.string.right)}: $xAxisPlus" - super.bind(binding, position) + super.bind(holder, position) binding.root.setOnClickListener { onClick.invoke(this, position) } } diff --git a/app/src/main/java/emu/skyline/adapter/controller/ControllerTypeViewItem.kt b/app/src/main/java/emu/skyline/adapter/controller/ControllerTypeViewItem.kt index ac8f2767..1f3f8a8a 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerTypeViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerTypeViewItem.kt @@ -15,13 +15,14 @@ import emu.skyline.input.ControllerType * This item is used to display the [type] of the currently active controller */ class ControllerTypeViewItem(private val type : ControllerType, private val onClick : (item : ControllerTypeViewItem, position : Int) -> Unit) : ControllerViewItem() { - override fun bind(binding : ControllerItemBinding, position : Int) { + override fun bind(holder : GenericViewHolder, position : Int) { + val binding = holder.binding val context = binding.root.context content = context.getString(R.string.controller_type) subContent = context.getString(type.stringRes) - super.bind(binding, position) + super.bind(holder, position) binding.root.setOnClickListener { onClick.invoke(this, position) } } diff --git a/app/src/main/java/emu/skyline/adapter/controller/ControllerViewItem.kt b/app/src/main/java/emu/skyline/adapter/controller/ControllerViewItem.kt index 541eb1b4..e4019766 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerViewItem.kt @@ -8,6 +8,7 @@ package emu.skyline.adapter.controller import android.view.ViewGroup import androidx.core.view.isGone import emu.skyline.adapter.GenericListItem +import emu.skyline.adapter.GenericViewHolder import emu.skyline.adapter.ViewBindingFactory import emu.skyline.adapter.inflater import emu.skyline.databinding.ControllerItemBinding @@ -21,8 +22,9 @@ open class ControllerViewItem(var content : String = "", var subContent : String override fun getViewBindingFactory() = ControllerBindingFactory - override fun bind(binding : ControllerItemBinding, position : Int) { + override fun bind(holder : GenericViewHolder, position : Int) { this.position = position + val binding = holder.binding binding.textTitle.apply { isGone = content.isEmpty() text = content