From 7e984dd57fd746ec648fefe2309283d0e754b7ee Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 18 Nov 2022 18:28:41 +0100 Subject: [PATCH] improve the UI --- .../libretube/db/obj/PlaylistBookmark.kt | 2 +- .../ui/adapters/PlaylistBookmarkAdapter.kt | 22 ++++++++++++++-- .../libretube/ui/fragments/HomeFragment.kt | 8 +++--- .../ui/fragments/PlaylistFragment.kt | 6 +++-- app/src/main/res/layout/fragment_home.xml | 2 +- .../main/res/layout/playlist_bookmark_row.xml | 25 +++++++++++-------- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/github/libretube/db/obj/PlaylistBookmark.kt b/app/src/main/java/com/github/libretube/db/obj/PlaylistBookmark.kt index f8b00ee86..fa7280580 100644 --- a/app/src/main/java/com/github/libretube/db/obj/PlaylistBookmark.kt +++ b/app/src/main/java/com/github/libretube/db/obj/PlaylistBookmark.kt @@ -13,4 +13,4 @@ data class PlaylistBookmark( var uploader: String? = null, var uploaderUrl: String? = null, var uploaderAvatar: String? = null -) \ No newline at end of file +) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt index bc0f96388..b93704cc8 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistBookmarkAdapter.kt @@ -2,13 +2,16 @@ package com.github.libretube.ui.adapters import android.view.LayoutInflater import android.view.ViewGroup +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.ui.sheets.PlaylistOptionsBottomSheet import com.github.libretube.ui.viewholders.PlaylistBookmarkViewHolder import com.github.libretube.util.ImageHelper +import com.github.libretube.util.NavigationHelper -class PlaylistBookmarksAdapter( +class PlaylistBookmarkAdapter( private val bookmarks: List ) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistBookmarkViewHolder { @@ -26,6 +29,21 @@ class PlaylistBookmarksAdapter( ImageHelper.loadImage(bookmark.thumbnailUrl, thumbnail) playlistName.text = bookmark.playlistName uploaderName.text = bookmark.uploader + + root.setOnClickListener { + NavigationHelper.navigatePlaylist(root.context, bookmark.playlistId, false) + } + + root.setOnLongClickListener { + PlaylistOptionsBottomSheet( + playlistId = bookmark.playlistId, + playlistName = bookmark.playlistName ?: "", + isOwner = false + ).show( + (root.context as AppCompatActivity).supportFragmentManager + ) + true + } } } -} \ No newline at end of file +} 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 bd8500766..29c5f75fc 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,7 @@ import com.github.libretube.databinding.FragmentHomeBinding import com.github.libretube.db.DatabaseHolder import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.toastFromMainThread -import com.github.libretube.ui.adapters.PlaylistBookmarksAdapter +import com.github.libretube.ui.adapters.PlaylistBookmarkAdapter import com.github.libretube.ui.adapters.PlaylistsAdapter import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.base.BaseFragment @@ -121,9 +121,9 @@ class HomeFragment : BaseFragment() { } if (bookmarkedPlaylists.isEmpty()) return@runOrError runOnUiThread { - makeVisible(binding.bookmarksRV, binding.bookmarksRV) - binding.playlistsRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) - binding.playlistsRV.adapter = PlaylistBookmarksAdapter(bookmarkedPlaylists) + makeVisible(binding.bookmarksTV, binding.bookmarksRV) + binding.bookmarksRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + binding.bookmarksRV.adapter = PlaylistBookmarkAdapter(bookmarkedPlaylists) } } } 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 fc69c015d..dd2c2fbe3 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 @@ -130,7 +130,11 @@ class PlaylistFragment : BaseFragment() { ) } + if (isOwner) binding.bookmark.visibility = View.GONE + binding.bookmark.setOnClickListener { + isBookmarked = !isBookmarked + updateBookmarkRes() query { if (isBookmarked) { DatabaseHolder.Database.playlistBookmarkDao().delete( @@ -149,8 +153,6 @@ class PlaylistFragment : BaseFragment() { ) } } - isBookmarked = !isBookmarked - updateBookmarkRes() } playlistAdapter = PlaylistAdapter( diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 587f448df..fd3979aa2 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -62,7 +62,7 @@ + android:text="@string/bookmarks" /> + android:layout_margin="5dp" + android:background="@drawable/rounded_ripple" + android:orientation="vertical" + android:padding="5dp"> + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:ellipsize="end" + android:maxLines="1" + android:textStyle="bold" /> + android:layout_height="wrap_content" + android:ellipsize="end" + android:maxLines="1" + android:textSize="14sp" /> \ No newline at end of file