diff options
author | t895 <clombardo169@gmail.com> | 2024-01-25 14:03:05 +0100 |
---|---|---|
committer | t895 <clombardo169@gmail.com> | 2024-01-25 14:04:59 +0100 |
commit | 7b01454d5f17bc39484895e95852c751a0efd098 (patch) | |
tree | 6f63f9bc8fc27ae4df9c8889e6a08627d3ebc6a5 /src/android | |
parent | Merge pull request #12781 from goldenx86/dozen (diff) | |
download | yuzu-7b01454d5f17bc39484895e95852c751a0efd098.tar yuzu-7b01454d5f17bc39484895e95852c751a0efd098.tar.gz yuzu-7b01454d5f17bc39484895e95852c751a0efd098.tar.bz2 yuzu-7b01454d5f17bc39484895e95852c751a0efd098.tar.lz yuzu-7b01454d5f17bc39484895e95852c751a0efd098.tar.xz yuzu-7b01454d5f17bc39484895e95852c751a0efd098.tar.zst yuzu-7b01454d5f17bc39484895e95852c751a0efd098.zip |
Diffstat (limited to 'src/android')
3 files changed, 22 insertions, 9 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AbstractDiffAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AbstractDiffAdapter.kt index f006f9e3d..0ab1b46c3 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AbstractDiffAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/AbstractDiffAdapter.kt @@ -14,15 +14,20 @@ import androidx.recyclerview.widget.RecyclerView * Generic adapter that implements an [AsyncDifferConfig] and covers some of the basic boilerplate * code used in every [RecyclerView]. * Type assigned to [Model] must inherit from [Object] in order to be compared properly. + * @param exact Decides whether each item will be compared by reference or by their contents */ -abstract class AbstractDiffAdapter<Model : Any, Holder : AbstractViewHolder<Model>> : - ListAdapter<Model, Holder>(AsyncDifferConfig.Builder(DiffCallback<Model>()).build()) { +abstract class AbstractDiffAdapter<Model : Any, Holder : AbstractViewHolder<Model>>( + exact: Boolean = true +) : ListAdapter<Model, Holder>(AsyncDifferConfig.Builder(DiffCallback<Model>(exact)).build()) { override fun onBindViewHolder(holder: Holder, position: Int) = holder.bind(currentList[position]) - private class DiffCallback<Model> : DiffUtil.ItemCallback<Model>() { + private class DiffCallback<Model>(val exact: Boolean) : DiffUtil.ItemCallback<Model>() { override fun areItemsTheSame(oldItem: Model & Any, newItem: Model & Any): Boolean { - return oldItem === newItem + if (exact) { + return oldItem === newItem + } + return oldItem == newItem } @SuppressLint("DiffUtilEquals") diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt index b4f4d950f..85c8249e6 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt @@ -30,7 +30,7 @@ import org.yuzu.yuzu_emu.utils.GameIconUtils import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder class GameAdapter(private val activity: AppCompatActivity) : - AbstractDiffAdapter<Game, GameAdapter.GameViewHolder>() { + AbstractDiffAdapter<Game, GameAdapter.GameViewHolder>(exact = false) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameViewHolder { CardGameBinding.inflate(LayoutInflater.from(parent.context), parent, false) .also { return GameViewHolder(it) } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt index c8a4a2d17..6859b7780 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt @@ -70,11 +70,19 @@ class Game( } override fun equals(other: Any?): Boolean { - if (other !is Game) { - return false - } + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Game + + if (title != other.title) return false + if (path != other.path) return false + if (programId != other.programId) return false + if (developer != other.developer) return false + if (version != other.version) return false + if (isHomebrew != other.isHomebrew) return false - return hashCode() == other.hashCode() + return true } override fun hashCode(): Int { |