Skip to content

Commit f10c0f9

Browse files
authored
Merge pull request #19 from DevelopersBreach/shreyas/konsist-setup
Setup Konsist module for enforcing architectural constraints
2 parents d5c5fdd + 5587c5c commit f10c0f9

File tree

33 files changed

+761
-121
lines changed

33 files changed

+761
-121
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- [x] Hide API key from code by using expect/actual for OpenAPI key
1919
- [x] Switch AI integration from OpenAI to Gemini
2020
- [x] Refactor network layer for cleaner architecture
21-
- [ ] Create a separate module for reusable UI components
21+
- [x] Create a separate module for reusable UI components
2222

2323
---
2424

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ plugins {
99
alias(libs.plugins.serialization) apply false
1010
alias(libs.plugins.googleSecrets) apply false
1111
alias(libs.plugins.jetbrainsKotlinJvm) apply false
12+
alias(libs.plugins.androidKotlinMultiplatformLibrary) apply false
1213
}

composeApp/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ kotlin {
7171

7272
sourceSets {
7373
val desktopMain by getting
74+
val commonMain by getting
75+
val commonTest by getting
76+
77+
val desktopTest by getting {
78+
dependencies {
79+
implementation(kotlin("test"))
80+
implementation(libs.konsist)
81+
}
82+
}
7483

7584
androidMain.dependencies {
7685
implementation(libs.androidx.activity.compose)
@@ -105,6 +114,7 @@ kotlin {
105114
implementation(libs.kermit)
106115
implementation(libs.arrow.core)
107116
implementation(libs.arrow.fx.coroutines)
117+
implementation(project(":design-system"))
108118
}
109119
desktopMain.dependencies {
110120
implementation(compose.desktop.currentOs)

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/components/ShowAlertDialog.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/components/UiStateHandler.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package com.developersbreach.kotlindictionarymultiplatform.ui.components
22

33
import androidx.compose.foundation.layout.Box
44
import androidx.compose.foundation.layout.fillMaxSize
5-
import androidx.compose.material3.CircularProgressIndicator
6-
import androidx.compose.material3.MaterialTheme
75
import androidx.compose.runtime.Composable
86
import androidx.compose.runtime.LaunchedEffect
97
import androidx.compose.runtime.mutableStateOf
108
import androidx.compose.runtime.saveable.rememberSaveable
119
import androidx.compose.ui.Alignment
1210
import androidx.compose.ui.Modifier
11+
import com.developersbreach.designsystem.components.KdAlertDialog
12+
import com.developersbreach.designsystem.components.KdCircularProgressIndicator
1313
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
1414
import kotlindictionarymultiplatform.composeapp.generated.resources.error_info_unavailable
1515
import kotlindictionarymultiplatform.composeapp.generated.resources.error_occurred
16+
import kotlindictionarymultiplatform.composeapp.generated.resources.ok
1617
import org.jetbrains.compose.resources.stringResource
1718

1819
@Composable
@@ -30,20 +31,23 @@ fun <T> UiStateHandler(
3031
Box(modifier = Modifier.fillMaxSize()) {
3132
when (uiState) {
3233
is UiState.Loading -> {
33-
CircularProgressIndicator(
34+
KdCircularProgressIndicator(
3435
modifier = Modifier.align(Alignment.Center),
35-
color = MaterialTheme.colorScheme.onBackground,
3636
)
3737
}
3838

3939
is UiState.Error -> {
4040
if (!shouldDismissErrorDialog.value) {
4141
val errorDetails = uiState.throwable
42-
ShowAlertDialog(
43-
onButtonClick = { shouldDismissErrorDialog.value = true },
42+
KdAlertDialog(
43+
onDismissRequest = { shouldDismissErrorDialog.value = true },
4444
modifier = Modifier,
4545
title = stringResource(Res.string.error_occurred),
4646
description = errorDetails.message ?: stringResource(Res.string.error_info_unavailable),
47+
buttonTitle = stringResource(Res.string.ok),
48+
onButtonClick = {
49+
shouldDismissErrorDialog.value = true
50+
},
4751
)
4852
}
4953
}
@@ -52,9 +56,8 @@ fun <T> UiStateHandler(
5256
}
5357

5458
if (isLoading) {
55-
CircularProgressIndicator(
59+
KdCircularProgressIndicator(
5660
modifier = Modifier.align(Alignment.Center),
57-
color = MaterialTheme.colorScheme.onBackground,
5861
)
5962
}
6063
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/CodeExampleBox.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
1616
import androidx.compose.material.icons.Icons
1717
import androidx.compose.material.icons.filled.Check
1818
import androidx.compose.material.icons.filled.ContentCopy
19-
import androidx.compose.material3.Icon
2019
import androidx.compose.material3.MaterialTheme
21-
import androidx.compose.material3.Text
2220
import androidx.compose.runtime.Composable
2321
import androidx.compose.runtime.getValue
2422
import androidx.compose.runtime.mutableStateOf
@@ -32,6 +30,8 @@ import androidx.compose.ui.text.font.FontFamily
3230
import androidx.compose.ui.text.font.FontWeight
3331
import androidx.compose.ui.unit.dp
3432
import androidx.compose.ui.unit.sp
33+
import com.developersbreach.designsystem.components.KdIcon
34+
import com.developersbreach.designsystem.components.KdText
3535
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
3636
import kotlindictionarymultiplatform.composeapp.generated.resources.copied
3737
import kotlindictionarymultiplatform.composeapp.generated.resources.copy
@@ -78,7 +78,7 @@ fun CodeExampleBox(
7878
horizontalArrangement = Arrangement.SpaceBetween,
7979
verticalAlignment = Alignment.CenterVertically,
8080
) {
81-
Text(
81+
KdText(
8282
text = stringResource(Res.string.kotlin),
8383
color = MaterialTheme.colorScheme.onPrimary,
8484
fontWeight = FontWeight.Bold,
@@ -99,13 +99,15 @@ fun CodeExampleBox(
9999
}
100100
.padding(4.dp),
101101
) {
102-
Icon(
102+
KdIcon(
103+
modifier = Modifier,
103104
imageVector = if (copied) Icons.Default.Check else Icons.Default.ContentCopy,
104105
contentDescription = stringResource(Res.string.copy),
105106
tint = MaterialTheme.colorScheme.onPrimary,
106107
)
107108
Spacer(modifier = Modifier.width(4.dp))
108-
Text(
109+
KdText(
110+
modifier = Modifier,
109111
text = if (copied) stringResource(Res.string.copied) else stringResource(Res.string.copy),
110112
fontSize = 12.sp,
111113
color = MaterialTheme.colorScheme.onPrimary,
@@ -116,7 +118,7 @@ fun CodeExampleBox(
116118

117119
Spacer(modifier = Modifier.height(8.dp))
118120

119-
Text(
121+
KdText(
120122
text = code,
121123
modifier = Modifier.padding(
122124
start = 12.dp,

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/DetailScreenComponents.kt

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import androidx.compose.foundation.clickable
44
import androidx.compose.foundation.layout.Spacer
55
import androidx.compose.foundation.layout.height
66
import androidx.compose.material3.MaterialTheme
7-
import androidx.compose.material3.Text
87
import androidx.compose.runtime.Composable
98
import androidx.compose.ui.Modifier
109
import androidx.compose.ui.text.font.FontWeight
1110
import androidx.compose.ui.unit.dp
11+
import com.developersbreach.designsystem.components.KdText
1212
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Section
1313
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Syntax
1414
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
@@ -25,7 +25,7 @@ fun TableOfContents(
2525
item: String,
2626
onClick: () -> Unit,
2727
) {
28-
Text(
28+
KdText(
2929
text = item,
3030
modifier = Modifier.clickable { onClick() },
3131
color = MaterialTheme.colorScheme.onSurface,
@@ -37,13 +37,15 @@ fun TableOfContents(
3737
fun IntroductionSection(
3838
intro: String,
3939
) {
40-
Text(
40+
KdText(
41+
modifier = Modifier,
4142
text = stringResource(resource = Res.string.introduction),
4243
style = MaterialTheme.typography.headlineLarge,
4344
color = MaterialTheme.colorScheme.onPrimary,
4445
)
4546
Spacer(Modifier.height(4.dp))
46-
Text(
47+
KdText(
48+
modifier = Modifier,
4749
text = intro,
4850
style = MaterialTheme.typography.bodyMedium,
4951
)
@@ -54,19 +56,22 @@ fun IntroductionSection(
5456
fun SyntaxSection(
5557
syntax: Syntax,
5658
) {
57-
Text(
59+
KdText(
60+
modifier = Modifier,
5861
text = stringResource(resource = Res.string.syntax),
5962
style = MaterialTheme.typography.headlineLarge,
6063
color = MaterialTheme.colorScheme.onPrimary,
6164
)
6265
Spacer(Modifier.height(4.dp))
63-
Text(
66+
KdText(
67+
modifier = Modifier,
6468
text = syntax.signature,
6569
style = MaterialTheme.typography.bodyMedium,
6670
)
6771
syntax.notes?.let {
6872
Spacer(Modifier.height(4.dp))
69-
Text(
73+
KdText(
74+
modifier = Modifier,
7075
text = stringResource(
7176
Res.string.notes_with_value,
7277
it,
@@ -82,7 +87,8 @@ fun SectionBlock(
8287
section: Section,
8388
) {
8489
section.heading?.let {
85-
Text(
90+
KdText(
91+
modifier = Modifier,
8692
text = it,
8793
style = MaterialTheme.typography.headlineLarge,
8894
color = MaterialTheme.colorScheme.onPrimary,
@@ -91,7 +97,8 @@ fun SectionBlock(
9197
}
9298

9399
section.content?.let {
94-
Text(
100+
KdText(
101+
modifier = Modifier,
95102
text = it,
96103
style = MaterialTheme.typography.bodyMedium,
97104
)
@@ -100,7 +107,8 @@ fun SectionBlock(
100107

101108
section.codeExamples.forEach { example ->
102109
example.description?.let {
103-
Text(
110+
KdText(
111+
modifier = Modifier,
104112
text = it,
105113
fontWeight = FontWeight.Bold,
106114
style = MaterialTheme.typography.bodyMedium,
@@ -116,14 +124,16 @@ fun SectionBlock(
116124
fun PitfallsSection(
117125
pitfalls: List<String>,
118126
) {
119-
Text(
127+
KdText(
128+
modifier = Modifier,
120129
text = stringResource(resource = Res.string.pitfalls),
121130
style = MaterialTheme.typography.headlineLarge,
122131
color = MaterialTheme.colorScheme.onPrimary,
123132
)
124133
Spacer(Modifier.height(4.dp))
125134
pitfalls.forEach {
126-
Text(
135+
KdText(
136+
modifier = Modifier,
127137
text = stringResource(
128138
Res.string.bullet_item,
129139
it,
@@ -138,14 +148,16 @@ fun PitfallsSection(
138148
fun RelatedTopicsSection(
139149
relatedTopics: List<String>,
140150
) {
141-
Text(
151+
KdText(
152+
modifier = Modifier,
142153
text = stringResource(resource = Res.string.related_topics),
143154
style = MaterialTheme.typography.headlineLarge,
144155
color = MaterialTheme.colorScheme.onPrimary,
145156
)
146157
Spacer(Modifier.height(4.dp))
147158
relatedTopics.forEach {
148-
Text(
159+
KdText(
160+
modifier = Modifier,
149161
text = stringResource(
150162
Res.string.bullet_item,
151163
it,

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/DetailScreenUI.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import androidx.compose.foundation.lazy.LazyColumn
88
import androidx.compose.foundation.lazy.items
99
import androidx.compose.foundation.lazy.rememberLazyListState
1010
import androidx.compose.material3.MaterialTheme
11-
import androidx.compose.material3.Scaffold
12-
import androidx.compose.material3.Text
1311
import androidx.compose.runtime.Composable
1412
import androidx.compose.runtime.rememberCoroutineScope
1513
import androidx.compose.ui.Modifier
1614
import androidx.compose.ui.unit.dp
15+
import com.developersbreach.designsystem.components.KdScaffold
16+
import com.developersbreach.designsystem.components.KdText
1717
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
1818
import kotlindictionarymultiplatform.composeapp.generated.resources.table_of_contents
1919
import kotlinx.coroutines.launch
@@ -24,20 +24,21 @@ fun DetailScreenUI(
2424
detailUiState: DetailUiState,
2525
navigateUp: () -> Unit,
2626
) {
27-
Scaffold(
27+
KdScaffold(
28+
modifier = Modifier,
2829
topBar = {
2930
DetailTopBar(
3031
title = detailUiState.topicName,
3132
navigateUp = navigateUp,
3233
)
3334
},
34-
containerColor = MaterialTheme.colorScheme.background,
35-
) { innerPadding ->
36-
DetailContent(
37-
detailUiState = detailUiState,
38-
modifier = Modifier.padding(innerPadding),
39-
)
40-
}
35+
content = { innerPadding ->
36+
DetailContent(
37+
detailUiState = detailUiState,
38+
modifier = Modifier.padding(innerPadding),
39+
)
40+
},
41+
)
4142
}
4243

4344
@Composable
@@ -55,7 +56,8 @@ private fun DetailContent(
5556
.padding(horizontal = 16.dp),
5657
) {
5758
item {
58-
Text(
59+
KdText(
60+
modifier = Modifier,
5961
text = stringResource(Res.string.table_of_contents),
6062
style = MaterialTheme.typography.titleLarge,
6163
color = MaterialTheme.colorScheme.onPrimary,

0 commit comments

Comments
 (0)