mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 23:36:42 +01:00
Improving click and long press interactions with the relay list item and status bar items
This commit is contained in:
@@ -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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,20 +56,17 @@ 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)
|
|
||||||
.pointerInput(Unit) {
|
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
|
onTap = {
|
||||||
|
onClick()
|
||||||
|
},
|
||||||
onLongPress = {
|
onLongPress = {
|
||||||
accountViewModel.toastManager.toast(
|
accountViewModel.toastManager.toast(
|
||||||
R.string.read_from_relay,
|
R.string.read_from_relay,
|
||||||
@@ -73,25 +75,30 @@ fun RelayStatusRow(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Download,
|
||||||
|
contentDescription = stringRes(R.string.read_from_relay),
|
||||||
|
modifier = Size15Modifier,
|
||||||
tint = MaterialTheme.colorScheme.allGoodColor,
|
tint = MaterialTheme.colorScheme.allGoodColor,
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = countToHumanReadableBytes(item.relayStat.receivedBytes),
|
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.Upload,
|
|
||||||
stringRes(R.string.write_to_relay),
|
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
modifier.pointerInput(Unit) {
|
||||||
.size(15.dp)
|
|
||||||
.pointerInput(Unit) {
|
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
|
onTap = {
|
||||||
|
onClick()
|
||||||
|
},
|
||||||
onLongPress = {
|
onLongPress = {
|
||||||
accountViewModel.toastManager.toast(
|
accountViewModel.toastManager.toast(
|
||||||
R.string.write_to_relay,
|
R.string.write_to_relay,
|
||||||
@@ -100,25 +107,30 @@ fun RelayStatusRow(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Upload,
|
||||||
|
stringRes(R.string.write_to_relay),
|
||||||
|
modifier = Size15Modifier,
|
||||||
tint = MaterialTheme.colorScheme.allGoodColor,
|
tint = MaterialTheme.colorScheme.allGoodColor,
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = countToHumanReadableBytes(item.relayStat.sentBytes),
|
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,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Icon(
|
Row(
|
||||||
imageVector = Icons.Default.SyncProblem,
|
|
||||||
stringRes(R.string.errors),
|
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
modifier.pointerInput(Unit) {
|
||||||
.size(15.dp)
|
|
||||||
.pointerInput(Unit) {
|
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
|
onTap = {
|
||||||
|
onClick()
|
||||||
|
},
|
||||||
onLongPress = {
|
onLongPress = {
|
||||||
accountViewModel.toastManager.toast(
|
accountViewModel.toastManager.toast(
|
||||||
R.string.errors,
|
R.string.errors,
|
||||||
@@ -127,6 +139,11 @@ fun RelayStatusRow(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.SyncProblem,
|
||||||
|
stringRes(R.string.errors),
|
||||||
|
modifier = Size15Modifier,
|
||||||
tint =
|
tint =
|
||||||
if (item.relayStat.errorCounter > 0) {
|
if (item.relayStat.errorCounter > 0) {
|
||||||
MaterialTheme.colorScheme.warningColor
|
MaterialTheme.colorScheme.warningColor
|
||||||
@@ -138,35 +155,32 @@ fun RelayStatusRow(
|
|||||||
Text(
|
Text(
|
||||||
text = countToHumanReadable(item.relayStat.errorCounter, "errors"),
|
text = countToHumanReadable(item.relayStat.errorCounter, "errors"),
|
||||||
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)
|
|
||||||
.pointerInput(Unit) {
|
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
|
onTap = {
|
||||||
|
onClick()
|
||||||
|
},
|
||||||
onLongPress = {
|
onLongPress = {
|
||||||
accountViewModel.toastManager.toast(
|
accountViewModel.toastManager.toast(
|
||||||
R.string.spam,
|
R.string.spam,
|
||||||
R.string.spam_description,
|
R.string.spam_description,
|
||||||
)
|
)
|
||||||
scope.launch {
|
|
||||||
Toast
|
|
||||||
.makeText(
|
|
||||||
context,
|
|
||||||
stringRes(context, R.string.spam),
|
|
||||||
Toast.LENGTH_SHORT,
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.DeleteSweep,
|
||||||
|
stringRes(R.string.spam),
|
||||||
|
modifier = Size15Modifier,
|
||||||
tint =
|
tint =
|
||||||
if (item.relayStat.spamCounter > 0) {
|
if (item.relayStat.spamCounter > 0) {
|
||||||
MaterialTheme.colorScheme.warningColor
|
MaterialTheme.colorScheme.warningColor
|
||||||
@@ -178,8 +192,9 @@ fun RelayStatusRow(
|
|||||||
Text(
|
Text(
|
||||||
text = countToHumanReadable(item.relayStat.spamCounter, "spam"),
|
text = countToHumanReadable(item.relayStat.spamCounter, "spam"),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
fontSize = 12.sp,
|
fontSize = Font12SP,
|
||||||
modifier = modifier,
|
modifier = HalfStartPadding,
|
||||||
color = MaterialTheme.colorScheme.placeholderText,
|
color = MaterialTheme.colorScheme.placeholderText,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user