mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #1909 from Bnyro/master
Bookmarks in the library, option to reset them
This commit is contained in:
commit
bbb09e47dc
@ -111,6 +111,7 @@ object PreferenceKeys {
|
||||
const val CLEAR_WATCH_POSITIONS = "clear_watch_positions"
|
||||
const val SHARE_WITH_TIME_CODE = "share_with_time_code"
|
||||
const val CONFIRM_UNSUBSCRIBE = "confirm_unsubscribing"
|
||||
const val CLEAR_BOOKMARKS = "clear_bookmarks"
|
||||
|
||||
/**
|
||||
* History
|
||||
|
@ -10,6 +10,7 @@ import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.PlaylistId
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.databinding.PlaylistRowBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toID
|
||||
@ -27,7 +28,7 @@ import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class PlaylistAdapter(
|
||||
private val videoFeed: MutableList<com.github.libretube.api.obj.StreamItem>,
|
||||
private val videoFeed: MutableList<StreamItem>,
|
||||
private val playlistId: String,
|
||||
private val isOwner: Boolean,
|
||||
private val childFragmentManager: FragmentManager
|
||||
@ -37,7 +38,7 @@ class PlaylistAdapter(
|
||||
return videoFeed.size
|
||||
}
|
||||
|
||||
fun updateItems(newItems: List<com.github.libretube.api.obj.StreamItem>) {
|
||||
fun updateItems(newItems: List<StreamItem>) {
|
||||
val oldSize = videoFeed.size
|
||||
videoFeed.addAll(newItems)
|
||||
notifyItemRangeInserted(oldSize, videoFeed.size)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.github.libretube.ui.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -53,19 +54,23 @@ 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) {
|
||||
fetchHome(LocaleHelper.getTrendingRegion(requireContext()))
|
||||
fetchHome()
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
fetchHome(LocaleHelper.getTrendingRegion(requireContext()))
|
||||
fetchHome()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun fetchHome(trendingRegion: String) {
|
||||
private suspend fun fetchHome() {
|
||||
val token = PreferenceHelper.getToken()
|
||||
runOrError {
|
||||
val feed = SubscriptionHelper.getFeed().withMaxSize(20)
|
||||
@ -82,7 +87,9 @@ class HomeFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
runOrError {
|
||||
val trending = RetrofitInstance.api.getTrending(trendingRegion).withMaxSize(10)
|
||||
val trending = RetrofitInstance.api.getTrending(
|
||||
LocaleHelper.getTrendingRegion(requireContext())
|
||||
).withMaxSize(10)
|
||||
if (trending.isEmpty()) return@runOrError
|
||||
runOnUiThread {
|
||||
makeVisible(binding.trendingRV, binding.trendingTV)
|
||||
@ -96,6 +103,7 @@ class HomeFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
runOrError {
|
||||
if (token == "") return@runOrError
|
||||
val playlists = RetrofitInstance.authApi.getUserPlaylists(token).withMaxSize(20)
|
||||
if (playlists.isEmpty()) return@runOrError
|
||||
runOnUiThread {
|
||||
@ -123,7 +131,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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -134,6 +145,7 @@ class HomeFragment : BaseFragment() {
|
||||
action.invoke()
|
||||
} catch (e: Exception) {
|
||||
e.localizedMessage?.let { context?.toastFromMainThread(it) }
|
||||
Log.e("fetching home tab", e.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -44,6 +44,14 @@ class HistorySettings : BasePreferenceFragment() {
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
val resetBookmarks = findPreference<Preference>(PreferenceKeys.CLEAR_BOOKMARKS)
|
||||
resetBookmarks?.setOnPreferenceClickListener {
|
||||
showClearDialog(R.string.clear_bookmarks) {
|
||||
Database.playlistBookmarkDao().deleteAll()
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun showClearDialog(title: Int, action: () -> Unit) {
|
||||
|
36
app/src/main/res/layout/fragment_bookmarks.xml
Normal file
36
app/src/main/res/layout/fragment_bookmarks.xml
Normal 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>
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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>
|
@ -383,6 +383,8 @@
|
||||
<string name="trending">What\'s trending now</string>
|
||||
<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>
|
||||
|
@ -59,4 +59,13 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/bookmarks">
|
||||
|
||||
<Preference
|
||||
android:title="@string/clear_bookmarks"
|
||||
app:icon="@drawable/ic_bookmark"
|
||||
app:key="clear_bookmarks" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user