Правка чата
This commit is contained in:
@@ -26,6 +26,10 @@ import kotlinx.coroutines.delay
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.GraphicEq
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
|
||||
@Composable
|
||||
fun AppAudioPlayer(
|
||||
@@ -47,6 +51,7 @@ fun AppAudioPlayer(
|
||||
var currentPosition by remember { mutableLongStateOf(0L) }
|
||||
var duration by remember { mutableLongStateOf(0L) }
|
||||
var playbackSpeed by remember { mutableFloatStateOf(1.0f) }
|
||||
var layoutSize by remember { mutableStateOf(IntSize.Zero) }
|
||||
|
||||
val fileName = remember(url) { url.substringAfterLast("/") }
|
||||
|
||||
@@ -110,7 +115,7 @@ fun AppAudioPlayer(
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(36.dp)
|
||||
.size(40.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color.White)
|
||||
.clickable { if (isPlaying) exoPlayer.pause() else exoPlayer.play() },
|
||||
@@ -119,8 +124,8 @@ fun AppAudioPlayer(
|
||||
Icon(
|
||||
imageVector = if (isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow,
|
||||
contentDescription = null,
|
||||
tint = Color(0xFF3390EC),
|
||||
modifier = Modifier.size(24.dp)
|
||||
tint = Color(0xFF3096E5),
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -129,68 +134,94 @@ fun AppAudioPlayer(
|
||||
.weight(1f)
|
||||
.padding(horizontal = 12.dp)
|
||||
) {
|
||||
Slider(
|
||||
value = if (duration > 0) currentPosition.toFloat() / duration.toFloat() else 0f,
|
||||
onValueChange = {
|
||||
val newPos = (it * duration).toLong()
|
||||
exoPlayer.seekTo(newPos)
|
||||
currentPosition = newPos
|
||||
},
|
||||
modifier = Modifier.height(16.dp),
|
||||
colors = SliderDefaults.colors(
|
||||
thumbColor = Color.White,
|
||||
activeTrackColor = Color.White,
|
||||
inactiveTrackColor = Color.White.copy(alpha = 0.3f)
|
||||
)
|
||||
)
|
||||
// Waveform / Progress
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(32.dp)
|
||||
.onSizeChanged { layoutSize = it }
|
||||
.pointerInput(duration) {
|
||||
detectTapGestures { offset ->
|
||||
if (duration > 0 && layoutSize.width > 0) {
|
||||
val pct = offset.x / layoutSize.width.toFloat()
|
||||
val newPos = (pct * duration).toLong()
|
||||
exoPlayer.seekTo(newPos)
|
||||
currentPosition = newPos
|
||||
}
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
androidx.compose.foundation.Canvas(modifier = Modifier.fillMaxSize()) {
|
||||
val barCount = 35
|
||||
val barSpacing = 2.dp.toPx()
|
||||
val barWidth = (size.width - (barCount - 1) * barSpacing) / barCount
|
||||
val progress = if (duration > 0) currentPosition.toFloat() / duration.toFloat() else 0f
|
||||
|
||||
// Fake consistent waveform items
|
||||
val barHeights = listOf(
|
||||
0.4f, 0.6f, 0.3f, 0.8f, 0.5f, 0.9f, 0.4f, 0.7f, 0.5f, 0.8f,
|
||||
0.3f, 0.7f, 0.6f, 0.9f, 0.4f, 0.8f, 0.5f, 0.7f, 0.3f, 0.9f,
|
||||
0.5f, 0.6f, 0.4f, 0.8f, 0.6f, 0.7f, 0.5f, 0.4f, 0.5f, 0.7f,
|
||||
0.4f, 0.3f, 0.5f, 0.6f, 0.4f
|
||||
)
|
||||
|
||||
for (i in 0 until barCount) {
|
||||
val x = i * (barWidth + barSpacing)
|
||||
val heightPct = barHeights[i % barHeights.size]
|
||||
val barHeight = size.height * heightPct
|
||||
val isActive = (i.toFloat() / barCount) <= progress
|
||||
|
||||
drawRoundRect(
|
||||
color = if (isActive) Color.White else Color.White.copy(alpha = 0.25f),
|
||||
topLeft = androidx.compose.ui.geometry.Offset(x, (size.height - barHeight) / 2),
|
||||
size = androidx.compose.ui.geometry.Size(barWidth, barHeight),
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(2.dp.toPx())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = formatDuration(currentPosition),
|
||||
fontSize = 10.sp,
|
||||
text = "${formatDuration(currentPosition)} / ${formatDuration(duration)}",
|
||||
fontSize = 11.sp,
|
||||
color = contentColor.copy(alpha = 0.7f)
|
||||
)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = "3.3 MB", // Mock size
|
||||
fontSize = 10.sp,
|
||||
color = contentColor.copy(alpha = 0.7f)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
if (!isVoiceMessage) {
|
||||
Icon(
|
||||
Icons.Default.Download,
|
||||
contentDescription = null,
|
||||
tint = contentColor.copy(alpha = 0.7f),
|
||||
modifier = Modifier.size(12.dp)
|
||||
modifier = Modifier.size(14.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isVoiceMessage) {
|
||||
Surface(
|
||||
onClick = {
|
||||
playbackSpeed = when (playbackSpeed) {
|
||||
1.0f -> 1.5f
|
||||
1.5f -> 2.0f
|
||||
else -> 1.0f
|
||||
}
|
||||
exoPlayer.playbackParameters = PlaybackParameters(playbackSpeed)
|
||||
},
|
||||
color = Color.White.copy(alpha = 0.2f),
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.size(32.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Text(
|
||||
text = "${if (playbackSpeed % 1.0f == 0.0f) playbackSpeed.toInt() else playbackSpeed}x",
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.White
|
||||
)
|
||||
Surface(
|
||||
onClick = {
|
||||
playbackSpeed = when (playbackSpeed) {
|
||||
1.0f -> 1.5f
|
||||
1.5f -> 2.0f
|
||||
else -> 1.0f
|
||||
}
|
||||
exoPlayer.playbackParameters = PlaybackParameters(playbackSpeed)
|
||||
},
|
||||
color = Color.White.copy(alpha = 0.15f),
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.size(36.dp)
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Text(
|
||||
text = "${if (playbackSpeed % 1.0f == 0.0f) playbackSpeed.toInt() else playbackSpeed}x",
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.Black,
|
||||
color = Color.White
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Bookmark
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -24,22 +26,30 @@ fun AppAvatar(
|
||||
size: Dp = 48.dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val isSavedMessages = remember(name) {
|
||||
name.equals("Избранное", ignoreCase = true) || name.equals("Saved Messages", ignoreCase = true)
|
||||
}
|
||||
|
||||
val initials = remember(name) {
|
||||
val words = name.trim().split("\\s+".toRegex())
|
||||
if (words.size >= 2) {
|
||||
(words[0].take(1) + words[1].take(1)).uppercase()
|
||||
} else if (name.length >= 2) {
|
||||
name.take(2).uppercase()
|
||||
} else {
|
||||
name.take(1).uppercase()
|
||||
if (isSavedMessages) "" else {
|
||||
val words = name.trim().split("\\s+".toRegex())
|
||||
if (words.size >= 2) {
|
||||
(words[0].take(1) + words[1].take(1)).uppercase()
|
||||
} else if (name.length >= 2) {
|
||||
name.take(2).uppercase()
|
||||
} else {
|
||||
name.take(1).uppercase()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val avatarColor = Color(0xFF4AA6F3) // Premium Telegram Blue (Web)
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.size(size)
|
||||
.clip(SoftSquareShape)
|
||||
.background(MaterialTheme.colorScheme.primary.copy(alpha = 0.2f)),
|
||||
.background(avatarColor),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (!url.isNullOrBlank()) {
|
||||
@@ -49,10 +59,17 @@ fun AppAvatar(
|
||||
modifier = Modifier.size(size),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
} else if (isSavedMessages) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Bookmark,
|
||||
contentDescription = null,
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size((size.value * 0.5).dp)
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = initials,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
color = Color.White,
|
||||
fontSize = (size.value * 0.4).sp,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.Bold,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
105
client-mobile/core/presentation/components/AppMediaLightbox.kt
Normal file
105
client-mobile/core/presentation/components/AppMediaLightbox.kt
Normal file
@@ -0,0 +1,105 @@
|
||||
package core.presentation.components
|
||||
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectTransformGestures
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import coil.compose.AsyncImage
|
||||
|
||||
@Composable
|
||||
fun AppMediaLightbox(
|
||||
url: String,
|
||||
type: String = "image",
|
||||
onClose: () -> Unit
|
||||
) {
|
||||
Dialog(
|
||||
onDismissRequest = onClose,
|
||||
properties = DialogProperties(
|
||||
usePlatformDefaultWidth = false,
|
||||
decorFitsSystemWindows = false
|
||||
)
|
||||
) {
|
||||
var scale by remember { mutableFloatStateOf(1f) }
|
||||
var offset by remember { mutableStateOf(androidx.compose.ui.geometry.Offset.Zero) }
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
.pointerInput(Unit) {
|
||||
detectTransformGestures { _, pan, zoom, _ ->
|
||||
scale = (scale * zoom).coerceIn(1f, 5f)
|
||||
offset += pan
|
||||
}
|
||||
}
|
||||
) {
|
||||
if (type == "video") {
|
||||
AppVideoPlayer(
|
||||
url = url,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
useController = true,
|
||||
autoPlay = true
|
||||
)
|
||||
} else {
|
||||
AsyncImage(
|
||||
model = url,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.graphicsLayer(
|
||||
scaleX = scale,
|
||||
scaleY = scale,
|
||||
translationX = offset.x,
|
||||
translationY = offset.y
|
||||
),
|
||||
contentScale = ContentScale.Fit
|
||||
)
|
||||
}
|
||||
|
||||
// Top Bar
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.statusBarsPadding()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onClose,
|
||||
modifier = Modifier
|
||||
.clip(CircleShape)
|
||||
.background(Color.Black.copy(alpha = 0.5f))
|
||||
) {
|
||||
Icon(Icons.Default.Close, contentDescription = null, tint = Color.White)
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = { /* Handle download */ },
|
||||
modifier = Modifier
|
||||
.clip(CircleShape)
|
||||
.background(Color.Black.copy(alpha = 0.5f))
|
||||
) {
|
||||
Icon(Icons.Default.Download, contentDescription = null, tint = Color.White)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ fun AppVideoPlayer(
|
||||
modifier: Modifier = Modifier,
|
||||
useController: Boolean = true,
|
||||
autoPlay: Boolean = true,
|
||||
isMuted: Boolean = false,
|
||||
onVideoFinished: () -> Unit = {}
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
@@ -28,6 +29,7 @@ fun AppVideoPlayer(
|
||||
ExoPlayer.Builder(context).build().apply {
|
||||
val mediaItem = MediaItem.fromUri(url)
|
||||
setMediaItem(mediaItem)
|
||||
volume = if (isMuted) 0f else 1f
|
||||
prepare()
|
||||
playWhenReady = autoPlay
|
||||
addListener(object : Player.Listener {
|
||||
@@ -40,6 +42,10 @@ fun AppVideoPlayer(
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(isMuted) {
|
||||
exoPlayer.volume = if (isMuted) 0f else 1f
|
||||
}
|
||||
|
||||
// Очистка ресурсов при выходе
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
|
||||
Reference in New Issue
Block a user