Use call_up and call_down drawables

This commit is contained in:
Juha Heinanen
2025-11-14 12:46:43 +02:00
parent 50a74391e5
commit 10f4fedc60
11 changed files with 70 additions and 94 deletions
@@ -39,7 +39,9 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
@@ -170,19 +172,19 @@ private fun Details(ctx: Context, details: ArrayList<Details>) {
items(details) { detail -> items(details) { detail ->
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
Image( Image(
painter = painterResource(detail.direction), painter = painterResource(
if (callUp(detail.direction)) R.drawable.call_up else R.drawable.call_down
),
colorFilter = ColorFilter.tint(colorResource(id = callTint(detail.direction))),
contentDescription = "Direction", contentDescription = "Direction",
modifier = Modifier.width(64.dp) modifier = Modifier.width(64.dp)
.clickable { .clickable {
Toast.makeText(ctx, Toast.makeText(ctx,
when (detail.direction) { when (detail.direction) {
R.drawable.call_down_green, CALL_DOWN_GREEN, CALL_UP_GREEN -> ctx.getString(R.string.call_answered)
R.drawable.call_up_green-> ctx.getString(R.string.call_answered) CALL_DOWN_BLUE -> ctx.getString(R.string.call_answered_elsewhere)
R.drawable.call_down_blue -> ctx.getString(R.string.call_answered_elsewhere) CALL_MISSED_IN, CALL_MISSED_OUT -> ctx.getString(R.string.call_missed)
R.drawable.call_missed_in, CALL_DOWN_RED, CALL_UP_RED -> ctx.getString(R.string.call_rejected)
R.drawable.call_missed_out -> ctx.getString(R.string.call_missed)
R.drawable.call_down_red,
R.drawable.call_up_red-> ctx.getString(R.string.call_rejected)
else -> "" else -> ""
}, },
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
@@ -215,7 +217,7 @@ private fun startTime(detail: Details): String {
startTimeText = stopText startTimeText = stopText
durationText = "?" durationText = "?"
} else { } else {
if (startTime == null || detail.direction == R.drawable.call_down_blue) { if (startTime == null || detail.direction == CALL_DOWN_BLUE) {
startTimeText = stopText startTimeText = stopText
durationText = "" durationText = ""
} else { } else {
@@ -49,8 +49,10 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
@@ -97,7 +99,9 @@ private fun CallsScreen(navController: NavController, viewModel: ViewModel, aor:
} }
Scaffold( Scaffold(
modifier = Modifier.fillMaxSize().imePadding(), modifier = Modifier
.fillMaxSize()
.imePadding(),
containerColor = MaterialTheme.colorScheme.background, containerColor = MaterialTheme.colorScheme.background,
topBar = { topBar = {
Column( Column(
@@ -271,7 +275,9 @@ private fun Calls(
val lazyListState = rememberLazyListState() val lazyListState = rememberLazyListState()
LazyColumn( LazyColumn(
modifier = Modifier.fillMaxWidth().padding(start = 16.dp, end = 4.dp) modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 4.dp)
.verticalScrollbar( .verticalScrollbar(
state = lazyListState, state = lazyListState,
width = 4.dp, width = 4.dp,
@@ -382,8 +388,8 @@ private fun Calls(
CustomElements.TextAvatar(contact.name, contact.color) CustomElements.TextAvatar(contact.name, contact.color)
} }
null -> { null -> {
val avatarImage = BitmapFactory val avatarImage =
.decodeResource(ctx.resources, R.drawable.person_image) BitmapFactory.decodeResource(ctx.resources, R.drawable.person_image)
CustomElements.ImageAvatar(avatarImage) CustomElements.ImageAvatar(avatarImage)
} }
} }
@@ -394,7 +400,13 @@ private fun Calls(
recordings = true recordings = true
if (count > 3) if (count > 3)
continue continue
Image(painterResource(d.direction), "Direction") Image(
painter = painterResource(
if (callUp(d.direction)) R.drawable.call_up else R.drawable.call_down
),
colorFilter = ColorFilter.tint(colorResource(id = callTint(d.direction))),
contentDescription = "Direction"
)
count++ count++
} }
if (count > 3) if (count > 3)
@@ -436,25 +448,16 @@ private fun loadCallHistory(aor: String): MutableList<CallRow> {
if (h.aor == aor) { if (h.aor == aor) {
val direction: Int = if (h.direction == "in") { val direction: Int = if (h.direction == "in") {
if (h.startTime != null) { if (h.startTime != null) {
if (h.startTime != h.stopTime) if (h.startTime != h.stopTime) CALL_DOWN_GREEN else CALL_DOWN_BLUE
R.drawable.call_down_green
else
R.drawable.call_down_blue
} else {
if (h.rejected)
R.drawable.call_down_red
else
R.drawable.call_missed_in
} }
} else {
if (h.startTime != null) {
R.drawable.call_up_green
} else {
if (h.rejected)
R.drawable.call_up_red
else else
R.drawable.call_missed_out if (h.rejected) CALL_DOWN_RED else CALL_MISSED_IN
} }
else {
if (h.startTime != null)
CALL_UP_GREEN
else
if (h.rejected) CALL_UP_RED else CALL_MISSED_OUT
} }
if (res.isNotEmpty() && res.last().peerUri == h.peerUri) if (res.isNotEmpty() && res.last().peerUri == h.peerUri)
res.last().details.add(CallRow.Details( res.last().details.add(CallRow.Details(
@@ -482,3 +485,18 @@ private fun removeFromHistory(callHistory: MutableState<List<CallRow>>, callRow:
CallHistoryNew.save() CallHistoryNew.save()
} }
fun callUp(direction: Int): Boolean {
return when (direction) {
CALL_UP_GREEN, CALL_UP_RED, CALL_MISSED_OUT -> true
else -> false
}
}
fun callTint(direction: Int): Int {
return when (direction) {
CALL_UP_GREEN, CALL_DOWN_GREEN -> R.color.colorTrafficGreen
CALL_UP_RED, CALL_DOWN_RED -> R.color.colorTrafficRed
CALL_DOWN_BLUE -> R.color.colorPrimary
else -> R.color.colorTrafficYellow
}
}
@@ -33,6 +33,14 @@ const val MESSAGE_UP = 2131165306
const val MESSAGE_UP_FAIL = 2131165307 const val MESSAGE_UP_FAIL = 2131165307
const val MESSAGE_UP_WAIT = 2131165308 const val MESSAGE_UP_WAIT = 2131165308
const val CALL_UP_GREEN = 2131165323
const val CALL_DOWN_GREEN = 2131165316
const val CALL_UP_RED = 2131165324
const val CALL_DOWN_BLUE = 2131165315
const val CALL_DOWN_RED = 2131165317
const val CALL_MISSED_OUT = 2131165320
const val CALL_MISSED_IN = 2131165319
val mediaEncMap = mapOf("zrtp" to "ZRTP", "dtls_srtp" to "DTLS-SRTPF", "srtp-mand" to "SRTP-MAND", val mediaEncMap = mapOf("zrtp" to "ZRTP", "dtls_srtp" to "DTLS-SRTPF", "srtp-mand" to "SRTP-MAND",
"srtp" to "SRTP", "" to "--") "srtp" to "SRTP", "" to "--")
@@ -2,8 +2,7 @@
android:width="20dp" android:width="20dp"
android:height="20dp" android:height="20dp"
android:viewportWidth="960" android:viewportWidth="960"
android:viewportHeight="960" android:viewportHeight="960" >
android:tint="@color/colorPrimary" >
<path <path
android:fillColor="@android:color/white" android:fillColor="@android:color/white"
android:pathData="M232.35,775.65L232.35,428.65L315.35,428.65L315.35,634L714.85,234.5L773.5,293.15L374,692.65L579.35,692.65L579.35,775.65L232.35,775.65Z"/> android:pathData="M232.35,775.65L232.35,428.65L315.35,428.65L315.35,634L714.85,234.5L773.5,293.15L374,692.65L579.35,692.65L579.35,775.65L232.35,775.65Z"/>
@@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="@color/colorTrafficGreen" >
<path
android:fillColor="@android:color/white"
android:pathData="M232.35,775.65L232.35,428.65L315.35,428.65L315.35,634L714.85,234.5L773.5,293.15L374,692.65L579.35,692.65L579.35,775.65L232.35,775.65Z"/>
</vector>
@@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="@color/colorTrafficRed" >
<path
android:fillColor="@android:color/white"
android:pathData="M232.35,775.65L232.35,428.65L315.35,428.65L315.35,634L714.85,234.5L773.5,293.15L374,692.65L579.35,692.65L579.35,775.65L232.35,775.65Z"/>
</vector>
@@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="@color/colorTrafficYellow" >
<path
android:fillColor="@android:color/white"
android:pathData="M232.35,775.65L232.35,428.65L315.35,428.65L315.35,634L714.85,234.5L773.5,293.15L374,692.65L579.35,692.65L579.35,775.65L232.35,775.65Z"/>
</vector>
@@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="@color/colorTrafficYellow" >
<path
android:fillColor="@android:color/white"
android:pathData="M243,727.65L184.35,669L583.85,269.5L378.5,269.5L378.5,186.5L725.5,186.5L725.5,533.5L642.5,533.5L642.5,328.15L243,727.65Z"/>
</vector>
+9
View File
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="960"
android:viewportHeight="960" >
<path
android:fillColor="@android:color/white"
android:pathData="M243,727.65L184.35,669L583.85,269.5L378.5,269.5L378.5,186.5L725.5,186.5L725.5,533.5L642.5,533.5L642.5,328.15L243,727.65Z"/>
</vector>
@@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="@color/colorTrafficGreen">
<path
android:fillColor="@android:color/white"
android:pathData="M243,727.65L184.35,669L583.85,269.5L378.5,269.5L378.5,186.5L725.5,186.5L725.5,533.5L642.5,533.5L642.5,328.15L243,727.65Z"/>
</vector>
-10
View File
@@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="@color/colorTrafficRed" >
<path
android:fillColor="@android:color/white"
android:pathData="M243,727.65L184.35,669L583.85,269.5L378.5,269.5L378.5,186.5L725.5,186.5L725.5,533.5L642.5,533.5L642.5,328.15L243,727.65Z"/>
</vector>