From 7eed23835bef30b2ce1a622ce21acbfc976c4054 Mon Sep 17 00:00:00 2001 From: breensmbaka Date: Sun, 26 May 2024 10:07:32 +0300 Subject: [PATCH 1/7] Migrating to the K2 Compiler --- BeeTablesCompose/build.gradle.kts | 8 +------- app/build.gradle.kts | 7 +------ build.gradle.kts | 1 + 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/BeeTablesCompose/build.gradle.kts b/BeeTablesCompose/build.gradle.kts index a3edf70..387dfdd 100644 --- a/BeeTablesCompose/build.gradle.kts +++ b/BeeTablesCompose/build.gradle.kts @@ -17,6 +17,7 @@ plugins { id("com.android.library") id("org.jetbrains.kotlin.android") id("maven-publish") + id("org.jetbrains.kotlin.plugin.compose") } android { @@ -46,13 +47,6 @@ android { kotlinOptions { jvmTarget = "1.8" } - buildFeatures { - compose = true - } - composeOptions { - kotlinCompilerExtensionVersion = "1.5.14" - } - packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 679ce42..e4255b9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -16,6 +16,7 @@ plugins { id("com.android.application") id("org.jetbrains.kotlin.android") + id("org.jetbrains.kotlin.plugin.compose") } android { @@ -51,12 +52,6 @@ android { kotlinOptions { jvmTarget = "1.8" } - buildFeatures { - compose = true - } - composeOptions { - kotlinCompilerExtensionVersion = "1.5.14" - } packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" diff --git a/build.gradle.kts b/build.gradle.kts index 8e13975..0596df7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,6 +4,7 @@ plugins { id("org.jetbrains.kotlin.android") version "1.9.24" apply false id("com.android.library") version "8.1.4" apply false id("com.diffplug.spotless") version "6.19.0" apply false + id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" apply false } subprojects { From d369b3c90b19c1431ffcdfc7f1217dccaacfe9ba Mon Sep 17 00:00:00 2001 From: breensmbaka Date: Sun, 26 May 2024 15:36:06 +0300 Subject: [PATCH 2/7] Update kotlin plugin version from 1.9.24 to 2.0.0 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0596df7..c56d84e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id("com.android.application") version "8.1.4" apply false - id("org.jetbrains.kotlin.android") version "1.9.24" apply false + id("org.jetbrains.kotlin.android") version "2.0.0" apply false id("com.android.library") version "8.1.4" apply false id("com.diffplug.spotless") version "6.19.0" apply false id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" apply false From 518a419d99cd53ebe77c5986e0afda586909b5ad Mon Sep 17 00:00:00 2001 From: JoelKanyi Date: Sun, 26 May 2024 21:40:48 +0300 Subject: [PATCH 3/7] FIX: Table isn't quite visible when user changes to dark theme #14 --- .../beetablescompose/BeeTablesCompose.kt | 17 +- .../components/TableHeaderComponent.kt | 6 +- ...bleHeaderComponentWithoutColumnDividers.kt | 3 +- .../components/TableRowComponent.kt | 6 +- ...ableRowComponentWithoutVerticalDividers.kt | 5 +- .../beetablescompose/utils/ColorUtils.kt | 28 ++ .../breens/beetablescompose/MainActivity.kt | 380 +++++++++--------- 7 files changed, 246 insertions(+), 199 deletions(-) create mode 100644 BeeTablesCompose/src/main/java/com/breens/beetablescompose/utils/ColorUtils.kt diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt index 2aece75..a6dbac6 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt @@ -33,6 +33,8 @@ import com.breens.beetablescompose.components.TableHeaderComponentWithoutColumnD import com.breens.beetablescompose.components.TableRowComponent import com.breens.beetablescompose.components.TableRowComponentWithoutDividers import com.breens.beetablescompose.utils.extractMembers +import com.breens.beetablescompose.utils.lightColor +import com.breens.beetablescompose.utils.lightGray /** * 🐝 A Compose UI data table library. @@ -61,21 +63,24 @@ inline fun BeeTablesCompose( data: List, enableTableHeaderTitles: Boolean = true, headerTableTitles: List, - headerTitlesBorderColor: Color = Color.LightGray, + headerTitlesBorderColor: Color = lightGray(), headerTitlesTextStyle: TextStyle = MaterialTheme.typography.bodySmall, - headerTitlesBackGroundColor: Color = Color.White, - tableRowColors: List = listOf(Color.White, Color.White), - rowBorderColor: Color = Color.LightGray, + headerTitlesBackGroundColor: Color = lightColor(), + tableRowColors: List = listOf( + lightColor(), + lightColor(), + ), + rowBorderColor: Color = lightGray(), rowTextStyle: TextStyle = MaterialTheme.typography.bodySmall, tableElevation: Dp = 0.dp, shape: RoundedCornerShape = RoundedCornerShape(4.dp), borderStroke: BorderStroke = BorderStroke( width = 1.dp, - color = Color.LightGray, + color = lightGray(), ), disableVerticalDividers: Boolean = false, dividerThickness: Dp = 1.dp, - horizontalDividerColor: Color = Color.LightGray, + horizontalDividerColor: Color = lightGray(), contentAlignment: Alignment = Alignment.Center, textAlign: TextAlign = TextAlign.Center, tablePadding: Dp = 0.dp, diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponent.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponent.kt index 2b9a080..23dc5f9 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponent.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponent.kt @@ -35,6 +35,8 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import com.breens.beetablescompose.utils.darkColor +import com.breens.beetablescompose.utils.lightGray @Composable fun TableHeaderComponent( @@ -85,9 +87,9 @@ fun TableHeaderComponentPreview() { val titles = listOf("Team", "Home", "Away", "Points") TableHeaderComponent( headerTableTitles = titles, - headerTitlesBorderColor = Color.Black, + headerTitlesBorderColor = darkColor(), headerTitlesTextStyle = MaterialTheme.typography.labelMedium, - headerTitlesBackGroundColor = Color.LightGray, + headerTitlesBackGroundColor = lightGray(), contentAlignment = Alignment.Center, textAlign = TextAlign.Center, tablePadding = 0.dp, diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponentWithoutColumnDividers.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponentWithoutColumnDividers.kt index 4eef107..811b527 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponentWithoutColumnDividers.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableHeaderComponentWithoutColumnDividers.kt @@ -36,6 +36,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import com.breens.beetablescompose.utils.lightColor @Composable fun TableHeaderComponentWithoutColumnDividers( @@ -91,7 +92,7 @@ fun TableHeaderComponentWithoutColumnDividersPreview() { TableHeaderComponentWithoutColumnDividers( headerTableTitles = titles, headerTitlesTextStyle = MaterialTheme.typography.bodySmall, - headerTitlesBackGroundColor = Color.White, + headerTitlesBackGroundColor = lightColor(), dividerThickness = 1.dp, contentAlignment = Alignment.Center, textAlign = TextAlign.Center, diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt index f1212b2..d001bc6 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt @@ -35,6 +35,8 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import com.breens.beetablescompose.utils.lightColor +import com.breens.beetablescompose.utils.lightGray @Composable fun TableRowComponent( @@ -87,9 +89,9 @@ fun TableRowComponentPreview() { TableRowComponent( data = titles, - rowBorderColor = Color.LightGray, + rowBorderColor = lightGray(), rowTextStyle = MaterialTheme.typography.bodySmall, - rowBackGroundColor = Color.White, + rowBackGroundColor = lightColor(), contentAlignment = Alignment.Center, textAlign = TextAlign.Center, tablePadding = 0.dp, diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt index 5ee9766..d579067 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt @@ -36,6 +36,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import com.breens.beetablescompose.utils.lightGray @Composable fun TableRowComponentWithoutDividers( @@ -94,9 +95,9 @@ fun TableRowComponentWithoutDividersPreview() { TableRowComponentWithoutDividers( data = titles, rowTextStyle = MaterialTheme.typography.bodySmall, - rowBackGroundColor = Color.White, + rowBackGroundColor = MaterialTheme.colorScheme.background, dividerThickness = 1.dp, - horizontalDividerColor = Color.LightGray, + horizontalDividerColor = lightGray(), contentAlignment = Alignment.Center, textAlign = TextAlign.Center, tablePadding = 0.dp, diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/utils/ColorUtils.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/utils/ColorUtils.kt new file mode 100644 index 0000000..9017dba --- /dev/null +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/utils/ColorUtils.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2023 Breens Mbaka + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.breens.beetablescompose.utils + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable + +@Composable +fun lightGray() = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.12f) + +@Composable +fun darkColor() = MaterialTheme.colorScheme.onBackground + +@Composable +fun lightColor() = MaterialTheme.colorScheme.background diff --git a/app/src/main/java/com/breens/beetablescompose/MainActivity.kt b/app/src/main/java/com/breens/beetablescompose/MainActivity.kt index 3afd623..4cbdbbf 100644 --- a/app/src/main/java/com/breens/beetablescompose/MainActivity.kt +++ b/app/src/main/java/com/breens/beetablescompose/MainActivity.kt @@ -29,6 +29,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.Checkbox import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Slider +import androidx.compose.material3.Surface import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.runtime.getValue @@ -40,6 +41,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import com.breens.beetablescompose.ui.theme.BeeTablesComposeTheme import com.breens.beetablescompose.utils.premierLeagueTeams import com.breens.beetablescompose.utils.titles @@ -47,212 +49,218 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - var disableVerticalDividers by remember { - mutableStateOf(false) - } - var horizontalDividerThickness by remember { - mutableStateOf(0.6f) - } - - var enableHeaderTitles by remember { - mutableStateOf(false) - } - - var centerContent by remember { - mutableStateOf(false) - } - - var centerTextAlignment by remember { - mutableStateOf(false) - } - - var increaseColumnWidth by remember { - mutableStateOf(null) - } + BeeTablesComposeTheme { + Surface( + color = MaterialTheme.colorScheme.background, + ) { + var disableVerticalDividers by remember { + mutableStateOf(false) + } + var horizontalDividerThickness by remember { + mutableStateOf(0.6f) + } - LazyColumn(contentPadding = PaddingValues(16.dp)) { - item { - BeeTablesCompose( - data = premierLeagueTeams, - enableTableHeaderTitles = enableHeaderTitles, - disableVerticalDividers = disableVerticalDividers, - dividerThickness = horizontalDividerThickness.dp, - columnToIndexIncreaseWidth = increaseColumnWidth?.minus(1), - headerTableTitles = titles, - headerTitlesBackGroundColor = Color(0XFFE9AB17), - tableRowColors = listOf( - MaterialTheme.colorScheme.surface, - MaterialTheme.colorScheme.surface, - ), - contentAlignment = if (centerContent) Alignment.Center else Alignment.CenterStart, - textAlign = if (centerTextAlignment) TextAlign.Center else TextAlign.Start, - ) + var enableHeaderTitles by remember { + mutableStateOf(false) + } - Spacer(modifier = Modifier.padding(12.dp)) - } + var centerContent by remember { + mutableStateOf(false) + } - item { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Text( - text = "Enable Table Header Titles", - style = MaterialTheme.typography.bodyMedium, - ) - Switch( - checked = enableHeaderTitles, - onCheckedChange = { - enableHeaderTitles = it - }, - ) + var centerTextAlignment by remember { + mutableStateOf(false) } - Spacer(modifier = Modifier.padding(12.dp)) - } - item { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Text( - text = "Hide Vertical Divider", - style = MaterialTheme.typography.bodyMedium, - ) - Switch( - checked = disableVerticalDividers, - onCheckedChange = { - disableVerticalDividers = it - }, - ) + var increaseColumnWidth by remember { + mutableStateOf(null) } - Spacer(modifier = Modifier.padding(8.dp)) - } + LazyColumn(contentPadding = PaddingValues(16.dp)) { + item { + BeeTablesCompose( + data = premierLeagueTeams, + enableTableHeaderTitles = enableHeaderTitles, + disableVerticalDividers = disableVerticalDividers, + dividerThickness = horizontalDividerThickness.dp, + columnToIndexIncreaseWidth = increaseColumnWidth?.minus(1), + headerTableTitles = titles, + headerTitlesBackGroundColor = Color(0XFFE9AB17), + tableRowColors = listOf( + MaterialTheme.colorScheme.surface, + MaterialTheme.colorScheme.surface, + ), + contentAlignment = if (centerContent) Alignment.Center else Alignment.CenterStart, + textAlign = if (centerTextAlignment) TextAlign.Center else TextAlign.Start, + ) - item { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Text( - text = "Divider Thickness", - style = MaterialTheme.typography.bodyMedium, - ) + Spacer(modifier = Modifier.padding(12.dp)) + } - Slider(value = horizontalDividerThickness, onValueChange = { - horizontalDividerThickness = it - }) - } - } + item { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text( + text = "Enable Table Header Titles", + style = MaterialTheme.typography.bodyMedium, + ) + Switch( + checked = enableHeaderTitles, + onCheckedChange = { + enableHeaderTitles = it + }, + ) + } - item { - Spacer(modifier = Modifier.padding(12.dp)) + Spacer(modifier = Modifier.padding(12.dp)) + } + item { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text( + text = "Hide Vertical Divider", + style = MaterialTheme.typography.bodyMedium, + ) + Switch( + checked = disableVerticalDividers, + onCheckedChange = { + disableVerticalDividers = it + }, + ) + } - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Text( - text = "Center Content", - style = MaterialTheme.typography.bodyMedium, - ) - Switch( - checked = centerContent, - onCheckedChange = { - centerContent = it - }, - ) - } + Spacer(modifier = Modifier.padding(8.dp)) + } - Spacer(modifier = Modifier.padding(12.dp)) - } + item { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text( + text = "Divider Thickness", + style = MaterialTheme.typography.bodyMedium, + ) - item { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Text( - text = "Text Alignment Center", - style = MaterialTheme.typography.bodyMedium, - ) - Switch( - checked = centerTextAlignment, - onCheckedChange = { - centerTextAlignment = it - }, - ) - } + Slider(value = horizontalDividerThickness, onValueChange = { + horizontalDividerThickness = it + }) + } + } - Spacer(modifier = Modifier.padding(12.dp)) - } + item { + Spacer(modifier = Modifier.padding(12.dp)) - item { - Column { - Text( - text = "The Column To Increase Width", - style = MaterialTheme.typography.bodyMedium, - ) - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text(text = "1", style = MaterialTheme.typography.bodySmall) - Checkbox( - checked = increaseColumnWidth == 1, - onCheckedChange = { - increaseColumnWidth = if (it) 1 else null - }, - ) - } + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text( + text = "Center Content", + style = MaterialTheme.typography.bodyMedium, + ) + Switch( + checked = centerContent, + onCheckedChange = { + centerContent = it + }, + ) + } - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text(text = "2", style = MaterialTheme.typography.bodySmall) - Checkbox( - checked = increaseColumnWidth == 2, - onCheckedChange = { - increaseColumnWidth = if (it) 2 else null - }, - ) + Spacer(modifier = Modifier.padding(12.dp)) } - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text(text = "3", style = MaterialTheme.typography.bodySmall) - Checkbox( - checked = increaseColumnWidth == 3, - onCheckedChange = { - increaseColumnWidth = if (it) 3 else null - }, - ) + item { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text( + text = "Text Alignment Center", + style = MaterialTheme.typography.bodyMedium, + ) + Switch( + checked = centerTextAlignment, + onCheckedChange = { + centerTextAlignment = it + }, + ) + } + + Spacer(modifier = Modifier.padding(12.dp)) } - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text(text = "4", style = MaterialTheme.typography.bodySmall) - Checkbox( - checked = increaseColumnWidth == 4, - onCheckedChange = { - increaseColumnWidth = if (it) 4 else null - }, - ) + item { + Column { + Text( + text = "The Column To Increase Width", + style = MaterialTheme.typography.bodyMedium, + ) + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text(text = "1", style = MaterialTheme.typography.bodySmall) + Checkbox( + checked = increaseColumnWidth == 1, + onCheckedChange = { + increaseColumnWidth = if (it) 1 else null + }, + ) + } + + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text(text = "2", style = MaterialTheme.typography.bodySmall) + Checkbox( + checked = increaseColumnWidth == 2, + onCheckedChange = { + increaseColumnWidth = if (it) 2 else null + }, + ) + } + + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text(text = "3", style = MaterialTheme.typography.bodySmall) + Checkbox( + checked = increaseColumnWidth == 3, + onCheckedChange = { + increaseColumnWidth = if (it) 3 else null + }, + ) + } + + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text(text = "4", style = MaterialTheme.typography.bodySmall) + Checkbox( + checked = increaseColumnWidth == 4, + onCheckedChange = { + increaseColumnWidth = if (it) 4 else null + }, + ) + } + } } } } From c8029049ee8444302d8b433530afe1421acaeddc Mon Sep 17 00:00:00 2001 From: Breens Robert <72180010+Breens-Mbaka@users.noreply.github.com> Date: Thu, 30 May 2024 09:21:03 +0300 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5f8c6f..7c215d3 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ repositories { ```gradle dependencies { - implementation("com.github.Breens-Mbaka:BeeTablesCompose:1.0.5") + implementation("com.github.Breens-Mbaka:BeeTablesCompose:1.2.0") } ``` From 927bfe903da10ba311fbb049ac62319ecec522f5 Mon Sep 17 00:00:00 2001 From: Breens Robert <72180010+Breens-Mbaka@users.noreply.github.com> Date: Thu, 30 May 2024 09:25:47 +0300 Subject: [PATCH 5/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c215d3..e2d4b79 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Also __[follow](https://github.com/Breens-Mbaka)__ me for my next creations! # License ```xml -Designed and developed by 2023 Breens Mbaka +Designed and developed by 2024 Breens Mbaka Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 762ed0c226c17cea79d16b6b83ff3d3b4d707f67 Mon Sep 17 00:00:00 2001 From: breensmbaka Date: Sun, 9 Jun 2024 11:59:03 +0300 Subject: [PATCH 6/7] Update instructions when minification is enabled for release build apps that use the library --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index e2d4b79..f4a8bac 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ dependencies { } ``` +# Usage + - Import the library: Import the BeeTablesCompose function into your Compose-based project. - Prepare your data: Organize your data in a list of objects to be displayed in the table. @@ -66,6 +68,17 @@ dependencies {

+# NOTE ⚠ī¸đŸš¨ +- Before building a release APK of your app, if you have enabled minification, make sure to annotate your table data classes with @Keep. This will prevent the class from being removed at runtime. +```kotlin +@Keep +data class User( + val name: String, + val email: Int, + val city: String +) +``` + # Want a new shiny feature đŸĒŠâœ¨ - If you want to request a new feature please first read this [short guide](https://github.com/Breens-Mbaka/BeeTablesCompose/blob/master/.github/ISSUE_TEMPLATE/feature_request.md) From 068e88404c71d679fd30331f9fb0e04ea9304e0f Mon Sep 17 00:00:00 2001 From: Gwabstech Date: Wed, 3 Jul 2024 14:46:40 +0100 Subject: [PATCH 7/7] Added click on the cells inside the content row each cell is clickable --- .../java/com/breens/beetablescompose/BeeTablesCompose.kt | 4 ++++ .../beetablescompose/components/TableRowComponent.kt | 9 ++++++++- .../TableRowComponentWithoutVerticalDividers.kt | 6 +++++- .../java/com/breens/beetablescompose/MainActivity.kt | 7 +++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt index a6dbac6..c2793bd 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/BeeTablesCompose.kt @@ -85,6 +85,7 @@ inline fun BeeTablesCompose( textAlign: TextAlign = TextAlign.Center, tablePadding: Dp = 0.dp, columnToIndexIncreaseWidth: Int? = null, + crossinline onRowClick: (Int) -> Unit = {}, ) { OutlinedCard( elevation = CardDefaults.cardElevation(defaultElevation = tableElevation), @@ -142,6 +143,7 @@ inline fun BeeTablesCompose( textAlign = textAlign, tablePadding = tablePadding, columnToIndexIncreaseWidth = columnToIndexIncreaseWidth, + onRowClick = { onRowClick(it) }, ) } else { TableRowComponent( @@ -154,6 +156,8 @@ inline fun BeeTablesCompose( textAlign = textAlign, tablePadding = tablePadding, columnToIndexIncreaseWidth = columnToIndexIncreaseWidth, + onRowClick = { onRowClick(it) }, + ) } } diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt index d001bc6..56a6688 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponent.kt @@ -15,8 +15,10 @@ */ package com.breens.beetablescompose.components +import android.widget.Toast import androidx.compose.foundation.background import androidx.compose.foundation.border +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth @@ -29,6 +31,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -49,6 +52,7 @@ fun TableRowComponent( tablePadding: Dp, columnToIndexIncreaseWidth: Int?, dividerThickness: Dp, + onRowClick: (Int) -> Unit = {}, ) { Row( Modifier @@ -64,7 +68,8 @@ fun TableRowComponent( .border( width = dividerThickness, color = rowBorderColor, - ), + ) + .clickable { onRowClick(index) }, contentAlignment = contentAlignment, ) { Text( @@ -85,11 +90,13 @@ fun TableRowComponent( @Composable @Preview(showBackground = true) fun TableRowComponentPreview() { + val context = LocalContext.current val titles = listOf("Man Utd", "26", "7", "95") TableRowComponent( data = titles, rowBorderColor = lightGray(), + onRowClick = { Toast.makeText(context, "Row ...${titles[it]},", Toast.LENGTH_SHORT).show() }, rowTextStyle = MaterialTheme.typography.bodySmall, rowBackGroundColor = lightColor(), contentAlignment = Alignment.Center, diff --git a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt index d579067..5efdf43 100644 --- a/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt +++ b/BeeTablesCompose/src/main/java/com/breens/beetablescompose/components/TableRowComponentWithoutVerticalDividers.kt @@ -16,6 +16,7 @@ package com.breens.beetablescompose.components import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -49,6 +50,7 @@ fun TableRowComponentWithoutDividers( textAlign: TextAlign, tablePadding: Dp, columnToIndexIncreaseWidth: Int?, + onRowClick: (Int) -> Unit = {}, ) { Column( modifier = Modifier.padding(horizontal = tablePadding), @@ -62,8 +64,10 @@ fun TableRowComponentWithoutDividers( val weight = if (index == columnToIndexIncreaseWidth) 8f else 2f Box( modifier = Modifier - .weight(weight), + .weight(weight) + .clickable { onRowClick(index) }, contentAlignment = contentAlignment, + ) { Text( text = title, diff --git a/app/src/main/java/com/breens/beetablescompose/MainActivity.kt b/app/src/main/java/com/breens/beetablescompose/MainActivity.kt index 4cbdbbf..5a72579 100644 --- a/app/src/main/java/com/breens/beetablescompose/MainActivity.kt +++ b/app/src/main/java/com/breens/beetablescompose/MainActivity.kt @@ -16,6 +16,7 @@ package com.breens.beetablescompose import android.os.Bundle +import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.Arrangement @@ -39,6 +40,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.breens.beetablescompose.ui.theme.BeeTablesComposeTheme @@ -49,6 +51,7 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { + val context = LocalContext.current BeeTablesComposeTheme { Surface( color = MaterialTheme.colorScheme.background, @@ -92,6 +95,10 @@ class MainActivity : ComponentActivity() { ), contentAlignment = if (centerContent) Alignment.Center else Alignment.CenterStart, textAlign = if (centerTextAlignment) TextAlign.Center else TextAlign.Start, + + onRowClick = { index -> + Log.i("TAG", "AM click at position ${ premierLeagueTeams[index]}") + }, ) Spacer(modifier = Modifier.padding(12.dp))