Share compact bitrate labels between streaming and recording controls

This commit is contained in:
evgeny committed 2026-10-28 12:08:06 +01:00
1 parent 306163b00c
commit 57d4978d4d
2 files changed
+16 -10

No files matched your search

@@ -10,6 +10,8 @@ import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
@@ -24,9 +26,22 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.utun.chat.R
import java.text.NumberFormat
internal enum class CaptureIconShape { CAMERA, CHIP, GAUGE, SCREEN }
/** Короткое локализованное значение битрейта для шкалы в записи и трансляции. */
@Composable
internal fun captureBitrateLabel(bitrate: Int): String {
val mega = bitrate >= 1_000_000
val value = NumberFormat.getNumberInstance(LocalConfiguration.current.locales[0]).apply {
maximumFractionDigits = if (mega && bitrate < 10_000_000) 1 else 0
isGroupingUsed = false
}.format(bitrate.toDouble() / if (mega) 1_000_000 else 1_000)
return stringResource(if (mega) R.string.stream_bitrate_short_m else R.string.stream_bitrate_short_k, value)
}
/** Единый размер касания, подсказки и семантика для обычных кнопок и переключателя звука. */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -71,7 +71,6 @@ import com.utun.chat.data.LensType
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.text.NumberFormat
import kotlin.math.roundToInt
/** Выход закрывает reader либо прямой preview output; foreground publisher останавливается явно. */
@@ -256,15 +255,7 @@ private fun StreamCaptureToolbar(cameras: List<StreamCamera>, config: StreamCapt
var menu by remember { mutableStateOf<StreamOption?>(null) }
LaunchedEffect(enabled) { if (!enabled) menu = null }
LaunchedEffect(menu) { LogManager.addLog("DEBUG", "stream", "toolbar menu=$menu enabled=$enabled manualBitrateRange=${mode?.manualBitrateRange}") }
val locale = LocalConfiguration.current.locales[0]
val shortBitrate = config?.let {
val mega = it.bitrate >= 1_000_000
val value = NumberFormat.getNumberInstance(locale).apply {
maximumFractionDigits = if (mega && it.bitrate < 10_000_000) 1 else 0
isGroupingUsed = false
}.format(it.bitrate.toDouble() / if (mega) 1_000_000 else 1_000)
stringResource(if (mega) R.string.stream_bitrate_short_m else R.string.stream_bitrate_short_k, value)
} ?: "—"
val shortBitrate = config?.let { captureBitrateLabel(it.bitrate) } ?: "—"
val bitrateValue = config?.let { stringResource(R.string.stream_bitrate_value, it.bitrate / 1_000_000.0) } ?: "—"
val bitrateDescription = if (config != null && config.videoBitrate == null)
stringResource(R.string.stream_bitrate_auto_value, bitrateValue) else stringResource(R.string.stream_bitrate, bitrateValue)