mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
improve home section
This commit is contained in:
parent
42e326f9b8
commit
89be23a858
@ -60,7 +60,7 @@ class VideosAdapter(
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VideosViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
return when {
|
||||
forceMode in listOf(ForceMode.TRENDING, ForceMode.RELATED) -> VideosViewHolder(TrendingRowBinding.inflate(layoutInflater, parent, false))
|
||||
forceMode in listOf(ForceMode.TRENDING, ForceMode.RELATED, ForceMode.HOME) -> VideosViewHolder(TrendingRowBinding.inflate(layoutInflater, parent, false))
|
||||
forceMode == ForceMode.CHANNEL -> VideosViewHolder(VideoRowBinding.inflate(layoutInflater, parent, false))
|
||||
PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.ALTERNATIVE_VIDEOS_LAYOUT,
|
||||
@ -83,11 +83,14 @@ class VideosAdapter(
|
||||
|
||||
// Trending layout
|
||||
holder.trendingRowBinding?.apply {
|
||||
if (forceMode == ForceMode.RELATED) {
|
||||
val params = root.layoutParams
|
||||
params.width = (180).toDp(root.context.resources).toInt()
|
||||
root.layoutParams = params
|
||||
// set a fixed width for better visuals
|
||||
val params = root.layoutParams
|
||||
when (forceMode) {
|
||||
ForceMode.RELATED -> params.width = (180).toDp(root.context.resources).toInt()
|
||||
ForceMode.HOME -> params.width = (250).toDp(root.context.resources).toInt()
|
||||
else -> {}
|
||||
}
|
||||
root.layoutParams = params
|
||||
|
||||
textViewTitle.text = video.title
|
||||
textViewChannel.text =
|
||||
@ -168,7 +171,8 @@ class VideosAdapter(
|
||||
TRENDING,
|
||||
ROW,
|
||||
CHANNEL,
|
||||
RELATED
|
||||
RELATED,
|
||||
HOME
|
||||
}
|
||||
|
||||
fun getLayout(context: Context): LayoutManager {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.ui.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@ -51,29 +50,37 @@ class HomeFragment : BaseFragment() {
|
||||
findNavController().navigate(R.id.libraryFragment)
|
||||
}
|
||||
|
||||
binding.refresh.setOnRefreshListener {
|
||||
binding.refresh.isRefreshing = true
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
fetchHome(LocaleHelper.getTrendingRegion(requireContext()))
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
fetchHome(requireContext(), LocaleHelper.getTrendingRegion(requireContext()))
|
||||
fetchHome(LocaleHelper.getTrendingRegion(requireContext()))
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun fetchHome(context: Context, trendingRegion: String) {
|
||||
private suspend fun fetchHome(trendingRegion: String) {
|
||||
val token = PreferenceHelper.getToken()
|
||||
val appContext = context.applicationContext
|
||||
runOrError(appContext) {
|
||||
runOrError {
|
||||
val feed = SubscriptionHelper.getFeed().withMaxSize(20)
|
||||
if (feed.isEmpty()) return@runOrError
|
||||
runOnUiThread {
|
||||
makeVisible(binding.featuredRV, binding.featuredTV)
|
||||
binding.featuredRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
binding.featuredRV.adapter = VideosAdapter(
|
||||
feed.toMutableList(),
|
||||
childFragmentManager,
|
||||
forceMode = VideosAdapter.Companion.ForceMode.RELATED
|
||||
forceMode = VideosAdapter.Companion.ForceMode.HOME
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
runOrError(appContext) {
|
||||
runOrError {
|
||||
val trending = RetrofitInstance.api.getTrending(trendingRegion).withMaxSize(10)
|
||||
if (trending.isEmpty()) return@runOrError
|
||||
runOnUiThread {
|
||||
makeVisible(binding.trendingRV, binding.trendingTV)
|
||||
binding.trendingRV.layoutManager = GridLayoutManager(context, 2)
|
||||
@ -85,8 +92,9 @@ class HomeFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
runOrError(appContext) {
|
||||
runOrError {
|
||||
val playlists = RetrofitInstance.authApi.getUserPlaylists(token).withMaxSize(20)
|
||||
if (playlists.isEmpty()) return@runOrError
|
||||
runOnUiThread {
|
||||
makeVisible(binding.playlistsRV, binding.playlistsTV)
|
||||
binding.playlistsRV.layoutManager = LinearLayoutManager(context)
|
||||
@ -105,12 +113,12 @@ class HomeFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun runOrError(context: Context, action: suspend () -> Unit) {
|
||||
private fun runOrError(action: suspend () -> Unit) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
action.invoke()
|
||||
} catch (e: Exception) {
|
||||
e.localizedMessage?.let { context.toastFromMainThread(it) }
|
||||
e.localizedMessage?.let { context?.toastFromMainThread(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,5 +128,7 @@ class HomeFragment : BaseFragment() {
|
||||
it.visibility = View.VISIBLE
|
||||
}
|
||||
binding.progress.visibility = View.GONE
|
||||
binding.scroll.visibility = View.VISIBLE
|
||||
binding.refresh.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.github.libretube.ui.models
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.SubscriptionHelper
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.api.obj.Subscription
|
||||
|
@ -9,64 +9,72 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scroll"
|
||||
<com.github.libretube.ui.views.CustomSwipeToRefresh
|
||||
android:id="@+id/refresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
<ScrollView
|
||||
android:id="@+id/scroll"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="10dp">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/featuredTV"
|
||||
style="@style/HomeCategoryTitle"
|
||||
android:text="@string/featured" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/featuredRV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/trendingTV"
|
||||
style="@style/HomeCategoryTitle"
|
||||
android:text="@string/trending" />
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/featuredTV"
|
||||
style="@style/HomeCategoryTitle"
|
||||
android:text="@string/featured" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/trendingRV"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/featuredRV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:id="@+id/trendingTV"
|
||||
style="@style/HomeCategoryTitle"
|
||||
android:text="@string/trending" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/playlistsTV"
|
||||
style="@style/HomeCategoryTitle"
|
||||
android:text="@string/playlists" />
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/playlistsRV"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/trendingRV"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
||||
<TextView
|
||||
android:id="@+id/playlistsTV"
|
||||
style="@style/HomeCategoryTitle"
|
||||
android:text="@string/playlists" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/playlistsRV"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</com.github.libretube.ui.views.CustomSwipeToRefresh>
|
||||
|
||||
</FrameLayout>
|
Loading…
x
Reference in New Issue
Block a user