Skip to content

Commit 04475fe

Browse files
committed
Enhance UI and add text swapping functionality
This commit introduces several UI improvements and new features to the `DiffCheckerScreen`: - **Swap Text Inputs:** - Added an `IconButton` with a `SwapVert` icon between the old and new text input fields. - Clicking this button swaps the content of the two `OutlinedTextField`s. - If real-time diff is enabled, the diff is recalculated after swapping. - **TopAppBar Styling:** - The "Diffly" title in the `TopAppBar` now uses `MaterialTheme.typography.titleLarge` with `FontWeight.Bold` and the primary color. - A "v1.0" version text is added to the `TopAppBar` actions, styled with `MaterialTheme.typography.titleSmall` and gray color. - **Diff Count Display:** - In `CharDiffText.kt`, the headers "Original Text" and "Changed Text" now display a count of changed/deleted lines (e.g., "-3") and changed/added lines (e.g., "+5") respectively. These counts are color-coded (red for deletions, green for additions). - **Layout and Spacing Adjustments:** - Adjusted padding and spacing around UI elements like the "Real-time Diff" switch, text input fields, and the "Find Difference" button for better visual balance. - Reduced padding within individual diff line items in `CharDiffText.kt` for a more compact display. - **Dependency Updates:** - Added `androidx.compose.material:material-icons-core` and `androidx.compose.material:material-icons-extended` dependencies for icon usage. - Removed `junit` and `androidx-ui-test-junit4` version references and `junit-jupiter` library from `libs.versions.toml`. - **IDE Configuration:** - Added `.idea/inspectionProfiles/Project_Default.xml` to configure project-specific inspection settings, primarily related to Jetpack Compose previews.
1 parent 2eb33f0 commit 04475fe

6 files changed

Lines changed: 157 additions & 29 deletions

File tree

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ dependencies {
6161
implementation(libs.androidx.ui)
6262
implementation(libs.androidx.ui.graphics)
6363
implementation(libs.androidx.ui.tooling.preview)
64+
implementation(libs.androidx.material)
6465
implementation(libs.androidx.material3)
66+
implementation(libs.androidx.material.icons.core)
67+
implementation(libs.androidx.material.icons.extended)
6568
androidTestImplementation(libs.androidx.espresso.core)
6669
androidTestImplementation(platform(libs.androidx.compose.bom))
6770
debugImplementation(libs.androidx.ui.tooling)

app/src/main/java/dev/jahidhasanco/diffly/presentation/component/CharDiffText.kt

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@ fun CharDiffText(diffResult: List<DiffEntry>) {
3333
.fillMaxHeight()
3434
) {
3535
item {
36-
Text(
37-
"Original Text",
38-
modifier = Modifier.padding(8.dp),
39-
style = MaterialTheme.typography.titleMedium
40-
)
36+
Row {
37+
Text(
38+
"Original Text",
39+
modifier = Modifier.padding(8.dp),
40+
style = MaterialTheme.typography.titleMedium
41+
)
42+
val count =
43+
diffResult.count { it.type == DiffType.CHANGED || it.type == DiffType.DELETED }
44+
if (count > 0)
45+
Text(
46+
"-${count}",
47+
modifier = Modifier.padding(8.dp),
48+
style = MaterialTheme.typography.bodyMedium.copy(
49+
color = delete,
50+
fontWeight = MaterialTheme.typography.titleMedium.fontWeight
51+
)
52+
)
53+
}
4154
}
4255
items(diffResult) { entry ->
4356
entry.oldLine?.let { line ->
@@ -57,7 +70,7 @@ fun CharDiffText(diffResult: List<DiffEntry>) {
5770
Box(
5871
modifier = Modifier
5972
.fillMaxWidth()
60-
.padding(4.dp)
73+
.padding(horizontal = 2.dp, vertical = 1.dp)
6174
.background(color = color)
6275
) {
6376
if (!charDiffs.isNullOrEmpty()) {
@@ -79,11 +92,24 @@ fun CharDiffText(diffResult: List<DiffEntry>) {
7992
.fillMaxHeight()
8093
) {
8194
item {
82-
Text(
83-
"Changed Text",
84-
modifier = Modifier.padding(8.dp),
85-
style = MaterialTheme.typography.titleMedium
86-
)
95+
Row {
96+
Text(
97+
"Changed Text",
98+
modifier = Modifier.padding(8.dp),
99+
style = MaterialTheme.typography.titleMedium
100+
)
101+
val count =
102+
diffResult.count { it.type == DiffType.CHANGED || it.type == DiffType.ADDED }
103+
if (count > 0)
104+
Text(
105+
"+${count}",
106+
modifier = Modifier.padding(8.dp),
107+
style = MaterialTheme.typography.bodyMedium.copy(
108+
color = added,
109+
fontWeight = MaterialTheme.typography.titleMedium.fontWeight
110+
)
111+
)
112+
}
87113
}
88114
items(diffResult) { entry ->
89115
entry.newLine?.let { line ->
@@ -103,7 +129,7 @@ fun CharDiffText(diffResult: List<DiffEntry>) {
103129
Box(
104130
modifier = Modifier
105131
.fillMaxWidth()
106-
.padding(4.dp)
132+
.padding(horizontal = 2.dp, vertical = 1.dp)
107133
.background(color)
108134

109135
) {

app/src/main/java/dev/jahidhasanco/diffly/presentation/component/InlineCharDiffText.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import dev.jahidhasanco.diffly.presentation.theme.delete
1515
fun InlineCharDiffText(charDiffs: List<CharDiff>) {
1616
val annotatedString = buildAnnotatedString {
1717
charDiffs.forEach { cd ->
18-
1918
val backgroundColor = when (cd.type) {
2019
CharDiffType.UNCHANGED -> Color.Unspecified
2120
CharDiffType.INSERTED -> added

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

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ import androidx.compose.foundation.layout.fillMaxSize
1010
import androidx.compose.foundation.layout.fillMaxWidth
1111
import androidx.compose.foundation.layout.height
1212
import androidx.compose.foundation.layout.padding
13+
import androidx.compose.foundation.layout.size
14+
import androidx.compose.foundation.rememberScrollState
1315
import androidx.compose.foundation.shape.RoundedCornerShape
16+
import androidx.compose.material.icons.Icons
17+
import androidx.compose.material.icons.filled.SwapVert
1418
import androidx.compose.material3.Button
1519
import androidx.compose.material3.ButtonDefaults
1620
import androidx.compose.material3.ExperimentalMaterial3Api
21+
import androidx.compose.material3.Icon
22+
import androidx.compose.material3.IconButton
23+
import androidx.compose.material3.IconButtonDefaults
1724
import androidx.compose.material3.MaterialTheme
1825
import androidx.compose.material3.OutlinedTextField
1926
import androidx.compose.material3.Scaffold
@@ -32,6 +39,7 @@ import androidx.compose.runtime.setValue
3239
import androidx.compose.ui.Alignment
3340
import androidx.compose.ui.Modifier
3441
import androidx.compose.ui.graphics.Color
42+
import androidx.compose.ui.text.font.FontWeight
3543
import androidx.compose.ui.unit.dp
3644
import dev.jahidhasanco.diffly.presentation.MainViewModel
3745
import dev.jahidhasanco.diffly.presentation.component.CharDiffText
@@ -45,21 +53,34 @@ fun DiffCheckerScreen(viewModel: MainViewModel) {
4553
var newText by remember { mutableStateOf("") }
4654
val diffResult by viewModel.diffResult.collectAsState()
4755
var realTimeDiff by remember { mutableStateOf(false) }
48-
56+
val scrollState = rememberScrollState()
4957
Scaffold(
5058
modifier = Modifier
5159
.fillMaxSize(),
5260
containerColor = background,
5361
topBar = {
5462
TopAppBar(
5563
title = {
56-
Text("Diffly")
64+
Text(
65+
"Diffly",
66+
style = MaterialTheme.typography.titleLarge.copy(
67+
fontWeight = FontWeight.Bold
68+
),
69+
color = primary,
70+
)
5771
},
58-
5972
colors = TopAppBarDefaults.topAppBarColors(
6073
containerColor = Color.White,
6174
titleContentColor = primary
6275
),
76+
actions = {
77+
Text(
78+
text = "v1.0",
79+
style = MaterialTheme.typography.titleSmall,
80+
color = Color.Gray,
81+
modifier = Modifier.padding(end = 16.dp)
82+
)
83+
}
6384
)
6485
}) { innerPadding ->
6586
Column(
@@ -71,13 +92,15 @@ fun DiffCheckerScreen(viewModel: MainViewModel) {
7192
Row(
7293
verticalAlignment = Alignment.CenterVertically,
7394
horizontalArrangement = Arrangement.Center,
74-
modifier = Modifier.padding(bottom = 8.dp)
95+
modifier = Modifier
96+
.padding(bottom = 8.dp)
97+
.fillMaxWidth()
7598
) {
7699
Text(
77100
text = "Real-time Diff",
78101
style = MaterialTheme.typography.titleMedium,
79102
color = if (realTimeDiff) primary else Color.Gray,
80-
modifier = Modifier.padding(end = 8.dp)
103+
modifier = Modifier.padding(end = 20.dp)
81104
)
82105
Switch(
83106
checked = realTimeDiff,
@@ -128,7 +151,36 @@ fun DiffCheckerScreen(viewModel: MainViewModel) {
128151
singleLine = false
129152
)
130153

131-
Spacer(modifier = Modifier.height(8.dp))
154+
155+
Spacer(modifier = Modifier.height(4.dp))
156+
157+
// swap icon button
158+
IconButton(
159+
onClick = {
160+
val temp = oldText
161+
oldText = newText
162+
newText = temp
163+
if (realTimeDiff) {
164+
viewModel.calculateDiff(oldText, newText)
165+
}
166+
},
167+
colors = IconButtonDefaults.iconButtonColors(
168+
containerColor = Color.Transparent,
169+
contentColor = primary
170+
),
171+
modifier = Modifier
172+
.align(Alignment.CenterHorizontally)
173+
.padding(vertical = 8.dp)
174+
) {
175+
Icon(
176+
imageVector = Icons.Default.SwapVert,
177+
contentDescription = "Swap", tint = primary,
178+
modifier = Modifier
179+
.padding(2.dp)
180+
.size(28.dp)
181+
)
182+
}
183+
Spacer(modifier = Modifier.height(4.dp))
132184
OutlinedTextField(
133185
value = newText, onValueChange = {
134186
newText = it
@@ -182,9 +234,6 @@ fun DiffCheckerScreen(viewModel: MainViewModel) {
182234
) {
183235
Text("Find Difference")
184236
}
185-
186-
Spacer(modifier = Modifier.height(16.dp))
187-
188237
CharDiffText(diffResult)
189238
}
190239
}

gradle/libs.versions.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
agp = "8.10.0-alpha08"
33
kotlin = "2.0.21"
44
coreKtx = "1.16.0"
5-
junit = "4.13.2"
6-
junitVersion = "1.2.1"
75
espressoCore = "3.6.1"
86
lifecycleRuntimeKtx = "2.9.2"
97
activityCompose = "1.10.1"
108
composeBom = "2024.09.00"
11-
junitJupiter = "5.8.1"
9+
materialIconsCore = "1.7.8"
10+
materialIconsExtended = "1.7.8"
11+
material = "1.8.3"
1212

1313
[libraries]
1414
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
15-
junit = { group = "junit", name = "junit", version.ref = "junit" }
16-
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
15+
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core", version.ref = "materialIconsCore" }
16+
androidx-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "materialIconsExtended" } # Added
1717
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
1818
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
1919
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
@@ -23,9 +23,10 @@ androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
2323
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
2424
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
2525
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
26-
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
2726
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
28-
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junitJupiter" }
27+
androidx-material = { group = "androidx.compose.material", name = "material", version.ref = "material" }
28+
29+
2930

3031
[plugins]
3132
android-application = { id = "com.android.application", version.ref = "agp" }

0 commit comments

Comments
 (0)