mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-20 09:15:26 +02:00
Paste from history
This commit is contained in:
parent
6b45eb7bec
commit
1a6d6fdce4
@ -158,7 +158,8 @@ private fun CalculatorScreen(
|
|||||||
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f))
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f))
|
||||||
.fillMaxSize(),
|
.fillMaxSize(),
|
||||||
historyItems = uiState.history,
|
historyItems = uiState.history,
|
||||||
historyItemHeightCallback = { historyItemHeight = it }
|
historyItemHeightCallback = { historyItemHeight = it },
|
||||||
|
onTextClick = addSymbol
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
textFields = { maxDragAmount ->
|
textFields = { maxDragAmount ->
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
package com.sadellie.unitto.feature.calculator.components
|
package com.sadellie.unitto.feature.calculator.components
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.horizontalScroll
|
import androidx.compose.foundation.horizontalScroll
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
@ -55,7 +57,8 @@ import java.util.*
|
|||||||
internal fun HistoryList(
|
internal fun HistoryList(
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
historyItems: List<HistoryItem>,
|
historyItems: List<HistoryItem>,
|
||||||
historyItemHeightCallback: (Int) -> Unit
|
historyItemHeightCallback: (Int) -> Unit,
|
||||||
|
onTextClick: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val verticalArrangement by remember(historyItems) {
|
val verticalArrangement by remember(historyItems) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
@ -90,14 +93,16 @@ internal fun HistoryList(
|
|||||||
// We do this so that callback for items height is called only once
|
// We do this so that callback for items height is called only once
|
||||||
item {
|
item {
|
||||||
HistoryListItem(
|
HistoryListItem(
|
||||||
modifier = Modifier.onPlaced { historyItemHeightCallback(it.size.height) }.padding(horizontal = 8.dp),
|
modifier = Modifier.onPlaced { historyItemHeightCallback(it.size.height) },
|
||||||
historyItem = historyItems.first()
|
historyItem = historyItems.first(),
|
||||||
|
onTextClick = onTextClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
items(historyItems.drop(1)) { historyItem ->
|
items(historyItems.drop(1)) { historyItem ->
|
||||||
HistoryListItem(
|
HistoryListItem(
|
||||||
modifier = Modifier.padding(horizontal = 8.dp),
|
modifier = Modifier,
|
||||||
historyItem = historyItem
|
historyItem = historyItem,
|
||||||
|
onTextClick = onTextClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,29 +112,40 @@ internal fun HistoryList(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun HistoryListItem(
|
private fun HistoryListItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
historyItem: HistoryItem
|
historyItem: HistoryItem,
|
||||||
|
onTextClick: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
Column(modifier = modifier) {
|
Column(modifier = modifier) {
|
||||||
Text(
|
Box(
|
||||||
text = historyItem.expression,
|
Modifier.clickable { onTextClick(historyItem.expression) }
|
||||||
maxLines = 1,
|
) {
|
||||||
modifier = Modifier
|
Text(
|
||||||
.fillMaxWidth()
|
text = historyItem.expression,
|
||||||
.horizontalScroll(rememberScrollState(), reverseScrolling = true),
|
maxLines = 1,
|
||||||
style = NumbersTextStyleDisplayMedium,
|
modifier = Modifier
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
.fillMaxWidth()
|
||||||
textAlign = TextAlign.End
|
.padding(horizontal = 8.dp)
|
||||||
)
|
.horizontalScroll(rememberScrollState(), reverseScrolling = true),
|
||||||
Text(
|
style = NumbersTextStyleDisplayMedium,
|
||||||
text = Formatter.format(historyItem.result),
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
maxLines = 1,
|
textAlign = TextAlign.End
|
||||||
modifier = Modifier
|
)
|
||||||
.fillMaxWidth()
|
}
|
||||||
.horizontalScroll(rememberScrollState(), reverseScrolling = true),
|
Box(
|
||||||
style = NumbersTextStyleDisplayMedium,
|
Modifier.clickable { onTextClick(historyItem.result) }
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f),
|
) {
|
||||||
textAlign = TextAlign.End
|
Text(
|
||||||
)
|
text = Formatter.format(historyItem.result),
|
||||||
|
maxLines = 1,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 8.dp)
|
||||||
|
.horizontalScroll(rememberScrollState(), reverseScrolling = true),
|
||||||
|
style = NumbersTextStyleDisplayMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f),
|
||||||
|
textAlign = TextAlign.End
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,6 +176,7 @@ private fun PreviewHistoryList() {
|
|||||||
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f))
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f))
|
||||||
.fillMaxSize(),
|
.fillMaxSize(),
|
||||||
historyItems = historyItems,
|
historyItems = historyItems,
|
||||||
historyItemHeightCallback = {}
|
historyItemHeightCallback = {},
|
||||||
|
onTextClick = {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user