Add extension to retrieve input manager from context

This commit is contained in:
Willi Ye 2021-01-31 22:55:56 +01:00 committed by ◱ Mark
parent f5d5caf939
commit a261ff8413
5 changed files with 10 additions and 12 deletions

View File

@ -8,7 +8,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.InputManagerProviderEntryPoint
import emu.skyline.di.getInputManager
import emu.skyline.input.ButtonGuestEvent
import emu.skyline.input.ButtonId
@ -19,7 +19,7 @@ class ControllerButtonViewItem(private val controllerId : Int, val button : Butt
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
content = button.long?.let { holder.itemView.context.getString(it) } ?: button.toString()
val guestEvent = ButtonGuestEvent(controllerId, button)
subContent = InputManagerProviderEntryPoint.getInputManager(holder.binding.root.context).eventMap.filter { it.value is ButtonGuestEvent && it.value == guestEvent }.keys.firstOrNull()?.toString() ?: ""
subContent = holder.binding.root.context.getInputManager().eventMap.filter { it.value is ButtonGuestEvent && it.value == guestEvent }.keys.firstOrNull()?.toString() ?: ""
super.bind(holder, position)

View File

@ -9,7 +9,7 @@ import emu.skyline.R
import emu.skyline.adapter.GenericListItem
import emu.skyline.adapter.GenericViewHolder
import emu.skyline.databinding.ControllerItemBinding
import emu.skyline.di.InputManagerProviderEntryPoint
import emu.skyline.di.getInputManager
import emu.skyline.input.GeneralType
import emu.skyline.input.JoyConLeftController
@ -21,7 +21,7 @@ import emu.skyline.input.JoyConLeftController
class ControllerGeneralViewItem(private val controllerId : Int, val type : GeneralType, private val onClick : (item : ControllerGeneralViewItem, position : Int) -> Unit) : ControllerViewItem() {
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
val context = holder.itemView.context
val controller = InputManagerProviderEntryPoint.getInputManager(context).controllers[controllerId]!!
val controller = context.getInputManager().controllers[controllerId]!!
content = context.getString(type.stringRes)
subContent = when (type) {

View File

@ -9,7 +9,7 @@ import emu.skyline.R
import emu.skyline.adapter.GenericListItem
import emu.skyline.adapter.GenericViewHolder
import emu.skyline.databinding.ControllerItemBinding
import emu.skyline.di.InputManagerProviderEntryPoint
import emu.skyline.di.getInputManager
import emu.skyline.input.AxisGuestEvent
import emu.skyline.input.ButtonGuestEvent
import emu.skyline.input.StickId
@ -20,7 +20,7 @@ import emu.skyline.input.StickId
class ControllerStickViewItem(private val controllerId : Int, val stick : StickId, private val onClick : (item : ControllerStickViewItem, position : Int) -> Unit) : ControllerViewItem(stick.toString()) {
override fun bind(holder : GenericViewHolder<ControllerItemBinding>, position : Int) {
val context = holder.itemView.context
val inputManager = InputManagerProviderEntryPoint.getInputManager(context)
val inputManager = context.getInputManager()
val buttonGuestEvent = ButtonGuestEvent(controllerId, stick.button)
val button = inputManager.eventMap.filter { it.value is ButtonGuestEvent && it.value == buttonGuestEvent }.keys.firstOrNull()?.toString() ?: context.getString(R.string.none)

View File

@ -11,8 +11,6 @@ import emu.skyline.input.InputManager
@InstallIn(SingletonComponent::class)
interface InputManagerProviderEntryPoint {
fun inputManager() : InputManager
companion object {
fun getInputManager(context : Context) = EntryPointAccessors.fromApplication(context, InputManagerProviderEntryPoint::class.java).inputManager()
}
}
fun Context.getInputManager() = EntryPointAccessors.fromApplication(this, InputManagerProviderEntryPoint::class.java).inputManager()

View File

@ -12,7 +12,7 @@ import android.util.AttributeSet
import androidx.preference.Preference
import androidx.preference.Preference.SummaryProvider
import emu.skyline.R
import emu.skyline.di.InputManagerProviderEntryPoint
import emu.skyline.di.getInputManager
import emu.skyline.input.ControllerActivity
/**
@ -26,7 +26,7 @@ class ControllerPreference @JvmOverloads constructor(context : Context, attrs :
override var requestCode = 0
private val inputManager = InputManagerProviderEntryPoint.getInputManager(context)
private val inputManager = context.getInputManager()
init {
for (i in 0 until attrs!!.attributeCount) {