add a bookmarks fragment to the library

This commit is contained in:
Bnyro 2022-11-19 10:52:27 +01:00
parent c5714bb206
commit 7211143398
9 changed files with 144 additions and 47 deletions

View File

@ -6,13 +6,15 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
import com.github.libretube.db.obj.PlaylistBookmark
import com.github.libretube.extensions.toDp
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.viewholders.PlaylistBookmarkViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
class PlaylistBookmarkAdapter(
private val bookmarks: List<PlaylistBookmark>
private val bookmarks: List<PlaylistBookmark>,
private val bookmarkMode: BookmarkMode = BookmarkMode.FRAGMENT
) : RecyclerView.Adapter<PlaylistBookmarkViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistBookmarkViewHolder {
val binding = PlaylistBookmarkRowBinding.inflate(LayoutInflater.from(parent.context), parent, false)
@ -26,6 +28,12 @@ class PlaylistBookmarkAdapter(
override fun onBindViewHolder(holder: PlaylistBookmarkViewHolder, position: Int) {
val bookmark = bookmarks[position]
holder.binding.apply {
if (bookmarkMode == BookmarkMode.HOME) {
val params = root.layoutParams
params.width = (210).toDp(root.context.resources).toInt()
root.layoutParams = params
}
ImageHelper.loadImage(bookmark.thumbnailUrl, thumbnail)
playlistName.text = bookmark.playlistName
uploaderName.text = bookmark.uploader
@ -46,4 +54,11 @@ class PlaylistBookmarkAdapter(
}
}
}
companion object {
enum class BookmarkMode {
HOME,
FRAGMENT
}
}
}

View File

@ -0,0 +1,41 @@
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.GridLayoutManager
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 = GridLayoutManager(context, 2)
binding.bookmarksRV.adapter = PlaylistBookmarkAdapter(bookmarks)
binding.bookmarksRV.visibility = View.VISIBLE
binding.emptyBookmarks.visibility = View.GONE
}
}

View File

@ -53,6 +53,10 @@ class HomeFragment : BaseFragment() {
findNavController().navigate(R.id.libraryFragment)
}
binding.bookmarksTV.setOnClickListener {
findNavController().navigate(R.id.bookmarksFragment)
}
binding.refresh.setOnRefreshListener {
binding.refresh.isRefreshing = true
lifecycleScope.launch(Dispatchers.IO) {
@ -123,7 +127,10 @@ class HomeFragment : BaseFragment() {
runOnUiThread {
makeVisible(binding.bookmarksTV, binding.bookmarksRV)
binding.bookmarksRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
binding.bookmarksRV.adapter = PlaylistBookmarkAdapter(bookmarkedPlaylists)
binding.bookmarksRV.adapter = PlaylistBookmarkAdapter(
bookmarkedPlaylists,
PlaylistBookmarkAdapter.Companion.BookmarkMode.HOME
)
}
}
}

View File

@ -55,13 +55,17 @@ class LibraryFragment : BaseFragment() {
val watchHistoryEnabled =
PreferenceHelper.getBoolean(PreferenceKeys.WATCH_HISTORY_TOGGLE, true)
if (!watchHistoryEnabled) {
binding.showWatchHistory.visibility = View.GONE
binding.watchHistory.visibility = View.GONE
} else {
binding.showWatchHistory.setOnClickListener {
binding.watchHistory.setOnClickListener {
findNavController().navigate(R.id.watchHistoryFragment)
}
}
binding.bookmarks.setOnClickListener {
findNavController().navigate(R.id.bookmarksFragment)
}
binding.downloads.setOnClickListener {
findNavController().navigate(R.id.downloadsFragment)
}

View File

@ -0,0 +1,36 @@
<?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>

View File

@ -47,61 +47,49 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/showWatchHistory"
<TextView
android:id="@+id/watch_history"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal"
android:padding="10dp">
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" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:src="@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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:text="@string/watch_history"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
<TextView
android:id="@+id/downloads"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:src="@drawable/ic_download" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:text="@string/downloads"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
android:drawablePadding="10dp"
android:paddingHorizontal="15dp"
android:paddingVertical="12dp"
android:text="@string/downloads"
android:textSize="18sp"
android:textStyle="bold"
app:drawableStartCompat="@drawable/ic_download" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:descendantFocusability="blocksDescendants">
<androidx.recyclerview.widget.RecyclerView

View File

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="200dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/rounded_ripple"

View File

@ -54,4 +54,9 @@
android:name="com.github.libretube.ui.fragments.DownloadsFragment"
android:label="@string/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>

View File

@ -384,6 +384,7 @@
<string name="bookmarks">Bookmarks</string>
<string name="bookmark">Bookmark</string>
<string name="clear_bookmarks">Clear bookmarks</string>
<string name="bookmarks_empty">No bookmarks yet!</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>