Wait for Android channel loading once before radio activation
This commit is contained in:
1 parent
a0e440c0f5
commit
e61dc8cd06
2 files changed
+10
-4
No files matched your search
@@ -20,6 +20,8 @@ import com.utun.chat.data.CallController
|
||||
import com.utun.chat.data.CallPhase
|
||||
import com.utun.chat.data.RadioCallController
|
||||
import com.utun.chat.data.RadioCallPhase
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.BackHandler
|
||||
@@ -211,13 +213,17 @@ class MainActivity : AppCompatActivity() {
|
||||
val fileChannels by vm.channels.collectAsState()
|
||||
val radioCall by RadioCallController.state.collectAsState()
|
||||
val radioActivation by RadioCallController.activation.collectAsState()
|
||||
LaunchedEffect(radioActivation, fileChannels) {
|
||||
LaunchedEffect(radioActivation?.id) {
|
||||
val activation = radioActivation ?: return@LaunchedEffect
|
||||
if (fileChannels.none { it.id == activation.channelId }) return@LaunchedEffect
|
||||
val channels = withTimeoutOrNull(5000) { vm.channels.first { items -> items.any { it.id == activation.channelId } } }
|
||||
if (RadioCallController.activation.value?.id != activation.id) return@LaunchedEffect
|
||||
if (channels == null) { RadioCallController.activated(activation.id, false); return@LaunchedEffect }
|
||||
screen = Screen.Chat
|
||||
vm.enableRadioForCall(activation.channelId) { success -> RadioCallController.activated(activation.id, success) }
|
||||
}
|
||||
BackHandler(radioCall != null && radioCall?.phase != RadioCallPhase.ENDED) { RadioCallController.end() }
|
||||
BackHandler(radioCall != null && radioCall?.phase != RadioCallPhase.ENDED) {
|
||||
if (radioCall?.phase != RadioCallPhase.PREPARING) RadioCallController.end()
|
||||
}
|
||||
LaunchedEffect(requestedFiles, fileChannels) {
|
||||
requestedFiles?.let { target ->
|
||||
val channel = fileChannels.find { it.id == target.group.toULong().toString() }
|
||||
|
||||
@@ -46,7 +46,7 @@ fun RadioCallDialog(state: RadioCallState) {
|
||||
RadioCallPhase.ENDED -> RadioCallController.reasonText(state.reason)
|
||||
}))
|
||||
Spacer(Modifier.height(20.dp))
|
||||
if (state.phase != RadioCallPhase.ENDED) {
|
||||
if (state.phase != RadioCallPhase.ENDED && state.phase != RadioCallPhase.PREPARING) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
TextButton(onClick = { RadioCallController.end(state.id) }) {
|
||||
Text(stringResource(if (state.phase == RadioCallPhase.INCOMING) R.string.decline else android.R.string.cancel))
|
||||
|
||||
Reference in new issue
Block a user