mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 04:52:31 +02:00
Indicate whether account has pubkey or privkey
This commit is contained in:
@@ -26,6 +26,7 @@ private const val OLD_PREFS_FILENAME = "secret_keeper"
|
|||||||
|
|
||||||
data class AccountInfo(
|
data class AccountInfo(
|
||||||
val npub: String,
|
val npub: String,
|
||||||
|
val hasPrivKey: Boolean,
|
||||||
val current: Boolean,
|
val current: Boolean,
|
||||||
val displayName: String?,
|
val displayName: String?,
|
||||||
val profilePicture: String?
|
val profilePicture: String?
|
||||||
@@ -151,9 +152,11 @@ object LocalPreferences {
|
|||||||
fun allSavedAccounts(): List<AccountInfo> {
|
fun allSavedAccounts(): List<AccountInfo> {
|
||||||
return savedAccounts.map { npub ->
|
return savedAccounts.map { npub ->
|
||||||
val prefs = encryptedPreferences(npub)
|
val prefs = encryptedPreferences(npub)
|
||||||
|
val hasPrivKey = prefs.getString(PrefKeys.NOSTR_PRIVKEY, null) != null
|
||||||
|
|
||||||
AccountInfo(
|
AccountInfo(
|
||||||
npub = npub,
|
npub = npub,
|
||||||
|
hasPrivKey = hasPrivKey,
|
||||||
current = npub == currentAccount,
|
current = npub == currentAccount,
|
||||||
displayName = prefs.getString(PrefKeys.DISPLAY_NAME, null),
|
displayName = prefs.getString(PrefKeys.DISPLAY_NAME, null),
|
||||||
profilePicture = prefs.getString(PrefKeys.PROFILE_PICTURE_URL, null)
|
profilePicture = prefs.getString(PrefKeys.PROFILE_PICTURE_URL, null)
|
||||||
|
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
@@ -23,7 +24,10 @@ import androidx.compose.material.TextButton
|
|||||||
import androidx.compose.material.TopAppBar
|
import androidx.compose.material.TopAppBar
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
import androidx.compose.material.icons.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.Key
|
||||||
import androidx.compose.material.icons.filled.Logout
|
import androidx.compose.material.icons.filled.Logout
|
||||||
|
import androidx.compose.material.icons.filled.RadioButtonChecked
|
||||||
|
import androidx.compose.material.icons.filled.Visibility
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
@@ -84,41 +88,71 @@ fun AccountSwitchBottomSheet(
|
|||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(32.dp, 16.dp),
|
.padding(16.dp, 16.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.clickable {
|
modifier = Modifier.weight(1f).clickable {
|
||||||
accountStateViewModel.switchUser(acc.npub)
|
accountStateViewModel.switchUser(acc.npub)
|
||||||
},
|
},
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
AsyncImageProxy(
|
Box(
|
||||||
model = ResizeImage(acc.profilePicture, 64.dp),
|
modifier = Modifier.width(55.dp).padding(0.dp)
|
||||||
placeholder = BitmapPainter(RoboHashCache.get(context, acc.npub)),
|
) {
|
||||||
fallback = BitmapPainter(RoboHashCache.get(context, acc.npub)),
|
AsyncImageProxy(
|
||||||
error = BitmapPainter(RoboHashCache.get(context, acc.npub)),
|
model = ResizeImage(acc.profilePicture, 55.dp),
|
||||||
contentDescription = stringResource(id = R.string.profile_image),
|
placeholder = BitmapPainter(RoboHashCache.get(context, acc.npub)),
|
||||||
modifier = Modifier
|
fallback = BitmapPainter(RoboHashCache.get(context, acc.npub)),
|
||||||
.width(64.dp)
|
error = BitmapPainter(RoboHashCache.get(context, acc.npub)),
|
||||||
.height(64.dp)
|
contentDescription = stringResource(id = R.string.profile_image),
|
||||||
.clip(shape = CircleShape)
|
modifier = Modifier
|
||||||
)
|
.width(55.dp)
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
.height(55.dp)
|
||||||
Column {
|
.clip(shape = CircleShape)
|
||||||
acc.displayName?.let {
|
)
|
||||||
Text(it)
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.size(20.dp).align(Alignment.TopEnd)
|
||||||
|
) {
|
||||||
|
if (acc.hasPrivKey) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Key,
|
||||||
|
contentDescription = "Has private key",
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colors.primary
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Visibility,
|
||||||
|
contentDescription = "Read only, no private key",
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colors.primary
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Text(acc.npub.toShortenHex())
|
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
if (current) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Text("✓")
|
val npubShortHex = acc.npub.toShortenHex()
|
||||||
|
|
||||||
|
if (acc.displayName != null && acc.displayName != npubShortHex) {
|
||||||
|
Text(acc.displayName)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(npubShortHex)
|
||||||
|
}
|
||||||
|
Column(modifier = Modifier.width(32.dp)) {
|
||||||
|
if (current) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.RadioButtonChecked,
|
||||||
|
contentDescription = "Active account",
|
||||||
|
tint = MaterialTheme.colors.secondary
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { accountStateViewModel.logOff(acc.npub) }
|
onClick = { accountStateViewModel.logOff(acc.npub) }
|
||||||
) {
|
) {
|
||||||
|
Reference in New Issue
Block a user