Skip to content

Commit 341ca50

Browse files
committed
make calling icon change color depending on call state
1 parent 9ebe470 commit 341ca50

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ package com.zoffcc.applications.trifa
33
import CAPTURE_VIDEO_FPS
44
import CAPTURE_VIDEO_HEIGHT
55
import CAPTURE_VIDEO_WIDTH
6+
import avstatestorecallstate
67
import com.zoffcc.applications.ffmpegav.AVActivity
78
import com.zoffcc.applications.ffmpegav.AVActivity.ffmpegav_init
89
import global_prefs
910
import kotlinx.coroutines.CoroutineScope
1011
import kotlinx.coroutines.flow.MutableStateFlow
1112
import kotlinx.coroutines.flow.StateFlow
13+
import kotlinx.coroutines.launch
1214
import java.nio.ByteBuffer
1315
import java.util.concurrent.Semaphore
1416

17+
data class AVStateCallState(val call_state: AVState.CALL_STATUS = AVState.CALL_STATUS.CALL_STATUS_NONE)
18+
1519
data class AVState(val a: Int)
1620
{
1721
enum class CALL_DEVICES_STATE {
@@ -43,7 +47,7 @@ data class AVState(val a: Int)
4347
private var audio_in_source = ""
4448
private var video_in_device = ""
4549
private var video_in_source = ""
46-
private var calling_state = CALL_STATUS.CALL_STATUS_NONE
50+
var calling_state = CALL_STATUS.CALL_STATUS_NONE
4751
private var devices_state = CALL_DEVICES_STATE.CALL_DEVICES_STATE_CLOSED
4852
private var call_with_friend_pubkey: String? = null
4953
private var semaphore_avstate = CustomSemaphore(1)
@@ -140,6 +144,7 @@ data class AVState(val a: Int)
140144
fun calling_state_set(value: CALL_STATUS)
141145
{
142146
calling_state = value
147+
avstatestorecallstate.update(status = value)
143148
}
144149

145150
fun ffmpeg_init_done_get(): Boolean
@@ -502,4 +507,27 @@ fun CoroutineScope.createAVStateStore(): AVStateStore
502507
{
503508
override val stateFlow: StateFlow<AVState> = mutableStateFlow
504509
}
510+
}
511+
512+
interface AVStateStoreCallState
513+
{
514+
val stateFlow: StateFlow<AVStateCallState>
515+
val state get() = stateFlow.value
516+
fun update(status: AVState.CALL_STATUS)
517+
}
518+
519+
fun CoroutineScope.createAVStateStoreCallState(): AVStateStoreCallState
520+
{
521+
val mutableStateFlow = MutableStateFlow(AVStateCallState())
522+
523+
return object : AVStateStoreCallState
524+
{
525+
override val stateFlow: StateFlow<AVStateCallState> = mutableStateFlow
526+
override fun update(status: AVState.CALL_STATUS)
527+
{
528+
launch {
529+
mutableStateFlow.value = state.copy(call_state = status)
530+
}
531+
}
532+
}
505533
}

src/main/kotlin/com/zoffcc/applications/trifa2/ChatApp.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import com.zoffcc.applications.trifa.TRIFAGlobals
4848
import com.zoffcc.applications.trifa.ToxVars
4949
import com.zoffcc.applications.trifa.ToxVars.TOX_MESSAGE_TYPE
5050
import com.zoffcc.applications.trifa.createAVStateStore
51+
import com.zoffcc.applications.trifa.createAVStateStoreCallState
5152
import com.zoffcc.applications.trifa.createContactStore
5253
import com.zoffcc.applications.trifa.createGroupPeerStore
5354
import com.zoffcc.applications.trifa.createGroupStore
@@ -69,6 +70,7 @@ val groupstore = CoroutineScope(SupervisorJob()).createGroupStore()
6970
val savepathstore = CoroutineScope(SupervisorJob()).createSavepathStore()
7071
val toxdatastore = CoroutineScope(SupervisorJob()).createToxDataStore()
7172
val avstatestore = CoroutineScope(SupervisorJob()).createAVStateStore()
73+
val avstatestorecallstate = CoroutineScope(SupervisorJob()).createAVStateStoreCallState()
7274

7375
@Composable
7476
fun ChatAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boolean = true, contactList: StateContacts, ui_scale: Float)
@@ -85,6 +87,7 @@ fun ChatAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boolea
8587
IconButton(onClick = {/* Do Something*/ }) {
8688
Icon(Icons.Filled.Call, null)
8789
}
90+
val curren_callstate by avstatestorecallstate.stateFlow.collectAsState()
8891
IconButton(onClick = {
8992
// video call button pressed
9093
val friendpubkey = contactList.selectedContactPubkey
@@ -112,10 +115,9 @@ fun ChatAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boolea
112115
avstatestore.state.start_av_call()
113116
println("toxav: set 003")
114117
}) {
115-
// TODO: make this actually work!
116-
if (avstatestore.state.calling_state_get() == AVState.CALL_STATUS.CALL_STATUS_CALLING)
118+
if (curren_callstate.call_state == AVState.CALL_STATUS.CALL_STATUS_CALLING)
117119
{
118-
Icon(imageVector = Icons.Filled.Videocam, contentDescription = null,
120+
Icon(imageVector = Icons.Filled.Videocam, contentDescription = "",
119121
tint = Color.Red)
120122
}
121123
else

0 commit comments

Comments
 (0)