show toast error if unable to hide words

pull/851/head
VASH 2024-05-04 19:13:45 +02:00
rodzic 1345ad3745
commit 201a6d4462
1 zmienionych plików z 18 dodań i 4 usunięć

Wyświetl plik

@ -43,6 +43,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
@ -251,16 +252,14 @@ private fun AddMuteWordTextField(accountViewModel: AccountViewModel) {
KeyboardActions(
onSend = {
if (hasChanged) {
accountViewModel.hide(currentWordToAdd.value)
currentWordToAdd.value = ""
hideIfWritable(accountViewModel, currentWordToAdd)
}
},
),
singleLine = true,
trailingIcon = {
AddButton(isActive = hasChanged, modifier = HorzPadding) {
accountViewModel.hide(currentWordToAdd.value)
currentWordToAdd.value = ""
hideIfWritable(accountViewModel, currentWordToAdd)
}
},
)
@ -376,3 +375,18 @@ fun ShowWordButton(
Text(text = stringResource(text), color = Color.White, textAlign = TextAlign.Center)
}
}
private fun hideIfWritable(
accountViewModel: AccountViewModel,
currentWordToAdd: MutableState<String>,
) {
if (!accountViewModel.isWriteable()) {
accountViewModel.toast(
R.string.read_only_user,
R.string.login_with_a_private_key_to_be_able_to_hide_word,
)
} else {
accountViewModel.hide(currentWordToAdd.value)
currentWordToAdd.value = ""
}
}