Added tooltips to mic and speakerphone icons

This commit is contained in:
Juha Heinanen
2025-04-26 07:28:33 +03:00
parent 964af9fe9d
commit d19bf4db78
2 changed files with 59 additions and 69 deletions

View File

@ -82,7 +82,6 @@ import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.outlined.Clear import androidx.compose.material.icons.outlined.Clear
import androidx.compose.material3.BasicAlertDialog import androidx.compose.material3.BasicAlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors import androidx.compose.material3.ButtonColors
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
@ -93,21 +92,17 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.RichTooltip
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.material3.TooltipBox
import androidx.compose.material3.TooltipDefaults
import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator
import androidx.compose.material3.pulltorefresh.pullToRefresh import androidx.compose.material3.pulltorefresh.pullToRefresh
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.material3.rememberTooltipState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
@ -116,7 +111,6 @@ import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -153,12 +147,10 @@ import com.tutpro.baresip.CustomElements.SelectableAlertDialog
import com.tutpro.baresip.CustomElements.Text import com.tutpro.baresip.CustomElements.Text
import com.tutpro.baresip.CustomElements.verticalScrollbar import com.tutpro.baresip.CustomElements.verticalScrollbar
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.Locale import java.util.Locale
import kotlin.collections.set
import kotlin.system.exitProcess import kotlin.system.exitProcess
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@ -685,34 +677,9 @@ class MainActivity : ComponentActivity() {
containerColor = LocalCustomColors.current.primary containerColor = LocalCustomColors.current.primary
), ),
actions = { actions = {
val scope = rememberCoroutineScope()
val tooltipState = rememberTooltipState() IconButton(
TooltipBox( modifier = Modifier.combinedClickable(
positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),
tooltip = {
RichTooltip(
title = { Text(
text = "Call Recording",
color = LocalCustomColors.current.alert,
fontSize = 18.sp,
modifier = Modifier.padding(bottom = 4.dp)
) },
text = { Text(
text = "If activated, new incoming or outgoing calls are recorded.",
color = LocalCustomColors.current.itemText,
fontSize = 16.sp
) },
caretSize = TooltipDefaults.caretSize,
shape = RoundedCornerShape(16.dp),
colors = TooltipDefaults.richTooltipColors(
containerColor = LocalCustomColors.current.cardBackground,
),
)
},
enableUserInput = true,
state = tooltipState
) {
IconButton(
onClick = { onClick = {
if (Call.call("connected") == null) { if (Call.call("connected") == null) {
BaresipService.isRecOn = !BaresipService.isRecOn BaresipService.isRecOn = !BaresipService.isRecOn
@ -726,31 +693,46 @@ class MainActivity : ComponentActivity() {
} else } else
Toast.makeText(ctx, R.string.rec_in_call, Toast.LENGTH_SHORT).show() Toast.makeText(ctx, R.string.rec_in_call, Toast.LENGTH_SHORT).show()
}, },
) { onLongClick = {
Icon( alertTitle.value = "Call Recording"
imageVector = recImage, alertMessage.value = "If activated, new incoming and outgoing calls will be recorded." +
tint = Color.Unspecified, "Recordings can be played on Call Details page"
contentDescription = null showAlert.value = true
) }
} ),
onClick = {}
) {
Icon(
imageVector = recImage,
tint = Color.Unspecified,
contentDescription = null
)
} }
Spacer(modifier = Modifier.width(16.dp)) Spacer(modifier = Modifier.width(16.dp))
IconButton( IconButton(
modifier = Modifier.padding(end=12.dp), modifier = Modifier.padding(end=12.dp)
onClick = { .combinedClickable(
if (Call.call("connected") != null) { onClick = {
BaresipService.isMicMuted = !BaresipService.isMicMuted if (Call.call("connected") != null) {
if (BaresipService.isMicMuted) { BaresipService.isMicMuted = !BaresipService.isMicMuted
micIcon = R.drawable.mic_off if (BaresipService.isMicMuted) {
Api.calls_mute(true) micIcon = R.drawable.mic_off
} else { Api.calls_mute(true)
micIcon = R.drawable.mic_on } else {
Api.calls_mute(false) micIcon = R.drawable.mic_on
} Api.calls_mute(false)
} }
} }
},
onLongClick = {
alertTitle.value = "Microphone"
alertMessage.value = "If activated, microphone is muted."
showAlert.value = true
},
),
onClick = {}
) { ) {
Icon( Icon(
imageVector = ImageVector.vectorResource(micIcon), imageVector = ImageVector.vectorResource(micIcon),
@ -759,18 +741,26 @@ class MainActivity : ComponentActivity() {
} }
IconButton( IconButton(
modifier = Modifier.padding(end=6.dp), modifier = Modifier.padding(end=6.dp)
onClick = { .combinedClickable(
if (Build.VERSION.SDK_INT >= 31) onClick = {
Log.d(TAG, "Toggling speakerphone when dev/mode is " + if (Build.VERSION.SDK_INT >= 31)
"${am.communicationDevice!!.type}/${am.mode}" Log.d(TAG, "Toggling speakerphone when dev/mode is " +
) "${am.communicationDevice!!.type}/${am.mode}"
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(ctx), am) )
speakerIcon = if (Utils.isSpeakerPhoneOn(am)) Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(ctx), am)
R.drawable.speaker_on speakerIcon = if (Utils.isSpeakerPhoneOn(am))
else R.drawable.speaker_on
R.drawable.speaker_off else
} R.drawable.speaker_off
},
onLongClick = {
alertTitle.value = "Speakerphone"
alertMessage.value = "If activated, audio is player via speakerphone."
showAlert.value = true
},
),
onClick = {}
) { ) {
Icon( Icon(
imageVector = ImageVector.vectorResource(speakerIcon), imageVector = ImageVector.vectorResource(speakerIcon),