improve the UI

This commit is contained in:
Bnyro 2022-11-18 18:28:41 +01:00
parent 48951f13c3
commit 7e984dd57f
6 changed files with 45 additions and 20 deletions

View File

@ -13,4 +13,4 @@ data class PlaylistBookmark(
var uploader: String? = null,
var uploaderUrl: String? = null,
var uploaderAvatar: String? = null
)
)

View File

@ -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<PlaylistBookmark>
) : RecyclerView.Adapter<PlaylistBookmarkViewHolder>() {
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
}
}
}
}
}

View File

@ -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)
}
}
}

View File

@ -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(

View File

@ -62,7 +62,7 @@
<TextView
android:id="@+id/bookmarksTV"
style="@style/HomeCategoryTitle"
android:text="@string/playlists" />
android:text="@string/bookmarks" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/bookmarksRV"

View File

@ -2,32 +2,37 @@
<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="250dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_margin="5dp"
android:background="@drawable/rounded_ripple"
android:orientation="vertical"
android:padding="5dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.ExtraLarge"
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Medium"
tools:src="@tools:sample/backgrounds/scenic" />
<TextView
android:id="@+id/playlistName"
android:textSize="18sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:maxLines="1"
android:textStyle="bold" />
<TextView
android:id="@+id/uploaderName"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textSize="14sp" />
</LinearLayout>