Merge pull request #3842 from Bnyro/master

Show file size in download dialog
This commit is contained in:
Bnyro 2023-05-27 20:09:04 +02:00 committed by GitHub
commit 570800685f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -20,6 +20,7 @@ data class PipedStream(
val fps: Int? = null, val fps: Int? = null,
val audioTrackName: String? = null, val audioTrackName: String? = null,
val audioTrackId: String? = null, val audioTrackId: String? = null,
val contentLength: Long = -1
) { ) {
fun getQualityString(fileName: String): String { fun getQualityString(fileName: String): String {
return "${fileName}_${quality?.replace(" ", "_")}_$format." + return "${fileName}_${quality?.replace(" ", "_")}_$format." +

View File

@ -3,6 +3,7 @@ package com.github.libretube.ui.dialogs
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.text.InputFilter import android.text.InputFilter
import android.text.format.Formatter
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
@ -108,7 +109,10 @@ class DownloadDialog(
val videoArrayAdapter = ArrayAdapter( val videoArrayAdapter = ArrayAdapter(
requireContext(), requireContext(),
R.layout.dropdown_item, R.layout.dropdown_item,
videoStreams.map { "${it.quality} ${it.format}" }.toMutableList().also { videoStreams.map {
val fileSize = Formatter.formatShortFileSize(context, it.contentLength)
"${it.quality} ${it.format} ($fileSize)"
}.toMutableList().also {
it.add(0, getString(R.string.no_video)) it.add(0, getString(R.string.no_video))
}, },
) )
@ -116,7 +120,10 @@ class DownloadDialog(
val audioArrayAdapter = ArrayAdapter( val audioArrayAdapter = ArrayAdapter(
requireContext(), requireContext(),
R.layout.dropdown_item, R.layout.dropdown_item,
audioStreams.map { "${it.quality} ${it.format}" }.toMutableList().also { audioStreams.map {
val fileSize = Formatter.formatShortFileSize(context, it.contentLength)
"${it.quality} ${it.codec} ($fileSize)"
}.toMutableList().also {
it.add(0, getString(R.string.no_audio)) it.add(0, getString(R.string.no_audio))
}, },
) )
@ -217,7 +224,11 @@ class DownloadDialog(
} }
} }
private fun getStreamSelection(streams: List<PipedStream>, quality: String, format: String): Int? { private fun getStreamSelection(
streams: List<PipedStream>,
quality: String,
format: String
): Int? {
if (quality.isBlank()) return null if (quality.isBlank()) return null
streams.forEachIndexed { index, pipedStream -> streams.forEachIndexed { index, pipedStream ->