From 888b68e566ae90215485fdd837326c6f2f7e0e6b Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 5 Aug 2023 18:44:10 +0200 Subject: [PATCH] chore: simplify RecyclerView.Adapter#getItemCount where possible --- .../com/github/libretube/ui/adapters/BottomSheetAdapter.kt | 4 +--- .../java/com/github/libretube/ui/adapters/CommentsAdapter.kt | 4 +--- .../java/com/github/libretube/ui/adapters/DownloadsAdapter.kt | 4 +--- .../com/github/libretube/ui/adapters/IconsSheetAdapter.kt | 4 +--- .../github/libretube/ui/adapters/LegacySubscriptionAdapter.kt | 4 +--- .../com/github/libretube/ui/adapters/NavBarOptionsAdapter.kt | 4 +--- .../com/github/libretube/ui/adapters/PlayingQueueAdapter.kt | 4 +--- .../java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt | 4 +--- .../com/github/libretube/ui/adapters/SearchHistoryAdapter.kt | 4 +--- .../github/libretube/ui/adapters/SearchSuggestionsAdapter.kt | 4 +--- .../libretube/ui/adapters/SubscriptionChannelAdapter.kt | 4 +--- .../com/github/libretube/ui/adapters/WatchHistoryAdapter.kt | 2 +- 12 files changed, 12 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/BottomSheetAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/BottomSheetAdapter.kt index b58462ce4..f48017d03 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/BottomSheetAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/BottomSheetAdapter.kt @@ -35,7 +35,5 @@ class BottomSheetAdapter( } } - override fun getItemCount(): Int { - return items.size - } + override fun getItemCount() = items.size } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index 90b4f4195..e426da06a 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -134,7 +134,5 @@ class CommentsAdapter( } } - override fun getItemCount(): Int { - return comments.size - } + override fun getItemCount() = comments.size } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt index 122cf65d0..8d43203bc 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt @@ -141,7 +141,5 @@ class DownloadsAdapter( notifyItemInserted(position) } - override fun getItemCount(): Int { - return downloads.size - } + override fun getItemCount() = downloads.size } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/IconsSheetAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/IconsSheetAdapter.kt index 807e8c867..41ba6fc91 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/IconsSheetAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/IconsSheetAdapter.kt @@ -18,9 +18,7 @@ class IconsSheetAdapter : RecyclerView.Adapter() { return IconsSheetViewHolder(binding) } - override fun getItemCount(): Int { - return availableIcons.size - } + override fun getItemCount() = availableIcons.size override fun onBindViewHolder(holder: IconsSheetViewHolder, position: Int) { val appIcon = availableIcons[position] diff --git a/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt index 6fed50ccc..3d8114638 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt @@ -47,7 +47,5 @@ class LegacySubscriptionAdapter( } } - override fun getItemCount(): Int { - return subscriptions.size - } + override fun getItemCount() = subscriptions.size } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/NavBarOptionsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/NavBarOptionsAdapter.kt index 8c12b0a69..f8ea9fe70 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/NavBarOptionsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/NavBarOptionsAdapter.kt @@ -22,9 +22,7 @@ class NavBarOptionsAdapter( return NavBarOptionsViewHolder(binding) } - override fun getItemCount(): Int { - return items.size - } + override fun getItemCount() = items.size override fun onBindViewHolder(holder: NavBarOptionsViewHolder, position: Int) { val item = items[position] diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlayingQueueAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlayingQueueAdapter.kt index dec3d6921..4a38cd38f 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlayingQueueAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlayingQueueAdapter.kt @@ -24,9 +24,7 @@ class PlayingQueueAdapter : RecyclerView.Adapter() { return PlayingQueueViewHolder(binding) } - override fun getItemCount(): Int { - return PlayingQueue.size() - } + override fun getItemCount() = PlayingQueue.size() @SuppressLint("SetTextI18n") override fun onBindViewHolder(holder: PlayingQueueViewHolder, position: Int) { diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt index 3b82baab7..fb583a2e8 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt @@ -18,9 +18,7 @@ class PlaylistsAdapter( private val playlistType: PlaylistType ) : RecyclerView.Adapter() { - override fun getItemCount(): Int { - return playlists.size - } + override fun getItemCount() = playlists.size fun updateItems(newItems: List) { val oldSize = playlists.size diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt index 7054f4a6e..cf2097bce 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt @@ -18,9 +18,7 @@ class SearchHistoryAdapter( ) : RecyclerView.Adapter() { - override fun getItemCount(): Int { - return historyList.size - } + override fun getItemCount() = historyList.size override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder { val layoutInflater = LayoutInflater.from(parent.context) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SearchSuggestionsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SearchSuggestionsAdapter.kt index cdc5508c8..1cf707125 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SearchSuggestionsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SearchSuggestionsAdapter.kt @@ -13,9 +13,7 @@ class SearchSuggestionsAdapter( ) : RecyclerView.Adapter() { - override fun getItemCount(): Int { - return suggestionsList.size - } + override fun getItemCount() = suggestionsList.size override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionsViewHolder { val layoutInflater = LayoutInflater.from(parent.context) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt index 2f090910e..09bbd69a2 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt @@ -17,9 +17,7 @@ class SubscriptionChannelAdapter( private val subscriptions: MutableList ) : RecyclerView.Adapter() { - override fun getItemCount(): Int { - return subscriptions.size - } + override fun getItemCount() = subscriptions.size override fun onCreateViewHolder( parent: ViewGroup, diff --git a/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt index b0d40ec04..020879aee 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt @@ -24,7 +24,7 @@ class WatchHistoryAdapter( private var visibleCount = minOf(10, watchHistory.size) - override fun getItemCount(): Int = visibleCount + override fun getItemCount() = visibleCount fun removeFromWatchHistory(position: Int) { val history = watchHistory[position]