mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Use playlists layout for bookmarks
This commit is contained in:
parent
0045e41902
commit
3434974efc
@ -1,13 +1,17 @@
|
|||||||
package com.github.libretube.ui.adapters
|
package com.github.libretube.ui.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
|
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
|
||||||
|
import com.github.libretube.databinding.PlaylistRowBinding
|
||||||
|
import com.github.libretube.db.DatabaseHolder
|
||||||
import com.github.libretube.db.obj.PlaylistBookmark
|
import com.github.libretube.db.obj.PlaylistBookmark
|
||||||
import com.github.libretube.enums.PlaylistType
|
import com.github.libretube.enums.PlaylistType
|
||||||
import com.github.libretube.extensions.toPixel
|
import com.github.libretube.extensions.query
|
||||||
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
||||||
import com.github.libretube.ui.viewholders.PlaylistBookmarkViewHolder
|
import com.github.libretube.ui.viewholders.PlaylistBookmarkViewHolder
|
||||||
import com.github.libretube.util.ImageHelper
|
import com.github.libretube.util.ImageHelper
|
||||||
@ -18,12 +22,15 @@ class PlaylistBookmarkAdapter(
|
|||||||
private val bookmarkMode: BookmarkMode = BookmarkMode.FRAGMENT
|
private val bookmarkMode: BookmarkMode = BookmarkMode.FRAGMENT
|
||||||
) : RecyclerView.Adapter<PlaylistBookmarkViewHolder>() {
|
) : RecyclerView.Adapter<PlaylistBookmarkViewHolder>() {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistBookmarkViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaylistBookmarkViewHolder {
|
||||||
val binding = PlaylistBookmarkRowBinding.inflate(
|
val layoutInflater = LayoutInflater.from(parent.context)
|
||||||
LayoutInflater.from(parent.context),
|
return when (bookmarkMode) {
|
||||||
parent,
|
BookmarkMode.HOME -> PlaylistBookmarkViewHolder(
|
||||||
false
|
PlaylistBookmarkRowBinding.inflate(layoutInflater, parent, false)
|
||||||
)
|
)
|
||||||
return PlaylistBookmarkViewHolder(binding)
|
BookmarkMode.FRAGMENT -> PlaylistBookmarkViewHolder(
|
||||||
|
PlaylistRowBinding.inflate(layoutInflater, parent, false)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
@ -32,13 +39,7 @@ class PlaylistBookmarkAdapter(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: PlaylistBookmarkViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: PlaylistBookmarkViewHolder, position: Int) {
|
||||||
val bookmark = bookmarks[position]
|
val bookmark = bookmarks[position]
|
||||||
holder.binding.apply {
|
holder.playlistBookmarkBinding?.apply {
|
||||||
if (bookmarkMode == BookmarkMode.HOME) {
|
|
||||||
val params = root.layoutParams
|
|
||||||
params.width = (210).toPixel().toInt()
|
|
||||||
root.layoutParams = params
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageHelper.loadImage(bookmark.thumbnailUrl, thumbnail)
|
ImageHelper.loadImage(bookmark.thumbnailUrl, thumbnail)
|
||||||
playlistName.text = bookmark.playlistName
|
playlistName.text = bookmark.playlistName
|
||||||
uploaderName.text = bookmark.uploader
|
uploaderName.text = bookmark.uploader
|
||||||
@ -62,6 +63,52 @@ class PlaylistBookmarkAdapter(
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.playlistBinding?.apply {
|
||||||
|
var isBookmarked = true
|
||||||
|
|
||||||
|
ImageHelper.loadImage(bookmark.thumbnailUrl, playlistThumbnail)
|
||||||
|
playlistTitle.text = bookmark.playlistName
|
||||||
|
playlistDescription.text = bookmark.uploader
|
||||||
|
|
||||||
|
deletePlaylist.setImageResource(R.drawable.ic_bookmark)
|
||||||
|
deletePlaylist.setOnClickListener {
|
||||||
|
isBookmarked = !isBookmarked
|
||||||
|
deletePlaylist.setImageResource(
|
||||||
|
if (isBookmarked) R.drawable.ic_bookmark else R.drawable.ic_bookmark_outlined
|
||||||
|
)
|
||||||
|
query {
|
||||||
|
if (!isBookmarked) {
|
||||||
|
DatabaseHolder.Database.playlistBookmarkDao()
|
||||||
|
.deleteById(bookmark.playlistId)
|
||||||
|
} else {
|
||||||
|
DatabaseHolder.Database.playlistBookmarkDao()
|
||||||
|
.insertAll(bookmark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deletePlaylist.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
root.setOnClickListener {
|
||||||
|
NavigationHelper.navigatePlaylist(
|
||||||
|
root.context,
|
||||||
|
bookmark.playlistId,
|
||||||
|
PlaylistType.PUBLIC
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
root.setOnLongClickListener {
|
||||||
|
PlaylistOptionsBottomSheet(
|
||||||
|
playlistId = bookmark.playlistId,
|
||||||
|
playlistName = bookmark.playlistName ?: "",
|
||||||
|
playlistType = PlaylistType.PUBLIC
|
||||||
|
).show(
|
||||||
|
(root.context as AppCompatActivity).supportFragmentManager
|
||||||
|
)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -5,6 +5,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.github.libretube.databinding.FragmentBookmarksBinding
|
import com.github.libretube.databinding.FragmentBookmarksBinding
|
||||||
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
||||||
import com.github.libretube.extensions.awaitQuery
|
import com.github.libretube.extensions.awaitQuery
|
||||||
@ -32,7 +33,7 @@ class BookmarksFragment : BaseFragment() {
|
|||||||
|
|
||||||
if (bookmarks.isEmpty()) return
|
if (bookmarks.isEmpty()) return
|
||||||
|
|
||||||
binding.bookmarksRV.layoutManager = GridLayoutManager(context, 2)
|
binding.bookmarksRV.layoutManager = LinearLayoutManager(context)
|
||||||
binding.bookmarksRV.adapter = PlaylistBookmarkAdapter(bookmarks)
|
binding.bookmarksRV.adapter = PlaylistBookmarkAdapter(bookmarks)
|
||||||
|
|
||||||
binding.bookmarksRV.visibility = View.VISIBLE
|
binding.bookmarksRV.visibility = View.VISIBLE
|
||||||
|
@ -2,7 +2,17 @@ package com.github.libretube.ui.viewholders
|
|||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
|
import com.github.libretube.databinding.PlaylistBookmarkRowBinding
|
||||||
|
import com.github.libretube.databinding.PlaylistRowBinding
|
||||||
|
|
||||||
class PlaylistBookmarkViewHolder(
|
class PlaylistBookmarkViewHolder : RecyclerView.ViewHolder {
|
||||||
val binding: PlaylistBookmarkRowBinding
|
var playlistBookmarkBinding: PlaylistBookmarkRowBinding? = null
|
||||||
) : RecyclerView.ViewHolder(binding.root)
|
var playlistBinding: PlaylistRowBinding? = null
|
||||||
|
|
||||||
|
constructor(binding: PlaylistBookmarkRowBinding) : super(binding.root) {
|
||||||
|
playlistBookmarkBinding = binding
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(binding: PlaylistRowBinding) : super(binding.root) {
|
||||||
|
playlistBinding = binding
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="210dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:background="@drawable/rounded_ripple"
|
android:background="@drawable/rounded_ripple"
|
||||||
|
@ -93,7 +93,7 @@
|
|||||||
android:id="@+id/delete_playlist"
|
android:id="@+id/delete_playlist"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:src="@drawable/ic_delete"
|
android:src="@drawable/ic_delete"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
Loading…
Reference in New Issue
Block a user