move openAmber to AmberUtils
This commit is contained in:
@@ -1,13 +1,38 @@
|
|||||||
package com.vitorpamplona.amethyst.service
|
package com.vitorpamplona.amethyst.service
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
|
import com.vitorpamplona.amethyst.ServiceManager
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
||||||
import com.vitorpamplona.amethyst.ui.actions.openAmber
|
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
|
|
||||||
object AmberUtils {
|
object AmberUtils {
|
||||||
var content: String = ""
|
var content: String = ""
|
||||||
var isActivityRunning: Boolean = false
|
var isActivityRunning: Boolean = false
|
||||||
|
|
||||||
|
fun openAmber(
|
||||||
|
data: String,
|
||||||
|
type: SignerType,
|
||||||
|
intentResult: ActivityResultLauncher<Intent>,
|
||||||
|
pubKey: HexKey
|
||||||
|
) {
|
||||||
|
ServiceManager.shouldPauseService = false
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$data"))
|
||||||
|
val signerType = when (type) {
|
||||||
|
SignerType.SIGN_EVENT -> "sign_event"
|
||||||
|
SignerType.NIP04_ENCRYPT -> "nip04_encrypt"
|
||||||
|
SignerType.NIP04_DECRYPT -> "nip04_decrypt"
|
||||||
|
SignerType.NIP44_ENCRYPT -> "nip44_encrypt"
|
||||||
|
SignerType.NIP44_DECRYPT -> "nip44_decrypt"
|
||||||
|
SignerType.GET_PUBLIC_KEY -> "get_public_key"
|
||||||
|
}
|
||||||
|
intent.putExtra("type", signerType)
|
||||||
|
intent.putExtra("pubKey", pubKey)
|
||||||
|
intent.`package` = "com.greenart7c3.nostrsigner.debug"
|
||||||
|
intentResult.launch(intent)
|
||||||
|
}
|
||||||
|
|
||||||
fun decryptBookmark(encryptedContent: String, pubKey: HexKey) {
|
fun decryptBookmark(encryptedContent: String, pubKey: HexKey) {
|
||||||
if (content.isBlank()) {
|
if (content.isBlank()) {
|
||||||
isActivityRunning = true
|
isActivityRunning = true
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.vitorpamplona.amethyst.service
|
package com.vitorpamplona.amethyst.service
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.Amethyst
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.service.relays.COMMON_FEED_TYPES
|
import com.vitorpamplona.amethyst.service.relays.COMMON_FEED_TYPES
|
||||||
@@ -10,7 +9,6 @@ import com.vitorpamplona.amethyst.service.relays.JsonFilter
|
|||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
import com.vitorpamplona.amethyst.service.relays.TypedFilter
|
import com.vitorpamplona.amethyst.service.relays.TypedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
||||||
import com.vitorpamplona.amethyst.ui.actions.openAmber
|
|
||||||
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
|
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
|
||||||
import com.vitorpamplona.quartz.events.BadgeAwardEvent
|
import com.vitorpamplona.quartz.events.BadgeAwardEvent
|
||||||
import com.vitorpamplona.quartz.events.BadgeProfilesEvent
|
import com.vitorpamplona.quartz.events.BadgeProfilesEvent
|
||||||
@@ -192,13 +190,12 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
|
|||||||
super.auth(relay, challenge)
|
super.auth(relay, challenge)
|
||||||
|
|
||||||
if (this::account.isInitialized) {
|
if (this::account.isInitialized) {
|
||||||
val context = Amethyst.instance
|
|
||||||
val loggedInWithAmber = account.loginWithAmber
|
val loggedInWithAmber = account.loginWithAmber
|
||||||
val event = account.createAuthEvent(relay, challenge, loggedInWithAmber)
|
val event = account.createAuthEvent(relay, challenge, loggedInWithAmber)
|
||||||
|
|
||||||
if (loggedInWithAmber && !account.isWriteable()) {
|
if (loggedInWithAmber && !account.isWriteable()) {
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
openAmber(
|
AmberUtils.openAmber(
|
||||||
event.toJson(),
|
event.toJson(),
|
||||||
SignerType.SIGN_EVENT,
|
SignerType.SIGN_EVENT,
|
||||||
IntentUtils.authActivityResultLauncher,
|
IntentUtils.authActivityResultLauncher,
|
||||||
|
|||||||
+2
-2
@@ -4,10 +4,10 @@ import android.util.Log
|
|||||||
import com.vitorpamplona.amethyst.AccountInfo
|
import com.vitorpamplona.amethyst.AccountInfo
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
import com.vitorpamplona.amethyst.LocalPreferences
|
import com.vitorpamplona.amethyst.LocalPreferences
|
||||||
|
import com.vitorpamplona.amethyst.service.AmberUtils
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
import com.vitorpamplona.amethyst.service.IntentUtils
|
import com.vitorpamplona.amethyst.service.IntentUtils
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
||||||
import com.vitorpamplona.amethyst.ui.actions.openAmber
|
|
||||||
import com.vitorpamplona.quartz.events.RelayAuthEvent
|
import com.vitorpamplona.quartz.events.RelayAuthEvent
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -74,7 +74,7 @@ class RegisterAccounts(
|
|||||||
Log.d("fcm register", account.npub)
|
Log.d("fcm register", account.npub)
|
||||||
val events = signEventsToProveControlOfAccounts(listOf(account), notificationToken, account.loggedInWithAmber)
|
val events = signEventsToProveControlOfAccounts(listOf(account), notificationToken, account.loggedInWithAmber)
|
||||||
if (events.isNotEmpty()) {
|
if (events.isNotEmpty()) {
|
||||||
openAmber(
|
AmberUtils.openAmber(
|
||||||
events.first().toJson(),
|
events.first().toJson(),
|
||||||
SignerType.SIGN_EVENT,
|
SignerType.SIGN_EVENT,
|
||||||
IntentUtils.activityResultLauncher,
|
IntentUtils.activityResultLauncher,
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.actions
|
package com.vitorpamplona.amethyst.ui.actions
|
||||||
|
|
||||||
import android.app.Activity.RESULT_OK
|
import android.app.Activity.RESULT_OK
|
||||||
import android.content.Intent
|
|
||||||
import android.net.Uri
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -39,6 +36,7 @@ import androidx.compose.ui.window.Dialog
|
|||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ServiceManager
|
import com.vitorpamplona.amethyst.ServiceManager
|
||||||
|
import com.vitorpamplona.amethyst.service.AmberUtils
|
||||||
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||||
import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
|
import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
@@ -56,28 +54,6 @@ enum class SignerType {
|
|||||||
GET_PUBLIC_KEY
|
GET_PUBLIC_KEY
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openAmber(
|
|
||||||
data: String,
|
|
||||||
type: SignerType,
|
|
||||||
intentResult: ActivityResultLauncher<Intent>,
|
|
||||||
pubKey: HexKey
|
|
||||||
) {
|
|
||||||
ServiceManager.shouldPauseService = false
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$data"))
|
|
||||||
val signerType = when (type) {
|
|
||||||
SignerType.SIGN_EVENT -> "sign_event"
|
|
||||||
SignerType.NIP04_ENCRYPT -> "nip04_encrypt"
|
|
||||||
SignerType.NIP04_DECRYPT -> "nip04_decrypt"
|
|
||||||
SignerType.NIP44_ENCRYPT -> "nip44_encrypt"
|
|
||||||
SignerType.NIP44_DECRYPT -> "nip44_decrypt"
|
|
||||||
SignerType.GET_PUBLIC_KEY -> "get_public_key"
|
|
||||||
}
|
|
||||||
intent.putExtra("type", signerType)
|
|
||||||
intent.putExtra("pubKey", pubKey)
|
|
||||||
intent.`package` = "com.greenart7c3.nostrsigner.debug"
|
|
||||||
intentResult.launch(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SignerDialog(
|
fun SignerDialog(
|
||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
@@ -114,7 +90,7 @@ fun SignerDialog(
|
|||||||
)
|
)
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
openAmber(data, type, intentResult, pubKey)
|
AmberUtils.openAmber(data, type, intentResult, pubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
@@ -205,7 +181,7 @@ fun SignerDialog(
|
|||||||
)
|
)
|
||||||
Button(
|
Button(
|
||||||
shape = ButtonBorder,
|
shape = ButtonBorder,
|
||||||
onClick = { openAmber(data, type, intentResult, pubKey) }
|
onClick = { AmberUtils.openAmber(data, type, intentResult, pubKey) }
|
||||||
) {
|
) {
|
||||||
Text("Open Amber")
|
Text("Open Amber")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,12 +90,12 @@ import com.vitorpamplona.amethyst.model.ConnectivityType
|
|||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
|
import com.vitorpamplona.amethyst.service.AmberUtils
|
||||||
import com.vitorpamplona.amethyst.service.OnlineChecker
|
import com.vitorpamplona.amethyst.service.OnlineChecker
|
||||||
import com.vitorpamplona.amethyst.service.ReverseGeoLocationUtil
|
import com.vitorpamplona.amethyst.service.ReverseGeoLocationUtil
|
||||||
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
|
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
|
||||||
import com.vitorpamplona.amethyst.ui.actions.NewRelayListView
|
import com.vitorpamplona.amethyst.ui.actions.NewRelayListView
|
||||||
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
import com.vitorpamplona.amethyst.ui.actions.SignerType
|
||||||
import com.vitorpamplona.amethyst.ui.actions.openAmber
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ClickableUrl
|
import com.vitorpamplona.amethyst.ui.components.ClickableUrl
|
||||||
import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji
|
import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji
|
||||||
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
||||||
@@ -1608,7 +1608,7 @@ private fun RenderPrivateMessage(
|
|||||||
if (accountViewModel.loggedInWithAmber()) {
|
if (accountViewModel.loggedInWithAmber()) {
|
||||||
val event = note.event
|
val event = note.event
|
||||||
SideEffect {
|
SideEffect {
|
||||||
openAmber(
|
AmberUtils.openAmber(
|
||||||
event?.content() ?: "",
|
event?.content() ?: "",
|
||||||
SignerType.NIP04_DECRYPT,
|
SignerType.NIP04_DECRYPT,
|
||||||
activityLauncher,
|
activityLauncher,
|
||||||
|
|||||||
Reference in New Issue
Block a user