Skip to content
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- [x] Hide API key from code by using expect/actual for OpenAPI key
- [x] Switch AI integration from OpenAI to Gemini
- [x] Refactor network layer for cleaner architecture
- [ ] Create a separate module for reusable UI components
- [x] Create a separate module for reusable UI components

---

Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ plugins {
alias(libs.plugins.serialization) apply false
alias(libs.plugins.googleSecrets) apply false
alias(libs.plugins.jetbrainsKotlinJvm) apply false
alias(libs.plugins.androidKotlinMultiplatformLibrary) apply false
}
10 changes: 10 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ kotlin {

sourceSets {
val desktopMain by getting
val commonMain by getting
val commonTest by getting

val desktopTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.konsist)
}
}

androidMain.dependencies {
implementation(libs.androidx.activity.compose)
Expand Down Expand Up @@ -105,6 +114,7 @@ kotlin {
implementation(libs.kermit)
implementation(libs.arrow.core)
implementation(libs.arrow.fx.coroutines)
implementation(project(":design-system"))
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.developersbreach.kotlindictionarymultiplatform.ui.components

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.developersbreach.designsystem.components.KdAlertDialog
import com.developersbreach.designsystem.components.KdText
import com.developersbreach.designsystem.components.KdTextButton
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
import kotlindictionarymultiplatform.composeapp.generated.resources.ok
import org.jetbrains.compose.resources.stringResource
Expand All @@ -16,14 +16,31 @@ fun ShowAlertDialog(
title: String,
description: String,
) {
AlertDialog(
KdAlertDialog(
onDismissRequest = onButtonClick,
title = { Text(text = title) },
text = { Text(text = description) },
title = {
KdText(
modifier = Modifier,
text = title,
)
},
text = {
KdText(
modifier = Modifier,
text = description,
)
},
confirmButton = {
TextButton(onClick = onButtonClick) {
Text(text = stringResource(Res.string.ok))
}
KdTextButton(
modifier = Modifier,
onClick = onButtonClick,
content = {
KdText(
modifier = Modifier,
text = stringResource(Res.string.ok),
)
},
)
},
modifier = modifier,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.developersbreach.kotlindictionarymultiplatform.ui.components

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.developersbreach.designsystem.components.KdCircularProgressIndicator
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
import kotlindictionarymultiplatform.composeapp.generated.resources.error_info_unavailable
import kotlindictionarymultiplatform.composeapp.generated.resources.error_occurred
Expand All @@ -30,7 +30,7 @@ fun <T> UiStateHandler(
Box(modifier = Modifier.fillMaxSize()) {
when (uiState) {
is UiState.Loading -> {
CircularProgressIndicator(
KdCircularProgressIndicator(
modifier = Modifier.align(Alignment.Center),
color = MaterialTheme.colorScheme.onBackground,
)
Expand All @@ -52,7 +52,7 @@ fun <T> UiStateHandler(
}

if (isLoading) {
CircularProgressIndicator(
KdCircularProgressIndicator(
modifier = Modifier.align(Alignment.Center),
color = MaterialTheme.colorScheme.onBackground,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -32,6 +30,8 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.developersbreach.designsystem.components.KdIcon
import com.developersbreach.designsystem.components.KdText
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
import kotlindictionarymultiplatform.composeapp.generated.resources.copied
import kotlindictionarymultiplatform.composeapp.generated.resources.copy
Expand Down Expand Up @@ -78,7 +78,7 @@ fun CodeExampleBox(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
KdText(
text = stringResource(Res.string.kotlin),
color = MaterialTheme.colorScheme.onPrimary,
fontWeight = FontWeight.Bold,
Expand All @@ -99,13 +99,15 @@ fun CodeExampleBox(
}
.padding(4.dp),
) {
Icon(
KdIcon(
modifier = Modifier,
imageVector = if (copied) Icons.Default.Check else Icons.Default.ContentCopy,
contentDescription = stringResource(Res.string.copy),
tint = MaterialTheme.colorScheme.onPrimary,
)
Spacer(modifier = Modifier.width(4.dp))
Text(
KdText(
modifier = Modifier,
text = if (copied) stringResource(Res.string.copied) else stringResource(Res.string.copy),
fontSize = 12.sp,
color = MaterialTheme.colorScheme.onPrimary,
Expand All @@ -116,7 +118,7 @@ fun CodeExampleBox(

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

Text(
KdText(
text = code,
modifier = Modifier.padding(
start = 12.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.developersbreach.designsystem.components.KdText
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Section
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Syntax
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
Expand All @@ -25,7 +25,7 @@ fun TableOfContents(
item: String,
onClick: () -> Unit,
) {
Text(
KdText(
text = item,
modifier = Modifier.clickable { onClick() },
color = MaterialTheme.colorScheme.onSurface,
Expand All @@ -37,13 +37,15 @@ fun TableOfContents(
fun IntroductionSection(
intro: String,
) {
Text(
KdText(
modifier = Modifier,
text = stringResource(resource = Res.string.introduction),
style = MaterialTheme.typography.headlineLarge,
color = MaterialTheme.colorScheme.onPrimary,
)
Spacer(Modifier.height(4.dp))
Text(
KdText(
modifier = Modifier,
text = intro,
style = MaterialTheme.typography.bodyMedium,
)
Expand All @@ -54,19 +56,22 @@ fun IntroductionSection(
fun SyntaxSection(
syntax: Syntax,
) {
Text(
KdText(
modifier = Modifier,
text = stringResource(resource = Res.string.syntax),
style = MaterialTheme.typography.headlineLarge,
color = MaterialTheme.colorScheme.onPrimary,
)
Spacer(Modifier.height(4.dp))
Text(
KdText(
modifier = Modifier,
text = syntax.signature,
style = MaterialTheme.typography.bodyMedium,
)
syntax.notes?.let {
Spacer(Modifier.height(4.dp))
Text(
KdText(
modifier = Modifier,
text = stringResource(
Res.string.notes_with_value,
it,
Expand All @@ -82,7 +87,8 @@ fun SectionBlock(
section: Section,
) {
section.heading?.let {
Text(
KdText(
modifier = Modifier,
text = it,
style = MaterialTheme.typography.headlineLarge,
color = MaterialTheme.colorScheme.onPrimary,
Expand All @@ -91,7 +97,8 @@ fun SectionBlock(
}

section.content?.let {
Text(
KdText(
modifier = Modifier,
text = it,
style = MaterialTheme.typography.bodyMedium,
)
Expand All @@ -100,7 +107,8 @@ fun SectionBlock(

section.codeExamples.forEach { example ->
example.description?.let {
Text(
KdText(
modifier = Modifier,
text = it,
fontWeight = FontWeight.Bold,
style = MaterialTheme.typography.bodyMedium,
Expand All @@ -116,14 +124,16 @@ fun SectionBlock(
fun PitfallsSection(
pitfalls: List<String>,
) {
Text(
KdText(
modifier = Modifier,
text = stringResource(resource = Res.string.pitfalls),
style = MaterialTheme.typography.headlineLarge,
color = MaterialTheme.colorScheme.onPrimary,
)
Spacer(Modifier.height(4.dp))
pitfalls.forEach {
Text(
KdText(
modifier = Modifier,
text = stringResource(
Res.string.bullet_item,
it,
Expand All @@ -138,14 +148,16 @@ fun PitfallsSection(
fun RelatedTopicsSection(
relatedTopics: List<String>,
) {
Text(
KdText(
modifier = Modifier,
text = stringResource(resource = Res.string.related_topics),
style = MaterialTheme.typography.headlineLarge,
color = MaterialTheme.colorScheme.onPrimary,
)
Spacer(Modifier.height(4.dp))
relatedTopics.forEach {
Text(
KdText(
modifier = Modifier,
text = stringResource(
Res.string.bullet_item,
it,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.developersbreach.designsystem.components.KdScaffold
import com.developersbreach.designsystem.components.KdText
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
import kotlindictionarymultiplatform.composeapp.generated.resources.table_of_contents
import kotlinx.coroutines.launch
Expand All @@ -24,20 +24,21 @@ fun DetailScreenUI(
detailUiState: DetailUiState,
navigateUp: () -> Unit,
) {
Scaffold(
KdScaffold(
modifier = Modifier,
topBar = {
DetailTopBar(
title = detailUiState.topicName,
navigateUp = navigateUp,
)
},
containerColor = MaterialTheme.colorScheme.background,
) { innerPadding ->
DetailContent(
detailUiState = detailUiState,
modifier = Modifier.padding(innerPadding),
)
}
content = { innerPadding ->
DetailContent(
detailUiState = detailUiState,
modifier = Modifier.padding(innerPadding),
)
},
)
}

@Composable
Expand All @@ -55,7 +56,8 @@ private fun DetailContent(
.padding(horizontal = 16.dp),
) {
item {
Text(
KdText(
modifier = Modifier,
text = stringResource(Res.string.table_of_contents),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onPrimary,
Expand Down
Loading
Loading