mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
Add the remember type to the multieventscreen
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.greenart7c3.nostrsigner.models
|
||||
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.greenart7c3.nostrsigner.ui.RememberType
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
|
||||
@@ -16,7 +17,7 @@ data class IntentData(
|
||||
val permissions: List<Permission>?,
|
||||
val currentAccount: String,
|
||||
val checked: MutableState<Boolean>,
|
||||
val rememberMyChoice: MutableState<Boolean>,
|
||||
val rememberType: MutableState<RememberType>,
|
||||
val bunkerRequest: BunkerRequest?,
|
||||
val route: String?,
|
||||
val event: Event?,
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.greenart7c3.nostrsigner.models.containsNip
|
||||
import com.greenart7c3.nostrsigner.relays.AmberListenerSingleton
|
||||
import com.greenart7c3.nostrsigner.service.IntentUtils.getUnsignedEvent
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import com.greenart7c3.nostrsigner.ui.RememberType
|
||||
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
||||
@@ -270,6 +271,7 @@ object BunkerRequestUtils {
|
||||
permissions.removeIf { it.kind == null && (it.type == "sign_event" || it.type == "nip") }
|
||||
permissions.removeIf { it.type == "nip" && (it.kind == null || !it.kind.containsNip()) }
|
||||
|
||||
@Suppress("KotlinConstantConditions")
|
||||
when (type) {
|
||||
SignerType.CONNECT -> {
|
||||
onReady(
|
||||
@@ -285,7 +287,7 @@ object BunkerRequestUtils {
|
||||
permissions,
|
||||
bunkerRequest.currentAccount,
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
bunkerRequest,
|
||||
route,
|
||||
null,
|
||||
@@ -315,7 +317,7 @@ object BunkerRequestUtils {
|
||||
permissions,
|
||||
bunkerRequest.currentAccount,
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
bunkerRequest,
|
||||
route,
|
||||
it,
|
||||
@@ -363,7 +365,7 @@ object BunkerRequestUtils {
|
||||
permissions,
|
||||
bunkerRequest.currentAccount,
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
bunkerRequest,
|
||||
route,
|
||||
null,
|
||||
@@ -386,7 +388,7 @@ object BunkerRequestUtils {
|
||||
permissions,
|
||||
bunkerRequest.currentAccount,
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
bunkerRequest,
|
||||
route,
|
||||
null,
|
||||
@@ -409,7 +411,7 @@ object BunkerRequestUtils {
|
||||
permissions,
|
||||
bunkerRequest.currentAccount,
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
bunkerRequest,
|
||||
route,
|
||||
null,
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.greenart7c3.nostrsigner.models.ReturnType
|
||||
import com.greenart7c3.nostrsigner.models.SignerType
|
||||
import com.greenart7c3.nostrsigner.models.containsNip
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import com.greenart7c3.nostrsigner.ui.RememberType
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
|
||||
import com.vitorpamplona.quartz.nip19Bech32.toNpub
|
||||
@@ -140,7 +141,7 @@ object IntentUtils {
|
||||
listOf(),
|
||||
Hex.decode(it.pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
it,
|
||||
@@ -187,7 +188,7 @@ object IntentUtils {
|
||||
listOf(),
|
||||
Hex.decode(pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
null,
|
||||
@@ -209,7 +210,7 @@ object IntentUtils {
|
||||
listOf(),
|
||||
"",
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
null,
|
||||
@@ -231,7 +232,7 @@ object IntentUtils {
|
||||
listOf(),
|
||||
"",
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
null,
|
||||
@@ -329,7 +330,7 @@ object IntentUtils {
|
||||
permissions,
|
||||
npub ?: Hex.decode(it.pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
it,
|
||||
@@ -381,7 +382,7 @@ object IntentUtils {
|
||||
permissions,
|
||||
npub ?: Hex.decode(pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
null,
|
||||
@@ -408,7 +409,7 @@ object IntentUtils {
|
||||
permissions,
|
||||
npub ?: Hex.decode(pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
null,
|
||||
@@ -435,7 +436,7 @@ object IntentUtils {
|
||||
permissions,
|
||||
npub ?: Hex.decode(pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
null,
|
||||
route,
|
||||
null,
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.greenart7c3.nostrsigner.models.Permission
|
||||
import com.greenart7c3.nostrsigner.models.ReturnType
|
||||
import com.greenart7c3.nostrsigner.models.SignerType
|
||||
import com.greenart7c3.nostrsigner.models.containsNip
|
||||
import com.greenart7c3.nostrsigner.ui.RememberType
|
||||
import com.vitorpamplona.ammolite.relays.COMMON_FEED_TYPES
|
||||
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
|
||||
import java.util.UUID
|
||||
@@ -127,7 +128,7 @@ object NostrConnectUtils {
|
||||
permissions,
|
||||
"",
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
mutableStateOf(RememberType.NEVER),
|
||||
BunkerRequest(
|
||||
UUID.randomUUID().toString().substring(0, 4),
|
||||
"connect",
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.greenart7c3.nostrsigner.ui
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -12,7 +11,6 @@ import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.CheckboxDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -21,7 +19,6 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -33,6 +30,7 @@ import com.greenart7c3.nostrsigner.models.Permission
|
||||
import com.greenart7c3.nostrsigner.models.SignerType
|
||||
import com.greenart7c3.nostrsigner.service.MultiEventScreenIntents
|
||||
import com.greenart7c3.nostrsigner.service.model.AmberEvent
|
||||
import com.greenart7c3.nostrsigner.ui.components.RememberMyChoice
|
||||
|
||||
@Composable
|
||||
fun SeeDetailsScreen(
|
||||
@@ -43,7 +41,7 @@ fun SeeDetailsScreen(
|
||||
modifier = modifier
|
||||
.fillMaxWidth(),
|
||||
) {
|
||||
var rememberMyChoice by remember { mutableStateOf(MultiEventScreenIntents.intents.first().rememberMyChoice.value) }
|
||||
var rememberType by remember { mutableStateOf(MultiEventScreenIntents.intents.first().rememberType.value) }
|
||||
val first = MultiEventScreenIntents.intents.first()
|
||||
val permission = if (first.type == SignerType.SIGN_EVENT) {
|
||||
Permission("sign_event", first.event!!.kind)
|
||||
@@ -64,32 +62,20 @@ fun SeeDetailsScreen(
|
||||
)
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.padding(vertical = 8.dp)
|
||||
.clickable {
|
||||
rememberMyChoice = !rememberMyChoice
|
||||
MultiEventScreenIntents.intents.forEach { intent ->
|
||||
intent.rememberMyChoice.value = rememberMyChoice
|
||||
}
|
||||
},
|
||||
Modifier.padding(vertical = 8.dp),
|
||||
) {
|
||||
Switch(
|
||||
modifier = Modifier.scale(0.85f),
|
||||
checked = rememberMyChoice,
|
||||
onCheckedChange = {
|
||||
rememberMyChoice = !rememberMyChoice
|
||||
RememberMyChoice(
|
||||
alwaysShow = true,
|
||||
shouldRunAcceptOrReject = null,
|
||||
onAccept = {},
|
||||
onReject = {},
|
||||
onChanged = {
|
||||
rememberType = it
|
||||
MultiEventScreenIntents.intents.forEach { intent ->
|
||||
intent.rememberMyChoice.value = rememberMyChoice
|
||||
intent.rememberType.value = rememberType
|
||||
}
|
||||
},
|
||||
)
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(start = 8.dp),
|
||||
text = stringResource(R.string.always_approve_this_permission),
|
||||
packageName = null,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+29
-53
@@ -20,7 +20,6 @@ import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.CheckboxDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
@@ -31,7 +30,6 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -103,7 +101,7 @@ fun MultiEventHomeScreen(
|
||||
}
|
||||
var localAccount by remember { mutableStateOf("") }
|
||||
val key = intents.firstOrNull()?.bunkerRequest?.localKey ?: "$packageName"
|
||||
var rememberMyChoice by remember { mutableStateOf(false) }
|
||||
var rememberType by remember { mutableStateOf(RememberType.NEVER) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
@@ -157,15 +155,23 @@ fun MultiEventHomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
AlwaysApproveSwitch(
|
||||
checked = rememberMyChoice,
|
||||
onClick = {
|
||||
rememberMyChoice = !rememberMyChoice
|
||||
intents.forEach {
|
||||
it.rememberMyChoice.value = rememberMyChoice
|
||||
}
|
||||
},
|
||||
)
|
||||
Row(
|
||||
Modifier.padding(vertical = 40.dp),
|
||||
) {
|
||||
RememberMyChoice(
|
||||
alwaysShow = true,
|
||||
shouldRunAcceptOrReject = null,
|
||||
onAccept = {},
|
||||
onReject = {},
|
||||
onChanged = {
|
||||
rememberType = it
|
||||
intents.forEach {
|
||||
it.rememberType.value = rememberType
|
||||
}
|
||||
},
|
||||
packageName = packageName,
|
||||
)
|
||||
}
|
||||
|
||||
AmberButton(
|
||||
Modifier.padding(bottom = 40.dp),
|
||||
@@ -224,14 +230,14 @@ fun MultiEventHomeScreen(
|
||||
if (intentData.type == SignerType.SIGN_EVENT) {
|
||||
val localEvent = intentData.event!!
|
||||
|
||||
if (intentData.rememberMyChoice.value && intentData.checked.value) {
|
||||
if (intentData.rememberType.value != RememberType.NEVER && intentData.checked.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
localKey,
|
||||
intentData,
|
||||
localEvent.kind,
|
||||
intentData.rememberMyChoice.value,
|
||||
RememberType.ALWAYS,
|
||||
true,
|
||||
intentData.rememberType.value,
|
||||
thisAccount,
|
||||
)
|
||||
}
|
||||
@@ -308,14 +314,14 @@ fun MultiEventHomeScreen(
|
||||
}
|
||||
}
|
||||
} else if (intentData.type == SignerType.SIGN_MESSAGE) {
|
||||
if (intentData.rememberMyChoice.value && intentData.checked.value) {
|
||||
if (intentData.rememberType.value != RememberType.NEVER && intentData.checked.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
localKey,
|
||||
intentData,
|
||||
null,
|
||||
intentData.rememberMyChoice.value,
|
||||
RememberType.ALWAYS,
|
||||
true,
|
||||
intentData.rememberType.value,
|
||||
thisAccount,
|
||||
)
|
||||
}
|
||||
@@ -434,14 +440,14 @@ fun MultiEventHomeScreen(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (intentData.rememberMyChoice.value && intentData.checked.value) {
|
||||
if (intentData.rememberType.value != RememberType.NEVER && intentData.checked.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
localKey,
|
||||
intentData,
|
||||
null,
|
||||
intentData.rememberMyChoice.value,
|
||||
RememberType.ALWAYS,
|
||||
true,
|
||||
intentData.rememberType.value,
|
||||
thisAccount,
|
||||
)
|
||||
}
|
||||
@@ -567,14 +573,14 @@ fun MultiEventHomeScreen(
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
if (intentData.rememberMyChoice.value && intentData.checked.value) {
|
||||
if (intentData.rememberType.value != RememberType.NEVER && intentData.checked.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
localKey,
|
||||
intentData,
|
||||
null,
|
||||
false,
|
||||
RememberType.ALWAYS,
|
||||
intentData.rememberType.value,
|
||||
thisAccount,
|
||||
)
|
||||
}
|
||||
@@ -726,33 +732,3 @@ fun PermissionCard(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AlwaysApproveSwitch(
|
||||
checked: Boolean,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.padding(vertical = 40.dp)
|
||||
.clickable {
|
||||
onClick()
|
||||
},
|
||||
) {
|
||||
Switch(
|
||||
modifier = Modifier.scale(0.85f),
|
||||
checked = checked,
|
||||
onCheckedChange = {
|
||||
onClick()
|
||||
},
|
||||
)
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(start = 8.dp),
|
||||
text = stringResource(R.string.always_approve_these_permissions),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user