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 c7bd5bfd8..c6bcba59c 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 @@ -1,12 +1,16 @@ package com.github.libretube.ui.adapters import android.annotation.SuppressLint +import android.content.Context 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 +import androidx.recyclerview.widget.RecyclerView.LayoutManager import com.github.libretube.R import com.github.libretube.api.obj.StreamItem import com.github.libretube.constants.PreferenceKeys @@ -27,7 +31,7 @@ class VideosAdapter( private val streamItems: MutableList, private val childFragmentManager: FragmentManager, private val showAllAtOnce: Boolean = true, - private val forceType: Int = FORCE_NONE + private val forceMode: ForceMode = ForceMode.NONE ) : RecyclerView.Adapter() { var index = 10 @@ -55,8 +59,8 @@ class VideosAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VideosViewHolder { val layoutInflater = LayoutInflater.from(parent.context) return when { - forceType == FORCE_TRENDING -> VideosViewHolder(TrendingRowBinding.inflate(layoutInflater, parent, false)) - forceType == FORCE_CHANNEL -> VideosViewHolder(VideoRowBinding.inflate(layoutInflater, parent, false)) + forceMode == ForceMode.TRENDING -> VideosViewHolder(TrendingRowBinding.inflate(layoutInflater, parent, false)) + forceMode == ForceMode.CHANNEL -> VideosViewHolder(VideoRowBinding.inflate(layoutInflater, parent, false)) PreferenceHelper.getBoolean( PreferenceKeys.ALTERNATIVE_VIDEOS_LAYOUT, false @@ -122,7 +126,7 @@ class VideosAdapter( ImageHelper.loadImage(video.thumbnail, thumbnail) - if (forceType != FORCE_CHANNEL) { + if (forceMode != ForceMode.CHANNEL) { ImageHelper.loadImage(video.uploaderAvatar, channelImage) channelName.text = video.uploaderName @@ -152,9 +156,29 @@ class VideosAdapter( } companion object { - const val FORCE_NONE = 0 - const val FORCE_TRENDING = 1 - const val FORCE_NORMAL = 2 - const val FORCE_CHANNEL = 3 + enum class ForceMode { + NONE, + TRENDING, + ROW, + CHANNEL + } + + fun getLayout(context: Context): LayoutManager { + return if (PreferenceHelper.getBoolean( + PreferenceKeys.ALTERNATIVE_VIDEOS_LAYOUT, + false + ) + ) { + LinearLayoutManager(context) + } else { + GridLayoutManager( + context, + PreferenceHelper.getString( + PreferenceKeys.GRID_COLUMNS, + context.resources.getInteger(R.integer.grid_items).toString() + ).toInt() + ) + } + } } } 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 a70df31d8..af450143a 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 @@ -175,7 +175,7 @@ class ChannelFragment : BaseFragment() { channelAdapter = VideosAdapter( response.relatedStreams.orEmpty().toMutableList(), childFragmentManager, - forceType = VideosAdapter.FORCE_CHANNEL + forceMode = VideosAdapter.Companion.ForceMode.CHANNEL ) binding.channelRecView.adapter = channelAdapter } 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 a2c49b88a..648bb4285 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 @@ -16,7 +16,6 @@ import com.github.libretube.extensions.TAG import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.base.BaseFragment -import com.github.libretube.util.LayoutHelper import com.github.libretube.util.LocaleHelper import com.github.libretube.util.PreferenceHelper import com.google.android.material.snackbar.Snackbar @@ -101,7 +100,7 @@ class HomeFragment : BaseFragment() { childFragmentManager ) - binding.recview.layoutManager = LayoutHelper.getVideoLayout(requireContext()) + binding.recview.layoutManager = VideosAdapter.getLayout(requireContext()) } } } 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 390506505..269d625d8 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 @@ -31,7 +31,6 @@ import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope -import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.fasterxml.jackson.databind.ObjectMapper import com.github.libretube.R @@ -331,7 +330,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { // FullScreen button trigger // hide fullscreen button if auto rotation enabled playerBinding.fullscreen.visibility = - if (PlayerHelper.autoRotationEnabled) View.GONE else View.VISIBLE + if (PlayerHelper.autoRotationEnabled) View.INVISIBLE else View.VISIBLE playerBinding.fullscreen.setOnClickListener { // hide player controller exoPlayerView.hideController() @@ -382,8 +381,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { binding.commentsRecView.layoutManager = LinearLayoutManager(view?.context) binding.commentsRecView.setItemViewCacheSize(20) - binding.relatedRecView.layoutManager = - GridLayoutManager(view?.context, resources.getInteger(R.integer.grid_items)) + binding.relatedRecView.layoutManager = VideosAdapter.getLayout(requireContext()) } private fun setFullscreen() { 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 3745164e3..fb03c7af1 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 @@ -18,7 +18,6 @@ import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.models.SubscriptionsViewModel import com.github.libretube.ui.sheets.BaseBottomSheet -import com.github.libretube.util.LayoutHelper import com.github.libretube.util.PreferenceHelper class SubscriptionsFragment : BaseFragment() { @@ -49,7 +48,7 @@ class SubscriptionsFragment : BaseFragment() { binding.subProgress.visibility = View.VISIBLE - binding.subFeed.layoutManager = LayoutHelper.getVideoLayout(requireContext()) + binding.subFeed.layoutManager = VideosAdapter.getLayout(requireContext()) if (viewModel.videoFeed.value == null || !loadFeedInBackground) { viewModel.videoFeed.value = null diff --git a/app/src/main/java/com/github/libretube/util/LayoutHelper.kt b/app/src/main/java/com/github/libretube/util/LayoutHelper.kt index 849946ffd..f8d65ac90 100644 --- a/app/src/main/java/com/github/libretube/util/LayoutHelper.kt +++ b/app/src/main/java/com/github/libretube/util/LayoutHelper.kt @@ -1,26 +1,3 @@ package com.github.libretube.util -import android.content.Context -import androidx.recyclerview.widget.GridLayoutManager -import androidx.recyclerview.widget.LinearLayoutManager -import com.github.libretube.R -import com.github.libretube.constants.PreferenceKeys - -object LayoutHelper { - fun getVideoLayout(context: Context) = if ( - PreferenceHelper.getBoolean( - PreferenceKeys.ALTERNATIVE_VIDEOS_LAYOUT, - false - ) - ) { - LinearLayoutManager(context) - } else { - GridLayoutManager( - context, - PreferenceHelper.getString( - PreferenceKeys.GRID_COLUMNS, - context.resources.getInteger(R.integer.grid_items).toString() - ).toInt() - ) - } -} +object LayoutHelper