From 01dee2280209ddeab92c2955cf9f621081368200 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 19 Nov 2022 11:19:07 +0100 Subject: [PATCH] cleanup adapters --- .../github/libretube/ui/adapters/ChaptersAdapter.kt | 3 ++- .../github/libretube/ui/adapters/PlaylistAdapter.kt | 10 ++++++---- .../github/libretube/ui/adapters/PlaylistsAdapter.kt | 7 +++---- .../com/github/libretube/ui/adapters/SearchAdapter.kt | 9 ++++----- .../com/github/libretube/ui/adapters/VideosAdapter.kt | 7 +++---- .../libretube/ui/adapters/WatchHistoryAdapter.kt | 7 +++---- .../github/libretube/ui/fragments/ChannelFragment.kt | 4 +--- .../com/github/libretube/ui/fragments/HomeFragment.kt | 4 +--- .../github/libretube/ui/fragments/LibraryFragment.kt | 3 +-- .../github/libretube/ui/fragments/PlayerFragment.kt | 4 +--- .../github/libretube/ui/fragments/PlaylistFragment.kt | 3 +-- .../libretube/ui/fragments/SearchResultFragment.kt | 2 +- .../libretube/ui/fragments/SubscriptionsFragment.kt | 1 - .../github/libretube/ui/fragments/TrendsFragment.kt | 3 +-- .../libretube/ui/fragments/WatchHistoryFragment.kt | 3 +-- 15 files changed, 29 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt index 16caf2ecc..8b7f64a68 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt @@ -5,6 +5,7 @@ import android.text.format.DateUtils import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.api.obj.ChapterSegment import com.github.libretube.databinding.ChapterColumnBinding import com.github.libretube.ui.viewholders.ChaptersViewHolder import com.github.libretube.util.ImageHelper @@ -12,7 +13,7 @@ import com.github.libretube.util.ThemeHelper import com.google.android.exoplayer2.ExoPlayer class ChaptersAdapter( - private val chapters: List, + private val chapters: List, private val exoPlayer: ExoPlayer ) : RecyclerView.Adapter() { private var selectedPosition = 0 diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt index e2eec73c9..1d8780f58 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt @@ -6,7 +6,6 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.obj.PlaylistId @@ -14,6 +13,7 @@ import com.github.libretube.api.obj.StreamItem import com.github.libretube.databinding.PlaylistRowBinding import com.github.libretube.extensions.TAG import com.github.libretube.extensions.toID +import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.sheets.VideoOptionsBottomSheet @@ -30,8 +30,7 @@ import java.io.IOException class PlaylistAdapter( private val videoFeed: MutableList, private val playlistId: String, - private val isOwner: Boolean, - private val childFragmentManager: FragmentManager + private val isOwner: Boolean ) : RecyclerView.Adapter() { override fun getItemCount(): Int { @@ -64,7 +63,10 @@ class PlaylistAdapter( val videoName = streamItem.title!! root.setOnLongClickListener { VideoOptionsBottomSheet(videoId, videoName) - .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) + .show( + (root.context as BaseActivity).supportFragmentManager, + VideoOptionsBottomSheet::class.java.name + ) true } 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 52440e9d6..0169c0b95 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 @@ -4,7 +4,6 @@ import android.app.Activity import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R import com.github.libretube.api.RetrofitInstance @@ -12,6 +11,7 @@ import com.github.libretube.api.obj.PlaylistId import com.github.libretube.api.obj.Playlists import com.github.libretube.databinding.PlaylistsRowBinding import com.github.libretube.extensions.TAG +import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet import com.github.libretube.ui.viewholders.PlaylistsViewHolder import com.github.libretube.util.ImageHelper @@ -25,8 +25,7 @@ import retrofit2.HttpException import java.io.IOException class PlaylistsAdapter( - private val playlists: MutableList, - private val childFragmentManager: FragmentManager + private val playlists: MutableList ) : RecyclerView.Adapter() { override fun getItemCount(): Int { @@ -81,7 +80,7 @@ class PlaylistsAdapter( isOwner = true ) playlistOptionsDialog.show( - childFragmentManager, + (root.context as BaseActivity).supportFragmentManager, PlaylistOptionsBottomSheet::class.java.name ) true diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt index 75a985a43..395e0dc8e 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt @@ -4,7 +4,6 @@ import android.annotation.SuppressLint import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.R import com.github.libretube.api.obj.ContentItem @@ -13,6 +12,7 @@ import com.github.libretube.databinding.PlaylistsRowBinding import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.toID +import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.extensions.setupSubscriptionButton @@ -24,8 +24,7 @@ import com.github.libretube.util.NavigationHelper import com.github.libretube.util.TextUtils class SearchAdapter( - private val searchItems: MutableList, - private val childFragmentManager: FragmentManager + private val searchItems: MutableList ) : RecyclerView.Adapter() { @@ -101,7 +100,7 @@ class SearchAdapter( val videoName = item.title!! root.setOnLongClickListener { VideoOptionsBottomSheet(videoId, videoName) - .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) + .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name) true } channelContainer.setOnClickListener { @@ -148,7 +147,7 @@ class SearchAdapter( val playlistId = item.url!!.toID() val playlistName = item.name!! PlaylistOptionsBottomSheet(playlistId, playlistName, false) - .show(childFragmentManager, PlaylistOptionsBottomSheet::class.java.name) + .show((root.context as BaseActivity).supportFragmentManager, PlaylistOptionsBottomSheet::class.java.name) true } } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt index c55762cda..55175357d 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt @@ -6,7 +6,6 @@ import android.text.format.DateUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -19,6 +18,7 @@ import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.toDp import com.github.libretube.extensions.toID +import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.sheets.VideoOptionsBottomSheet @@ -30,7 +30,6 @@ import com.github.libretube.util.TextUtils class VideosAdapter( private val streamItems: MutableList, - private val childFragmentManager: FragmentManager, private val showAllAtOnce: Boolean = true, private val forceMode: ForceMode = ForceMode.NONE ) : RecyclerView.Adapter() { @@ -113,7 +112,7 @@ class VideosAdapter( if (videoId == null || videoName == null) return@setOnLongClickListener true VideoOptionsBottomSheet(videoId, videoName) - .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) + .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name) true } @@ -154,7 +153,7 @@ class VideosAdapter( root.setOnLongClickListener { if (videoId == null || videoName == null) return@setOnLongClickListener true VideoOptionsBottomSheet(videoId, videoName) - .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) + .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name) true } 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 dfec905cb..fcdeb76ea 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 @@ -2,11 +2,11 @@ package com.github.libretube.ui.adapters import android.view.LayoutInflater import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.databinding.WatchHistoryRowBinding import com.github.libretube.db.DatabaseHolder import com.github.libretube.db.obj.WatchHistoryItem +import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.sheets.VideoOptionsBottomSheet @@ -15,8 +15,7 @@ import com.github.libretube.util.ImageHelper import com.github.libretube.util.NavigationHelper class WatchHistoryAdapter( - private val watchHistory: MutableList, - private val childFragmentManager: FragmentManager + private val watchHistory: MutableList ) : RecyclerView.Adapter() { @@ -56,7 +55,7 @@ class WatchHistoryAdapter( } root.setOnLongClickListener { VideoOptionsBottomSheet(video.videoId, video.title!!) - .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) + .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name) true } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt index a9cb01a24..fdf17ffbc 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt @@ -183,7 +183,6 @@ class ChannelFragment : BaseFragment() { // recyclerview of the videos by the channel channelAdapter = VideosAdapter( response.relatedStreams.orEmpty().toMutableList(), - childFragmentManager, forceMode = VideosAdapter.Companion.ForceMode.CHANNEL ) binding.channelRecView.adapter = channelAdapter @@ -229,8 +228,7 @@ class ChannelFragment : BaseFragment() { } val adapter = SearchAdapter( - response.content.toMutableList(), - childFragmentManager + response.content.toMutableList() ) runOnUiThread { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt index e40ccf5fc..82fcefa5d 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt @@ -80,7 +80,6 @@ class HomeFragment : BaseFragment() { binding.featuredRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) binding.featuredRV.adapter = VideosAdapter( feed.toMutableList(), - childFragmentManager, forceMode = VideosAdapter.Companion.ForceMode.HOME ) } @@ -96,7 +95,6 @@ class HomeFragment : BaseFragment() { binding.trendingRV.layoutManager = GridLayoutManager(context, 2) binding.trendingRV.adapter = VideosAdapter( trending.toMutableList(), - childFragmentManager, forceMode = VideosAdapter.Companion.ForceMode.TRENDING ) } @@ -109,7 +107,7 @@ class HomeFragment : BaseFragment() { runOnUiThread { makeVisible(binding.playlistsRV, binding.playlistsTV) binding.playlistsRV.layoutManager = LinearLayoutManager(context) - binding.playlistsRV.adapter = PlaylistsAdapter(playlists.toMutableList(), childFragmentManager) + binding.playlistsRV.adapter = PlaylistsAdapter(playlists.toMutableList()) binding.playlistsRV.adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt index d217feb83..8799979da 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt @@ -135,8 +135,7 @@ class LibraryFragment : BaseFragment() { } val playlistsAdapter = PlaylistsAdapter( - playlists.toMutableList(), - childFragmentManager + playlists.toMutableList() ) // listen for playlists to become deleted diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index f7ca045e2..441fe1b13 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -977,13 +977,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { if (PlayerHelper.alternativeVideoLayout) { binding.alternativeTrendingRec.adapter = VideosAdapter( relatedStreams.orEmpty().toMutableList(), - childFragmentManager, forceMode = VideosAdapter.Companion.ForceMode.RELATED ) } else { binding.relatedRecView.adapter = VideosAdapter( - relatedStreams.orEmpty().toMutableList(), - childFragmentManager + relatedStreams.orEmpty().toMutableList() ) } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index 1da15f3af..cfbde5dc0 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -157,8 +157,7 @@ class PlaylistFragment : BaseFragment() { playlistAdapter = PlaylistAdapter( response.relatedStreams.orEmpty().toMutableList(), playlistId!!, - isOwner, - childFragmentManager + isOwner ) // listen for playlist items to become deleted diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt index 0fcbb0da2..780c29f1b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt @@ -96,7 +96,7 @@ class SearchResultFragment : BaseFragment() { runOnUiThread { if (response.items?.isNotEmpty() == true) { binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext()) - searchAdapter = SearchAdapter(response.items, childFragmentManager) + searchAdapter = SearchAdapter(response.items) binding.searchRecycler.adapter = searchAdapter } else { binding.searchContainer.visibility = View.GONE diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index fb03c7af1..55d1e918b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -155,7 +155,6 @@ class SubscriptionsFragment : BaseFragment() { binding.subProgress.visibility = View.GONE subscriptionAdapter = VideosAdapter( sortedFeed.toMutableList(), - childFragmentManager, showAllAtOnce = false ) binding.subFeed.adapter = subscriptionAdapter diff --git a/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt index adc7b2251..317d281f2 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/TrendsFragment.kt @@ -85,8 +85,7 @@ class TrendsFragment : BaseFragment() { } binding.recview.adapter = VideosAdapter( - response.toMutableList(), - childFragmentManager + response.toMutableList() ) binding.recview.layoutManager = VideosAdapter.getLayout(requireContext()) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt index 2a291b0da..623415cdc 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt @@ -41,8 +41,7 @@ class WatchHistoryFragment : BaseFragment() { } val watchHistoryAdapter = WatchHistoryAdapter( - watchHistory.toMutableList(), - childFragmentManager + watchHistory.toMutableList() ) val itemTouchCallback = object : ItemTouchHelper.SimpleCallback(