mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +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 fileName = "fileName"
|
||||
const val openQueueOnce = "openQueue"
|
||||
const val keepQueue = "keepQueue"
|
||||
const val playlistType = "playlistType"
|
||||
}
|
||||
|
@ -127,11 +127,16 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
private val commentsViewModel: CommentsViewModel by activityViewModels()
|
||||
|
||||
/**
|
||||
* video information
|
||||
* Video information passed by the intent
|
||||
*/
|
||||
private var videoId: String? = null
|
||||
private var playlistId: String? = null
|
||||
private var channelId: String? = null
|
||||
private var keepQueue: Boolean = false
|
||||
|
||||
/**
|
||||
* Video information fetched at runtime
|
||||
*/
|
||||
private var isLive = false
|
||||
private lateinit var streams: Streams
|
||||
|
||||
@ -179,6 +184,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
videoId = it.getString(IntentData.videoId)!!.toID()
|
||||
playlistId = it.getString(IntentData.playlistId)
|
||||
channelId = it.getString(IntentData.channelId)
|
||||
keepQueue = it.getBoolean(IntentData.keepQueue, false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +208,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
context?.hideKeyboard(view)
|
||||
|
||||
// clear the playing queue
|
||||
PlayingQueue.resetToDefaults()
|
||||
if (!keepQueue) PlayingQueue.resetToDefaults()
|
||||
|
||||
changeOrientationMode()
|
||||
|
||||
|
@ -9,14 +9,20 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
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.db.DatabaseHolder.Companion.Database
|
||||
import com.github.libretube.extensions.awaitQuery
|
||||
import com.github.libretube.extensions.query
|
||||
import com.github.libretube.extensions.toPixel
|
||||
import com.github.libretube.ui.adapters.WatchHistoryAdapter
|
||||
import com.github.libretube.ui.base.BaseFragment
|
||||
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.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class WatchHistoryFragment : BaseFragment() {
|
||||
private lateinit var binding: FragmentWatchHistoryBinding
|
||||
@ -52,6 +58,40 @@ class WatchHistoryFragment : BaseFragment() {
|
||||
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
|
||||
binding.watchHistoryRecView.layoutManager = LinearLayoutManager(requireContext()).apply {
|
||||
reverseLayout = true
|
||||
@ -88,17 +128,17 @@ class WatchHistoryFragment : BaseFragment() {
|
||||
|
||||
// observe changes
|
||||
watchHistoryAdapter.registerAdapterDataObserver(object :
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (watchHistoryAdapter.itemCount == 0) {
|
||||
binding.watchHistoryRecView.visibility = View.GONE
|
||||
binding.historyEmpty.visibility = View.VISIBLE
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (watchHistoryAdapter.itemCount == 0) {
|
||||
binding.historyScrollView.visibility = View.GONE
|
||||
binding.historyEmpty.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
binding.watchHistoryRecView.adapter = watchHistoryAdapter
|
||||
binding.historyEmpty.visibility = View.GONE
|
||||
binding.watchHistoryRecView.visibility = View.VISIBLE
|
||||
binding.historyScrollView.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
@ -49,23 +49,29 @@ object NavigationHelper {
|
||||
context: Context,
|
||||
videoId: String?,
|
||||
playlistId: String? = null,
|
||||
channelId: String? = null
|
||||
channelId: String? = null,
|
||||
keepQueue: Boolean = false
|
||||
) {
|
||||
if (videoId == null) return
|
||||
|
||||
val bundle = Bundle()
|
||||
bundle.putString(IntentData.videoId, videoId.toID())
|
||||
bundle.putString(IntentData.playlistId, playlistId)
|
||||
bundle.putString(IntentData.channelId, channelId)
|
||||
val bundle = Bundle().apply {
|
||||
putString(IntentData.videoId, videoId.toID())
|
||||
putString(IntentData.playlistId, playlistId)
|
||||
putString(IntentData.channelId, channelId)
|
||||
putBoolean(IntentData.keepQueue, keepQueue)
|
||||
}
|
||||
|
||||
val frag = PlayerFragment()
|
||||
frag.arguments = bundle
|
||||
val activity = context as AppCompatActivity
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
activity.supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, frag)
|
||||
.replace(
|
||||
R.id.container,
|
||||
PlayerFragment().apply {
|
||||
arguments = bundle
|
||||
}
|
||||
)
|
||||
.commitNow()
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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_height="match_parent">
|
||||
|
||||
@ -26,12 +27,56 @@
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/watchHistoryRecView"
|
||||
<ScrollView
|
||||
android:id="@+id/historyScrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:visibility="gone" />
|
||||
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
|
||||
android:id="@+id/watchHistoryRecView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:nestedScrollingEnabled="false" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue
Block a user