-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallScreen.kt
More file actions
384 lines (360 loc) · 14.9 KB
/
Copy pathCallScreen.kt
File metadata and controls
384 lines (360 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
package com.example.intra
import androidx.compose.animation.core.*
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Call
import androidx.compose.material.icons.filled.CallEnd
import androidx.compose.material.icons.filled.Mic
import androidx.compose.material.icons.filled.MicOff
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.VolumeUp
import androidx.compose.material.icons.filled.VolumeOff
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Brush
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.delay
import coil.compose.AsyncImage
import coil.request.ImageRequest
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.material.icons.filled.Videocam
import androidx.compose.material.icons.filled.VideocamOff
import androidx.compose.material.icons.filled.Cameraswitch
import org.webrtc.SurfaceViewRenderer
import org.webrtc.RendererCommon
@Composable
fun CallScreen(
state: CallState,
onEndCall: () -> Unit,
onRejectCall: () -> Unit,
onAcceptCall: () -> Unit,
onToggleMute: () -> Unit,
onToggleSpeaker: () -> Unit,
onToggleVideo: () -> Unit,
onSwitchCamera: () -> Unit,
webRTCClient: WebRTCClient? = null
) {
// 🔥 TIMER STATE - Call duration track karne ke liye
var callSeconds by remember(state.status) { mutableStateOf(0) }
val context = LocalContext.current
// 🔥 TIMER LOGIC - Connected hone pe start, status change pe auto stop
LaunchedEffect(state.status) {
if (state.status == CallStatus.CONNECTED) {
callSeconds = 0 // Reset timer
while (true) {
delay(1000) // 1 second wait
callSeconds++ // Increment seconds
}
}
}
Box(
modifier = Modifier
.fillMaxSize()
.background(
Brush.verticalGradient(
colors = listOf(
Color(0xFF321954),
Color(0xFF9B28D9),
Color(0xFFE5B80E)
)
)
),
contentAlignment = Alignment.Center
) {
// --- VIDEO CALL BACKGROUND ---
if (state.isVideoCall && state.status == CallStatus.CONNECTED) {
AndroidView(
factory = { ctx ->
SurfaceViewRenderer(ctx).apply {
if (webRTCClient != null) {
init(webRTCClient.eglBaseContext, null)
setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL)
webRTCClient.setupRemoteVideoRenderer(this)
}
}
},
modifier = Modifier.fillMaxSize(),
onRelease = { renderer ->
webRTCClient?.removeRemoteVideoRenderer(renderer)
renderer.release()
}
)
}
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.fillMaxSize()
.padding(vertical = 60.dp)
) {
// --- TOP SECTION: Avatar & Status (Same) ---
Column(horizontalAlignment = Alignment.CenterHorizontally) {
if (!state.isVideoCall || state.status != CallStatus.CONNECTED) {
AvatarGlowRing(
isActive = state.status != CallStatus.CONNECTED
)
Box(
modifier = Modifier
.size(120.dp)
.clip(CircleShape)
.background(Color.White.copy(alpha = 0.2f)),
contentAlignment = Alignment.Center
) {
if (state.profilePhotoUrl != null) {
AsyncImage(
model = state.profilePhotoUrl,
contentDescription = null,
modifier = Modifier.fillMaxSize()
)
} else {
Icon(
imageVector = Icons.Default.Person,
contentDescription = null,
tint = Color.White,
modifier = Modifier.size(60.dp)
)
}
}
}
if (!state.isVideoCall || state.status != CallStatus.CONNECTED) {
Spacer(modifier = Modifier.height(24.dp))
Text(
text = state.targetUser,
color = Color.White,
fontSize = 30.sp,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(8.dp))
AnimatedContent(
targetState = state.status,
transitionSpec = { fadeIn() togetherWith fadeOut() },
label = "callStatus"
) { status ->
Text(
text = when (status) {
CallStatus.OUTGOING -> "Calling..."
CallStatus.INCOMING -> "Incoming Call..."
CallStatus.CONNECTED -> formatTime(callSeconds)
else -> ""
},
color = Color.White.copy(alpha = 0.7f),
fontSize = 18.sp
)
}
} else {
// Transparent overlay texts for Video Call
Column(
modifier = Modifier.fillMaxWidth().padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = state.targetUser,
color = Color.White,
fontSize = 24.sp,
fontWeight = FontWeight.Bold
)
Text(
text = formatTime(callSeconds),
color = Color.White,
fontSize = 16.sp
)
}
}
}
// --- LOCAL VIDEO (PiP) ---
if (state.isVideoCall && state.status == CallStatus.CONNECTED && state.isVideoEnabled) {
Box(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.padding(bottom = 32.dp, end = 16.dp),
contentAlignment = Alignment.BottomEnd
) {
Box(
modifier = Modifier
.width(100.dp)
.height(150.dp)
.clip(androidx.compose.foundation.shape.RoundedCornerShape(12.dp))
.background(Color.Black)
) {
AndroidView(
factory = { ctx ->
SurfaceViewRenderer(ctx).apply {
if (webRTCClient != null) {
init(webRTCClient.eglBaseContext, null)
setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL)
setZOrderMediaOverlay(true)
webRTCClient.setupLocalVideoRenderer(this)
}
}
},
modifier = Modifier.fillMaxSize(),
onRelease = { renderer ->
webRTCClient?.removeLocalVideoRenderer(renderer)
renderer.release()
}
)
}
}
} else {
Spacer(modifier = Modifier.weight(1f))
}
// --- BOTTOM SECTION: Buttons ---
Row(
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 32.dp)
) {
if (state.status == CallStatus.INCOMING) {
// 🔥 INCOMING CALL UI - FIXED REJECT BUTTON
// ❌ Reject Button - Ab signal bhejega
CallActionButton(
icon = Icons.Default.CallEnd,
color = Color(0xFFEF4444),
onClick = onRejectCall // ✅ New callback
)
// ✅ Accept Button
CallActionButton(
icon = Icons.Default.Call,
color = Color(0xFF22C55E),
onClick = onAcceptCall
)
} else {
// --- ACTIVE / OUTGOING CALL UI ---
CallActionButton(
icon = if (state.isMuted) Icons.Default.MicOff else Icons.Default.Mic,
color = if (state.isMuted) Color.White else Color.White.copy(alpha = 0.2f),
iconTint = if (state.isMuted) Color.Black else Color.White,
onClick = onToggleMute
)
if (state.isVideoCall) {
CallActionButton(
icon = if (state.isVideoEnabled) Icons.Default.Videocam else Icons.Default.VideocamOff,
color = if (state.isVideoEnabled) Color.White else Color.White.copy(alpha = 0.2f),
iconTint = if (state.isVideoEnabled) Color.Black else Color.White,
onClick = onToggleVideo
)
CallActionButton(
icon = Icons.Default.Cameraswitch,
color = Color.White.copy(alpha = 0.2f),
iconTint = Color.White,
onClick = onSwitchCamera
)
}
// End Call Button (Same for Connected/Outgoing)
CallActionButton(
icon = Icons.Default.CallEnd,
color = Color(0xFFEF4444),
size = 72.dp,
onClick = onEndCall
)
if (!state.isVideoCall) {
CallActionButton(
icon = if (state.isSpeakerOn) Icons.Default.VolumeUp else Icons.Default.VolumeOff,
color = if (state.isSpeakerOn) Color.White else Color.White.copy(alpha = 0.2f),
iconTint = if (state.isSpeakerOn) Color.Black else Color.White,
onClick = onToggleSpeaker
)
}
}
}
}
}
}
// 🔥 ANIMATED RIPPLE RINGS COMPOSABLE
// Yeh 3 ripple rings banata hai jo continuously animate hoti rehti hain
//@Composable
//fun AnimatedRippleRings() {
// Infinite animation for continuous ripple effect
// val infiniteTransition = rememberInfiniteTransition(label = "ripple")
// 3 alag-alag ripple rings ke liye animations
//val scales = List(3) { index ->
//infiniteTransition.animateFloat(
//initialValue = 1f,
//targetValue = 2f,
//animationSpec = infiniteRepeatable(
//animation = tween(
// durationMillis = 2000,
// easing = LinearEasing
// ),
// repeatMode = RepeatMode.Restart,
// initialStartOffset = StartOffset(index * 666) // Har ring thoda delay se start hogi
// ),
// label = "scale$index"
//)
//}
//val alphas = List(3) { index ->
// infiniteTransition.animateFloat(
// initialValue = 0.6f,
// targetValue = 0f,
// animationSpec = infiniteRepeatable(
// animation = tween(
// durationMillis = 2000,
// easing = LinearEasing
//),
// repeatMode = RepeatMode.Restart,
// initialStartOffset = StartOffset(index * 666)
// ),
// label = "alpha$index"
// )
// }
// 3 ripple rings render karte hain
// Box(contentAlignment = Alignment.Center) {
// scales.forEachIndexed { index, scale ->
//Box(
// modifier = Modifier
// .size(120.dp)
// .scale(scale.value)
// .clip(CircleShape)
// .background(Color.White.copy(alpha = alphas[index].value * 0.3f))
// )
// }
// }
//}
@Composable
fun CallActionButton(
icon: ImageVector,
color: Color,
iconTint: Color = Color.White,
size: androidx.compose.ui.unit.Dp = 56.dp,
onClick: () -> Unit
) {
IconButton(
onClick = onClick,
modifier = Modifier
.size(size)
.clip(CircleShape)
.background(color)
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = iconTint,
modifier = Modifier.size(size * 0.5f)
)
}
}
// 🔥 TIME FORMATTER - Seconds ko mm:ss format me convert karta hai
fun formatTime(seconds: Int): String {
val m = seconds / 60
val s = seconds % 60
return "%02d:%02d".format(m, s)
}