diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/StatsDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/StatsDialog.kt new file mode 100644 index 0000000000..c8fe8bb446 --- /dev/null +++ b/app/src/main/java/com/github/libretube/ui/dialogs/StatsDialog.kt @@ -0,0 +1,42 @@ +package com.github.libretube.ui.dialogs + +import android.annotation.SuppressLint +import android.app.Dialog +import android.os.Bundle +import androidx.fragment.app.DialogFragment +import com.github.libretube.R +import com.github.libretube.databinding.DialogStatsBinding +import com.github.libretube.util.TextUtils +import com.google.android.exoplayer2.ExoPlayer +import com.google.android.material.dialog.MaterialAlertDialogBuilder + +class StatsDialog( + private val player: ExoPlayer, + private val videoId: String +) : DialogFragment() { + + @SuppressLint("SetTextI18n") + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val binding = DialogStatsBinding.inflate(layoutInflater) + 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" + ) + + return MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.stats_for_nerds) + .setView(binding.root) + .setPositiveButton(R.string.okay, null) + .create() + } +} diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 9a1760fd98..c53046d2e2 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -78,6 +78,7 @@ import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.ShareDialog +import com.github.libretube.ui.dialogs.StatsDialog import com.github.libretube.ui.extensions.setAspectRatio import com.github.libretube.ui.extensions.setupSubscriptionButton import com.github.libretube.ui.interfaces.OnlinePlayerOptions @@ -1379,6 +1380,12 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions { .show(childFragmentManager) } + override fun onStatsClicked() { + if (!this::streams.isInitialized) return + StatsDialog(exoPlayer, videoId ?: return) + .show(childFragmentManager, null) + } + override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) { super.onPictureInPictureModeChanged(isInPictureInPictureMode) if (isInPictureInPictureMode) { diff --git a/app/src/main/java/com/github/libretube/ui/interfaces/OnlinePlayerOptions.kt b/app/src/main/java/com/github/libretube/ui/interfaces/OnlinePlayerOptions.kt index d9e37f6e6d..1435840e07 100644 --- a/app/src/main/java/com/github/libretube/ui/interfaces/OnlinePlayerOptions.kt +++ b/app/src/main/java/com/github/libretube/ui/interfaces/OnlinePlayerOptions.kt @@ -6,4 +6,6 @@ interface OnlinePlayerOptions { fun onQualityClicked() fun onAudioStreamClicked() + + fun onStatsClicked() } diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 1eb45d6844..5e9e968a62 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -348,6 +348,12 @@ internal class CustomExoPlayerView( } ) { it.onCaptionsClicked() + }, + BottomSheetItem( + context.getString(R.string.stats_for_nerds), + R.drawable.ic_info + ) { + it.onStatsClicked() } ) ) diff --git a/app/src/main/java/com/github/libretube/util/TextUtils.kt b/app/src/main/java/com/github/libretube/util/TextUtils.kt index 2fa2b81126..a1a5e5c78d 100644 --- a/app/src/main/java/com/github/libretube/util/TextUtils.kt +++ b/app/src/main/java/com/github/libretube/util/TextUtils.kt @@ -77,4 +77,9 @@ object TextUtils { DateUtils.getRelativeTimeSpanString(unixTime) } } + + fun formatBitrate(bitrate: Int?): String { + bitrate ?: return "" + return "${bitrate / 1024}kbps" + } } diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml index 4a71c06a80..fed2fb1161 100644 --- a/app/src/main/res/drawable/ic_info.xml +++ b/app/src/main/res/drawable/ic_info.xml @@ -2,9 +2,9 @@ android:width="24dp" android:height="24dp" android:tint="?attr/colorControlNormal" - android:viewportWidth="48" - android:viewportHeight="48"> + android:viewportWidth="24" + android:viewportHeight="24"> + android:fillColor="@android:color/white" + android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z" /> diff --git a/app/src/main/res/layout/dialog_stats.xml b/app/src/main/res/layout/dialog_stats.xml new file mode 100644 index 0000000000..26d32be771 --- /dev/null +++ b/app/src/main/res/layout/dialog_stats.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c5492e5491..ac54ad6d66 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -444,6 +444,8 @@ Custom speed Use a different playback speed than for the normal player. Category + Stats for nerds + Video ID Download Service Shows a notification when downloading media. diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index 1c6e6ea059..01fc1ed300 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -64,6 +64,15 @@ + +