Ответы, аудио, голосовые
This commit is contained in:
@@ -25,6 +25,7 @@ import core.utils.VoiceRecorder
|
||||
import core.utils.copyUriToFile
|
||||
import java.io.File
|
||||
import ru.knot.messager.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -37,10 +38,37 @@ fun ChatDetailScreen(
|
||||
val state by viewModel.state.collectAsState()
|
||||
val context = LocalContext.current
|
||||
val listState = rememberLazyListState()
|
||||
val scope = rememberCoroutineScope()
|
||||
val voiceRecorder = remember { VoiceRecorder(context) }
|
||||
var textInput by remember { mutableStateOf("") }
|
||||
var isEmojiPickerVisible by remember { mutableStateOf(false) }
|
||||
var isRecording by remember { mutableStateOf(false) }
|
||||
|
||||
var autoPlayingMessageId by remember { mutableStateOf<String?>(null) }
|
||||
var currentPlaybackSpeed by remember { mutableFloatStateOf(1.0f) }
|
||||
|
||||
val playNextVoiceMessage = { currentId: String, speed: Float ->
|
||||
val currentIndex = state.messages.indexOfFirst { it.id == currentId }
|
||||
if (currentIndex != -1 && currentIndex < state.messages.size - 1) {
|
||||
val nextVoiceIndexInSublist = state.messages.subList(currentIndex + 1, state.messages.size)
|
||||
.indexOfFirst { it.mediaType == chats.domain.model.MediaType.AUDIO && it.content.isNullOrEmpty() }
|
||||
|
||||
if (nextVoiceIndexInSublist != -1) {
|
||||
val actualNextIndex = currentIndex + 1 + nextVoiceIndexInSublist
|
||||
autoPlayingMessageId = state.messages[actualNextIndex].id
|
||||
currentPlaybackSpeed = speed
|
||||
|
||||
// Прокручиваем к следующему сообщению, иначе оно не распарсится LazyColumn
|
||||
scope.launch {
|
||||
listState.animateScrollToItem(actualNextIndex)
|
||||
}
|
||||
} else {
|
||||
autoPlayingMessageId = null
|
||||
}
|
||||
} else {
|
||||
autoPlayingMessageId = null
|
||||
}
|
||||
}
|
||||
|
||||
// Пикер галереи
|
||||
val galleryLauncher = rememberLauncherForActivityResult(
|
||||
@@ -126,7 +154,9 @@ fun ChatDetailScreen(
|
||||
MessageBubble(
|
||||
message = message,
|
||||
isCurrentUser = message.senderId == viewModel.getCurrentUserId(),
|
||||
senderAvatar = if (message.senderId == viewModel.getCurrentUserId()) null else message.senderAvatar,
|
||||
autoPlay = message.id == autoPlayingMessageId,
|
||||
initialPlaybackSpeed = if (message.id == autoPlayingMessageId) currentPlaybackSpeed else 1.0f,
|
||||
onVoiceFinished = { speed -> playNextVoiceMessage(message.id, speed) },
|
||||
onReactionClick = { emoji -> viewModel.addReaction(message.id, emoji) }
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user