From 1380f05d1a01a8b1caee46283e008d61b1551fce Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 3 Aug 2026 15:32:28 +0300 Subject: [PATCH] More call code styling --- .../com/tutpro/baresip/CallDetailsScreen.kt | 29 ++++------- .../kotlin/com/tutpro/baresip/CallHistory.kt | 1 + .../kotlin/com/tutpro/baresip/CallsScreen.kt | 52 ++++++------------- 3 files changed, 27 insertions(+), 55 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallDetailsScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/CallDetailsScreen.kt index 5b766b2e..e0d0a27b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallDetailsScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallDetailsScreen.kt @@ -174,18 +174,21 @@ private fun Peer(ctx: Context, callRow: CallRow) { @Composable private fun Details(ctx: Context, details: SnapshotStateList
, onDelete: (Details) -> Unit) { Row(verticalAlignment = Alignment.CenterVertically) { - Text(text = stringResource(R.string.direction), + Text( + text = stringResource(R.string.direction), fontSize = 16.sp, fontWeight = FontWeight.SemiBold, modifier = Modifier.width(96.dp) ) Spacer(modifier = Modifier.width(6.dp)) - Text(text = stringResource(R.string.time), + Text( + text = stringResource(R.string.time), fontSize = 16.sp, fontWeight = FontWeight.SemiBold ) Spacer(modifier = Modifier.weight(1f)) - Text(text = stringResource(R.string.calls_duration), + Text( + text = stringResource(R.string.calls_duration), modifier = Modifier.padding(end = 12.dp), fontSize = 16.sp, fontWeight = FontWeight.SemiBold @@ -336,8 +339,7 @@ private fun Duration(ctx: Context, detail: Details, durationText: String) { } else withContext(Dispatchers.Main) { - Toast.makeText(ctx, "Source file not found", Toast.LENGTH_SHORT) - .show() + Toast.makeText(ctx, "Source file not found", Toast.LENGTH_SHORT).show() } } } catch (e: Exception) { @@ -354,8 +356,7 @@ private fun Duration(ctx: Context, detail: Details, durationText: String) { showDialog = showPlaybackDialog, mediaPlayer = mediaPlayer, onStop = { - if (mediaPlayer.isPlaying) - mediaPlayer.stop() + if (mediaPlayer.isPlaying) mediaPlayer.stop() mediaPlayer.reset() showPlaybackDialog.value = false } @@ -504,16 +505,10 @@ private fun Duration(ctx: Context, detail: Details, durationText: String) { } } catch (e: Exception) { Log.e(TAG, "Playback failed: $e") - Toast.makeText( - ctx, "Playback error", - Toast.LENGTH_SHORT - ).show() + Toast.makeText(ctx, "Playback error", Toast.LENGTH_SHORT).show() } else - Toast.makeText( - ctx, "Failed to process audio file", - Toast.LENGTH_SHORT - ).show() + Toast.makeText(ctx, "Failed to process audio file", Toast.LENGTH_SHORT).show() } } } @@ -578,9 +573,7 @@ private fun PlaybackDialog( } }, confirmButton = { - TextButton(onClick = { onStop() }) { - Text(stringResource(R.string.stop)) - } + TextButton(onClick = { onStop() }) { Text(stringResource(R.string.stop)) } } ) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt index db6a469e..899e785a 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt @@ -148,5 +148,6 @@ class CallHistoryNew(val aor: String, val peerUri: String, val direction: String Log.d(TAG, "[${h.aor}, ${h.peerUri}, ${h.direction}, ${h.startTime}," + "${h.stopTime}, ${h.rejected}, ${h.recording}") } + } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt index 5976aca7..6f484562 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt @@ -101,21 +101,17 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor: val ctx = LocalContext.current LaunchedEffect(ua, refreshTrigger) { - if (ua.account.isMobile) - Utils.cancelMissedCallsNotification(ctx) + if (ua.account.isMobile) Utils.cancelMissedCallsNotification(ctx) callHistory.value = loadCallHistory(aor) isHistoryLoaded = true } DisposableEffect(lifecycleOwner) { val observer = LifecycleEventObserver { _, event -> - if (event == Lifecycle.Event.ON_RESUME) - refreshTrigger++ + if (event == Lifecycle.Event.ON_RESUME) refreshTrigger++ } lifecycleOwner.lifecycle.addObserver(observer) - onDispose { - lifecycleOwner.lifecycle.removeObserver(observer) - } + onDispose { lifecycleOwner.lifecycle.removeObserver(observer) } } BackHandler(enabled = true) { @@ -137,14 +133,7 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor: }, content = { contentPadding -> if (isHistoryLoaded) - CallsContent( - LocalContext.current, - navController, - viewModel, - contentPadding, - ua, - callHistory - ) + CallsContent(LocalContext.current, navController, viewModel, contentPadding, ua, callHistory) }, ) } @@ -206,9 +195,7 @@ private fun TopAppBar(navController: NavController, ua: UserAgent, callHistory: } }, actions = { - IconButton( - onClick = { expanded = !expanded } - ) { + IconButton(onClick = { expanded = !expanded }) { Icon(imageVector = Icons.Filled.Menu, contentDescription = "Menu") } CustomElements.DropdownMenu( @@ -230,9 +217,8 @@ private fun TopAppBar(navController: NavController, ua: UserAgent, callHistory: account.callHistory = !account.callHistory Account.saveAccounts() } - blocked -> { + blocked -> navController.navigate("blocked/invite/${account.aor}") - } } } ) @@ -250,10 +236,7 @@ private fun CallsContent( callHistory: MutableState> ) { Column( - modifier = Modifier - .fillMaxWidth() - .padding(contentPadding) - .padding(bottom = 16.dp), + modifier = Modifier.fillMaxWidth().padding(contentPadding).padding(bottom = 16.dp), verticalArrangement = Arrangement.spacedBy(12.dp) ) { Account(ua.account) @@ -378,14 +361,13 @@ private fun Calls( ctx.getString(R.string.airplane_mode) showAlert.value = true } - else - if (!Utils.isDefaultSmsApp(ctx)) { + else if (!Utils.isDefaultSmsApp(ctx)) { alertTitle.value = ctx.getString(R.string.notice) alertMessage.value = ctx.getString(R.string.enable_default_messaging) showAlert.value = true } - else { + else { handleIntent(ctx, viewModel, intent, "message") navController.navigateUp() } @@ -478,22 +460,19 @@ private fun Calls( else CustomElements.TextAvatar(contact.name, contact.color) } - null -> { + null -> Icon( imageVector = Icons.Filled.AccountCircle, contentDescription = "Avatar", modifier = Modifier.size(36.dp).scale(1.2f), tint = MaterialTheme.colorScheme.secondary ) - } } Spacer(modifier = Modifier.width(4.dp)) var count = 1 for (d in callRow.details) { - if (d.recording.isNotEmpty() && d.recording[0] != "") - recordings = true - if (count > 3) - continue + if (d.recording.isNotEmpty() && d.recording[0] != "") recordings = true + if (count > 3) continue Icon( imageVector = if (callUp(d.direction)) Icons.AutoMirrored.Filled.CallMade @@ -557,10 +536,9 @@ private fun loadCallHistory(aor: String): MutableList { if (h.rejected) CALL_UP_RED else CALL_MISSED_OUT } if (res.isNotEmpty() && res.last().peerUri == h.peerUri) - res.last().details.add(CallRow.Details( - direction, h.startTime, - h.stopTime, h.recording.toList() - )) + res.last().details.add( + CallRow.Details(direction, h.startTime, h.stopTime, h.recording.toList()) + ) else res.add(CallRow(h.aor, h.peerUri, direction, h.startTime, h.stopTime, h.recording.toList())) }