diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/MainActivity.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/MainActivity.kt index 7b53e38b..9d9021d5 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/MainActivity.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/MainActivity.kt @@ -39,6 +39,7 @@ import com.utun.chat.data.IncomingCallManager import com.utun.chat.data.InviteData import com.utun.chat.data.LogManager import com.utun.chat.data.Message +import com.utun.chat.data.ConversationTarget import com.utun.chat.data.NativeLib import com.utun.chat.data.RadioOverlayService import com.utun.chat.data.RadioAudioEngine @@ -161,6 +162,7 @@ class MainActivity : ComponentActivity() { var showJoinDialog by remember { mutableStateOf(false) } var inviteChannelId by remember { mutableStateOf(null) } var videoMessage by remember { mutableStateOf(null) } + var videoTarget by remember { mutableStateOf(null) } var photoMessage by remember { mutableStateOf(null) } var hadCall by remember { mutableStateOf(false) } var screenBeforeCall by remember { mutableStateOf(null) } @@ -220,7 +222,7 @@ class MainActivity : ComponentActivity() { BackHandler(enabled = screen != Screen.ChannelList) { when (screen) { Screen.MemberList -> screen = Screen.Chat - Screen.VideoRecord -> screen = Screen.Chat + Screen.VideoRecord -> screen = if (videoTarget is ConversationTarget.Pm) Screen.Dm else Screen.Chat Screen.PhotoRecord -> screen = Screen.Chat Screen.Chat -> screen = Screen.ChannelList Screen.Dm -> { vm.closeDm(); screen = Screen.ChannelList } @@ -298,7 +300,7 @@ class MainActivity : ComponentActivity() { onBack = { screen = Screen.ChannelList }, onPlayVideo = { msg -> videoMessage = msg }, onViewPhoto = { msg -> photoMessage = msg }, - onRecordVideo = { screen = Screen.VideoRecord }, + onRecordVideo = { videoTarget = ConversationTarget.Channel(channel.id); screen = Screen.VideoRecord }, onCapturePhoto = { screen = Screen.PhotoRecord } ) } @@ -324,8 +326,10 @@ class MainActivity : ComponentActivity() { DmChatScreen( conv = dm, messages = dmMessages, + viewModel = vm, onSendMessage = { vm.sendDmMessage(it) }, - onSendFile = { conv, path, name -> vm.sendDmFile(conv, path, name) }, + onRecordVideo = { videoTarget = ConversationTarget.Pm(dm.convId); screen = Screen.VideoRecord }, + onPlayVideo = { videoMessage = it }, onBack = { vm.closeDm(); screen = Screen.ChannelList } ) } @@ -338,14 +342,14 @@ class MainActivity : ComponentActivity() { onMinimize = { screen = screenBeforeCall ?: Screen.ChannelList } ) Screen.VideoRecord -> { - val channel = vm.currentChannel.collectAsState().value - if (channel != null) { + val target = videoTarget + if (target != null) { VideoRecordScreen( onSend = { path -> - vm.sendVideoMessage(path) - screen = Screen.Chat + vm.sendVideoMessage(path, target) + screen = if (target is ConversationTarget.Pm) Screen.Dm else Screen.Chat }, - onClose = { screen = Screen.Chat } + onClose = { screen = if (target is ConversationTarget.Pm) Screen.Dm else Screen.Chat } ) } } diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/ConversationComposer.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/ConversationComposer.kt index 53ff1829..e2452d8e 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/ConversationComposer.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/ConversationComposer.kt @@ -76,7 +76,7 @@ fun ConversationComposer(target: ConversationTarget, viewModel: ChatViewModel, o var cache: String? = null try { withContext(Dispatchers.IO) { cache = viewModel.copyUriToCache(context, attachment.uri, attachment.name) } - val path = cache ?: error("Не удалось скопировать вложение") + val path = cache ?: throw IllegalStateException("Не удалось скопировать вложение") if (video) viewModel.sendVideoMessage(path, attachment.target) else viewModel.sendAttachment(path, attachment.target, attachment.name) cache = null // Native/backend принял собственный cache-файл.