From a261ff84136dcb5619c97fff4a786d2bacb5267f Mon Sep 17 00:00:00 2001 From: Willi Ye Date: Sun, 31 Jan 2021 22:55:56 +0100 Subject: [PATCH] Add extension to retrieve input manager from context --- .../skyline/adapter/controller/ControllerButtonViewItem.kt | 4 ++-- .../skyline/adapter/controller/ControllerGeneralViewItem.kt | 4 ++-- .../skyline/adapter/controller/ControllerStickViewItem.kt | 4 ++-- .../java/emu/skyline/di/InputManagerProviderEntryPoint.kt | 6 ++---- .../java/emu/skyline/preference/ControllerPreference.kt | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) 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 82194a44..3524e56b 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerButtonViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerButtonViewItem.kt @@ -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, 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) 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 17295c92..491b40c0 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerGeneralViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerGeneralViewItem.kt @@ -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, 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) { 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 62b4159c..5cb75e03 100644 --- a/app/src/main/java/emu/skyline/adapter/controller/ControllerStickViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/controller/ControllerStickViewItem.kt @@ -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, 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) diff --git a/app/src/main/java/emu/skyline/di/InputManagerProviderEntryPoint.kt b/app/src/main/java/emu/skyline/di/InputManagerProviderEntryPoint.kt index f9a46040..2b320346 100644 --- a/app/src/main/java/emu/skyline/di/InputManagerProviderEntryPoint.kt +++ b/app/src/main/java/emu/skyline/di/InputManagerProviderEntryPoint.kt @@ -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() diff --git a/app/src/main/java/emu/skyline/preference/ControllerPreference.kt b/app/src/main/java/emu/skyline/preference/ControllerPreference.kt index 533452a5..ef36ac84 100644 --- a/app/src/main/java/emu/skyline/preference/ControllerPreference.kt +++ b/app/src/main/java/emu/skyline/preference/ControllerPreference.kt @@ -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) {