Skip to content

Commit

Permalink
adapted rust api changes on android side to show dot and blockies icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry-Borodin committed Aug 7, 2023
1 parent 4cd7d31 commit d88e258
Show file tree
Hide file tree
Showing 30 changed files with 181 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.parity.signer.components.SeedCard
import io.parity.signer.components.toImageContent
import io.parity.signer.dependencygraph.ServiceLocator
import io.parity.signer.domain.SharedViewModel
import io.parity.signer.domain.storage.getSeed
Expand Down Expand Up @@ -59,7 +58,7 @@ fun SelectSeed(seeds: MSeeds, sharedViewModel: SharedViewModel) {
) {
SeedCard(
seedName = cards[item].seedName,
identicon = cards[item].identicon.toImageContent()
identicon = cards[item].identicon
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import io.parity.signer.bottomsheets.sufficientcrypto.SufficientCryptoReadyViewModel
import io.parity.signer.components.*
import io.parity.signer.components.networkicon.IdentIconImage
import io.parity.signer.domain.intoImageBitmap
import io.parity.signer.ui.theme.Bg000
import io.parity.signer.ui.theme.modal
Expand Down Expand Up @@ -54,7 +55,7 @@ fun SufficientCryptoReady(
is MscContent.LoadMetadata -> Text("Metadata for " + c.name + " with version " + c.version)
is MscContent.LoadTypes -> Column {
Text("types " + c.types)
IdentIcon(identIcon = c.pic.toImageContent())
IdentIconImage(identIcon = c.pic)
}
}
}
Expand Down
121 changes: 0 additions & 121 deletions android/src/main/java/io/parity/signer/components/IdentIcon.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.parity.signer.components.networkicon.IdentIconImage
import io.parity.signer.domain.BASE58_STYLE_ABBREVIATE
import io.parity.signer.domain.abbreviateString
import io.parity.signer.ui.theme.*
Expand All @@ -27,7 +28,7 @@ fun KeyCardOld(identity: MAddressCard, multiselectMode: Boolean = false) {
.padding(8.dp)
) {
Box(contentAlignment = Alignment.BottomEnd) {
IdentIcon(identity.address.identicon.toImageContent())
IdentIconImage(identity.address.identicon)
}
Spacer(modifier = Modifier.width(10.dp))
Column {
Expand Down
6 changes: 4 additions & 2 deletions android/src/main/java/io/parity/signer/components/SeedCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.parity.signer.components.networkicon.IdentIconImage
import io.parity.signer.domain.BASE58_STYLE_ABBREVIATE
import io.parity.signer.domain.abbreviateString
import io.parity.signer.ui.theme.*
import io.parity.signer.uniffi.Identicon

@Deprecated("Use new KeySetItem for new screens")
@Composable
fun SeedCard(
seedName: String,
identicon: ImageContent,
identicon: Identicon,
base58: String = "",
showAddress: Boolean = false,
multiselectMode: Boolean = false,
Expand All @@ -38,7 +40,7 @@ fun SeedCard(
verticalAlignment = Alignment.CenterVertically,
) {
Box(contentAlignment = Alignment.BottomEnd) {
IdentIcon(identicon)
IdentIconImage(identicon)
if (multiselectMode) {
if(selected) {
Icon(Icons.Default.CheckCircle, "Not multiselected", tint = MaterialTheme.colors.Action400)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.parity.signer.components.networkicon

import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.parity.signer.components.networkicon.blockies.BlockiesIcon
import io.parity.signer.components.networkicon.dot.DotIcon
import io.parity.signer.ui.helpers.PreviewData
import io.parity.signer.ui.theme.SignerNewTheme
import io.parity.signer.uniffi.Identicon

/**
* Just draw a standard IdentIcon used everywhere, with standard size
*/
@Composable
fun IdentIconImage(
identIcon: Identicon,
modifier: Modifier = Modifier,
size: Dp = 28.dp
) {
when (identIcon) {
is Identicon.Blockies -> {
BlockiesIcon(
seed = identIcon.identity,
preferedSize = size,
modifier = modifier,
)
}

is Identicon.Dots -> {
DotIcon(seed = identIcon.identity,
size = size,
modifier = modifier,
)
}
// is ImageContent.Svg -> {//will be used for another type of icons
// val context = LocalContext.current
// val painter = rememberAsyncImagePainter(
// model = ImageRequest.Builder(context)
// .decoderFactory(SvgDecoder.Factory())
// .data(identIcon.toByteArray())
// .size(Size.ORIGINAL) // Set the target size to load the image at.
// .build(),
// )
// Image(
// painter = painter,
// contentDescription = stringResource(R.string.description_identicon),
// modifier = modifier
// .size(size)
// .clip(CircleShape)
// )
// }
}
}

/**
* As svg parsed async and in preview Dispatchers.IO is not working
* run preview on device to see it.
* Consider creating custom coil.ImageLoader with main ui fetch and parse dispatchers. Maybe for preview only.
*/
@Preview(
name = "light", group = "themes", uiMode = Configuration.UI_MODE_NIGHT_NO,
showBackground = true, backgroundColor = 0xFFFFFFFF,
)
@Preview(
name = "dark", group = "themes", uiMode = Configuration.UI_MODE_NIGHT_YES,
showBackground = true, backgroundColor = 0xFF000000,
)
@Composable
private fun PreviewIdentIcon() {
SignerNewTheme {
val iconDot = PreviewData.Identicon.dotIcon
val iconBlockies = PreviewData.Identicon.blockiesIcon

Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
IdentIconImage(iconDot)
IdentIconImage(iconBlockies)
IdentIconImage(iconDot, size = 18.dp)
IdentIconImage(iconBlockies, size = 18.dp)
IdentIconImage(iconDot, size = 56.dp)
IdentIconImage(iconBlockies, size = 56.dp)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.parity.signer.components
package io.parity.signer.components.networkicon

import android.content.res.Configuration
import androidx.compose.foundation.layout.Box
Expand All @@ -23,15 +23,15 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import io.parity.signer.components.networkicon.NetworkIcon
import io.parity.signer.domain.NetworkModel
import io.parity.signer.ui.helpers.PreviewData
import io.parity.signer.ui.theme.SignerNewTheme
import io.parity.signer.uniffi.Identicon


@Composable
fun IdentIconWithNetwork(
identicon: ImageContent,
identicon: Identicon,
networkLogoName: String,
size: Dp = 28.dp,
modifier: Modifier = Modifier,
Expand All @@ -40,7 +40,7 @@ fun IdentIconWithNetwork(
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
Box(modifier = modifier, contentAlignment = Alignment.BottomEnd) {
val cutoutSize = size / 2
IdentIcon(
IdentIconImage(
identIcon = identicon,
modifier = Modifier.clip(SubIconCutShape(cutoutSize)),
size = size
Expand Down Expand Up @@ -110,7 +110,7 @@ class SubIconCutShape(val innerIconSize: Dp) : Shape {
@Composable
private fun PreviewNetworkIconSizes() {
SignerNewTheme {
val iconPng = PreviewData.Identicon.exampleIdenticonPng
val iconPng = PreviewData.Identicon.dotIcon
val network = NetworkModel.createStub().logo
Column(
horizontalAlignment = Alignment.CenterHorizontally,
Expand All @@ -136,7 +136,7 @@ private fun PreviewNetworkIconSizes() {
)
@Composable
private fun PreviewNetworkIconUnknownIcons() {
val icon = PreviewData.Identicon.exampleIdenticonPng
val icon = PreviewData.Identicon.dotIcon
val network = NetworkModel.createStub()
val network2 = NetworkModel.createStub("Some")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.parity.signer.R
import io.parity.signer.components.IdentIconWithNetwork
import io.parity.signer.components.ImageContent
import io.parity.signer.components.networkicon.IdentIconWithNetwork
import io.parity.signer.components.base.SignerDivider
import io.parity.signer.components.toImageContent
import io.parity.signer.domain.BASE58_STYLE_ABBREVIATE
import io.parity.signer.domain.KeyModel
import io.parity.signer.domain.NetworkInfoModel
import io.parity.signer.domain.abbreviateString
import io.parity.signer.ui.helpers.PreviewData
import io.parity.signer.ui.theme.*
import io.parity.signer.uniffi.Address
import io.parity.signer.uniffi.Identicon
import io.parity.signer.uniffi.MAddressCard
import java.util.*

Expand Down Expand Up @@ -250,7 +249,7 @@ data class KeyCardModel(
data class KeyCardModelBase(
val base58: String,
val path: String,
val identIcon: ImageContent,
val identIcon: Identicon,
val networkLogo: String?,
val seedName: String,
val hasPassword: Boolean = false,
Expand Down Expand Up @@ -278,7 +277,7 @@ data class KeyCardModelBase(
base58 = address_card.base58,
path = address_card.address.path,
hasPassword = address_card.address.hasPwd,
identIcon = address_card.address.identicon.toImageContent(),
identIcon = address_card.address.identicon,
seedName = address_card.address.seedName,
networkLogo = networkLogo,
)
Expand All @@ -292,7 +291,7 @@ data class KeyCardModelBase(
base58 = base58,
path = address.path,
hasPassword = address.hasPwd,
identIcon = address.identicon.toImageContent(),
identIcon = address.identicon,
seedName = address.seedName,
networkLogo = networkLogo,
multiselect = false,
Expand All @@ -301,7 +300,7 @@ data class KeyCardModelBase(
fun createStub() = KeyCardModelBase(
base58 = "5F3sa2TJAWMqDhXG6jhV4N8ko9SxwGy8TpaNS1repo5EYjQX",
path = "//polkadot//path",
identIcon = PreviewData.Identicon.exampleIdenticonPng,
identIcon = PreviewData.Identicon.dotIcon,
seedName = "Seed Name",
networkLogo = "kusama",
hasPassword = false,
Expand Down
Loading

0 comments on commit d88e258

Please sign in to comment.