chat: UI настройки звука канала (Android toggle + JNI, desktop через C API) + trampoline

This commit is contained in:
evgeny committed 2026-09-22 01:25:55 +03:00
1 parent 3d9c79e752
commit cc0dcb071e
8 files changed
+116 -10

No files matched your search

@@ -85,6 +85,10 @@ object NativeLib {
fun setChatSetting(name: String, value: String) { nativeSetChatSetting(name, value) }
fun getChatSettingInt(name: String, def: Int = 0): Int = nativeGetChatSettingInt(name, def)
/* ── Per-channel «play sound on message» ── */
fun getSoundOnMessage(chId: String): Boolean = nativeGetSoundOnMessage(chId) != 0
fun setSoundOnMessage(chId: String, on: Boolean) { nativeSetSoundOnMessage(chId, on) }
/** Enable/disable forwarding native C logs to LogManager (expensive, off by default) */
fun subscribeNativeLogs(enabled: Boolean) { nativeSubscribeLogs(enabled) }
fun setUdpLogTarget(ip: String, port: Int) { nativeSetUdpLogTarget(ip, port) }
@@ -186,6 +190,8 @@ object NativeLib {
private external fun nativeSetDebugLevel(category: String, level: String)
private external fun nativeSetChatSetting(name: String, value: String)
private external fun nativeGetChatSettingInt(name: String, def: Int): Int
private external fun nativeGetSoundOnMessage(chId: String): Int
private external fun nativeSetSoundOnMessage(chId: String, on: Boolean)
private external fun nativeSubscribeLogs(enabled: Boolean)
private external fun nativeSetUdpLogTarget(ip: String, port: Int)
private external fun nativeRegenerateKeys()
@@ -70,6 +70,9 @@ fun ChatScreen(
val overlayShown by RadioOverlayService.isShown.collectAsState()
val localTalking by RadioAudioEngine.instance().talkingFlow.collectAsState()
/* звук сообщений канала */
val soundOn by viewModel.soundOn.collectAsState()
/* attach menu */
var showAttachMenu by remember { mutableStateOf(false) }
@@ -140,6 +143,9 @@ fun ChatScreen(
IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back") }
},
actions = {
IconButton(onClick = { viewModel.toggleSound() }) {
Text(if (soundOn) "\uD83D\uDD14" else "\uD83D\uDD15", fontSize = 18.sp)
}
IconButton(onClick = { viewModel.toggleRadio() }) {
Text(if (radioActive) "\uD83D\uDCFB" else "\uD83D\uDD07", fontSize = 18.sp)
}
@@ -94,6 +94,9 @@ class ChatViewModel : ViewModel() {
private val _currentChannel = MutableStateFlow<Channel?>(null)
val currentChannel: StateFlow<Channel?> = _currentChannel
private val _soundOn = MutableStateFlow(true)
val soundOn: StateFlow<Boolean> = _soundOn
private val _pubKey = MutableStateFlow("")
val pubKey: StateFlow<String> = _pubKey
@@ -857,10 +860,21 @@ class ChatViewModel : ViewModel() {
val r = repo ?: return
radioOff() /* рацию выключаем при переключении канала */
_currentChannel.value = channel
_soundOn.value = NativeLib.getSoundOnMessage(channel.id)
NotificationSound.setMuted(channel.id, !_soundOn.value)
r.connectChannel(channel.id)
refreshMessages(channel.id)
}
/* ── per-channel «play sound on message» ── */
fun toggleSound() {
val ch = _currentChannel.value ?: return
val on = !_soundOn.value
_soundOn.value = on
NotificationSound.setMuted(ch.id, !on)
NativeLib.setSoundOnMessage(ch.id, on)
}
/* ── DM (личные сообщения) ── */
fun refreshDmConversations() {