Indicate whether account has pubkey or privkey

This commit is contained in:
maxmoney21m 2023-03-12 21:20:00 +08:00
parent b1cb7d599f
commit 32b50418de
2 changed files with 60 additions and 23 deletions

View File

@ -26,6 +26,7 @@ private const val OLD_PREFS_FILENAME = "secret_keeper"
data class AccountInfo(
val npub: String,
val hasPrivKey: Boolean,
val current: Boolean,
val displayName: String?,
val profilePicture: String?
@ -151,9 +152,11 @@ object LocalPreferences {
fun allSavedAccounts(): List<AccountInfo> {
return savedAccounts.map { npub ->
val prefs = encryptedPreferences(npub)
val hasPrivKey = prefs.getString(PrefKeys.NOSTR_PRIVKEY, null) != null
AccountInfo(
npub = npub,
hasPrivKey = hasPrivKey,
current = npub == currentAccount,
displayName = prefs.getString(PrefKeys.DISPLAY_NAME, null),
profilePicture = prefs.getString(PrefKeys.PROFILE_PICTURE_URL, null)

View File

@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
@ -23,7 +24,10 @@ import androidx.compose.material.TextButton
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
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.RadioButtonChecked
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
@ -84,41 +88,71 @@ fun AccountSwitchBottomSheet(
Row(
modifier = Modifier
.fillMaxWidth()
.padding(32.dp, 16.dp),
.padding(16.dp, 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Row(
modifier = Modifier.clickable {
modifier = Modifier.weight(1f).clickable {
accountStateViewModel.switchUser(acc.npub)
},
verticalAlignment = Alignment.CenterVertically
) {
AsyncImageProxy(
model = ResizeImage(acc.profilePicture, 64.dp),
placeholder = BitmapPainter(RoboHashCache.get(context, acc.npub)),
fallback = BitmapPainter(RoboHashCache.get(context, acc.npub)),
error = BitmapPainter(RoboHashCache.get(context, acc.npub)),
contentDescription = stringResource(id = R.string.profile_image),
modifier = Modifier
.width(64.dp)
.height(64.dp)
.clip(shape = CircleShape)
)
Spacer(modifier = Modifier.width(16.dp))
Column {
acc.displayName?.let {
Text(it)
Box(
modifier = Modifier.width(55.dp).padding(0.dp)
) {
AsyncImageProxy(
model = ResizeImage(acc.profilePicture, 55.dp),
placeholder = BitmapPainter(RoboHashCache.get(context, acc.npub)),
fallback = BitmapPainter(RoboHashCache.get(context, acc.npub)),
error = BitmapPainter(RoboHashCache.get(context, acc.npub)),
contentDescription = stringResource(id = R.string.profile_image),
modifier = Modifier
.width(55.dp)
.height(55.dp)
.clip(shape = CircleShape)
)
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))
if (current) {
Text("")
Spacer(modifier = Modifier.width(16.dp))
Column(modifier = Modifier.weight(1f)) {
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(
onClick = { accountStateViewModel.logOff(acc.npub) }
) {