Skip to content

Commit ce93ec3

Browse files
committed
code improvement.
1 parent 2393a80 commit ce93ec3

File tree

7 files changed

+49
-19
lines changed

7 files changed

+49
-19
lines changed

app/src/main/java/me/bytebeats/views/charts/app/ui/screen/HomeScreen.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ private fun HomeScreenContent(modifier: Modifier) {
4747
verticalArrangement = Arrangement.Center,
4848
horizontalAlignment = Alignment.CenterHorizontally,
4949
) {
50-
ChartScreenSelector(text = "Pie Chart", nextScreen = Screen.Pie)
51-
ChartScreenSelector(text = "Line Chart", nextScreen = Screen.Line)
52-
ChartScreenSelector(text = "Bar Chart", nextScreen = Screen.Bar)
50+
ChartScreenSelector(
51+
text = "Pie Chart",
52+
nextScreen = Screen.Pie
53+
)
54+
ChartScreenSelector(
55+
text = "Line Chart",
56+
nextScreen = Screen.Line
57+
)
58+
ChartScreenSelector(
59+
text = "Bar Chart",
60+
nextScreen = Screen.Bar
61+
)
5362
}
5463
}
5564

@@ -59,7 +68,10 @@ private fun ChartScreenSelector(
5968
nextScreen: Screen
6069
) {
6170
Row(
62-
modifier = Modifier.padding(horizontal = Margins.horizontal, vertical = Margins.vertical)
71+
modifier = Modifier.padding(
72+
horizontal = Margins.horizontal,
73+
vertical = Margins.vertical
74+
)
6375
) {
6476
TextButton(
6577
onClick = { ScreenRouter.navigate(nextScreen) }

app/src/main/java/me/bytebeats/views/charts/app/ui/screen/bar/BarChartScreen.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ fun BarChartScreen() {
4747
topBar = {
4848
TopAppBar(
4949
navigationIcon = {
50-
IconButton(onClick = { ScreenRouter.navigateHome() }) {
50+
IconButton(
51+
onClick = { ScreenRouter.navigateHome() }
52+
) {
5153
Icon(
5254
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
5355
contentDescription = "Go back home"
@@ -72,7 +74,8 @@ private fun BarChartContent(modifier: Modifier = Modifier) {
7274
BarChartRow(barChartDataModel = barChartDataModel)
7375
DrawLabelLocation(
7476
barChartDataModel = barChartDataModel,
75-
newLocation = { barChartDataModel.labelLocation = it })
77+
newLocation = { barChartDataModel.labelLocation = it }
78+
)
7679
AddOrRemoveBar(barChartDataModel = barChartDataModel)
7780
}
7881
}

app/src/main/java/me/bytebeats/views/charts/app/ui/screen/line/LineChartDataModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.bytebeats.views.charts.app.ui.screen.line
22

33
import androidx.compose.runtime.getValue
4+
import androidx.compose.runtime.mutableFloatStateOf
45
import androidx.compose.runtime.mutableStateOf
56
import androidx.compose.runtime.setValue
67
import me.bytebeats.views.charts.line.LineChartData
@@ -31,7 +32,7 @@ class LineChartDataModel {
3132
)
3233
)
3334

34-
var horizontalOffset by mutableStateOf(5F)
35+
var horizontalOffset by mutableFloatStateOf(5F)
3536

3637
var pointDrawerType by mutableStateOf(PointDrawerType.Hollow)
3738
val pointDrawer: IPointDrawer

app/src/main/java/me/bytebeats/views/charts/app/ui/screen/line/LineChartScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ fun LineChartScreen() {
4141
TopAppBar(
4242
navigationIcon = {
4343
IconButton(
44-
onClick = { ScreenRouter.navigateHome() }) {
44+
onClick = { ScreenRouter.navigateHome() }
45+
) {
4546
Icon(
4647
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
4748
contentDescription = "Go back home"

app/src/main/java/me/bytebeats/views/charts/app/ui/screen/line/PointDrawerType.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ package me.bytebeats.views.charts.app.ui.screen.line
88
enum class PointDrawerType {
99
None,
1010
Filled,
11-
Hollow
12-
}
11+
Hollow;
12+
}

app/src/main/java/me/bytebeats/views/charts/app/ui/screen/pie/PieChartDataModel.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.bytebeats.views.charts.app.ui.screen.pie
22

33
import androidx.compose.runtime.getValue
4+
import androidx.compose.runtime.mutableFloatStateOf
45
import androidx.compose.runtime.mutableStateOf
56
import androidx.compose.runtime.setValue
67
import androidx.compose.ui.graphics.Color
@@ -13,7 +14,7 @@ import kotlin.random.Random
1314
* Quote: Peasant. Educated. Worker
1415
*/
1516
class PieChartDataModel {
16-
private val colors = mutableListOf<Color>(
17+
private val colors = mutableListOf(
1718
Color(0XFFF44336),
1819
Color(0XFFE91E63),
1920
Color(0XFF9C27B0),
@@ -29,17 +30,23 @@ class PieChartDataModel {
2930
Color(0XFF607D8B)
3031
)
3132

32-
var sliceThickness by mutableStateOf(25F)
33+
var sliceThickness by mutableFloatStateOf(25F)
3334

3435
var pieChartData by mutableStateOf(
3536
PieChartData(
3637
slices = listOf(
3738
PieChartData.Slice(
38-
randomLength(),
39-
randomColor()
39+
value = randomLength(),
40+
color = randomColor()
4041
),
41-
PieChartData.Slice(randomLength(), randomColor()),
42-
PieChartData.Slice(randomLength(), randomColor())
42+
PieChartData.Slice(
43+
value = randomLength(),
44+
color = randomColor()
45+
),
46+
PieChartData.Slice(
47+
value = randomLength(),
48+
color = randomColor()
49+
)
4350
)
4451
)
4552
)
@@ -50,7 +57,12 @@ class PieChartDataModel {
5057
fun addSlice() {
5158
pieChartData = pieChartData.copy(
5259
slices = slices.toMutableList().apply {
53-
add(PieChartData.Slice(randomLength(), randomColor()))
60+
add(
61+
PieChartData.Slice(
62+
value = randomLength(),
63+
color = randomColor()
64+
)
65+
)
5466
}.toList()
5567
)
5668
}
@@ -70,4 +82,4 @@ class PieChartDataModel {
7082
val randomIndex = Random.Default.nextInt(colors.size)
7183
return colors.removeAt(randomIndex)
7284
}
73-
}
85+
}

app/src/main/java/me/bytebeats/views/charts/app/ui/screen/pie/PieChartScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ fun PieChartScreen() {
4747
TopAppBar(
4848
navigationIcon = {
4949
IconButton(
50-
onClick = { ScreenRouter.navigateHome() }) {
50+
onClick = { ScreenRouter.navigateHome() }
51+
) {
5152
Icon(
5253
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
5354
contentDescription = "Go back Home"

0 commit comments

Comments
 (0)