forked from Louvorg/ReaderForSelfoss-multiplatform
		
	Fix repeating items in recyclerview
This commit is contained in:
		| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user