mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
refactor: remove constructors from StatsSheet
This commit is contained in:
parent
4cef17c9ab
commit
360a611601
@ -30,4 +30,5 @@ object IntentData {
|
||||
const val color = "color"
|
||||
const val streamItem = "streamItem"
|
||||
const val url = "url"
|
||||
const val videoStats = "videoStats"
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ 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.obj.VideoStats
|
||||
import com.github.libretube.util.TextUtils
|
||||
import java.util.Locale
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.roundToInt
|
||||
@ -688,4 +690,18 @@ object PlayerHelper {
|
||||
isFlagSet(roleFlags, C.ROLE_FLAG_MAIN) ||
|
||||
isFlagSet(roleFlags, C.ROLE_FLAG_ALTERNATE)
|
||||
}
|
||||
|
||||
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||
fun getVideoStats(player: ExoPlayer, videoId: String): VideoStats {
|
||||
val videoInfo = "${player.videoFormat?.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(
|
||||
player.videoFormat?.bitrate
|
||||
)
|
||||
}"
|
||||
val audioInfo = "${player.audioFormat?.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(player.audioFormat?.bitrate)
|
||||
}"
|
||||
val videoQuality = "${player.videoFormat?.width}x${player.videoFormat?.height} ${player.videoFormat?.frameRate?.toInt()}fps"
|
||||
return VideoStats(videoId, videoInfo, videoQuality, audioInfo)
|
||||
}
|
||||
}
|
||||
|
12
app/src/main/java/com/github/libretube/obj/VideoStats.kt
Normal file
12
app/src/main/java/com/github/libretube/obj/VideoStats.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class VideoStats(
|
||||
val videoId: String,
|
||||
val videoInfo: String,
|
||||
val videoQuality: String,
|
||||
val audioInfo: String
|
||||
) : Parcelable
|
@ -87,6 +87,7 @@ import com.github.libretube.helpers.NavigationHelper
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
import com.github.libretube.helpers.PlayerHelper.SPONSOR_HIGHLIGHT_CATEGORY
|
||||
import com.github.libretube.helpers.PlayerHelper.checkForSegments
|
||||
import com.github.libretube.helpers.PlayerHelper.getVideoStats
|
||||
import com.github.libretube.helpers.PlayerHelper.isInSegment
|
||||
import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
@ -1548,7 +1549,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
override fun onStatsClicked() {
|
||||
if (!this::streams.isInitialized) return
|
||||
StatsSheet(exoPlayer, videoId)
|
||||
val videoStats = getVideoStats(exoPlayer, videoId)
|
||||
StatsSheet()
|
||||
.apply { arguments = bundleOf(IntentData.videoStats to videoStats) }
|
||||
.show(childFragmentManager)
|
||||
}
|
||||
|
||||
|
@ -5,16 +5,15 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.DialogStatsBinding
|
||||
import com.github.libretube.util.TextUtils
|
||||
import com.github.libretube.extensions.parcelable
|
||||
import com.github.libretube.obj.VideoStats
|
||||
|
||||
class StatsSheet(
|
||||
private val player: ExoPlayer,
|
||||
private val videoId: String
|
||||
) : ExpandedBottomSheet() {
|
||||
class StatsSheet : ExpandedBottomSheet() {
|
||||
private var _binding: DialogStatsBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private lateinit var stats: VideoStats
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@ -25,27 +24,19 @@ class StatsSheet(
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
stats = arguments?.parcelable(IntentData.videoStats)!!
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
val binding = binding
|
||||
|
||||
binding.videoId.setText(videoId)
|
||||
binding.videoInfo.setText(
|
||||
"${player.videoFormat?.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(
|
||||
player.videoFormat?.bitrate
|
||||
)
|
||||
}"
|
||||
)
|
||||
binding.audioInfo.setText(
|
||||
"${player.audioFormat?.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(player.audioFormat?.bitrate)
|
||||
}"
|
||||
)
|
||||
binding.videoQuality.setText(
|
||||
"${player.videoFormat?.width}x${player.videoFormat?.height} ${player.videoFormat?.frameRate?.toInt()}fps"
|
||||
)
|
||||
binding.videoId.setText(stats.videoId)
|
||||
binding.videoInfo.setText(stats.videoInfo)
|
||||
binding.audioInfo.setText(stats.audioInfo)
|
||||
binding.videoQuality.setText(stats.videoQuality)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user