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>) { fun updateItems(newItems: List<StreamItem>) {
val oldSize = videoFeed.size
videoFeed.addAll(newItems) videoFeed.addAll(newItems)
notifyDataSetChanged() notifyItemRangeInserted(oldSize, videoFeed.size)
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistViewHolder {

View File

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

View File

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

View File

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

View File

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