mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
parent
c482bd0aaf
commit
54104b00ed
5 changed files with 77 additions and 4 deletions
|
|
@ -62,6 +62,8 @@ import androidx.compose.ui.window.DialogProperties
|
|||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.geeksville.mesh.model.Contact
|
||||
import org.meshtastic.core.database.entity.ContactSettings
|
||||
import org.meshtastic.core.model.util.formatMuteRemainingTime
|
||||
import org.meshtastic.core.strings.R
|
||||
import org.meshtastic.core.ui.component.MainAppBar
|
||||
import org.meshtastic.proto.AppOnlyProtos
|
||||
|
|
@ -201,8 +203,13 @@ fun ContactsScreen(
|
|||
},
|
||||
)
|
||||
|
||||
// Get contact settings for the dialog
|
||||
val contactSettings by viewModel.getContactSettings().collectAsStateWithLifecycle(initialValue = emptyMap())
|
||||
|
||||
MuteNotificationsDialog(
|
||||
showDialog = showMuteDialog,
|
||||
selectedContactKeys = selectedContactKeys.toList(),
|
||||
contactSettings = contactSettings,
|
||||
onDismiss = { showMuteDialog = false },
|
||||
onConfirm = { muteUntil ->
|
||||
showMuteDialog = false
|
||||
|
|
@ -216,6 +223,8 @@ fun ContactsScreen(
|
|||
@Composable
|
||||
fun MuteNotificationsDialog(
|
||||
showDialog: Boolean,
|
||||
selectedContactKeys: List<String>,
|
||||
contactSettings: Map<String, ContactSettings>,
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (Long) -> Unit, // Lambda to handle the confirmed mute duration
|
||||
) {
|
||||
|
|
@ -238,6 +247,35 @@ fun MuteNotificationsDialog(
|
|||
title = { Text(text = stringResource(R.string.mute_notifications)) },
|
||||
text = {
|
||||
Column {
|
||||
// Show current mute status
|
||||
selectedContactKeys.forEach { contactKey ->
|
||||
contactSettings[contactKey]?.let { settings ->
|
||||
val now = System.currentTimeMillis()
|
||||
val statusText =
|
||||
when {
|
||||
settings.muteUntil > 0 && settings.muteUntil != Long.MAX_VALUE -> {
|
||||
val remaining = settings.muteUntil - now
|
||||
if (remaining > 0) {
|
||||
val (days, hours) = formatMuteRemainingTime(remaining)
|
||||
if (days >= 1) {
|
||||
stringResource(R.string.mute_status_muted_for_days, days, hours)
|
||||
} else {
|
||||
stringResource(R.string.mute_status_muted_for_hours, hours)
|
||||
}
|
||||
} else {
|
||||
stringResource(R.string.mute_status_unmuted)
|
||||
}
|
||||
}
|
||||
settings.muteUntil == Long.MAX_VALUE -> stringResource(R.string.mute_status_always)
|
||||
else -> stringResource(R.string.mute_status_unmuted)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(R.string.currently) + " " + statusText,
|
||||
modifier = Modifier.padding(bottom = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
muteOptions.forEachIndexed { index, (stringRes, _) ->
|
||||
val isSelected = index == selectedOptionIndex
|
||||
val text = stringResource(stringRes)
|
||||
|
|
|
|||
|
|
@ -121,5 +121,7 @@ constructor(
|
|||
fun setMuteUntil(contacts: List<String>, until: Long) =
|
||||
viewModelScope.launch(Dispatchers.IO) { packetRepository.setMuteUntil(contacts, until) }
|
||||
|
||||
fun getContactSettings() = packetRepository.getContactSettings()
|
||||
|
||||
private fun getUser(userId: String?) = nodeRepository.getUser(userId ?: DataPacket.ID_BROADCAST)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue