Skip to content

Commit f3b9471

Browse files
committed
style(theme): 优化样式
1 parent 96b4558 commit f3b9471

File tree

5 files changed

+57
-21
lines changed

5 files changed

+57
-21
lines changed

app/src/main/java/com/jyn/composecalculator/DateViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DateViewModel(application: Application) : AndroidViewModel(application) {
3131
}
3232

3333
fun appendCompute(text: String) {
34-
if (!standards(text)) return
34+
if (!standards()) return
3535
inputText.value = inputText.value + text
3636
}
3737

@@ -76,7 +76,7 @@ class DateViewModel(application: Application) : AndroidViewModel(application) {
7676
}
7777
}
7878

79-
private fun standards(text: String): Boolean {
79+
private fun standards(): Boolean {
8080
val doesExist = inputText.value.last().toString() in arrayOf("÷", "×", "-", "+", ".")
8181
return !doesExist
8282
}

app/src/main/java/com/jyn/composecalculator/MainActivity.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import androidx.compose.ui.Modifier
1919
import androidx.compose.ui.graphics.Color
2020
import androidx.compose.ui.graphics.toArgb
2121
import androidx.compose.ui.platform.LocalConfiguration
22+
import androidx.compose.ui.platform.LocalContext
2223
import androidx.compose.ui.tooling.preview.Preview
24+
import androidx.compose.ui.unit.dp
2325
import androidx.core.view.WindowCompat
2426
import androidx.lifecycle.viewmodel.compose.viewModel
2527
import com.apkfuns.logutils.LogUtils
@@ -32,6 +34,7 @@ import com.jyn.composecalculator.ui.theme.myTheme
3234
const val BOTTOM_FRACTION = 0.67f
3335
var isPortrait = false //横竖屏
3436
var isDark = false //暗黑模式
37+
var statusBarHeight = 0
3538

3639
class MainActivity : ComponentActivity() {
3740
override fun onCreate(savedInstanceState: Bundle?) {
@@ -56,6 +59,17 @@ class MainActivity : ComponentActivity() {
5659
darkIcons = !useDarkIcons
5760
)
5861
}
62+
63+
with(LocalContext.current) {
64+
val size: Int = resources.getDimensionPixelSize(
65+
resources.getIdentifier(
66+
"status_bar_height",
67+
"dimen",
68+
"android"
69+
)
70+
)
71+
}
72+
LogUtils.tag("main").i("statusBarHeight:$statusBarHeight")
5973
}
6074
}
6175
}

app/src/main/java/com/jyn/composecalculator/ui/TopResultView.kt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import androidx.compose.foundation.shape.RoundedCornerShape
1313
import androidx.compose.material.*
1414
import androidx.compose.material.SwipeableDefaults.resistanceConfig
1515
import androidx.compose.material.TabRowDefaults.Divider
16+
import androidx.compose.material.icons.Icons
17+
import androidx.compose.material.icons.filled.ArrowBack
1618
import androidx.compose.material3.Surface
17-
import androidx.compose.runtime.*
19+
import androidx.compose.runtime.Composable
20+
import androidx.compose.runtime.DisposableEffect
21+
import androidx.compose.runtime.remember
22+
import androidx.compose.runtime.rememberCoroutineScope
1823
import androidx.compose.ui.Modifier
19-
import androidx.compose.ui.draw.shadow
2024
import androidx.compose.ui.platform.LocalConfiguration
2125
import androidx.compose.ui.platform.LocalDensity
2226
import androidx.compose.ui.tooling.preview.Preview
@@ -26,15 +30,12 @@ import androidx.lifecycle.viewmodel.compose.viewModel
2630
import com.apkfuns.logutils.LogUtils
2731
import com.jyn.composecalculator.BOTTOM_FRACTION
2832
import com.jyn.composecalculator.DateViewModel
29-
import com.jyn.composecalculator.isPortrait
3033
import com.jyn.composecalculator.ui.theme.evaluator
3134
import com.jyn.composecalculator.ui.theme.myTheme
3235
import com.jyn.composecalculator.ui.view.InputText
3336
import com.jyn.composecalculator.ui.view.ItemText
3437
import com.jyn.composecalculator.ui.view.SlideIndicator
3538
import kotlinx.coroutines.launch
36-
import kotlin.math.abs
37-
3839

3940
/**
4041
* 上层结果
@@ -90,7 +91,11 @@ fun TopResultView() {
9091
tonalElevation = 3.dp,
9192
shadowElevation = 3.dp
9293
) {
93-
TextBox(process)
94+
TextBox(process, onClick = {
95+
coroutineScope.launch {
96+
state.animateTo(true, SwipeableDefaults.AnimationSpec)
97+
}
98+
})
9499
}
95100

96101
val callback = remember {
@@ -117,13 +122,29 @@ fun TopResultView() {
117122
* 计算布局 & 历史列表
118123
*/
119124
@Composable
120-
fun TextBox(process: Float) {
125+
fun TextBox(process: Float, onClick: () -> Unit) {
121126
val viewModel = viewModel<DateViewModel>()
122127
Column(
123128
modifier = Modifier
124129
.fillMaxWidth(),
125130
verticalArrangement = Arrangement.Bottom
126131
) {
132+
TopAppBar(
133+
modifier = Modifier
134+
.padding(top = 30.dp)
135+
.height(50.dp),
136+
title = { Text("历史记录", color = myTheme.textColor) },
137+
navigationIcon = {
138+
IconButton(onClick) {
139+
Icon(
140+
Icons.Filled.ArrowBack,
141+
null,
142+
tint = myTheme.textColor
143+
)
144+
}
145+
},
146+
backgroundColor = myTheme.topBg
147+
)
127148
LazyColumn(
128149
modifier = Modifier
129150
.weight(1f)
@@ -152,15 +173,15 @@ fun TextBox(process: Float) {
152173
modifier = Modifier.background(myTheme.topListBg),
153174
color = myTheme.topListBg,
154175
shape = RoundedCornerShape(topStart = 25.dp, topEnd = 25.dp),
155-
tonalElevation = 3.dp * (process),
156-
shadowElevation = 3.dp * (process),
176+
tonalElevation = 4.dp * (process),
177+
shadowElevation = 4.dp * (process),
157178
) {
158179
InputText(process)
159180
}
160181

161182
Box(
162183
modifier = Modifier
163-
.background(evaluator(1 - process, myTheme.bottomBg, myTheme.topBg))
184+
.background(myTheme.topBg)
164185
.padding(top = 10.dp, bottom = 10.dp)
165186
.fillMaxWidth()
166187
) {

app/src/main/java/com/jyn/composecalculator/ui/theme/Color.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ val bottomBgLight = Color(0xFFFFFFFF)
3131
val topBgLight = Color(0xFFEAEFFA)
3232
val topListBgLight = Color(0xFFF1F6FD)
3333

34-
val textColorDark = Color(0xFFC0E7FB)
34+
val textColorDark = Color(0xFFeeeeee)
3535
val btnNumBgDark = Color(0xFF29292B)
3636
val btnComputeBgDark = Color(0xFF004A78)
3737
val btnEqualBgDark = Color(0xFF0742A0)

app/src/main/java/com/jyn/composecalculator/ui/view/ItemTextView.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ fun InputText(process: Float) {
4949
Column(
5050
modifier = Modifier
5151
.align(Alignment.CenterEnd)
52-
.background(evaluator(1- process, myTheme.bottomBg, myTheme.topBg))
52+
.background(myTheme.topBg)
53+
// .background(evaluator(1- process, myTheme.bottomBg, myTheme.topBg))
5354
.height(viewModel.textBoxHeight * 1f)
5455
.alpha(1f)
5556
.padding(start = 10.dp, end = 10.dp),
@@ -64,7 +65,7 @@ fun InputText(process: Float) {
6465
text = viewModel.inputText.value,
6566
color = myTheme.textColor,
6667
maxLines = 1,
67-
fontSize = if (isPortrait) 50.sp else 25.sp,
68+
fontSize = if (isPortrait) 50.sp else 28.sp,
6869
textAlign = TextAlign.End,
6970
)
7071
CursorView(if (isPortrait) 50.dp else 25.dp)
@@ -78,19 +79,19 @@ fun InputText(process: Float) {
7879
.horizontalScroll(resultScrollState)
7980
.onSizeChanged { resultTextWidth.value = it.width },
8081
maxLines = 1,
81-
fontSize = if (isPortrait) 30.sp else 15.sp,
82+
fontSize = if (isPortrait) 30.sp else 20.sp,
8283
color = Color.Gray,
8384
textAlign = TextAlign.End,
8485
)
8586
}
8687

8788
Text(
8889
modifier = Modifier
89-
.padding(10.dp)
90+
.padding(start = 20.dp, top = 10.dp)
9091
.alpha(process),
9192
text = "当前表达式",
92-
color = Color.Gray,
93-
fontSize = if (isPortrait) 20.sp else 10.sp,
93+
color = myTheme.textColor,
94+
fontSize = if (isPortrait) 20.sp else 15.sp,
9495
)
9596
}
9697
}
@@ -105,7 +106,7 @@ fun ItemText(input: String, result: String) {
105106
Text(
106107
modifier = Modifier.fillMaxWidth(),
107108
text = input,
108-
fontSize = if (isPortrait) 33.sp else 16.sp,
109+
fontSize = if (isPortrait) 33.sp else 25.sp,
109110
maxLines = 1,
110111
textAlign = TextAlign.End,
111112
color = myTheme.textColor,
@@ -120,7 +121,7 @@ fun ItemText(input: String, result: String) {
120121
modifier = Modifier.fillMaxWidth(),
121122
text = result,
122123
color = Color.Gray,
123-
fontSize = if (isPortrait) 23.sp else 12.sp,
124+
fontSize = if (isPortrait) 23.sp else 20.sp,
124125
maxLines = 1,
125126
textAlign = TextAlign.End,
126127
style = TextStyle(

0 commit comments

Comments
 (0)