Show all sources in the sources list #90
@ -63,13 +63,6 @@ class SourcesActivity : AppCompatActivity(), DIAware {
|
||||
)
|
||||
binding.recyclerView.adapter = mAdapter
|
||||
mAdapter.notifyDataSetChanged()
|
||||
if (items.isEmpty()) {
|
||||
AmineB marked this conversation as resolved
|
||||
Toast.makeText(
|
||||
this@SourcesActivity,
|
||||
R.string.nothing_here,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
this@SourcesActivity,
|
||||
|
@ -61,9 +61,13 @@ class SourcesListAdapter(
|
||||
binding.sourceTitle.text = itm.title.getHtmlDecoded()
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int) = position.toLong()
|
||||
AmineB
commented
Are these two changes really needed ? Are these two changes really needed ?
davidoskky
commented
Yes, these are the changes that actually solve the problem. Yes, these are the changes that actually solve the problem.
The position keeps getting reset otherwise and that was why we would get a repeating list.
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user
Why was this deleted ?
This is unrelated to the issue, I just removed it since I stumbled upon it while finding a solution.
Just above:
It is thus redundant to print a message if no source is present since we already checked for that and handled it above.