From 658a6648ff044f54fc80cb0cce13842895b64acf Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 19 Sep 2022 22:21:30 +0200 Subject: [PATCH] fix prev --- .../com/github/libretube/fragments/PlayerFragment.kt | 6 +++--- .../libretube/sheets/VideoOptionsBottomSheet.kt | 3 ++- .../java/com/github/libretube/util/PlayingQueue.kt | 12 +++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 41534f0d5..858bca57d 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -757,8 +757,9 @@ class PlayerFragment : BaseFragment() { } private fun playVideo() { - PlayingQueue.updateCurrent(videoId!!) lifecycleScope.launchWhenCreated { + PlayingQueue.updateCurrent(videoId!!) + streams = try { RetrofitInstance.api.getStreams(videoId!!) } catch (e: IOException) { @@ -866,8 +867,7 @@ class PlayerFragment : BaseFragment() { var position: Long? = null Thread { try { - val watchPosition = Database.watchPositionDao().findById(videoId!!) - position = if (watchPosition != null) watchPosition.position else null + position = Database.watchPositionDao().findById(videoId!!)?.position // position is almost the end of the video => don't seek, start from beginning if (position!! > streams.duration!! * 1000 * 0.9) position = null } catch (e: Exception) { diff --git a/app/src/main/java/com/github/libretube/sheets/VideoOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/sheets/VideoOptionsBottomSheet.kt index b988c9f71..ba4fa68af 100644 --- a/app/src/main/java/com/github/libretube/sheets/VideoOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/sheets/VideoOptionsBottomSheet.kt @@ -37,8 +37,9 @@ class VideoOptionsBottomSheet( ) } + /** - * Check whether the player is running by observing the notification + * Check whether the player is running and add queue options */ if (PlayingQueue.isNotEmpty()) { optionsList += context?.getString(R.string.play_next)!! diff --git a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt index 7889d8f9f..651ff963c 100644 --- a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt +++ b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt @@ -32,15 +32,13 @@ object PlayingQueue { } } - fun getPrev(): String { - return queue[ - queue.indexOf(currentVideoId) - 1 - ] + fun getPrev(): String? { + val index = queue.indexOf(currentVideoId) + return if (index > 0) queue[index - 1] else null } fun hasPrev(): Boolean { - val currentIndex = queue.indexOf(currentVideoId) - return queue.size > currentIndex + 1 + return queue.indexOf(currentVideoId) > 0 } fun contains(videoId: String): Boolean { @@ -53,7 +51,7 @@ object PlayingQueue { fun updateCurrent(videoId: String) { currentVideoId = videoId - if (!contains(videoId)) add(videoId) + queue.add(videoId) } fun isNotEmpty() = queue.isNotEmpty()