minor improvements

This commit is contained in:
Bnyro 2022-09-19 21:43:13 +02:00
parent 0db7821418
commit c835f5ab80
5 changed files with 12 additions and 16 deletions

View File

@ -687,6 +687,9 @@ class PlayerFragment : BaseFragment() {
override fun onDestroy() {
super.onDestroy()
try {
// clear the playing queue
PlayingQueue.clear()
saveWatchPosition()
nowPlayingNotification.destroy()
activity?.requestedOrientation =

View File

@ -333,6 +333,9 @@ class BackgroundMode : Service() {
* destroy the [BackgroundMode] foreground service
*/
override fun onDestroy() {
// clear the playing queue
PlayingQueue.clear()
// called when the user pressed stop in the notification
// stop the service from being in the foreground and remove the notification
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

View File

@ -1,13 +1,9 @@
package com.github.libretube.sheets
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import com.github.libretube.R
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
import com.github.libretube.dialogs.AddToPlaylistDialog
import com.github.libretube.dialogs.DownloadDialog
import com.github.libretube.dialogs.ShareDialog
@ -44,18 +40,9 @@ class VideoOptionsBottomSheet(
/**
* Check whether the player is running by observing the notification
*/
try {
val notificationManager =
context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
notificationManager.activeNotifications.forEach {
if (it.id == PLAYER_NOTIFICATION_ID) {
optionsList += context?.getString(R.string.add_to_queue)!!
}
}
}
} catch (e: Exception) {
e.printStackTrace()
if (PlayingQueue.isNotEmpty()) {
optionsList += context?.getString(R.string.play_next)!!
optionsList += context?.getString(R.string.add_to_queue)!!
}
setSimpleItems(optionsList) { which ->

View File

@ -166,6 +166,7 @@ class NowPlayingNotification(
Context.NOTIFICATION_SERVICE
) as NotificationManager
notificationManager.cancel(PLAYER_NOTIFICATION_ID)
player.stop()
player.release()
}
}

View File

@ -51,4 +51,6 @@ object PlayingQueue {
currentVideoId = videoId
if (!contains(videoId)) add(videoId)
}
fun isNotEmpty() = queue.isNotEmpty()
}