2022-03-08 11:05:03 -08:00
|
|
|
package co.electriccoin.zcash.ui.design.component
|
2021-11-17 12:19:49 -08:00
|
|
|
|
2023-11-23 01:00:13 -08:00
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
2021-11-17 12:19:49 -08:00
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
2023-11-23 01:00:13 -08:00
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.foundation.layout.wrapContentWidth
|
2021-11-17 12:19:49 -08:00
|
|
|
import androidx.compose.runtime.Composable
|
2023-11-23 01:00:13 -08:00
|
|
|
import androidx.compose.runtime.remember
|
2021-11-17 12:19:49 -08:00
|
|
|
import androidx.compose.ui.Modifier
|
2021-12-09 12:21:30 -08:00
|
|
|
import androidx.compose.ui.platform.testTag
|
2023-11-23 01:00:13 -08:00
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
import cash.z.ecc.android.sdk.fixture.WalletFixture
|
|
|
|
import cash.z.ecc.android.sdk.model.SeedPhrase
|
2022-02-21 06:50:09 -08:00
|
|
|
import co.electriccoin.zcash.spackle.model.Index
|
2023-11-23 01:00:13 -08:00
|
|
|
import co.electriccoin.zcash.ui.design.theme.ZcashTheme
|
2023-03-01 04:58:47 -08:00
|
|
|
import kotlinx.collections.immutable.ImmutableList
|
2023-11-23 01:00:13 -08:00
|
|
|
import kotlinx.collections.immutable.toPersistentList
|
2021-11-17 12:19:49 -08:00
|
|
|
|
2023-11-23 01:00:13 -08:00
|
|
|
// TODO [#1001]: Row size should probably change for landscape layouts
|
|
|
|
// TODO [#1001]: https://github.com/Electric-Coin-Company/zashi-android/issues/1001
|
|
|
|
const val CHIP_GRID_COLUMN_SIZE = 12
|
2021-11-17 12:19:49 -08:00
|
|
|
|
2023-11-23 01:00:13 -08:00
|
|
|
@Preview
|
2021-11-17 12:19:49 -08:00
|
|
|
@Composable
|
2023-11-23 01:00:13 -08:00
|
|
|
private fun ComposablePreview() {
|
|
|
|
ZcashTheme(forceDarkMode = false) {
|
|
|
|
ChipGrid(
|
|
|
|
SeedPhrase.new(WalletFixture.Alice.seedPhrase).split.toPersistentList(),
|
|
|
|
onGridClick = {}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun ChipGrid(
|
|
|
|
wordList: ImmutableList<String>,
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
onGridClick: () -> Unit
|
|
|
|
) {
|
|
|
|
val interactionSource = remember { MutableInteractionSource() }
|
2021-12-09 12:21:30 -08:00
|
|
|
|
2023-11-23 01:00:13 -08:00
|
|
|
Row(
|
|
|
|
modifier = modifier.then(Modifier.fillMaxWidth()),
|
|
|
|
horizontalArrangement = Arrangement.Center
|
|
|
|
) {
|
|
|
|
Row(
|
2023-12-11 01:20:32 -08:00
|
|
|
modifier =
|
|
|
|
Modifier
|
|
|
|
.wrapContentWidth()
|
|
|
|
.clickable(
|
|
|
|
interactionSource = interactionSource,
|
|
|
|
// Disable ripple
|
|
|
|
indication = null,
|
|
|
|
onClick = onGridClick
|
|
|
|
)
|
|
|
|
.testTag(CommonTag.CHIP_LAYOUT)
|
2023-11-23 01:00:13 -08:00
|
|
|
) {
|
|
|
|
wordList.chunked(CHIP_GRID_COLUMN_SIZE).forEachIndexed { chunkIndex, chunk ->
|
|
|
|
// TODO [#1043]: Correctly align numbers and words on Recovery screen
|
|
|
|
// TODO [#1043]: https://github.com/Electric-Coin-Company/zashi-android/issues/1043
|
|
|
|
Column(
|
|
|
|
modifier = Modifier.padding(horizontal = ZcashTheme.dimens.spacingDefault)
|
|
|
|
) {
|
|
|
|
chunk.forEachIndexed { subIndex, word ->
|
2023-11-27 01:55:15 -08:00
|
|
|
ChipIndexed(
|
2023-11-23 01:00:13 -08:00
|
|
|
index = Index(chunkIndex * CHIP_GRID_COLUMN_SIZE + subIndex),
|
|
|
|
text = word,
|
|
|
|
modifier = Modifier.padding(ZcashTheme.dimens.spacingXtiny)
|
|
|
|
)
|
|
|
|
}
|
2021-12-09 12:21:30 -08:00
|
|
|
}
|
2021-11-17 12:19:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|