mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Merge pull request #4381 from Bnyro/master
fix: crash when closing player via x on top left
This commit is contained in:
commit
be0eb6513c
@ -5,22 +5,16 @@ import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.format.DateUtils
|
||||
import android.util.Base64
|
||||
import android.view.accessibility.CaptioningManager
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.core.app.RemoteActionCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.view.children
|
||||
import androidx.media3.common.AudioAttributes
|
||||
import androidx.media3.common.C
|
||||
import androidx.media3.common.PlaybackParameters
|
||||
@ -39,10 +33,6 @@ import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.enums.PlayerEvent
|
||||
import com.github.libretube.enums.SbSkipOptions
|
||||
import com.github.libretube.extensions.updateParameters
|
||||
import com.github.libretube.ui.sheets.BaseBottomSheet
|
||||
import com.github.libretube.ui.sheets.ChaptersBottomSheet
|
||||
import com.github.libretube.ui.sheets.ExpandedBottomSheet
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.util.Locale
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.roundToInt
|
||||
|
@ -20,10 +20,10 @@ import com.github.libretube.helpers.PlayerHelper
|
||||
import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams
|
||||
import com.github.libretube.obj.PlayerNotificationData
|
||||
import com.github.libretube.util.NowPlayingNotification
|
||||
import kotlin.io.path.exists
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.io.path.exists
|
||||
|
||||
/**
|
||||
* A service to play downloaded audio in the background
|
||||
|
@ -37,10 +37,10 @@ import com.github.libretube.ui.interfaces.TimeFrameReceiver
|
||||
import com.github.libretube.ui.listeners.SeekbarPreviewListener
|
||||
import com.github.libretube.ui.models.PlayerViewModel
|
||||
import com.github.libretube.util.OfflineTimeFrameReceiver
|
||||
import kotlin.io.path.exists
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.io.path.exists
|
||||
|
||||
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||
class OfflinePlayerActivity : BaseActivity() {
|
||||
|
@ -4,7 +4,6 @@ import android.graphics.Color
|
||||
import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
|
@ -22,10 +22,10 @@ import com.github.libretube.ui.viewholders.DownloadsViewHolder
|
||||
import com.github.libretube.util.TextUtils
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlin.io.path.deleteIfExists
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.fileSize
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlin.io.path.exists
|
||||
|
||||
class DownloadsAdapter(
|
||||
private val context: Context,
|
||||
|
@ -13,7 +13,6 @@ import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.constraintlayout.motion.widget.TransitionAdapter
|
||||
import androidx.core.view.isGone
|
||||
|
@ -1612,7 +1612,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
|
||||
if (!PlayerHelper.autoRotationEnabled ||
|
||||
if (!PlayerHelper.autoRotationEnabled || _binding == null ||
|
||||
// If in PiP mode, orientation is given as landscape.
|
||||
PictureInPictureCompat.isInPictureInPictureMode(requireActivity())
|
||||
) {
|
||||
@ -1623,7 +1623,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
// go to fullscreen mode
|
||||
Configuration.ORIENTATION_LANDSCAPE -> setFullscreen()
|
||||
// exit fullscreen if not landscape
|
||||
else -> if (_binding != null) unsetFullscreen()
|
||||
else -> unsetFullscreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import com.github.libretube.ui.adapters.ChaptersAdapter
|
||||
class ChaptersBottomSheet(
|
||||
private val chapters: List<ChapterSegment>,
|
||||
private val exoPlayer: ExoPlayer
|
||||
): ExpandedBottomSheet() {
|
||||
) : ExpandedBottomSheet() {
|
||||
private var _binding: BottomSheetBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
@ -41,7 +41,7 @@ class ChaptersBottomSheet(
|
||||
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
val updatePosition = object: Runnable {
|
||||
val updatePosition = object : Runnable {
|
||||
override fun run() {
|
||||
if (_binding == null) return
|
||||
handler.postDelayed(this, 200)
|
||||
@ -56,4 +56,4 @@ class ChaptersBottomSheet(
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
package com.github.libretube.ui.sheets
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.view.WindowManager
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.github.libretube.R
|
||||
|
@ -75,8 +75,10 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
||||
|
||||
binding.clearQueue.setOnClickListener {
|
||||
val currentIndex = PlayingQueue.currentIndex()
|
||||
PlayingQueue.setStreams(PlayingQueue.getStreams()
|
||||
.filterIndexed { index, _ -> index == currentIndex })
|
||||
PlayingQueue.setStreams(
|
||||
PlayingQueue.getStreams()
|
||||
.filterIndexed { index, _ -> index == currentIndex }
|
||||
)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
binding.sort.setOnClickListener {
|
||||
@ -122,7 +124,11 @@ class PlayingQueueSheet : ExpandedBottomSheet() {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun showSortDialog() {
|
||||
val sortOptions = listOf(R.string.creation_date, R.string.most_views, R.string.uploader_name)
|
||||
val sortOptions = listOf(
|
||||
R.string.creation_date,
|
||||
R.string.most_views,
|
||||
R.string.uploader_name
|
||||
)
|
||||
.map { requireContext().getString(it) }
|
||||
.toTypedArray()
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
|
@ -9,7 +9,7 @@ import android.view.WindowManager
|
||||
/**
|
||||
* A bottom sheet that allows touches on its top/background
|
||||
*/
|
||||
open class UndimmedBottomSheet: ExpandedBottomSheet() {
|
||||
open class UndimmedBottomSheet : ExpandedBottomSheet() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val dialog = super.onCreateDialog(savedInstanceState)
|
||||
|
||||
@ -46,4 +46,4 @@ open class UndimmedBottomSheet: ExpandedBottomSheet() {
|
||||
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user