move viewholders to its own package

This commit is contained in:
Bnyro 2022-09-24 12:42:42 +02:00
parent 5b4102ec57
commit a17a9364dc
32 changed files with 172 additions and 66 deletions

View File

@ -6,6 +6,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.BottomSheetItemBinding
import com.github.libretube.obj.BottomSheetItem
import com.github.libretube.ui.viewholders.BottomSheetViewHolder
class BottomSheetAdapter(
private val items: List<BottomSheetItem>,
@ -42,7 +43,3 @@ class BottomSheetAdapter(
return items.size
}
}
class BottomSheetViewHolder(
val binding: BottomSheetItemBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -1,5 +1,6 @@
package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.ViewGroup
@ -10,6 +11,7 @@ import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
import com.github.libretube.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.ChannelViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
@ -35,6 +37,7 @@ class ChannelAdapter(
return ChannelViewHolder(binding)
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) {
val trending = videoFeed[position]
holder.binding.apply {
@ -58,5 +61,3 @@ class ChannelAdapter(
}
}
}
class ChannelViewHolder(val binding: VideoRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.ChapterColumnBinding
import com.github.libretube.ui.viewholders.ChaptersViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.ThemeHelper
import com.google.android.exoplayer2.ExoPlayer
@ -54,5 +55,3 @@ class ChaptersAdapter(
return chapters.size
}
}
class ChaptersViewHolder(val binding: ChapterColumnBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -13,6 +13,7 @@ import com.github.libretube.api.obj.CommentsPage
import com.github.libretube.databinding.CommentsRowBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.formatShort
import com.github.libretube.ui.viewholders.CommentsViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import kotlinx.coroutines.CoroutineScope
@ -106,5 +107,3 @@ class CommentsAdapter(
}
}
}
class CommentsViewHolder(val binding: CommentsRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -10,6 +10,7 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.DownloadedMediaRowBinding
import com.github.libretube.obj.DownloadedFile
import com.github.libretube.ui.activities.OfflinePlayerActivity
import com.github.libretube.ui.viewholders.DownloadsViewHolder
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.File
@ -74,7 +75,3 @@ class DownloadsAdapter(
return files.size
}
}
class DownloadsViewHolder(
val binding: DownloadedMediaRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -5,6 +5,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.LegacySubscriptionChannelBinding
import com.github.libretube.extensions.toID
import com.github.libretube.ui.viewholders.LegacySubscriptionViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
@ -42,7 +43,3 @@ class LegacySubscriptionAdapter(
return subscriptions.size
}
}
class LegacySubscriptionViewHolder(
val binding: LegacySubscriptionChannelBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -7,6 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.databinding.NavOptionsItemBinding
import com.github.libretube.obj.NavBarItem
import com.github.libretube.ui.viewholders.NavBarOptionsViewHolder
class NavBarOptionsAdapter(
val items: MutableList<NavBarItem>
@ -49,7 +50,3 @@ class NavBarOptionsAdapter(
return items.filter { it.isEnabled }.size
}
}
class NavBarOptionsViewHolder(
val binding: NavOptionsItemBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -14,6 +14,7 @@ import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
import com.github.libretube.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.PlaylistViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.PreferenceHelper
@ -97,5 +98,3 @@ class PlaylistAdapter(
}
}
}
class PlaylistViewHolder(val binding: PlaylistRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -11,6 +11,7 @@ import com.github.libretube.api.RetrofitInstance
import com.github.libretube.databinding.PlaylistsRowBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.viewholders.PlaylistsViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.PreferenceHelper
@ -111,5 +112,3 @@ class PlaylistsAdapter(
}
}
}
class PlaylistsViewHolder(val binding: PlaylistsRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -1,11 +1,13 @@
package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.RepliesRowBinding
import com.github.libretube.extensions.formatShort
import com.github.libretube.ui.viewholders.RepliesViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
@ -31,6 +33,7 @@ class RepliesAdapter(
return RepliesViewHolder(binding)
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: RepliesViewHolder, position: Int) {
holder.binding.apply {
val reply = replies[position]
@ -61,5 +64,3 @@ class RepliesAdapter(
return replies.size
}
}
class RepliesViewHolder(val binding: RepliesRowBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -1,5 +1,6 @@
package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -7,6 +8,7 @@ import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.api.obj.SearchItem
import com.github.libretube.databinding.ChannelRowBinding
import com.github.libretube.databinding.PlaylistSearchRowBinding
import com.github.libretube.databinding.VideoRowBinding
@ -16,6 +18,7 @@ import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
import com.github.libretube.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SearchViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import kotlinx.coroutines.CoroutineScope
@ -23,12 +26,12 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class SearchAdapter(
private val searchItems: MutableList<com.github.libretube.api.obj.SearchItem>,
private val searchItems: MutableList<SearchItem>,
private val childFragmentManager: FragmentManager
) :
RecyclerView.Adapter<SearchViewHolder>() {
fun updateItems(newItems: List<com.github.libretube.api.obj.SearchItem>) {
fun updateItems(newItems: List<SearchItem>) {
val searchItemsSize = searchItems.size
searchItems.addAll(newItems)
notifyItemRangeInserted(searchItemsSize, newItems.size)
@ -78,7 +81,7 @@ class SearchAdapter(
}
}
private fun bindWatch(item: com.github.libretube.api.obj.SearchItem, binding: VideoRowBinding) {
private fun bindWatch(item: SearchItem, binding: VideoRowBinding) {
binding.apply {
ImageHelper.loadImage(item.thumbnail, thumbnail)
thumbnailDuration.setFormattedDuration(item.duration!!)
@ -109,8 +112,9 @@ class SearchAdapter(
}
}
@SuppressLint("SetTextI18n")
private fun bindChannel(
item: com.github.libretube.api.obj.SearchItem,
item: SearchItem,
binding: ChannelRowBinding
) {
binding.apply {
@ -160,7 +164,7 @@ class SearchAdapter(
}
private fun bindPlaylist(
item: com.github.libretube.api.obj.SearchItem,
item: SearchItem,
binding: PlaylistSearchRowBinding
) {
binding.apply {
@ -184,21 +188,3 @@ class SearchAdapter(
}
}
}
class SearchViewHolder : RecyclerView.ViewHolder {
var videoRowBinding: VideoRowBinding? = null
var channelRowBinding: ChannelRowBinding? = null
var playlistRowBinding: PlaylistSearchRowBinding? = null
constructor(binding: VideoRowBinding) : super(binding.root) {
videoRowBinding = binding
}
constructor(binding: ChannelRowBinding) : super(binding.root) {
channelRowBinding = binding
}
constructor(binding: PlaylistSearchRowBinding) : super(binding.root) {
playlistRowBinding = binding
}
}

View File

@ -8,6 +8,7 @@ import com.github.libretube.databinding.SearchhistoryRowBinding
import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.db.obj.SearchHistoryItem
import com.github.libretube.extensions.query
import com.github.libretube.ui.viewholders.SearchHistoryViewHolder
class SearchHistoryAdapter(
private var historyList: List<String>,
@ -47,6 +48,3 @@ class SearchHistoryAdapter(
}
}
}
class SearchHistoryViewHolder(val binding: SearchhistoryRowBinding) :
RecyclerView.ViewHolder(binding.root)

View File

@ -5,6 +5,7 @@ import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.SearchsuggestionRowBinding
import com.github.libretube.ui.viewholders.SearchSuggestionsViewHolder
class SearchSuggestionsAdapter(
private var suggestionsList: List<String>,
@ -32,6 +33,3 @@ class SearchSuggestionsAdapter(
}
}
}
class SearchSuggestionsViewHolder(val binding: SearchsuggestionRowBinding) :
RecyclerView.ViewHolder(binding.root)

View File

@ -7,6 +7,7 @@ import com.github.libretube.R
import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.databinding.ChannelSubscriptionRowBinding
import com.github.libretube.extensions.toID
import com.github.libretube.ui.viewholders.SubscriptionChannelViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
@ -50,6 +51,3 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<com.gith
}
}
}
class SubscriptionChannelViewHolder(val binding: ChannelSubscriptionRowBinding) :
RecyclerView.ViewHolder(binding.root)

View File

@ -1,5 +1,6 @@
package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.ViewGroup
@ -11,6 +12,7 @@ import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
import com.github.libretube.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SubscriptionViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
@ -44,6 +46,7 @@ class TrendingAdapter(
return SubscriptionViewHolder(binding)
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) {
val trending = streamItems[position]
holder.binding.apply {
@ -71,6 +74,3 @@ class TrendingAdapter(
}
}
}
class SubscriptionViewHolder(val binding: TrendingRowBinding) :
RecyclerView.ViewHolder(binding.root)

View File

@ -10,6 +10,7 @@ import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.WatchHistoryViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
@ -66,6 +67,3 @@ class WatchHistoryAdapter(
return watchHistory.size
}
}
class WatchHistoryViewHolder(val binding: WatchHistoryRowBinding) :
RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.BottomSheetItemBinding
class BottomSheetViewHolder(
val binding: BottomSheetItemBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.VideoRowBinding
class ChannelViewHolder(
val binding: VideoRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,6 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.ChapterColumnBinding
class ChaptersViewHolder(val binding: ChapterColumnBinding) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.CommentsRowBinding
class CommentsViewHolder(
val binding: CommentsRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.DownloadedMediaRowBinding
class DownloadsViewHolder(
val binding: DownloadedMediaRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.LegacySubscriptionChannelBinding
class LegacySubscriptionViewHolder(
val binding: LegacySubscriptionChannelBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.NavOptionsItemBinding
class NavBarOptionsViewHolder(
val binding: NavOptionsItemBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.PlaylistRowBinding
class PlaylistViewHolder(
val binding: PlaylistRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.PlaylistsRowBinding
class PlaylistsViewHolder(
val binding: PlaylistsRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.RepliesRowBinding
class RepliesViewHolder(
val binding: RepliesRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.SearchhistoryRowBinding
class SearchHistoryViewHolder(
val binding: SearchhistoryRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.SearchsuggestionRowBinding
class SearchSuggestionsViewHolder(
val binding: SearchsuggestionRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,24 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.ChannelRowBinding
import com.github.libretube.databinding.PlaylistSearchRowBinding
import com.github.libretube.databinding.VideoRowBinding
class SearchViewHolder : RecyclerView.ViewHolder {
var videoRowBinding: VideoRowBinding? = null
var channelRowBinding: ChannelRowBinding? = null
var playlistRowBinding: PlaylistSearchRowBinding? = null
constructor(binding: VideoRowBinding) : super(binding.root) {
videoRowBinding = binding
}
constructor(binding: ChannelRowBinding) : super(binding.root) {
channelRowBinding = binding
}
constructor(binding: PlaylistSearchRowBinding) : super(binding.root) {
playlistRowBinding = binding
}
}

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.ChannelSubscriptionRowBinding
class SubscriptionChannelViewHolder(
val binding: ChannelSubscriptionRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.TrendingRowBinding
class SubscriptionViewHolder(
val binding: TrendingRowBinding
) : RecyclerView.ViewHolder(binding.root)

View File

@ -0,0 +1,8 @@
package com.github.libretube.ui.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.WatchHistoryRowBinding
class WatchHistoryViewHolder(
val binding: WatchHistoryRowBinding
) : RecyclerView.ViewHolder(binding.root)