Merge pull request #4379 from Bnyro/master

chore: simplify RecyclerView.Adapter#getItemCount where possible
This commit is contained in:
Bnyro 2023-08-05 18:43:29 +02:00 committed by GitHub
commit 18698b4b62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 12 additions and 34 deletions

View File

@ -35,7 +35,5 @@ class BottomSheetAdapter(
} }
} }
override fun getItemCount(): Int { override fun getItemCount() = items.size
return items.size
}
} }

View File

@ -134,7 +134,5 @@ class CommentsAdapter(
} }
} }
override fun getItemCount(): Int { override fun getItemCount() = comments.size
return comments.size
}
} }

View File

@ -141,7 +141,5 @@ class DownloadsAdapter(
notifyItemInserted(position) notifyItemInserted(position)
} }
override fun getItemCount(): Int { override fun getItemCount() = downloads.size
return downloads.size
}
} }

View File

@ -18,9 +18,7 @@ class IconsSheetAdapter : RecyclerView.Adapter<IconsSheetViewHolder>() {
return IconsSheetViewHolder(binding) return IconsSheetViewHolder(binding)
} }
override fun getItemCount(): Int { override fun getItemCount() = availableIcons.size
return availableIcons.size
}
override fun onBindViewHolder(holder: IconsSheetViewHolder, position: Int) { override fun onBindViewHolder(holder: IconsSheetViewHolder, position: Int) {
val appIcon = availableIcons[position] val appIcon = availableIcons[position]

View File

@ -47,7 +47,5 @@ class LegacySubscriptionAdapter(
} }
} }
override fun getItemCount(): Int { override fun getItemCount() = subscriptions.size
return subscriptions.size
}
} }

View File

@ -22,9 +22,7 @@ class NavBarOptionsAdapter(
return NavBarOptionsViewHolder(binding) return NavBarOptionsViewHolder(binding)
} }
override fun getItemCount(): Int { override fun getItemCount() = items.size
return items.size
}
override fun onBindViewHolder(holder: NavBarOptionsViewHolder, position: Int) { override fun onBindViewHolder(holder: NavBarOptionsViewHolder, position: Int) {
val item = items[position] val item = items[position]

View File

@ -24,9 +24,7 @@ class PlayingQueueAdapter : RecyclerView.Adapter<PlayingQueueViewHolder>() {
return PlayingQueueViewHolder(binding) return PlayingQueueViewHolder(binding)
} }
override fun getItemCount(): Int { override fun getItemCount() = PlayingQueue.size()
return PlayingQueue.size()
}
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: PlayingQueueViewHolder, position: Int) { override fun onBindViewHolder(holder: PlayingQueueViewHolder, position: Int) {

View File

@ -18,9 +18,7 @@ class PlaylistsAdapter(
private val playlistType: PlaylistType private val playlistType: PlaylistType
) : RecyclerView.Adapter<PlaylistsViewHolder>() { ) : RecyclerView.Adapter<PlaylistsViewHolder>() {
override fun getItemCount(): Int { override fun getItemCount() = playlists.size
return playlists.size
}
fun updateItems(newItems: List<Playlists>) { fun updateItems(newItems: List<Playlists>) {
val oldSize = playlists.size val oldSize = playlists.size

View File

@ -18,9 +18,7 @@ class SearchHistoryAdapter(
) : ) :
RecyclerView.Adapter<SuggestionsViewHolder>() { RecyclerView.Adapter<SuggestionsViewHolder>() {
override fun getItemCount(): Int { override fun getItemCount() = historyList.size
return historyList.size
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)

View File

@ -13,9 +13,7 @@ class SearchSuggestionsAdapter(
) : ) :
RecyclerView.Adapter<SuggestionsViewHolder>() { RecyclerView.Adapter<SuggestionsViewHolder>() {
override fun getItemCount(): Int { override fun getItemCount() = suggestionsList.size
return suggestionsList.size
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder {
val layoutInflater = LayoutInflater.from(parent.context) val layoutInflater = LayoutInflater.from(parent.context)

View File

@ -17,9 +17,7 @@ class SubscriptionChannelAdapter(
private val subscriptions: MutableList<Subscription> private val subscriptions: MutableList<Subscription>
) : RecyclerView.Adapter<SubscriptionChannelViewHolder>() { ) : RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
override fun getItemCount(): Int { override fun getItemCount() = subscriptions.size
return subscriptions.size
}
override fun onCreateViewHolder( override fun onCreateViewHolder(
parent: ViewGroup, parent: ViewGroup,

View File

@ -24,7 +24,7 @@ class WatchHistoryAdapter(
private var visibleCount = minOf(10, watchHistory.size) private var visibleCount = minOf(10, watchHistory.size)
override fun getItemCount(): Int = visibleCount override fun getItemCount() = visibleCount
fun removeFromWatchHistory(position: Int) { fun removeFromWatchHistory(position: Int) {
val history = watchHistory[position] val history = watchHistory[position]