diff options
| author | 2024-01-10 12:51:14 -0500 | |
|---|---|---|
| committer | 2024-01-10 23:14:04 -0500 | |
| commit | 9130366a580aa1129a596bf6ee3ab4432d219b6d (patch) | |
| tree | 89d0375ae0044eb82530e7842330e0c312a46e5d /src | |
| parent | android: Create generic list adapter for basic lists (diff) | |
| download | yuzu-9130366a580aa1129a596bf6ee3ab4432d219b6d.tar.gz yuzu-9130366a580aa1129a596bf6ee3ab4432d219b6d.tar.xz yuzu-9130366a580aa1129a596bf6ee3ab4432d219b6d.zip | |
android: Refactor recycler view adapters to use AbstractListAdapter
Diffstat (limited to 'src')
7 files changed, 140 insertions, 236 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AppletAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AppletAdapter.kt index 4a05c5be9..41d7f72b8 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AppletAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AppletAdapter.kt | |||
| @@ -4,13 +4,11 @@ | |||
| 4 | package org.yuzu.yuzu_emu.adapters | 4 | package org.yuzu.yuzu_emu.adapters |
| 5 | 5 | ||
| 6 | import android.view.LayoutInflater | 6 | import android.view.LayoutInflater |
| 7 | import android.view.View | ||
| 8 | import android.view.ViewGroup | 7 | import android.view.ViewGroup |
| 9 | import android.widget.Toast | 8 | import android.widget.Toast |
| 10 | import androidx.core.content.res.ResourcesCompat | 9 | import androidx.core.content.res.ResourcesCompat |
| 11 | import androidx.fragment.app.FragmentActivity | 10 | import androidx.fragment.app.FragmentActivity |
| 12 | import androidx.navigation.findNavController | 11 | import androidx.navigation.findNavController |
| 13 | import androidx.recyclerview.widget.RecyclerView | ||
| 14 | import org.yuzu.yuzu_emu.HomeNavigationDirections | 12 | import org.yuzu.yuzu_emu.HomeNavigationDirections |
| 15 | import org.yuzu.yuzu_emu.NativeLibrary | 13 | import org.yuzu.yuzu_emu.NativeLibrary |
| 16 | import org.yuzu.yuzu_emu.R | 14 | import org.yuzu.yuzu_emu.R |
| @@ -19,72 +17,58 @@ import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding | |||
| 19 | import org.yuzu.yuzu_emu.model.Applet | 17 | import org.yuzu.yuzu_emu.model.Applet |
| 20 | import org.yuzu.yuzu_emu.model.AppletInfo | 18 | import org.yuzu.yuzu_emu.model.AppletInfo |
| 21 | import org.yuzu.yuzu_emu.model.Game | 19 | import org.yuzu.yuzu_emu.model.Game |
| 20 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | ||
| 22 | 21 | ||
| 23 | class AppletAdapter(val activity: FragmentActivity, var applets: List<Applet>) : | 22 | class AppletAdapter(val activity: FragmentActivity, applets: List<Applet>) : |
| 24 | RecyclerView.Adapter<AppletAdapter.AppletViewHolder>(), | 23 | AbstractListAdapter<Applet, AppletAdapter.AppletViewHolder>(applets) { |
| 25 | View.OnClickListener { | ||
| 26 | |||
| 27 | override fun onCreateViewHolder( | 24 | override fun onCreateViewHolder( |
| 28 | parent: ViewGroup, | 25 | parent: ViewGroup, |
| 29 | viewType: Int | 26 | viewType: Int |
| 30 | ): AppletAdapter.AppletViewHolder { | 27 | ): AppletAdapter.AppletViewHolder { |
| 31 | CardSimpleOutlinedBinding.inflate(LayoutInflater.from(parent.context), parent, false) | 28 | CardSimpleOutlinedBinding.inflate(LayoutInflater.from(parent.context), parent, false) |
| 32 | .apply { root.setOnClickListener(this@AppletAdapter) } | ||
| 33 | .also { return AppletViewHolder(it) } | 29 | .also { return AppletViewHolder(it) } |
| 34 | } | 30 | } |
| 35 | 31 | ||
| 36 | override fun onBindViewHolder(holder: AppletViewHolder, position: Int) = | ||
| 37 | holder.bind(applets[position]) | ||
| 38 | |||
| 39 | override fun getItemCount(): Int = applets.size | ||
| 40 | |||
| 41 | override fun onClick(view: View) { | ||
| 42 | val applet = (view.tag as AppletViewHolder).applet | ||
| 43 | val appletPath = NativeLibrary.getAppletLaunchPath(applet.appletInfo.entryId) | ||
| 44 | if (appletPath.isEmpty()) { | ||
| 45 | Toast.makeText( | ||
| 46 | YuzuApplication.appContext, | ||
| 47 | R.string.applets_error_applet, | ||
| 48 | Toast.LENGTH_SHORT | ||
| 49 | ).show() | ||
| 50 | return | ||
| 51 | } | ||
| 52 | |||
| 53 | if (applet.appletInfo == AppletInfo.Cabinet) { | ||
| 54 | view.findNavController() | ||
| 55 | .navigate(R.id.action_appletLauncherFragment_to_cabinetLauncherDialogFragment) | ||
| 56 | return | ||
| 57 | } | ||
| 58 | |||
| 59 | NativeLibrary.setCurrentAppletId(applet.appletInfo.appletId) | ||
| 60 | val appletGame = Game( | ||
| 61 | title = YuzuApplication.appContext.getString(applet.titleId), | ||
| 62 | path = appletPath | ||
| 63 | ) | ||
| 64 | val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame) | ||
| 65 | view.findNavController().navigate(action) | ||
| 66 | } | ||
| 67 | |||
| 68 | inner class AppletViewHolder(val binding: CardSimpleOutlinedBinding) : | 32 | inner class AppletViewHolder(val binding: CardSimpleOutlinedBinding) : |
| 69 | RecyclerView.ViewHolder(binding.root) { | 33 | AbstractViewHolder<Applet>(binding) { |
| 70 | lateinit var applet: Applet | 34 | override fun bind(model: Applet) { |
| 71 | 35 | binding.title.setText(model.titleId) | |
| 72 | init { | 36 | binding.description.setText(model.descriptionId) |
| 73 | itemView.tag = this | ||
| 74 | } | ||
| 75 | |||
| 76 | fun bind(applet: Applet) { | ||
| 77 | this.applet = applet | ||
| 78 | |||
| 79 | binding.title.setText(applet.titleId) | ||
| 80 | binding.description.setText(applet.descriptionId) | ||
| 81 | binding.icon.setImageDrawable( | 37 | binding.icon.setImageDrawable( |
| 82 | ResourcesCompat.getDrawable( | 38 | ResourcesCompat.getDrawable( |
| 83 | binding.icon.context.resources, | 39 | binding.icon.context.resources, |
| 84 | applet.iconId, | 40 | model.iconId, |
| 85 | binding.icon.context.theme | 41 | binding.icon.context.theme |
| 86 | ) | 42 | ) |
| 87 | ) | 43 | ) |
| 44 | |||
| 45 | binding.root.setOnClickListener { onClick(model) } | ||
| 46 | } | ||
| 47 | |||
| 48 | fun onClick(applet: Applet) { | ||
| 49 | val appletPath = NativeLibrary.getAppletLaunchPath(applet.appletInfo.entryId) | ||
| 50 | if (appletPath.isEmpty()) { | ||
| 51 | Toast.makeText( | ||
| 52 | binding.root.context, | ||
| 53 | R.string.applets_error_applet, | ||
| 54 | Toast.LENGTH_SHORT | ||
| 55 | ).show() | ||
| 56 | return | ||
| 57 | } | ||
| 58 | |||
| 59 | if (applet.appletInfo == AppletInfo.Cabinet) { | ||
| 60 | binding.root.findNavController() | ||
| 61 | .navigate(R.id.action_appletLauncherFragment_to_cabinetLauncherDialogFragment) | ||
| 62 | return | ||
| 63 | } | ||
| 64 | |||
| 65 | NativeLibrary.setCurrentAppletId(applet.appletInfo.appletId) | ||
| 66 | val appletGame = Game( | ||
| 67 | title = YuzuApplication.appContext.getString(applet.titleId), | ||
| 68 | path = appletPath | ||
| 69 | ) | ||
| 70 | val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame) | ||
| 71 | binding.root.findNavController().navigate(action) | ||
| 88 | } | 72 | } |
| 89 | } | 73 | } |
| 90 | } | 74 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/CabinetLauncherDialogAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/CabinetLauncherDialogAdapter.kt index e7b7c0f2f..a56137148 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/CabinetLauncherDialogAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/CabinetLauncherDialogAdapter.kt | |||
| @@ -4,12 +4,10 @@ | |||
| 4 | package org.yuzu.yuzu_emu.adapters | 4 | package org.yuzu.yuzu_emu.adapters |
| 5 | 5 | ||
| 6 | import android.view.LayoutInflater | 6 | import android.view.LayoutInflater |
| 7 | import android.view.View | ||
| 8 | import android.view.ViewGroup | 7 | import android.view.ViewGroup |
| 9 | import androidx.core.content.res.ResourcesCompat | 8 | import androidx.core.content.res.ResourcesCompat |
| 10 | import androidx.fragment.app.Fragment | 9 | import androidx.fragment.app.Fragment |
| 11 | import androidx.navigation.fragment.findNavController | 10 | import androidx.navigation.fragment.findNavController |
| 12 | import androidx.recyclerview.widget.RecyclerView | ||
| 13 | import org.yuzu.yuzu_emu.HomeNavigationDirections | 11 | import org.yuzu.yuzu_emu.HomeNavigationDirections |
| 14 | import org.yuzu.yuzu_emu.NativeLibrary | 12 | import org.yuzu.yuzu_emu.NativeLibrary |
| 15 | import org.yuzu.yuzu_emu.R | 13 | import org.yuzu.yuzu_emu.R |
| @@ -19,54 +17,43 @@ import org.yuzu.yuzu_emu.model.CabinetMode | |||
| 19 | import org.yuzu.yuzu_emu.adapters.CabinetLauncherDialogAdapter.CabinetModeViewHolder | 17 | import org.yuzu.yuzu_emu.adapters.CabinetLauncherDialogAdapter.CabinetModeViewHolder |
| 20 | import org.yuzu.yuzu_emu.model.AppletInfo | 18 | import org.yuzu.yuzu_emu.model.AppletInfo |
| 21 | import org.yuzu.yuzu_emu.model.Game | 19 | import org.yuzu.yuzu_emu.model.Game |
| 20 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | ||
| 22 | 21 | ||
| 23 | class CabinetLauncherDialogAdapter(val fragment: Fragment) : | 22 | class CabinetLauncherDialogAdapter(val fragment: Fragment) : |
| 24 | RecyclerView.Adapter<CabinetModeViewHolder>(), | 23 | AbstractListAdapter<CabinetMode, CabinetModeViewHolder>( |
| 25 | View.OnClickListener { | 24 | CabinetMode.values().copyOfRange(1, CabinetMode.entries.size).toList() |
| 26 | private val cabinetModes = CabinetMode.values().copyOfRange(1, CabinetMode.values().size) | 25 | ) { |
| 27 | 26 | ||
| 28 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CabinetModeViewHolder { | 27 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CabinetModeViewHolder { |
| 29 | DialogListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) | 28 | DialogListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) |
| 30 | .apply { root.setOnClickListener(this@CabinetLauncherDialogAdapter) } | ||
| 31 | .also { return CabinetModeViewHolder(it) } | 29 | .also { return CabinetModeViewHolder(it) } |
| 32 | } | 30 | } |
| 33 | 31 | ||
| 34 | override fun getItemCount(): Int = cabinetModes.size | ||
| 35 | |||
| 36 | override fun onBindViewHolder(holder: CabinetModeViewHolder, position: Int) = | ||
| 37 | holder.bind(cabinetModes[position]) | ||
| 38 | |||
| 39 | override fun onClick(view: View) { | ||
| 40 | val mode = (view.tag as CabinetModeViewHolder).cabinetMode | ||
| 41 | val appletPath = NativeLibrary.getAppletLaunchPath(AppletInfo.Cabinet.entryId) | ||
| 42 | NativeLibrary.setCurrentAppletId(AppletInfo.Cabinet.appletId) | ||
| 43 | NativeLibrary.setCabinetMode(mode.id) | ||
| 44 | val appletGame = Game( | ||
| 45 | title = YuzuApplication.appContext.getString(R.string.cabinet_applet), | ||
| 46 | path = appletPath | ||
| 47 | ) | ||
| 48 | val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame) | ||
| 49 | fragment.findNavController().navigate(action) | ||
| 50 | } | ||
| 51 | |||
| 52 | inner class CabinetModeViewHolder(val binding: DialogListItemBinding) : | 32 | inner class CabinetModeViewHolder(val binding: DialogListItemBinding) : |
| 53 | RecyclerView.ViewHolder(binding.root) { | 33 | AbstractViewHolder<CabinetMode>(binding) { |
| 54 | lateinit var cabinetMode: CabinetMode | 34 | override fun bind(model: CabinetMode) { |
| 55 | |||
| 56 | init { | ||
| 57 | itemView.tag = this | ||
| 58 | } | ||
| 59 | |||
| 60 | fun bind(cabinetMode: CabinetMode) { | ||
| 61 | this.cabinetMode = cabinetMode | ||
| 62 | binding.icon.setImageDrawable( | 35 | binding.icon.setImageDrawable( |
| 63 | ResourcesCompat.getDrawable( | 36 | ResourcesCompat.getDrawable( |
| 64 | binding.icon.context.resources, | 37 | binding.icon.context.resources, |
| 65 | cabinetMode.iconId, | 38 | model.iconId, |
| 66 | binding.icon.context.theme | 39 | binding.icon.context.theme |
| 67 | ) | 40 | ) |
| 68 | ) | 41 | ) |
| 69 | binding.title.setText(cabinetMode.titleId) | 42 | binding.title.setText(model.titleId) |
| 43 | |||
| 44 | binding.root.setOnClickListener { onClick(model) } | ||
| 45 | } | ||
| 46 | |||
| 47 | private fun onClick(mode: CabinetMode) { | ||
| 48 | val appletPath = NativeLibrary.getAppletLaunchPath(AppletInfo.Cabinet.entryId) | ||
| 49 | NativeLibrary.setCurrentAppletId(AppletInfo.Cabinet.appletId) | ||
| 50 | NativeLibrary.setCabinetMode(mode.id) | ||
| 51 | val appletGame = Game( | ||
| 52 | title = YuzuApplication.appContext.getString(R.string.cabinet_applet), | ||
| 53 | path = appletPath | ||
| 54 | ) | ||
| 55 | val action = HomeNavigationDirections.actionGlobalEmulationActivity(appletGame) | ||
| 56 | fragment.findNavController().navigate(action) | ||
| 70 | } | 57 | } |
| 71 | } | 58 | } |
| 72 | } | 59 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GamePropertiesAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GamePropertiesAdapter.kt index 95841d786..0046d5314 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GamePropertiesAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GamePropertiesAdapter.kt | |||
| @@ -12,23 +12,22 @@ import androidx.lifecycle.Lifecycle | |||
| 12 | import androidx.lifecycle.LifecycleOwner | 12 | import androidx.lifecycle.LifecycleOwner |
| 13 | import androidx.lifecycle.lifecycleScope | 13 | import androidx.lifecycle.lifecycleScope |
| 14 | import androidx.lifecycle.repeatOnLifecycle | 14 | import androidx.lifecycle.repeatOnLifecycle |
| 15 | import androidx.recyclerview.widget.RecyclerView | ||
| 16 | import kotlinx.coroutines.launch | 15 | import kotlinx.coroutines.launch |
| 17 | import org.yuzu.yuzu_emu.databinding.CardInstallableIconBinding | 16 | import org.yuzu.yuzu_emu.databinding.CardInstallableIconBinding |
| 18 | import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding | 17 | import org.yuzu.yuzu_emu.databinding.CardSimpleOutlinedBinding |
| 19 | import org.yuzu.yuzu_emu.model.GameProperty | 18 | import org.yuzu.yuzu_emu.model.GameProperty |
| 20 | import org.yuzu.yuzu_emu.model.InstallableProperty | 19 | import org.yuzu.yuzu_emu.model.InstallableProperty |
| 21 | import org.yuzu.yuzu_emu.model.SubmenuProperty | 20 | import org.yuzu.yuzu_emu.model.SubmenuProperty |
| 21 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | ||
| 22 | 22 | ||
| 23 | class GamePropertiesAdapter( | 23 | class GamePropertiesAdapter( |
| 24 | private val viewLifecycle: LifecycleOwner, | 24 | private val viewLifecycle: LifecycleOwner, |
| 25 | private var properties: List<GameProperty> | 25 | private var properties: List<GameProperty> |
| 26 | ) : | 26 | ) : AbstractListAdapter<GameProperty, AbstractViewHolder<GameProperty>>(properties) { |
| 27 | RecyclerView.Adapter<GamePropertiesAdapter.GamePropertyViewHolder>() { | ||
| 28 | override fun onCreateViewHolder( | 27 | override fun onCreateViewHolder( |
| 29 | parent: ViewGroup, | 28 | parent: ViewGroup, |
| 30 | viewType: Int | 29 | viewType: Int |
| 31 | ): GamePropertyViewHolder { | 30 | ): AbstractViewHolder<GameProperty> { |
| 32 | val inflater = LayoutInflater.from(parent.context) | 31 | val inflater = LayoutInflater.from(parent.context) |
| 33 | return when (viewType) { | 32 | return when (viewType) { |
| 34 | PropertyType.Submenu.ordinal -> { | 33 | PropertyType.Submenu.ordinal -> { |
| @@ -51,11 +50,6 @@ class GamePropertiesAdapter( | |||
| 51 | } | 50 | } |
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | override fun getItemCount(): Int = properties.size | ||
| 55 | |||
| 56 | override fun onBindViewHolder(holder: GamePropertyViewHolder, position: Int) = | ||
| 57 | holder.bind(properties[position]) | ||
| 58 | |||
| 59 | override fun getItemViewType(position: Int): Int { | 53 | override fun getItemViewType(position: Int): Int { |
| 60 | return when (properties[position]) { | 54 | return when (properties[position]) { |
| 61 | is SubmenuProperty -> PropertyType.Submenu.ordinal | 55 | is SubmenuProperty -> PropertyType.Submenu.ordinal |
| @@ -63,14 +57,10 @@ class GamePropertiesAdapter( | |||
| 63 | } | 57 | } |
| 64 | } | 58 | } |
| 65 | 59 | ||
| 66 | sealed class GamePropertyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
| 67 | abstract fun bind(property: GameProperty) | ||
| 68 | } | ||
| 69 | |||
| 70 | inner class SubmenuPropertyViewHolder(val binding: CardSimpleOutlinedBinding) : | 60 | inner class SubmenuPropertyViewHolder(val binding: CardSimpleOutlinedBinding) : |
| 71 | GamePropertyViewHolder(binding.root) { | 61 | AbstractViewHolder<GameProperty>(binding) { |
| 72 | override fun bind(property: GameProperty) { | 62 | override fun bind(model: GameProperty) { |
| 73 | val submenuProperty = property as SubmenuProperty | 63 | val submenuProperty = model as SubmenuProperty |
| 74 | 64 | ||
| 75 | binding.root.setOnClickListener { | 65 | binding.root.setOnClickListener { |
| 76 | submenuProperty.action.invoke() | 66 | submenuProperty.action.invoke() |
| @@ -108,9 +98,9 @@ class GamePropertiesAdapter( | |||
| 108 | } | 98 | } |
| 109 | 99 | ||
| 110 | inner class InstallablePropertyViewHolder(val binding: CardInstallableIconBinding) : | 100 | inner class InstallablePropertyViewHolder(val binding: CardInstallableIconBinding) : |
| 111 | GamePropertyViewHolder(binding.root) { | 101 | AbstractViewHolder<GameProperty>(binding) { |
| 112 | override fun bind(property: GameProperty) { | 102 | override fun bind(model: GameProperty) { |
| 113 | val installableProperty = property as InstallableProperty | 103 | val installableProperty = model as InstallableProperty |
| 114 | 104 | ||
| 115 | binding.title.setText(installableProperty.titleId) | 105 | binding.title.setText(installableProperty.titleId) |
| 116 | binding.description.setText(installableProperty.descriptionId) | 106 | binding.description.setText(installableProperty.descriptionId) |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt index 58ce343f4..b512845d5 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt | |||
| @@ -14,69 +14,37 @@ import androidx.lifecycle.Lifecycle | |||
| 14 | import androidx.lifecycle.LifecycleOwner | 14 | import androidx.lifecycle.LifecycleOwner |
| 15 | import androidx.lifecycle.lifecycleScope | 15 | import androidx.lifecycle.lifecycleScope |
| 16 | import androidx.lifecycle.repeatOnLifecycle | 16 | import androidx.lifecycle.repeatOnLifecycle |
| 17 | import androidx.recyclerview.widget.RecyclerView | ||
| 18 | import kotlinx.coroutines.launch | 17 | import kotlinx.coroutines.launch |
| 19 | import org.yuzu.yuzu_emu.R | 18 | import org.yuzu.yuzu_emu.R |
| 20 | import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding | 19 | import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding |
| 21 | import org.yuzu.yuzu_emu.fragments.MessageDialogFragment | 20 | import org.yuzu.yuzu_emu.fragments.MessageDialogFragment |
| 22 | import org.yuzu.yuzu_emu.model.HomeSetting | 21 | import org.yuzu.yuzu_emu.model.HomeSetting |
| 22 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | ||
| 23 | 23 | ||
| 24 | class HomeSettingAdapter( | 24 | class HomeSettingAdapter( |
| 25 | private val activity: AppCompatActivity, | 25 | private val activity: AppCompatActivity, |
| 26 | private val viewLifecycle: LifecycleOwner, | 26 | private val viewLifecycle: LifecycleOwner, |
| 27 | var options: List<HomeSetting> | 27 | options: List<HomeSetting> |
| 28 | ) : | 28 | ) : AbstractListAdapter<HomeSetting, HomeSettingAdapter.HomeOptionViewHolder>(options) { |
| 29 | RecyclerView.Adapter<HomeSettingAdapter.HomeOptionViewHolder>(), | ||
| 30 | View.OnClickListener { | ||
| 31 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { | 29 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { |
| 32 | val binding = | 30 | CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false) |
| 33 | CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false) | 31 | .also { return HomeOptionViewHolder(it) } |
| 34 | binding.root.setOnClickListener(this) | ||
| 35 | return HomeOptionViewHolder(binding) | ||
| 36 | } | ||
| 37 | |||
| 38 | override fun getItemCount(): Int { | ||
| 39 | return options.size | ||
| 40 | } | ||
| 41 | |||
| 42 | override fun onBindViewHolder(holder: HomeOptionViewHolder, position: Int) { | ||
| 43 | holder.bind(options[position]) | ||
| 44 | } | ||
| 45 | |||
| 46 | override fun onClick(view: View) { | ||
| 47 | val holder = view.tag as HomeOptionViewHolder | ||
| 48 | if (holder.option.isEnabled.invoke()) { | ||
| 49 | holder.option.onClick.invoke() | ||
| 50 | } else { | ||
| 51 | MessageDialogFragment.newInstance( | ||
| 52 | activity, | ||
| 53 | titleId = holder.option.disabledTitleId, | ||
| 54 | descriptionId = holder.option.disabledMessageId | ||
| 55 | ).show(activity.supportFragmentManager, MessageDialogFragment.TAG) | ||
| 56 | } | ||
| 57 | } | 32 | } |
| 58 | 33 | ||
| 59 | inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) : | 34 | inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) : |
| 60 | RecyclerView.ViewHolder(binding.root) { | 35 | AbstractViewHolder<HomeSetting>(binding) { |
| 61 | lateinit var option: HomeSetting | 36 | override fun bind(model: HomeSetting) { |
| 62 | 37 | binding.optionTitle.text = activity.resources.getString(model.titleId) | |
| 63 | init { | 38 | binding.optionDescription.text = activity.resources.getString(model.descriptionId) |
| 64 | itemView.tag = this | ||
| 65 | } | ||
| 66 | |||
| 67 | fun bind(option: HomeSetting) { | ||
| 68 | this.option = option | ||
| 69 | binding.optionTitle.text = activity.resources.getString(option.titleId) | ||
| 70 | binding.optionDescription.text = activity.resources.getString(option.descriptionId) | ||
| 71 | binding.optionIcon.setImageDrawable( | 39 | binding.optionIcon.setImageDrawable( |
| 72 | ResourcesCompat.getDrawable( | 40 | ResourcesCompat.getDrawable( |
| 73 | activity.resources, | 41 | activity.resources, |
| 74 | option.iconId, | 42 | model.iconId, |
| 75 | activity.theme | 43 | activity.theme |
| 76 | ) | 44 | ) |
| 77 | ) | 45 | ) |
| 78 | 46 | ||
| 79 | when (option.titleId) { | 47 | when (model.titleId) { |
| 80 | R.string.get_early_access -> | 48 | R.string.get_early_access -> |
| 81 | binding.optionLayout.background = | 49 | binding.optionLayout.background = |
| 82 | ContextCompat.getDrawable( | 50 | ContextCompat.getDrawable( |
| @@ -85,7 +53,7 @@ class HomeSettingAdapter( | |||
| 85 | ) | 53 | ) |
| 86 | } | 54 | } |
| 87 | 55 | ||
| 88 | if (!option.isEnabled.invoke()) { | 56 | if (!model.isEnabled.invoke()) { |
| 89 | binding.optionTitle.alpha = 0.5f | 57 | binding.optionTitle.alpha = 0.5f |
| 90 | binding.optionDescription.alpha = 0.5f | 58 | binding.optionDescription.alpha = 0.5f |
| 91 | binding.optionIcon.alpha = 0.5f | 59 | binding.optionIcon.alpha = 0.5f |
| @@ -93,7 +61,7 @@ class HomeSettingAdapter( | |||
| 93 | 61 | ||
| 94 | viewLifecycle.lifecycleScope.launch { | 62 | viewLifecycle.lifecycleScope.launch { |
| 95 | viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) { | 63 | viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) { |
| 96 | option.details.collect { updateOptionDetails(it) } | 64 | model.details.collect { updateOptionDetails(it) } |
| 97 | } | 65 | } |
| 98 | } | 66 | } |
| 99 | binding.optionDetail.postDelayed( | 67 | binding.optionDetail.postDelayed( |
| @@ -103,6 +71,20 @@ class HomeSettingAdapter( | |||
| 103 | }, | 71 | }, |
| 104 | 3000 | 72 | 3000 |
| 105 | ) | 73 | ) |
| 74 | |||
| 75 | binding.root.setOnClickListener { onClick(model) } | ||
| 76 | } | ||
| 77 | |||
| 78 | private fun onClick(model: HomeSetting) { | ||
| 79 | if (model.isEnabled.invoke()) { | ||
| 80 | model.onClick.invoke() | ||
| 81 | } else { | ||
| 82 | MessageDialogFragment.newInstance( | ||
| 83 | activity, | ||
| 84 | titleId = model.disabledTitleId, | ||
| 85 | descriptionId = model.disabledMessageId | ||
| 86 | ).show(activity.supportFragmentManager, MessageDialogFragment.TAG) | ||
| 87 | } | ||
| 106 | } | 88 | } |
| 107 | 89 | ||
| 108 | private fun updateOptionDetails(detailString: String) { | 90 | private fun updateOptionDetails(detailString: String) { |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/InstallableAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/InstallableAdapter.kt index e960fbaab..4218c4e52 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/InstallableAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/InstallableAdapter.kt | |||
| @@ -6,43 +6,33 @@ package org.yuzu.yuzu_emu.adapters | |||
| 6 | import android.view.LayoutInflater | 6 | import android.view.LayoutInflater |
| 7 | import android.view.View | 7 | import android.view.View |
| 8 | import android.view.ViewGroup | 8 | import android.view.ViewGroup |
| 9 | import androidx.recyclerview.widget.RecyclerView | ||
| 10 | import org.yuzu.yuzu_emu.databinding.CardInstallableBinding | 9 | import org.yuzu.yuzu_emu.databinding.CardInstallableBinding |
| 11 | import org.yuzu.yuzu_emu.model.Installable | 10 | import org.yuzu.yuzu_emu.model.Installable |
| 11 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | ||
| 12 | 12 | ||
| 13 | class InstallableAdapter(private val installables: List<Installable>) : | 13 | class InstallableAdapter(installables: List<Installable>) : |
| 14 | RecyclerView.Adapter<InstallableAdapter.InstallableViewHolder>() { | 14 | AbstractListAdapter<Installable, InstallableAdapter.InstallableViewHolder>(installables) { |
| 15 | override fun onCreateViewHolder( | 15 | override fun onCreateViewHolder( |
| 16 | parent: ViewGroup, | 16 | parent: ViewGroup, |
| 17 | viewType: Int | 17 | viewType: Int |
| 18 | ): InstallableAdapter.InstallableViewHolder { | 18 | ): InstallableAdapter.InstallableViewHolder { |
| 19 | val binding = | 19 | CardInstallableBinding.inflate(LayoutInflater.from(parent.context), parent, false) |
| 20 | CardInstallableBinding.inflate(LayoutInflater.from(parent.context), parent, false) | 20 | .also { return InstallableViewHolder(it) } |
| 21 | return InstallableViewHolder(binding) | ||
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | override fun getItemCount(): Int = installables.size | ||
| 25 | |||
| 26 | override fun onBindViewHolder(holder: InstallableAdapter.InstallableViewHolder, position: Int) = | ||
| 27 | holder.bind(installables[position]) | ||
| 28 | |||
| 29 | inner class InstallableViewHolder(val binding: CardInstallableBinding) : | 23 | inner class InstallableViewHolder(val binding: CardInstallableBinding) : |
| 30 | RecyclerView.ViewHolder(binding.root) { | 24 | AbstractViewHolder<Installable>(binding) { |
| 31 | lateinit var installable: Installable | 25 | override fun bind(model: Installable) { |
| 32 | 26 | binding.title.setText(model.titleId) | |
| 33 | fun bind(installable: Installable) { | 27 | binding.description.setText(model.descriptionId) |
| 34 | this.installable = installable | ||
| 35 | |||
| 36 | binding.title.setText(installable.titleId) | ||
| 37 | binding.description.setText(installable.descriptionId) | ||
| 38 | 28 | ||
| 39 | if (installable.install != null) { | 29 | if (model.install != null) { |
| 40 | binding.buttonInstall.visibility = View.VISIBLE | 30 | binding.buttonInstall.visibility = View.VISIBLE |
| 41 | binding.buttonInstall.setOnClickListener { installable.install.invoke() } | 31 | binding.buttonInstall.setOnClickListener { model.install.invoke() } |
| 42 | } | 32 | } |
| 43 | if (installable.export != null) { | 33 | if (model.export != null) { |
| 44 | binding.buttonExport.visibility = View.VISIBLE | 34 | binding.buttonExport.visibility = View.VISIBLE |
| 45 | binding.buttonExport.setOnClickListener { installable.export.invoke() } | 35 | binding.buttonExport.setOnClickListener { model.export.invoke() } |
| 46 | } | 36 | } |
| 47 | } | 37 | } |
| 48 | } | 38 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/LicenseAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/LicenseAdapter.kt index bc6ff1364..38bb1f96f 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/LicenseAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/LicenseAdapter.kt | |||
| @@ -7,49 +7,33 @@ import android.view.LayoutInflater | |||
| 7 | import android.view.View | 7 | import android.view.View |
| 8 | import android.view.ViewGroup | 8 | import android.view.ViewGroup |
| 9 | import androidx.appcompat.app.AppCompatActivity | 9 | import androidx.appcompat.app.AppCompatActivity |
| 10 | import androidx.recyclerview.widget.RecyclerView | ||
| 11 | import androidx.recyclerview.widget.RecyclerView.ViewHolder | ||
| 12 | import org.yuzu.yuzu_emu.YuzuApplication | ||
| 13 | import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding | 10 | import org.yuzu.yuzu_emu.databinding.ListItemSettingBinding |
| 14 | import org.yuzu.yuzu_emu.fragments.LicenseBottomSheetDialogFragment | 11 | import org.yuzu.yuzu_emu.fragments.LicenseBottomSheetDialogFragment |
| 15 | import org.yuzu.yuzu_emu.model.License | 12 | import org.yuzu.yuzu_emu.model.License |
| 13 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | ||
| 16 | 14 | ||
| 17 | class LicenseAdapter(private val activity: AppCompatActivity, var licenses: List<License>) : | 15 | class LicenseAdapter(private val activity: AppCompatActivity, licenses: List<License>) : |
| 18 | RecyclerView.Adapter<LicenseAdapter.LicenseViewHolder>(), | 16 | AbstractListAdapter<License, LicenseAdapter.LicenseViewHolder>(licenses) { |
| 19 | View.OnClickListener { | ||
| 20 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LicenseViewHolder { | 17 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LicenseViewHolder { |
| 21 | val binding = | 18 | ListItemSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false) |
| 22 | ListItemSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false) | 19 | .also { return LicenseViewHolder(it) } |
| 23 | binding.root.setOnClickListener(this) | ||
| 24 | return LicenseViewHolder(binding) | ||
| 25 | } | 20 | } |
| 26 | 21 | ||
| 27 | override fun getItemCount(): Int = licenses.size | 22 | inner class LicenseViewHolder(val binding: ListItemSettingBinding) : |
| 23 | AbstractViewHolder<License>(binding) { | ||
| 24 | override fun bind(model: License) { | ||
| 25 | binding.apply { | ||
| 26 | textSettingName.text = root.context.getString(model.titleId) | ||
| 27 | textSettingDescription.text = root.context.getString(model.descriptionId) | ||
| 28 | textSettingValue.visibility = View.GONE | ||
| 28 | 29 | ||
| 29 | override fun onBindViewHolder(holder: LicenseViewHolder, position: Int) { | 30 | root.setOnClickListener { onClick(model) } |
| 30 | holder.bind(licenses[position]) | 31 | } |
| 31 | } | ||
| 32 | |||
| 33 | override fun onClick(view: View) { | ||
| 34 | val license = (view.tag as LicenseViewHolder).license | ||
| 35 | LicenseBottomSheetDialogFragment.newInstance(license) | ||
| 36 | .show(activity.supportFragmentManager, LicenseBottomSheetDialogFragment.TAG) | ||
| 37 | } | ||
| 38 | |||
| 39 | inner class LicenseViewHolder(val binding: ListItemSettingBinding) : ViewHolder(binding.root) { | ||
| 40 | lateinit var license: License | ||
| 41 | |||
| 42 | init { | ||
| 43 | itemView.tag = this | ||
| 44 | } | 32 | } |
| 45 | 33 | ||
| 46 | fun bind(license: License) { | 34 | private fun onClick(license: License) { |
| 47 | this.license = license | 35 | LicenseBottomSheetDialogFragment.newInstance(license) |
| 48 | 36 | .show(activity.supportFragmentManager, LicenseBottomSheetDialogFragment.TAG) | |
| 49 | val context = YuzuApplication.appContext | ||
| 50 | binding.textSettingName.text = context.getString(license.titleId) | ||
| 51 | binding.textSettingDescription.text = context.getString(license.descriptionId) | ||
| 52 | binding.textSettingValue.visibility = View.GONE | ||
| 53 | } | 37 | } |
| 54 | } | 38 | } |
| 55 | } | 39 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/SetupAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/SetupAdapter.kt index 6b46d359e..02118e1a8 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/SetupAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/SetupAdapter.kt | |||
| @@ -10,7 +10,6 @@ import android.view.ViewGroup | |||
| 10 | import androidx.appcompat.app.AppCompatActivity | 10 | import androidx.appcompat.app.AppCompatActivity |
| 11 | import androidx.core.content.res.ResourcesCompat | 11 | import androidx.core.content.res.ResourcesCompat |
| 12 | import androidx.lifecycle.ViewModelProvider | 12 | import androidx.lifecycle.ViewModelProvider |
| 13 | import androidx.recyclerview.widget.RecyclerView | ||
| 14 | import com.google.android.material.button.MaterialButton | 13 | import com.google.android.material.button.MaterialButton |
| 15 | import org.yuzu.yuzu_emu.databinding.PageSetupBinding | 14 | import org.yuzu.yuzu_emu.databinding.PageSetupBinding |
| 16 | import org.yuzu.yuzu_emu.model.HomeViewModel | 15 | import org.yuzu.yuzu_emu.model.HomeViewModel |
| @@ -18,31 +17,19 @@ import org.yuzu.yuzu_emu.model.SetupCallback | |||
| 18 | import org.yuzu.yuzu_emu.model.SetupPage | 17 | import org.yuzu.yuzu_emu.model.SetupPage |
| 19 | import org.yuzu.yuzu_emu.model.StepState | 18 | import org.yuzu.yuzu_emu.model.StepState |
| 20 | import org.yuzu.yuzu_emu.utils.ViewUtils | 19 | import org.yuzu.yuzu_emu.utils.ViewUtils |
| 20 | import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder | ||
| 21 | 21 | ||
| 22 | class SetupAdapter(val activity: AppCompatActivity, val pages: List<SetupPage>) : | 22 | class SetupAdapter(val activity: AppCompatActivity, pages: List<SetupPage>) : |
| 23 | RecyclerView.Adapter<SetupAdapter.SetupPageViewHolder>() { | 23 | AbstractListAdapter<SetupPage, SetupAdapter.SetupPageViewHolder>(pages) { |
| 24 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SetupPageViewHolder { | 24 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SetupPageViewHolder { |
| 25 | val binding = PageSetupBinding.inflate(LayoutInflater.from(parent.context), parent, false) | 25 | PageSetupBinding.inflate(LayoutInflater.from(parent.context), parent, false) |
| 26 | return SetupPageViewHolder(binding) | 26 | .also { return SetupPageViewHolder(it) } |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | override fun getItemCount(): Int = pages.size | ||
| 30 | |||
| 31 | override fun onBindViewHolder(holder: SetupPageViewHolder, position: Int) = | ||
| 32 | holder.bind(pages[position]) | ||
| 33 | |||
| 34 | inner class SetupPageViewHolder(val binding: PageSetupBinding) : | 29 | inner class SetupPageViewHolder(val binding: PageSetupBinding) : |
| 35 | RecyclerView.ViewHolder(binding.root), SetupCallback { | 30 | AbstractViewHolder<SetupPage>(binding), SetupCallback { |
| 36 | lateinit var page: SetupPage | 31 | override fun bind(model: SetupPage) { |
| 37 | 32 | if (model.stepCompleted.invoke() == StepState.COMPLETE) { | |
| 38 | init { | ||
| 39 | itemView.tag = this | ||
| 40 | } | ||
| 41 | |||
| 42 | fun bind(page: SetupPage) { | ||
| 43 | this.page = page | ||
| 44 | |||
| 45 | if (page.stepCompleted.invoke() == StepState.COMPLETE) { | ||
| 46 | binding.buttonAction.visibility = View.INVISIBLE | 33 | binding.buttonAction.visibility = View.INVISIBLE |
| 47 | binding.textConfirmation.visibility = View.VISIBLE | 34 | binding.textConfirmation.visibility = View.VISIBLE |
| 48 | } | 35 | } |
| @@ -50,31 +37,31 @@ class SetupAdapter(val activity: AppCompatActivity, val pages: List<SetupPage>) | |||
| 50 | binding.icon.setImageDrawable( | 37 | binding.icon.setImageDrawable( |
| 51 | ResourcesCompat.getDrawable( | 38 | ResourcesCompat.getDrawable( |
| 52 | activity.resources, | 39 | activity.resources, |
| 53 | page.iconId, | 40 | model.iconId, |
| 54 | activity.theme | 41 | activity.theme |
| 55 | ) | 42 | ) |
| 56 | ) | 43 | ) |
| 57 | binding.textTitle.text = activity.resources.getString(page.titleId) | 44 | binding.textTitle.text = activity.resources.getString(model.titleId) |
| 58 | binding.textDescription.text = | 45 | binding.textDescription.text = |
| 59 | Html.fromHtml(activity.resources.getString(page.descriptionId), 0) | 46 | Html.fromHtml(activity.resources.getString(model.descriptionId), 0) |
| 60 | 47 | ||
| 61 | binding.buttonAction.apply { | 48 | binding.buttonAction.apply { |
| 62 | text = activity.resources.getString(page.buttonTextId) | 49 | text = activity.resources.getString(model.buttonTextId) |
| 63 | if (page.buttonIconId != 0) { | 50 | if (model.buttonIconId != 0) { |
| 64 | icon = ResourcesCompat.getDrawable( | 51 | icon = ResourcesCompat.getDrawable( |
| 65 | activity.resources, | 52 | activity.resources, |
| 66 | page.buttonIconId, | 53 | model.buttonIconId, |
| 67 | activity.theme | 54 | activity.theme |
| 68 | ) | 55 | ) |
| 69 | } | 56 | } |
| 70 | iconGravity = | 57 | iconGravity = |
| 71 | if (page.leftAlignedIcon) { | 58 | if (model.leftAlignedIcon) { |
| 72 | MaterialButton.ICON_GRAVITY_START | 59 | MaterialButton.ICON_GRAVITY_START |
| 73 | } else { | 60 | } else { |
| 74 | MaterialButton.ICON_GRAVITY_END | 61 | MaterialButton.ICON_GRAVITY_END |
| 75 | } | 62 | } |
| 76 | setOnClickListener { | 63 | setOnClickListener { |
| 77 | page.buttonAction.invoke(this@SetupPageViewHolder) | 64 | model.buttonAction.invoke(this@SetupPageViewHolder) |
| 78 | } | 65 | } |
| 79 | } | 66 | } |
| 80 | } | 67 | } |