Skip to content

Commit

Permalink
feat: clear dialpad input at long press (closes #419)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Oct 29, 2024
1 parent a9e26e9 commit 6109c34
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ fun CallLogsScreen(
NumberInput(
onNumberInput = callModel::onNumberInput,
onDelete = callModel::onBackSpace,
onClear = callModel::onClearNumberInput,
onDial = {
callModel.callNumber()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ val keypadNumbers: Array<Array<Pair<String, Any>>> = arrayOf(
fun NumberInput(
onNumberInput: (String) -> Unit,
onDelete: () -> Unit,
onClear: () -> Unit,
onDial: () -> Unit,
subscriptions: List<SubscriptionInfo>?,
onSubscriptionIndexChange: (Int) -> Unit
Expand All @@ -89,44 +90,49 @@ fun NumberInput(
horizontalArrangement = Arrangement.spacedBy(buttonSpacing)
) {
col.forEach {
val subcontent = it.second
if (subcontent is String) {
NumpadButtonWithSubcontent(
aspectRatio = 1.5f,
text = it.first,
onClick = {
onNumberInput(it.first)
when (val subContent = it.second) {
is String -> {
NumpadButtonWithSubcontent(
aspectRatio = 1.5f,
text = it.first,
onClick = {
onNumberInput(it.first)
}
) {
Text(
text = subContent,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodyMedium
)
}
) {
Text(
text = subcontent,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodyMedium
)
}
} else if (subcontent is ImageVector) {
NumpadButtonWithSubcontent(
aspectRatio = 1.5f,
text = it.first,
onClick = {
onNumberInput(it.first)

is ImageVector -> {
NumpadButtonWithSubcontent(
aspectRatio = 1.5f,
text = it.first,
onClick = {
onNumberInput(it.first)
}
) {
Icon(
modifier = Modifier.size(16.dp),
imageVector = subContent,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface
)
}
) {
Icon(
modifier = Modifier.size(16.dp),
imageVector = subcontent,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface
}

else -> {
NumpadButton(
aspectRatio = 1.5f,
text = it.first,
onClick = {
onNumberInput(it.first)
}
)
}
} else {
NumpadButton(
aspectRatio = 1.5f,
text = it.first,
onClick = {
onNumberInput(it.first)
}
)
}
}
}
Expand All @@ -137,7 +143,7 @@ fun NumberInput(
) {
Spacer(modifier = Modifier.weight(1f))
NumpadButton(
onClick = { onDial.invoke() },
onClick = onDial,
backgroundColor = MaterialTheme.colorScheme.secondaryContainer
) {
Icon(
Expand All @@ -147,7 +153,8 @@ fun NumberInput(
)
}
NumpadButton(
onClick = { onDelete.invoke() },
onClick = onDelete,
onLongClick = onClear,
backgroundColor = MaterialTheme.colorScheme.tertiaryContainer
) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class CallModel(private val application: Application, savedStateHandle: SavedSta
}
}

fun onClearNumberInput() {
numberToCall = ""
_contacts.update {
emptyList()
}
}

fun callNumber(number: String = numberToCall) {
if (!PermissionHelper.hasPermission(application.applicationContext, *phonePerms)) return

Expand Down

0 comments on commit 6109c34

Please sign in to comment.