Merge pull request #465 from greenart7c3/main
show icon for paid relays in the relay list
This commit is contained in:
@@ -12,5 +12,6 @@ data class RelaySetupInfo(
|
|||||||
val downloadCountInBytes: Int = 0,
|
val downloadCountInBytes: Int = 0,
|
||||||
val uploadCountInBytes: Int = 0,
|
val uploadCountInBytes: Int = 0,
|
||||||
val spamCount: Int = 0,
|
val spamCount: Int = 0,
|
||||||
val feedTypes: Set<FeedType>
|
val feedTypes: Set<FeedType>,
|
||||||
|
val paidRelay: Boolean = false
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.actions
|
package com.vitorpamplona.amethyst.ui.actions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
@@ -29,6 +30,7 @@ import androidx.compose.material.icons.filled.Cancel
|
|||||||
import androidx.compose.material.icons.filled.DeleteSweep
|
import androidx.compose.material.icons.filled.DeleteSweep
|
||||||
import androidx.compose.material.icons.filled.Download
|
import androidx.compose.material.icons.filled.Download
|
||||||
import androidx.compose.material.icons.filled.Groups
|
import androidx.compose.material.icons.filled.Groups
|
||||||
|
import androidx.compose.material.icons.filled.Paid
|
||||||
import androidx.compose.material.icons.filled.Public
|
import androidx.compose.material.icons.filled.Public
|
||||||
import androidx.compose.material.icons.filled.Search
|
import androidx.compose.material.icons.filled.Search
|
||||||
import androidx.compose.material.icons.filled.SyncProblem
|
import androidx.compose.material.icons.filled.SyncProblem
|
||||||
@@ -62,6 +64,7 @@ import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.Font14SP
|
import com.vitorpamplona.amethyst.ui.theme.Font14SP
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size35dp
|
import com.vitorpamplona.amethyst.ui.theme.Size35dp
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.lang.Math.round
|
import java.lang.Math.round
|
||||||
|
|
||||||
@@ -69,9 +72,16 @@ import java.lang.Math.round
|
|||||||
fun NewRelayListView(onClose: () -> Unit, accountViewModel: AccountViewModel, relayToAdd: String = "", nav: (String) -> Unit) {
|
fun NewRelayListView(onClose: () -> Unit, accountViewModel: AccountViewModel, relayToAdd: String = "", nav: (String) -> Unit) {
|
||||||
val postViewModel: NewRelayListViewModel = viewModel()
|
val postViewModel: NewRelayListViewModel = viewModel()
|
||||||
val feedState by postViewModel.relays.collectAsState()
|
val feedState by postViewModel.relays.collectAsState()
|
||||||
|
val context = LocalContext.current
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
postViewModel.load(accountViewModel.account)
|
postViewModel.load(accountViewModel.account)
|
||||||
|
postViewModel.relays.value.forEach { item ->
|
||||||
|
loadRelayInfo(item.url, context, scope) {
|
||||||
|
postViewModel.togglePaidRelay(item, it.limitation?.payment_required ?: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
@@ -117,6 +127,7 @@ fun NewRelayListView(onClose: () -> Unit, accountViewModel: AccountViewModel, re
|
|||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
ServerConfigHeader()
|
ServerConfigHeader()
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerConfig(
|
ServerConfig(
|
||||||
item,
|
item,
|
||||||
onToggleDownload = { postViewModel.toggleDownload(it) },
|
onToggleDownload = { postViewModel.toggleDownload(it) },
|
||||||
@@ -130,7 +141,9 @@ fun NewRelayListView(onClose: () -> Unit, accountViewModel: AccountViewModel, re
|
|||||||
|
|
||||||
onDelete = { postViewModel.deleteRelay(it) },
|
onDelete = { postViewModel.deleteRelay(it) },
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav
|
nav = nav,
|
||||||
|
scope = scope,
|
||||||
|
context = context
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,10 +242,10 @@ fun ServerConfig(
|
|||||||
|
|
||||||
onDelete: (RelaySetupInfo) -> Unit,
|
onDelete: (RelaySetupInfo) -> Unit,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit
|
nav: (String) -> Unit,
|
||||||
|
context: Context,
|
||||||
|
scope: CoroutineScope
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
var relayInfo: RelayInformation? by remember { mutableStateOf(null) }
|
var relayInfo: RelayInformation? by remember { mutableStateOf(null) }
|
||||||
|
|
||||||
if (relayInfo != null) {
|
if (relayInfo != null) {
|
||||||
@@ -269,6 +282,20 @@ fun ServerConfig(
|
|||||||
|
|
||||||
Column(Modifier.weight(1f)) {
|
Column(Modifier.weight(1f)) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Paid,
|
||||||
|
null,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(end = 5.dp)
|
||||||
|
.size(15.dp),
|
||||||
|
tint = if (item.paidRelay) {
|
||||||
|
Color.Green
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colors.onSurface.copy(
|
||||||
|
alpha = 0.32f
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
Text(
|
Text(
|
||||||
text = item.url.removePrefix("wss://"),
|
text = item.url.removePrefix("wss://"),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -136,6 +136,12 @@ class NewRelayListViewModel : ViewModel() {
|
|||||||
it.updated(relay, relay.copy(feedTypes = newTypes))
|
it.updated(relay, relay.copy(feedTypes = newTypes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun togglePaidRelay(relay: RelaySetupInfo, paid: Boolean) {
|
||||||
|
_relays.update {
|
||||||
|
it.updated(relay, relay.copy(paidRelay = paid))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> Iterable<T>.updated(old: T, new: T): List<T> = map { if (it == old) new else it }
|
fun <T> Iterable<T>.updated(old: T, new: T): List<T> = map { if (it == old) new else it }
|
||||||
|
|||||||
Reference in New Issue
Block a user