mirror of
https://github.com/mollyim/monero-wallet-sdk.git
synced 2025-02-05 01:15:37 -05:00
demo: add new tab with copyable address
This commit is contained in:
parent
2bd227124a
commit
e022a27f04
@ -7,19 +7,13 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import im.molly.monero.Balance
|
||||
import im.molly.monero.Ledger
|
||||
import im.molly.monero.demo.data.model.WalletConfig
|
||||
import im.molly.monero.demo.ui.theme.AppTheme
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
@ -2,6 +2,7 @@ package im.molly.monero.demo.ui
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
@ -15,12 +16,14 @@ import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import im.molly.monero.Ledger
|
||||
import im.molly.monero.MoneroCurrency
|
||||
import im.molly.monero.PublicAddress
|
||||
import im.molly.monero.demo.data.model.WalletConfig
|
||||
import im.molly.monero.demo.ui.component.CopyableText
|
||||
import im.molly.monero.demo.ui.component.Toolbar
|
||||
import im.molly.monero.demo.ui.preview.PreviewParameterData
|
||||
import im.molly.monero.demo.ui.theme.AppIcons
|
||||
@ -114,18 +117,53 @@ private fun WalletScreenLoaded(
|
||||
var selectedTabIndex by rememberSaveable { mutableStateOf(0) }
|
||||
|
||||
WalletHeaderTabs(
|
||||
titles = listOf("Balance", "Transactions"),
|
||||
titles = listOf("Balance", "Send", "Receive", "History"),
|
||||
selectedTabIndex = selectedTabIndex,
|
||||
onTabSelected = { index -> selectedTabIndex = index },
|
||||
)
|
||||
|
||||
when (selectedTabIndex) {
|
||||
0 -> {
|
||||
WalletBalanceView(balance = uiState.balance, blockchainTime = uiState.blockchainTime)
|
||||
WalletBalanceView(
|
||||
balance = uiState.balance,
|
||||
blockchainTime = uiState.blockchainTime
|
||||
)
|
||||
}
|
||||
|
||||
1 -> {
|
||||
LazyColumn {
|
||||
1 -> {} // TODO
|
||||
|
||||
2 -> {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Primary address",
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
)
|
||||
CopyableText(
|
||||
text = uiState.config.publicAddress,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
3 -> {
|
||||
val scrollState = rememberLazyListState()
|
||||
|
||||
var lastTxId by remember { mutableStateOf("") }
|
||||
lastTxId = uiState.transactions.firstOrNull()?.transaction?.txId ?: ""
|
||||
|
||||
LaunchedEffect(lastTxId) {
|
||||
if (uiState.transactions.isNotEmpty()) {
|
||||
scrollState.scrollToItem(0)
|
||||
}
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
state = scrollState,
|
||||
) {
|
||||
transactionCardItems(
|
||||
items = uiState.transactions,
|
||||
onTransactionClick = onTransactionClick,
|
||||
|
@ -0,0 +1,34 @@
|
||||
package im.molly.monero.demo.ui.component
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun CopyableText(
|
||||
text: String,
|
||||
style: TextStyle,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
|
||||
Text(
|
||||
text = text,
|
||||
style = style,
|
||||
modifier = Modifier.combinedClickable(
|
||||
onClick = {},
|
||||
onLongClick = {
|
||||
clipboardManager.setText(AnnotatedString(text))
|
||||
Toast.makeText(context, "Text copied to clipboard", Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user