From 792950be7c79442d6b8fbdec8d97a55854cd62f3 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 1 Nov 2022 19:52:43 +0100 Subject: [PATCH 1/2] Remove unreachable condition --- .../apps/readerforselfossv2/android/SourcesActivity.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt index 4cce83e..5e3813b 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt @@ -63,13 +63,6 @@ class SourcesActivity : AppCompatActivity(), DIAware { ) binding.recyclerView.adapter = mAdapter mAdapter.notifyDataSetChanged() - if (items.isEmpty()) { - Toast.makeText( - this@SourcesActivity, - R.string.nothing_here, - Toast.LENGTH_SHORT - ).show() - } } else { Toast.makeText( this@SourcesActivity, From 6d610ed61aa82f7d491af110b075f0a47689e6c5 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 1 Nov 2022 19:53:22 +0100 Subject: [PATCH 2/2] Fix repeating items in recyclerview --- .../android/adapters/SourcesListAdapter.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt index 19b800a..906057d 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt @@ -61,9 +61,13 @@ class SourcesListAdapter( binding.sourceTitle.text = itm.title.getHtmlDecoded() } + override fun getItemId(position: Int) = position.toLong() + + override fun getItemViewType(position: Int) = position + override fun getItemCount(): Int = items.size - inner class ViewHolder(internal val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) { + inner class ViewHolder(private val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) { init { handleClickListeners() @@ -74,13 +78,13 @@ class SourcesListAdapter( val deleteBtn: Button = mView.findViewById(R.id.deleteBtn) deleteBtn.setOnClickListener { - val (id) = items[adapterPosition] + val (id) = items[bindingAdapterPosition] CoroutineScope(Dispatchers.IO).launch { val successfullyDeletedSource = repository.deleteSource(id) if (successfullyDeletedSource) { - items.removeAt(adapterPosition) - notifyItemRemoved(adapterPosition) - notifyItemRangeChanged(adapterPosition, itemCount) + items.removeAt(bindingAdapterPosition) + notifyItemRemoved(bindingAdapterPosition) + notifyItemRangeChanged(bindingAdapterPosition, itemCount) } else { Toast.makeText( app,