Improving click and long press interactions with the relay list item and status bar items

This commit is contained in:
Vitor Pamplona
2025-10-21 09:19:11 -04:00
parent d51d1f4453
commit a27df3a9b6
2 changed files with 138 additions and 122 deletions

View File

@@ -109,7 +109,8 @@ fun BasicRelaySetupInfoClickableRow(
) { ) {
RelayStatusRow( RelayStatusRow(
item = item, item = item,
modifier = HalfStartPadding.weight(1f), onClick = onClick,
modifier = Modifier.weight(1f),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) )
} }

View File

@@ -22,6 +22,8 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DeleteSweep import androidx.compose.material.icons.filled.DeleteSweep
@@ -43,6 +45,9 @@ import com.vitorpamplona.amethyst.service.countToHumanReadable
import com.vitorpamplona.amethyst.service.countToHumanReadableBytes import com.vitorpamplona.amethyst.service.countToHumanReadableBytes
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.Font12SP
import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
import com.vitorpamplona.amethyst.ui.theme.allGoodColor import com.vitorpamplona.amethyst.ui.theme.allGoodColor
import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.amethyst.ui.theme.warningColor import com.vitorpamplona.amethyst.ui.theme.warningColor
@@ -51,135 +56,145 @@ import kotlinx.coroutines.launch
@Composable @Composable
fun RelayStatusRow( fun RelayStatusRow(
item: BasicRelaySetupInfo, item: BasicRelaySetupInfo,
onClick: () -> Unit,
modifier: Modifier, modifier: Modifier,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
val scope = rememberCoroutineScope() Row(
val context = LocalContext.current
Icon(
imageVector = Icons.Default.Download,
contentDescription = stringRes(R.string.read_from_relay),
modifier = modifier =
Modifier modifier.pointerInput(Unit) {
.size(15.dp) detectTapGestures(
.pointerInput(Unit) { onTap = {
detectTapGestures( onClick()
onLongPress = { },
accountViewModel.toastManager.toast( onLongPress = {
R.string.read_from_relay, accountViewModel.toastManager.toast(
R.string.read_from_relay_description, R.string.read_from_relay,
) R.string.read_from_relay_description,
}, )
) },
}, )
tint = MaterialTheme.colorScheme.allGoodColor,
)
Text(
text = countToHumanReadableBytes(item.relayStat.receivedBytes),
maxLines = 1,
fontSize = 12.sp,
modifier = modifier,
color = MaterialTheme.colorScheme.placeholderText,
)
Icon(
imageVector = Icons.Default.Upload,
stringRes(R.string.write_to_relay),
modifier =
Modifier
.size(15.dp)
.pointerInput(Unit) {
detectTapGestures(
onLongPress = {
accountViewModel.toastManager.toast(
R.string.write_to_relay,
R.string.write_to_relay_description,
)
},
)
},
tint = MaterialTheme.colorScheme.allGoodColor,
)
Text(
text = countToHumanReadableBytes(item.relayStat.sentBytes),
maxLines = 1,
fontSize = 12.sp,
modifier = modifier,
color = MaterialTheme.colorScheme.placeholderText,
)
Icon(
imageVector = Icons.Default.SyncProblem,
stringRes(R.string.errors),
modifier =
Modifier
.size(15.dp)
.pointerInput(Unit) {
detectTapGestures(
onLongPress = {
accountViewModel.toastManager.toast(
R.string.errors,
R.string.errors_description,
)
},
)
},
tint =
if (item.relayStat.errorCounter > 0) {
MaterialTheme.colorScheme.warningColor
} else {
MaterialTheme.colorScheme.allGoodColor
}, },
) ) {
Icon(
imageVector = Icons.Default.Download,
contentDescription = stringRes(R.string.read_from_relay),
modifier = Size15Modifier,
tint = MaterialTheme.colorScheme.allGoodColor,
)
Text( Text(
text = countToHumanReadable(item.relayStat.errorCounter, "errors"), text = countToHumanReadableBytes(item.relayStat.receivedBytes),
maxLines = 1, maxLines = 1,
fontSize = 12.sp, fontSize = Font12SP,
modifier = modifier, modifier = HalfStartPadding,
color = MaterialTheme.colorScheme.placeholderText, color = MaterialTheme.colorScheme.placeholderText,
) )
}
Icon( Row(
imageVector = Icons.Default.DeleteSweep,
stringRes(R.string.spam),
modifier = modifier =
Modifier modifier.pointerInput(Unit) {
.size(15.dp) detectTapGestures(
.pointerInput(Unit) { onTap = {
detectTapGestures( onClick()
onLongPress = { },
accountViewModel.toastManager.toast( onLongPress = {
R.string.spam, accountViewModel.toastManager.toast(
R.string.spam_description, R.string.write_to_relay,
) R.string.write_to_relay_description,
scope.launch { )
Toast },
.makeText( )
context,
stringRes(context, R.string.spam),
Toast.LENGTH_SHORT,
).show()
}
},
)
},
tint =
if (item.relayStat.spamCounter > 0) {
MaterialTheme.colorScheme.warningColor
} else {
MaterialTheme.colorScheme.allGoodColor
}, },
) ) {
Icon(
imageVector = Icons.Default.Upload,
stringRes(R.string.write_to_relay),
modifier = Size15Modifier,
tint = MaterialTheme.colorScheme.allGoodColor,
)
Text( Text(
text = countToHumanReadable(item.relayStat.spamCounter, "spam"), text = countToHumanReadableBytes(item.relayStat.sentBytes),
maxLines = 1, maxLines = 1,
fontSize = 12.sp, fontSize = Font12SP,
modifier = modifier, modifier = HalfStartPadding,
color = MaterialTheme.colorScheme.placeholderText, color = MaterialTheme.colorScheme.placeholderText,
) )
}
Row(
modifier =
modifier.pointerInput(Unit) {
detectTapGestures(
onTap = {
onClick()
},
onLongPress = {
accountViewModel.toastManager.toast(
R.string.errors,
R.string.errors_description,
)
},
)
},
) {
Icon(
imageVector = Icons.Default.SyncProblem,
stringRes(R.string.errors),
modifier = Size15Modifier,
tint =
if (item.relayStat.errorCounter > 0) {
MaterialTheme.colorScheme.warningColor
} else {
MaterialTheme.colorScheme.allGoodColor
},
)
Text(
text = countToHumanReadable(item.relayStat.errorCounter, "errors"),
maxLines = 1,
fontSize = Font12SP,
modifier = HalfStartPadding,
color = MaterialTheme.colorScheme.placeholderText,
)
}
Row(
modifier =
modifier.pointerInput(Unit) {
detectTapGestures(
onTap = {
onClick()
},
onLongPress = {
accountViewModel.toastManager.toast(
R.string.spam,
R.string.spam_description,
)
},
)
},
) {
Icon(
imageVector = Icons.Default.DeleteSweep,
stringRes(R.string.spam),
modifier = Size15Modifier,
tint =
if (item.relayStat.spamCounter > 0) {
MaterialTheme.colorScheme.warningColor
} else {
MaterialTheme.colorScheme.allGoodColor
},
)
Text(
text = countToHumanReadable(item.relayStat.spamCounter, "spam"),
maxLines = 1,
fontSize = Font12SP,
modifier = HalfStartPadding,
color = MaterialTheme.colorScheme.placeholderText,
)
}
} }