android: рация — единый режим per-канал, не гаснет при выходе/заходе в группу
This commit is contained in:
1 parent
44d4265084
commit
0209bcf5d3
2 files changed
+28
-13
No files matched your search
@@ -149,7 +149,7 @@ class MainActivity : ComponentActivity() {
|
||||
Screen.MemberList -> screen = Screen.Chat
|
||||
Screen.VideoRecord -> screen = Screen.Chat
|
||||
Screen.PhotoRecord -> screen = Screen.Chat
|
||||
Screen.Chat -> { vm.radioOff(); screen = Screen.ChannelList }
|
||||
Screen.Chat -> screen = Screen.ChannelList
|
||||
Screen.Dm -> { vm.closeDm(); screen = Screen.ChannelList }
|
||||
Screen.Call -> screen = screenBeforeCall ?: Screen.ChannelList
|
||||
else -> screen = Screen.ChannelList
|
||||
|
||||
@@ -67,6 +67,9 @@ class ChatViewModel : ViewModel() {
|
||||
|
||||
private var radioToggleCount = 0
|
||||
|
||||
/* рация: активный канал (null = выключена). Одна рация — один канал. */
|
||||
private var radioChannelId: String? = null
|
||||
|
||||
private var callStartedMs = 0L
|
||||
private var callIncomingAtMs = 0L
|
||||
|
||||
@@ -509,6 +512,7 @@ class ChatViewModel : ViewModel() {
|
||||
if (data.size < 1 + cl) return
|
||||
val chId = String(data, 1, cl)
|
||||
LogManager.addLog("INFO", "VM", "CHANNEL_DELETED ch=$chId")
|
||||
if (radioChannelId == chId) turnRadioOff()
|
||||
if (_currentChannel.value?.id == chId) {
|
||||
_currentChannel.value = null
|
||||
_messages.value = emptyList()
|
||||
@@ -741,21 +745,28 @@ class ChatViewModel : ViewModel() {
|
||||
fun toggleRadio() {
|
||||
val ch = _currentChannel.value ?: return
|
||||
val groupId = ch.id.toULongOrNull()?.toLong() ?: return
|
||||
val next = !_radioActive.value
|
||||
val wasOnHere = radioChannelId == ch.id
|
||||
val next = !wasOnHere
|
||||
radioToggleCount++
|
||||
val caller = Throwable().stackTrace.drop(1).take(8)
|
||||
.joinToString(" <- ") { "${it.className.substringAfterLast('.')}.${it.methodName}:${it.lineNumber}" }
|
||||
LogManager.addLog("DEBUG", "RADIO_DBG",
|
||||
"toggleRadio#$radioToggleCount next=$next prevActive=${_radioActive.value} " +
|
||||
"radioChannelId=$radioChannelId cur=${ch.id} " +
|
||||
"thread=${Thread.currentThread().name} t=${System.currentTimeMillis()} caller=$caller")
|
||||
NativeLib.radioSetActive(groupId, next)
|
||||
_radioActive.value = next
|
||||
if (next) {
|
||||
radioChannelId?.takeIf { it != ch.id }?.toULongOrNull()?.toLong()
|
||||
?.let { NativeLib.radioSetActive(it, false) } /* выключаем старый канал */
|
||||
radioChannelId = ch.id
|
||||
NativeLib.radioSetActive(groupId, true)
|
||||
radioAudio.start(groupId)
|
||||
} else {
|
||||
_radioTalking.value = null
|
||||
radioChannelId = null
|
||||
NativeLib.radioSetActive(groupId, false)
|
||||
radioAudio.stop()
|
||||
_radioTalking.value = null
|
||||
}
|
||||
_radioActive.value = next
|
||||
syncRadioOverlay()
|
||||
LogManager.addLog("INFO", "VM", "toggleRadio -> ${if (next) "on" else "off"} group=$groupId")
|
||||
}
|
||||
@@ -770,23 +781,25 @@ class ChatViewModel : ViewModel() {
|
||||
radioAudio.talkEnd()
|
||||
}
|
||||
|
||||
fun radioOff() {
|
||||
if (!_radioActive.value && !radioAudio.isActive()) return
|
||||
val ch = _currentChannel.value ?: return
|
||||
val groupId = ch.id.toULongOrNull()?.toLong() ?: return
|
||||
NativeLib.radioSetActive(groupId, false)
|
||||
/* Полностью выключить рацию (используется при удалении активного канала). */
|
||||
private fun turnRadioOff() {
|
||||
val chId = radioChannelId ?: return
|
||||
chId.toULongOrNull()?.toLong()?.let { NativeLib.radioSetActive(it, false) }
|
||||
radioChannelId = null
|
||||
_radioActive.value = false
|
||||
_radioTalking.value = null
|
||||
radioAudio.stop()
|
||||
syncRadioOverlay()
|
||||
}
|
||||
|
||||
private fun syncRadioOverlay() {
|
||||
val ctx = ChatApplication.instance
|
||||
val overlayEnabled = ctx.configProvider.getRadioOverlay()
|
||||
val radioOn = radioChannelId != null
|
||||
LogManager.addLog("DEBUG", "RADIO_DBG",
|
||||
"syncRadioOverlay active=${_radioActive.value} overlayEnabled=$overlayEnabled " +
|
||||
"syncRadioOverlay radioOn=$radioOn channel=$radioChannelId overlayEnabled=$overlayEnabled " +
|
||||
"isShown=${RadioOverlayService.isShown.value} t=${System.currentTimeMillis()}")
|
||||
if (_radioActive.value && overlayEnabled)
|
||||
if (radioOn && overlayEnabled)
|
||||
RadioOverlayService.start(ctx)
|
||||
else
|
||||
RadioOverlayService.stop(ctx)
|
||||
@@ -863,8 +876,9 @@ class ChatViewModel : ViewModel() {
|
||||
|
||||
fun selectChannel(channel: Channel) {
|
||||
val r = repo ?: return
|
||||
radioOff() /* рацию выключаем при переключении канала */
|
||||
_currentChannel.value = channel
|
||||
_radioActive.value = (radioChannelId == channel.id)
|
||||
if (radioChannelId != channel.id) _radioTalking.value = null
|
||||
_soundOn.value = NativeLib.getSoundOnMessage(channel.id)
|
||||
NotificationSound.setMuted(channel.id, !_soundOn.value)
|
||||
r.connectChannel(channel.id)
|
||||
@@ -1028,6 +1042,7 @@ class ChatViewModel : ViewModel() {
|
||||
val r = repo ?: return
|
||||
LogManager.addLog("INFO", "VM", "deleteChannel ch=$channelId")
|
||||
r.deleteChannel(channelId)
|
||||
if (radioChannelId == channelId) turnRadioOff()
|
||||
if (_currentChannel.value?.id == channelId) {
|
||||
_currentChannel.value = null
|
||||
_messages.value = emptyList()
|
||||
|
||||
Reference in new issue
Block a user