mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #2534 from Bnyro/master
Add play all and clear actions to watch history
This commit is contained in:
commit
9bf7088a24
@ -9,5 +9,6 @@ object IntentData {
|
|||||||
const val position = "position"
|
const val position = "position"
|
||||||
const val fileName = "fileName"
|
const val fileName = "fileName"
|
||||||
const val openQueueOnce = "openQueue"
|
const val openQueueOnce = "openQueue"
|
||||||
|
const val keepQueue = "keepQueue"
|
||||||
const val playlistType = "playlistType"
|
const val playlistType = "playlistType"
|
||||||
}
|
}
|
||||||
|
@ -127,11 +127,16 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
private val commentsViewModel: CommentsViewModel by activityViewModels()
|
private val commentsViewModel: CommentsViewModel by activityViewModels()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* video information
|
* Video information passed by the intent
|
||||||
*/
|
*/
|
||||||
private var videoId: String? = null
|
private var videoId: String? = null
|
||||||
private var playlistId: String? = null
|
private var playlistId: String? = null
|
||||||
private var channelId: String? = null
|
private var channelId: String? = null
|
||||||
|
private var keepQueue: Boolean = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Video information fetched at runtime
|
||||||
|
*/
|
||||||
private var isLive = false
|
private var isLive = false
|
||||||
private lateinit var streams: Streams
|
private lateinit var streams: Streams
|
||||||
|
|
||||||
@ -179,6 +184,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
videoId = it.getString(IntentData.videoId)!!.toID()
|
videoId = it.getString(IntentData.videoId)!!.toID()
|
||||||
playlistId = it.getString(IntentData.playlistId)
|
playlistId = it.getString(IntentData.playlistId)
|
||||||
channelId = it.getString(IntentData.channelId)
|
channelId = it.getString(IntentData.channelId)
|
||||||
|
keepQueue = it.getBoolean(IntentData.keepQueue, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +208,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
context?.hideKeyboard(view)
|
context?.hideKeyboard(view)
|
||||||
|
|
||||||
// clear the playing queue
|
// clear the playing queue
|
||||||
PlayingQueue.resetToDefaults()
|
if (!keepQueue) PlayingQueue.resetToDefaults()
|
||||||
|
|
||||||
changeOrientationMode()
|
changeOrientationMode()
|
||||||
|
|
||||||
|
@ -9,14 +9,20 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.api.obj.StreamItem
|
||||||
import com.github.libretube.databinding.FragmentWatchHistoryBinding
|
import com.github.libretube.databinding.FragmentWatchHistoryBinding
|
||||||
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
|
||||||
|
import com.github.libretube.extensions.query
|
||||||
import com.github.libretube.extensions.toPixel
|
import com.github.libretube.extensions.toPixel
|
||||||
import com.github.libretube.ui.adapters.WatchHistoryAdapter
|
import com.github.libretube.ui.adapters.WatchHistoryAdapter
|
||||||
import com.github.libretube.ui.base.BaseFragment
|
import com.github.libretube.ui.base.BaseFragment
|
||||||
import com.github.libretube.ui.models.PlayerViewModel
|
import com.github.libretube.ui.models.PlayerViewModel
|
||||||
|
import com.github.libretube.util.NavigationHelper
|
||||||
|
import com.github.libretube.util.PlayingQueue
|
||||||
import com.github.libretube.util.ProxyHelper
|
import com.github.libretube.util.ProxyHelper
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
class WatchHistoryFragment : BaseFragment() {
|
class WatchHistoryFragment : BaseFragment() {
|
||||||
private lateinit var binding: FragmentWatchHistoryBinding
|
private lateinit var binding: FragmentWatchHistoryBinding
|
||||||
@ -52,6 +58,40 @@ class WatchHistoryFragment : BaseFragment() {
|
|||||||
it.uploaderAvatar = ProxyHelper.rewriteUrl(it.uploaderAvatar)
|
it.uploaderAvatar = ProxyHelper.rewriteUrl(it.uploaderAvatar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.clear.setOnClickListener {
|
||||||
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setTitle(R.string.clear_history)
|
||||||
|
.setMessage(R.string.irreversible)
|
||||||
|
.setPositiveButton(R.string.okay) { _, _ ->
|
||||||
|
binding.historyScrollView.visibility = View.GONE
|
||||||
|
binding.historyEmpty.visibility = View.VISIBLE
|
||||||
|
query {
|
||||||
|
Database.watchHistoryDao().deleteAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.playAll.setOnClickListener {
|
||||||
|
PlayingQueue.resetToDefaults()
|
||||||
|
PlayingQueue.add(
|
||||||
|
*watchHistory.reversed().map {
|
||||||
|
StreamItem(
|
||||||
|
url = "/watch?v=${it.videoId}",
|
||||||
|
title = it.title,
|
||||||
|
thumbnail = it.thumbnailUrl,
|
||||||
|
uploaderName = it.uploader,
|
||||||
|
uploaderUrl = it.uploaderUrl,
|
||||||
|
uploaderAvatar = it.uploaderAvatar,
|
||||||
|
uploadedDate = it.uploadDate,
|
||||||
|
duration = it.duration
|
||||||
|
)
|
||||||
|
}.toTypedArray()
|
||||||
|
)
|
||||||
|
NavigationHelper.navigateVideo(requireContext(), watchHistory.last().videoId, keepQueue = true)
|
||||||
|
}
|
||||||
|
|
||||||
// reversed order
|
// reversed order
|
||||||
binding.watchHistoryRecView.layoutManager = LinearLayoutManager(requireContext()).apply {
|
binding.watchHistoryRecView.layoutManager = LinearLayoutManager(requireContext()).apply {
|
||||||
reverseLayout = true
|
reverseLayout = true
|
||||||
@ -91,7 +131,7 @@ class WatchHistoryFragment : BaseFragment() {
|
|||||||
RecyclerView.AdapterDataObserver() {
|
RecyclerView.AdapterDataObserver() {
|
||||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||||
if (watchHistoryAdapter.itemCount == 0) {
|
if (watchHistoryAdapter.itemCount == 0) {
|
||||||
binding.watchHistoryRecView.visibility = View.GONE
|
binding.historyScrollView.visibility = View.GONE
|
||||||
binding.historyEmpty.visibility = View.VISIBLE
|
binding.historyEmpty.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,6 +139,6 @@ class WatchHistoryFragment : BaseFragment() {
|
|||||||
|
|
||||||
binding.watchHistoryRecView.adapter = watchHistoryAdapter
|
binding.watchHistoryRecView.adapter = watchHistoryAdapter
|
||||||
binding.historyEmpty.visibility = View.GONE
|
binding.historyEmpty.visibility = View.GONE
|
||||||
binding.watchHistoryRecView.visibility = View.VISIBLE
|
binding.historyScrollView.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,23 +49,29 @@ object NavigationHelper {
|
|||||||
context: Context,
|
context: Context,
|
||||||
videoId: String?,
|
videoId: String?,
|
||||||
playlistId: String? = null,
|
playlistId: String? = null,
|
||||||
channelId: String? = null
|
channelId: String? = null,
|
||||||
|
keepQueue: Boolean = false
|
||||||
) {
|
) {
|
||||||
if (videoId == null) return
|
if (videoId == null) return
|
||||||
|
|
||||||
val bundle = Bundle()
|
val bundle = Bundle().apply {
|
||||||
bundle.putString(IntentData.videoId, videoId.toID())
|
putString(IntentData.videoId, videoId.toID())
|
||||||
bundle.putString(IntentData.playlistId, playlistId)
|
putString(IntentData.playlistId, playlistId)
|
||||||
bundle.putString(IntentData.channelId, channelId)
|
putString(IntentData.channelId, channelId)
|
||||||
|
putBoolean(IntentData.keepQueue, keepQueue)
|
||||||
|
}
|
||||||
|
|
||||||
val frag = PlayerFragment()
|
|
||||||
frag.arguments = bundle
|
|
||||||
val activity = context as AppCompatActivity
|
val activity = context as AppCompatActivity
|
||||||
activity.supportFragmentManager.beginTransaction()
|
activity.supportFragmentManager.beginTransaction()
|
||||||
.remove(PlayerFragment())
|
.remove(PlayerFragment())
|
||||||
.commit()
|
.commit()
|
||||||
activity.supportFragmentManager.beginTransaction()
|
activity.supportFragmentManager.beginTransaction()
|
||||||
.replace(R.id.container, frag)
|
.replace(
|
||||||
|
R.id.container,
|
||||||
|
PlayerFragment().apply {
|
||||||
|
arguments = bundle
|
||||||
|
}
|
||||||
|
)
|
||||||
.commitNow()
|
.commitNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -26,12 +27,56 @@
|
|||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/historyScrollView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/play_all"
|
||||||
|
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="@string/play_all"
|
||||||
|
app:icon="@drawable/ic_playlist" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/clear"
|
||||||
|
style="@style/Widget.Material3.Button"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="@string/clear_history"
|
||||||
|
app:icon="@drawable/ic_delete" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/watchHistoryRecView"
|
android:id="@+id/watchHistoryRecView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:nestedScrollingEnabled="false"
|
android:nestedScrollingEnabled="false" />
|
||||||
android:visibility="gone" />
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
Loading…
Reference in New Issue
Block a user