From fb5ef97f135141189f469480f4e17c7a1bddc615 Mon Sep 17 00:00:00 2001 From: Mohsen Rezania Date: Sat, 6 Apr 2024 02:47:31 +0200 Subject: [PATCH 1/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c0bed9..c93e7f8 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ implementation 'io.github.linx64:reusablecomponents:' Version Catalog: ```Kotlin-dsl -reusablecomponents_version = -reusableComponents = { group = "io.github.linx64", name = "reusablecomponents", version.ref = "reuseableComponents" } +reusable-components = +reusableComponents = { group = "io.github.linx64", name = "reusablecomponents", version.ref = "reusable-components" } ``` ## Components From d3ffaacca31707d1c6c5f6317a13e5c6b1a66bc1 Mon Sep 17 00:00:00 2001 From: Mohsen Rezania Date: Sun, 7 Apr 2024 02:20:08 +0300 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c93e7f8..42a2ae6 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,9 @@ ScrollableScreen { } ``` -And that's it! You have a scrollable screen with a few buttons +And that's it! You have a scrollable screen with a few buttons. -You can customize the container by passing your own `modifier` to it. The same goes for the buttons, you can pass your own `modifier` to the buttons. +You can customize the container by passing your `modifier` to it. The same goes for the buttons. **Important note:** To use the Preview components, you'll need to add your theme first, then use the components to create your UI. From 44c5c6dbedac1af083cb2afb5ce77eadd36bd464 Mon Sep 17 00:00:00 2001 From: Mohsen Rzna Date: Tue, 9 Apr 2024 12:58:11 +0300 Subject: [PATCH 3/3] Code refactor --- .../client/reusable/ui/screens/HomeScreen.kt | 8 +- gradle.properties | 3 +- reusablecomponents/build.gradle.kts | 2 +- .../containers/CenteredColumn.kt | 2 +- .../reusablecomponents/dialogs/BaseDialog.kt | 99 +++++++++++++++++++ .../previews/AppScreenComponent.kt | 16 ++- .../reusablecomponents/spacers/Spacers.kt | 2 +- .../src/main/res/values/strings.xml | 2 +- 8 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 reusablecomponents/src/main/kotlin/com/client/reusablecomponents/dialogs/BaseDialog.kt diff --git a/app/src/main/java/com/client/reusable/ui/screens/HomeScreen.kt b/app/src/main/java/com/client/reusable/ui/screens/HomeScreen.kt index fccb22a..36f0fdc 100644 --- a/app/src/main/java/com/client/reusable/ui/screens/HomeScreen.kt +++ b/app/src/main/java/com/client/reusable/ui/screens/HomeScreen.kt @@ -13,7 +13,7 @@ import com.client.reusablecomponents.containers.ScrollableScreen import com.client.reusablecomponents.previews.AppScreenComponent import com.client.reusablecomponents.previews.MultiThemePreviews import com.client.reusablecomponents.spacers.FillHeightSpacer -import com.client.reusablecomponents.spacers.FillHorizontalHeight +import com.client.reusablecomponents.spacers.HorizontalSpacer @Composable fun HomeScreen() { @@ -26,15 +26,15 @@ fun HomeScreen() { FillHeightSpacer() - FillHorizontalHeight() + HorizontalSpacer() PrimaryButton(text = R.string.app_name, onClick = {}) - FillHorizontalHeight() + HorizontalSpacer() PrimaryButton(text = R.string.app_name, onClick = {}) - FillHorizontalHeight() + HorizontalSpacer() SecondaryButton(text = R.string.app_name, onClick = {}) } diff --git a/gradle.properties b/gradle.properties index 14faa19..3465747 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,7 @@ org.gradle.caching=true org.gradle.configuration-cache.problems=warn org.gradle.configureondemand=false org.gradle.parallel=true +org.gradle.configuration-cache=true GROUP=io.github.linx64 VERSION_NAME=1.0 @@ -29,4 +30,4 @@ POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/LinX64/Reusable.git POM_DEVELOPER_ID=LinX64 POM_DEVELOPER_NAME=Mohsen -POM_DEVELOPER_URL=https://github.com/LinX64/ \ No newline at end of file +POM_DEVELOPER_URL=https://github.com/LinX64/ diff --git a/reusablecomponents/build.gradle.kts b/reusablecomponents/build.gradle.kts index 9105bdd..9ee96e8 100644 --- a/reusablecomponents/build.gradle.kts +++ b/reusablecomponents/build.gradle.kts @@ -53,6 +53,7 @@ dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) implementation(libs.androidx.ui) implementation(libs.androidx.ui.graphics) @@ -60,7 +61,6 @@ dependencies { implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material.iconsExtended) - debugImplementation(libs.androidx.ui.test.manifest) debugImplementation(libs.androidx.ui.tooling) } diff --git a/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/containers/CenteredColumn.kt b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/containers/CenteredColumn.kt index 1f6c3c3..7b184c7 100644 --- a/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/containers/CenteredColumn.kt +++ b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/containers/CenteredColumn.kt @@ -31,7 +31,7 @@ fun CenteredColumn( @Preview(showBackground = true) @Composable -private fun CenterColumnPreview() { +private fun CenteredColumnPreview() { AppScreenComponent { CenteredColumn { Text(text = "Text in center") diff --git a/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/dialogs/BaseDialog.kt b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/dialogs/BaseDialog.kt new file mode 100644 index 0000000..6e54445 --- /dev/null +++ b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/dialogs/BaseDialog.kt @@ -0,0 +1,99 @@ +package com.client.reusablecomponents.dialogs + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Error +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import io.github.linx64.reusablecomponents.R + +@Composable +fun BaseErrorDialog( + modifier: Modifier = Modifier, + title: String, + message: String, + icon: ImageVector = Icons.Default.Error, + iconTint: Color = MaterialTheme.colorScheme.error, + shouldShowDismiss: Boolean = false +) { + val shouldShowDialog = remember { mutableStateOf(true) } + if (shouldShowDialog.value) { + AlertDialog( + modifier = modifier, + icon = { Icon(icon, iconTint) }, + title = { Text(text = title) }, + text = { Text(text = message) }, + onDismissRequest = { shouldShowDialog.value = false }, + confirmButton = { ConfirmButton(shouldShowDialog) }, + dismissButton = { DismissButton(shouldShowDismiss, shouldShowDialog) } + ) + } +} + +@Composable +private fun Icon( + icon: ImageVector, + iconTint: Color +) { + Icon( + modifier = Modifier.size(48.dp), + imageVector = icon, + contentDescription = null, + tint = iconTint + ) +} + +@Composable +private fun ConfirmButton(shouldShowDialog: MutableState) { + TextButton( + onClick = { + shouldShowDialog.value = false + } + ) { + Text(text = stringResource(R.string.ok)) + } +} + +@Composable +private fun DismissButton( + shouldShowDismiss: Boolean, + shouldShowDialog: MutableState +) { + if (shouldShowDismiss) { + TextButton( + onClick = { + shouldShowDialog.value = false + } + ) { + Text(text = "Dismiss") + } + } +} + +@Preview(showBackground = true) +@Composable +private fun BaseErrorDialogPreview() { + Column( + modifier = Modifier.fillMaxSize() + ) { + BaseErrorDialog( + title = "Error", + message = "Please enter valid email and password!" + ) + } +} diff --git a/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/previews/AppScreenComponent.kt b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/previews/AppScreenComponent.kt index e272f96..b22a82b 100644 --- a/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/previews/AppScreenComponent.kt +++ b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/previews/AppScreenComponent.kt @@ -10,7 +10,7 @@ import com.client.reusablecomponents.containers.CenteredColumn import io.github.linx64.reusablecomponents.R /** - * A component that wraps the content in a [Surface] and centers the content. + * A component that wraps the content in a [Surface] and then centers it * The content is placed in a [Column]. * IMPORTANT: Remember to add your own Theme while using this component. */ @@ -20,16 +20,12 @@ fun AppScreenComponent( content: @Composable () -> Unit, ) { Surface( - modifier = Modifier.fillMaxSize(), + modifier = Modifier + .fillMaxSize() + .then(modifier), ) { - Column( - modifier = Modifier - .fillMaxSize() - .then(modifier), - ) { - CenteredColumn { - content() - } + CenteredColumn { + content() } } } diff --git a/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/spacers/Spacers.kt b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/spacers/Spacers.kt index aeac450..84aecc0 100644 --- a/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/spacers/Spacers.kt +++ b/reusablecomponents/src/main/kotlin/com/client/reusablecomponents/spacers/Spacers.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @Composable -fun FillHorizontalHeight() = Spacer(modifier = Modifier.height(16.dp)) +fun HorizontalSpacer() = Spacer(modifier = Modifier.height(16.dp)) /** * Spacers for Column diff --git a/reusablecomponents/src/main/res/values/strings.xml b/reusablecomponents/src/main/res/values/strings.xml index 1d802a0..22b6706 100644 --- a/reusablecomponents/src/main/res/values/strings.xml +++ b/reusablecomponents/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - Ok + OK Dismiss Cancel \ No newline at end of file