Skip to content

Commit 102325f

Browse files
committed
Refactor: Move real-time diff switch to TopAppBar
This commit relocates the "Real-time Diff" switch from the main content area to the `TopAppBar` in `DiffCheckerScreen.kt`. - The `Switch` and its accompanying "Live" label are now part of the `actions` in the `TopAppBar`. - The label text is changed from "Real-time Diff" to "Live". - Minor padding and scaling adjustments were made to the `Switch` and its label for better visual fit within the `TopAppBar`. - The previous `Row` containing the switch below the `TopAppBar` has been removed.
1 parent e381a78 commit 102325f

1 file changed

Lines changed: 30 additions & 28 deletions

File tree

app/src/main/java/dev/jahidhasanco/diffly/presentation/screen/DiffCheckerScreen.kt

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
1212
import androidx.compose.foundation.layout.height
1313
import androidx.compose.foundation.layout.padding
1414
import androidx.compose.foundation.layout.size
15+
import androidx.compose.foundation.layout.wrapContentWidth
1516
import androidx.compose.foundation.rememberScrollState
1617
import androidx.compose.foundation.shape.RoundedCornerShape
1718
import androidx.compose.material.icons.Icons
@@ -42,6 +43,7 @@ import androidx.compose.runtime.remember
4243
import androidx.compose.runtime.setValue
4344
import androidx.compose.ui.Alignment
4445
import androidx.compose.ui.Modifier
46+
import androidx.compose.ui.draw.scale
4547
import androidx.compose.ui.graphics.Color
4648
import androidx.compose.ui.text.font.FontWeight
4749
import androidx.compose.ui.unit.dp
@@ -80,6 +82,34 @@ fun DiffCheckerScreen(viewModel: MainViewModel) {
8082
containerColor = Color.White, titleContentColor = primary
8183
), actions = {
8284
// Popup Menu Icon
85+
Row(
86+
verticalAlignment = Alignment.CenterVertically,
87+
horizontalArrangement = Arrangement.Center,
88+
modifier = Modifier
89+
.wrapContentWidth()
90+
) {
91+
Text(
92+
text = "Live",
93+
style = MaterialTheme.typography.titleMedium,
94+
color = if (realTimeDiff) primary else Color.Gray,
95+
modifier = Modifier.padding(end = 6.dp)
96+
)
97+
Switch(
98+
modifier = Modifier.padding(end = 4.dp).scale(0.7f),
99+
checked = realTimeDiff, onCheckedChange = {
100+
realTimeDiff = it
101+
if (it) {
102+
viewModel.calculateDiff(oldText, newText)
103+
}
104+
}, colors = SwitchDefaults.colors(
105+
checkedThumbColor = primary,
106+
uncheckedThumbColor = Color.Gray,
107+
checkedTrackColor = primary.copy(alpha = 0.3f),
108+
uncheckedTrackColor = Color.LightGray
109+
)
110+
)
111+
}
112+
83113
Box {
84114
IconButton(onClick = { expanded = true }) {
85115
Icon(
@@ -119,34 +149,6 @@ fun DiffCheckerScreen(viewModel: MainViewModel) {
119149
.padding(16.dp)
120150
.fillMaxSize()
121151
) {
122-
Row(
123-
verticalAlignment = Alignment.CenterVertically,
124-
horizontalArrangement = Arrangement.Center,
125-
modifier = Modifier
126-
.padding(bottom = 8.dp)
127-
.fillMaxWidth()
128-
) {
129-
Text(
130-
text = "Real-time Diff",
131-
style = MaterialTheme.typography.titleMedium,
132-
color = if (realTimeDiff) primary else Color.Gray,
133-
modifier = Modifier.padding(end = 20.dp)
134-
)
135-
Switch(
136-
checked = realTimeDiff, onCheckedChange = {
137-
realTimeDiff = it
138-
if (it) {
139-
viewModel.calculateDiff(oldText, newText)
140-
}
141-
}, colors = SwitchDefaults.colors(
142-
checkedThumbColor = primary,
143-
uncheckedThumbColor = Color.Gray,
144-
checkedTrackColor = primary.copy(alpha = 0.3f),
145-
uncheckedTrackColor = Color.LightGray
146-
)
147-
)
148-
}
149-
150152
OutlinedTextField(
151153
value = oldText,
152154
onValueChange = {

0 commit comments

Comments
 (0)