remove bad performing notifydatasetchanged

This commit is contained in:
Bnyro 2022-09-18 19:29:18 +02:00
parent 8f5de822d1
commit ba21ebb99e
5 changed files with 12 additions and 6 deletions

View File

@ -38,8 +38,9 @@ class PlaylistAdapter(
}
fun updateItems(newItems: List<StreamItem>) {
val oldSize = videoFeed.size
videoFeed.addAll(newItems)
notifyDataSetChanged()
notifyItemRangeInserted(oldSize, videoFeed.size)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistViewHolder {

View File

@ -34,8 +34,9 @@ class PlaylistsAdapter(
}
fun updateItems(newItems: List<Playlists>) {
val oldSize = playlists.size
playlists.addAll(newItems)
notifyDataSetChanged()
notifyItemRangeInserted(oldSize, playlists.size)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistsViewHolder {
@ -102,7 +103,9 @@ class PlaylistsAdapter(
try {
if (response.message == "ok") {
playlists.removeAt(position)
activity.runOnUiThread { notifyDataSetChanged() }
activity.runOnUiThread {
notifyItemRemoved(position)
}
}
} catch (e: Exception) {
Log.e(TAG(), e.toString())

View File

@ -30,13 +30,14 @@ class SearchHistoryAdapter(
historyText.text = historyQuery
deleteHistory.setOnClickListener {
val itemIndex = historyList.indexOf(historyQuery)
historyList -= historyQuery
Thread {
Database.searchHistoryDao().delete(
SearchHistoryItem(query = historyQuery)
)
}.start()
notifyDataSetChanged()
notifyItemRemoved(itemIndex)
}
root.setOnClickListener {

View File

@ -34,8 +34,9 @@ class TrendingAdapter(
}
fun updateItems() {
val oldSize = index
index += 10
notifyDataSetChanged()
notifyItemRangeInserted(oldSize, index)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder {

View File

@ -22,7 +22,7 @@ class WatchHistoryAdapter(
fun removeFromWatchHistory(position: Int) {
DatabaseHelper.removeFromWatchHistory(position)
watchHistory.removeAt(position)
notifyDataSetChanged()
notifyItemRemoved(position)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {