mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #2569 from Bnyro/master
Add playlist bookmarks to the library fragment
This commit is contained in:
commit
214da70890
@ -1,41 +0,0 @@
|
|||||||
package com.github.libretube.ui.fragments
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import com.github.libretube.databinding.FragmentBookmarksBinding
|
|
||||||
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
|
||||||
import com.github.libretube.extensions.awaitQuery
|
|
||||||
import com.github.libretube.ui.adapters.PlaylistBookmarkAdapter
|
|
||||||
import com.github.libretube.ui.base.BaseFragment
|
|
||||||
|
|
||||||
class BookmarksFragment : BaseFragment() {
|
|
||||||
private lateinit var binding: FragmentBookmarksBinding
|
|
||||||
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater,
|
|
||||||
container: ViewGroup?,
|
|
||||||
savedInstanceState: Bundle?
|
|
||||||
): View {
|
|
||||||
binding = FragmentBookmarksBinding.inflate(layoutInflater)
|
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
val bookmarks = awaitQuery {
|
|
||||||
Database.playlistBookmarkDao().getAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bookmarks.isEmpty()) return
|
|
||||||
|
|
||||||
binding.bookmarksRV.layoutManager = LinearLayoutManager(context)
|
|
||||||
binding.bookmarksRV.adapter = PlaylistBookmarkAdapter(bookmarks)
|
|
||||||
|
|
||||||
binding.bookmarksRV.visibility = View.VISIBLE
|
|
||||||
binding.emptyBookmarks.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,6 @@ import com.github.libretube.ui.adapters.VideosAdapter
|
|||||||
import com.github.libretube.ui.base.BaseFragment
|
import com.github.libretube.ui.base.BaseFragment
|
||||||
import com.github.libretube.ui.extensions.withMaxSize
|
import com.github.libretube.ui.extensions.withMaxSize
|
||||||
import com.github.libretube.util.LocaleHelper
|
import com.github.libretube.util.LocaleHelper
|
||||||
import com.github.libretube.util.PreferenceHelper
|
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -57,7 +56,7 @@ class HomeFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.bookmarksTV.setOnClickListener {
|
binding.bookmarksTV.setOnClickListener {
|
||||||
findNavController().navigate(R.id.bookmarksFragment)
|
findNavController().navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.refresh.setOnRefreshListener {
|
binding.refresh.setOnRefreshListener {
|
||||||
@ -73,7 +72,6 @@ class HomeFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun fetchHome() {
|
private suspend fun fetchHome() {
|
||||||
val token = PreferenceHelper.getToken()
|
|
||||||
runOrError {
|
runOrError {
|
||||||
val feed = SubscriptionHelper.getFeed().withMaxSize(20)
|
val feed = SubscriptionHelper.getFeed().withMaxSize(20)
|
||||||
if (feed.isEmpty()) return@runOrError
|
if (feed.isEmpty()) return@runOrError
|
||||||
|
@ -15,8 +15,11 @@ import com.github.libretube.R
|
|||||||
import com.github.libretube.api.PlaylistsHelper
|
import com.github.libretube.api.PlaylistsHelper
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.databinding.FragmentLibraryBinding
|
import com.github.libretube.databinding.FragmentLibraryBinding
|
||||||
|
import com.github.libretube.db.DatabaseHolder
|
||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
|
import com.github.libretube.extensions.awaitQuery
|
||||||
import com.github.libretube.extensions.toPixel
|
import com.github.libretube.extensions.toPixel
|
||||||
|
import com.github.libretube.ui.adapters.PlaylistBookmarkAdapter
|
||||||
import com.github.libretube.ui.adapters.PlaylistsAdapter
|
import com.github.libretube.ui.adapters.PlaylistsAdapter
|
||||||
import com.github.libretube.ui.base.BaseFragment
|
import com.github.libretube.ui.base.BaseFragment
|
||||||
import com.github.libretube.ui.dialogs.CreatePlaylistDialog
|
import com.github.libretube.ui.dialogs.CreatePlaylistDialog
|
||||||
@ -41,13 +44,15 @@ class LibraryFragment : BaseFragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
// initialize the layout managers
|
||||||
|
binding.bookmarksRecView.layoutManager = LinearLayoutManager(context)
|
||||||
|
binding.playlistRecView.layoutManager = LinearLayoutManager(context)
|
||||||
|
|
||||||
// listen for the mini player state changing
|
// listen for the mini player state changing
|
||||||
playerViewModel.isMiniPlayerVisible.observe(viewLifecycleOwner) {
|
playerViewModel.isMiniPlayerVisible.observe(viewLifecycleOwner) {
|
||||||
updateFABMargin(it)
|
updateFABMargin(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.playlistRecView.layoutManager = LinearLayoutManager(requireContext())
|
|
||||||
|
|
||||||
// hide watch history button of history disabled
|
// hide watch history button of history disabled
|
||||||
val watchHistoryEnabled =
|
val watchHistoryEnabled =
|
||||||
PreferenceHelper.getBoolean(PreferenceKeys.WATCH_HISTORY_TOGGLE, true)
|
PreferenceHelper.getBoolean(PreferenceKeys.WATCH_HISTORY_TOGGLE, true)
|
||||||
@ -59,10 +64,6 @@ class LibraryFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.bookmarks.setOnClickListener {
|
|
||||||
findNavController().navigate(R.id.bookmarksFragment)
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.downloads.setOnClickListener {
|
binding.downloads.setOnClickListener {
|
||||||
findNavController().navigate(R.id.downloadsFragment)
|
findNavController().navigate(R.id.downloadsFragment)
|
||||||
}
|
}
|
||||||
@ -73,10 +74,12 @@ class LibraryFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchPlaylists()
|
fetchPlaylists()
|
||||||
|
initBookmarks()
|
||||||
|
|
||||||
binding.playlistRefresh.isEnabled = true
|
binding.playlistRefresh.isEnabled = true
|
||||||
binding.playlistRefresh.setOnRefreshListener {
|
binding.playlistRefresh.setOnRefreshListener {
|
||||||
fetchPlaylists()
|
fetchPlaylists()
|
||||||
|
initBookmarks()
|
||||||
}
|
}
|
||||||
binding.createPlaylist.setOnClickListener {
|
binding.createPlaylist.setOnClickListener {
|
||||||
CreatePlaylistDialog {
|
CreatePlaylistDialog {
|
||||||
@ -85,6 +88,17 @@ class LibraryFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initBookmarks() {
|
||||||
|
val bookmarks = awaitQuery {
|
||||||
|
DatabaseHolder.Database.playlistBookmarkDao().getAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.bookmarksCV.visibility = if (bookmarks.isEmpty()) View.GONE else View.VISIBLE
|
||||||
|
if (bookmarks.isEmpty()) return
|
||||||
|
|
||||||
|
binding.bookmarksRecView.adapter = PlaylistBookmarkAdapter(bookmarks)
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateFABMargin(isMiniPlayerVisible: Boolean) {
|
private fun updateFABMargin(isMiniPlayerVisible: Boolean) {
|
||||||
// optimize CreatePlaylistFab bottom margin if miniPlayer active
|
// optimize CreatePlaylistFab bottom margin if miniPlayer active
|
||||||
val bottomMargin = if (isMiniPlayerVisible) 64 else 16
|
val bottomMargin = if (isMiniPlayerVisible) 64 else 16
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/emptyBookmarks"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:src="@drawable/ic_bookmark_outlined" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:text="@string/bookmarks_empty"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/bookmarksRV"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
@ -12,128 +12,147 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_margin="10dp">
|
android:layout_margin="10dp">
|
||||||
|
|
||||||
<LinearLayout
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
<LinearLayout
|
||||||
style="@style/Widget.Material3.CardView.Elevated"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
style="@style/Widget.Material3.CardView.Elevated"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/watch_history"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:orientation="vertical">
|
||||||
android:drawablePadding="10dp"
|
|
||||||
android:paddingHorizontal="15dp"
|
|
||||||
android:paddingVertical="12dp"
|
|
||||||
android:text="@string/watch_history"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:drawableStartCompat="@drawable/ic_time_outlined" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/bookmarks"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:drawablePadding="10dp"
|
|
||||||
android:paddingHorizontal="15dp"
|
|
||||||
android:paddingVertical="12dp"
|
|
||||||
android:text="@string/bookmarks"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:drawableStartCompat="@drawable/ic_bookmark_outlined" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/downloads"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:drawablePadding="10dp"
|
|
||||||
android:paddingHorizontal="15dp"
|
|
||||||
android:paddingVertical="12dp"
|
|
||||||
android:text="@string/downloads"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:drawableStartCompat="@drawable/ic_download" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
|
||||||
style="@style/Widget.Material3.CardView.Elevated"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_marginTop="20dp"
|
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:layout_weight="1">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="10dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/playlists"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/nothing_here"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/listIV"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:src="@drawable/ic_list" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_like"
|
android:id="@+id/watch_history"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/listIV"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:layout_centerHorizontal="true"
|
android:drawablePadding="10dp"
|
||||||
android:gravity="center"
|
android:paddingHorizontal="15dp"
|
||||||
android:text="@string/emptyList"
|
android:paddingVertical="12dp"
|
||||||
android:textSize="20sp"
|
android:text="@string/watch_history"
|
||||||
android:textStyle="bold" />
|
android:textSize="18sp"
|
||||||
</RelativeLayout>
|
android:textStyle="bold"
|
||||||
|
app:drawableStartCompat="@drawable/ic_time_outlined" />
|
||||||
|
|
||||||
<RelativeLayout
|
<TextView
|
||||||
|
android:id="@+id/downloads"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:drawablePadding="10dp"
|
||||||
|
android:paddingHorizontal="15dp"
|
||||||
|
android:paddingVertical="12dp"
|
||||||
|
android:text="@string/downloads"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:drawableStartCompat="@drawable/ic_download" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
style="@style/Widget.Material3.CardView.Elevated"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:orientation="vertical"
|
||||||
android:descendantFocusability="blocksDescendants">
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/playlists"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/nothing_here"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/listIV"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:src="@drawable/ic_list" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_like"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/listIV"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/emptyList"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/playlist_recView"
|
android:id="@+id/playlist_recView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content" />
|
||||||
android:nestedScrollingEnabled="false" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
<com.google.android.material.card.MaterialCardView
|
||||||
</LinearLayout>
|
android:id="@+id/bookmarksCV"
|
||||||
|
style="@style/Widget.Material3.CardView.Elevated"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/bookmarks"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/bookmarks_recView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
</com.github.libretube.ui.views.CustomSwipeToRefresh>
|
</com.github.libretube.ui.views.CustomSwipeToRefresh>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
@ -54,9 +54,4 @@
|
|||||||
android:name="com.github.libretube.ui.fragments.DownloadsFragment"
|
android:name="com.github.libretube.ui.fragments.DownloadsFragment"
|
||||||
android:label="@string/downloads"
|
android:label="@string/downloads"
|
||||||
tools:layout="@layout/fragment_downloads" />
|
tools:layout="@layout/fragment_downloads" />
|
||||||
<fragment
|
|
||||||
android:id="@+id/bookmarksFragment"
|
|
||||||
android:name="com.github.libretube.ui.fragments.BookmarksFragment"
|
|
||||||
android:label="@string/bookmarks"
|
|
||||||
tools:layout="@layout/fragment_bookmarks" />
|
|
||||||
</navigation>
|
</navigation>
|
Loading…
x
Reference in New Issue
Block a user