From 27d2d592e4376394c4d971b5b68d3af6d8a35078 Mon Sep 17 00:00:00 2001 From: Michael Flisar Date: Tue, 12 Nov 2024 11:32:37 +0100 Subject: [PATCH] . --- demo/android/build.gradle.kts | 2 +- demo/desktop/build.gradle.kts | 2 +- gradle-plugin/plugin/build.gradle.kts | 4 +- .../composechangelog/Platform.android.kt | 45 ++++++++++++++ .../composechangelog/Platform.kt | 14 +++++ .../composechangelog/ShowChangelogDialog.kt | 26 ++------ .../composechangelog/composables/Changelog.kt | 4 +- .../composechangelog/Platform.jvm.kt | 61 +++++++++++++++++++ 8 files changed, 131 insertions(+), 27 deletions(-) diff --git a/demo/android/build.gradle.kts b/demo/android/build.gradle.kts index bae6202..037aa3e 100644 --- a/demo/android/build.gradle.kts +++ b/demo/android/build.gradle.kts @@ -6,7 +6,7 @@ plugins { alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.parcelize) - id("compose-changelog") + id("io.github.mflisar.composechangelog.gradle-plugin") } val version = "1.0.4" diff --git a/demo/desktop/build.gradle.kts b/demo/desktop/build.gradle.kts index a8b6b00..5e4f5c8 100644 --- a/demo/desktop/build.gradle.kts +++ b/demo/desktop/build.gradle.kts @@ -5,7 +5,7 @@ plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.kotlin.compose) alias(libs.plugins.compose) - id("compose-changelog") + id("io.github.mflisar.composechangelog.gradle-plugin") } val version = "1.0.6" diff --git a/gradle-plugin/plugin/build.gradle.kts b/gradle-plugin/plugin/build.gradle.kts index 1a7114d..e4d65e6 100644 --- a/gradle-plugin/plugin/build.gradle.kts +++ b/gradle-plugin/plugin/build.gradle.kts @@ -36,8 +36,8 @@ dependencies { gradlePlugin { plugins { - create("com.michaelflisar.composechangelog.gradle.plugin") { - id = "compose-changelog" + create("$groupID.gradle-plugin") { + id = "$groupID.gradle-plugin" implementationClass = "com.michaelflisar.composechangelog.gradle.plugin.ClassLoaderPlugin" } //isAutomatedPublishing = false diff --git a/library/core/src/androidMain/kotlin/com/michaelflisar/composechangelog/Platform.android.kt b/library/core/src/androidMain/kotlin/com/michaelflisar/composechangelog/Platform.android.kt index 05bb543..f1af73c 100644 --- a/library/core/src/androidMain/kotlin/com/michaelflisar/composechangelog/Platform.android.kt +++ b/library/core/src/androidMain/kotlin/com/michaelflisar/composechangelog/Platform.android.kt @@ -1,9 +1,17 @@ package com.michaelflisar.composechangelog +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListScope +import androidx.compose.foundation.lazy.LazyListState +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import androidx.compose.ui.res.stringResource import com.michaelflisar.composechangelog.classes.ChangelogData import com.michaelflisar.composechangelog.classes.DataItemRelease +import com.michaelflisar.composechangelog.composables.Changelog import com.michaelflisar.composechangelog.internal.ChangelogParserUtil actual typealias Context = android.content.Context @@ -17,6 +25,43 @@ internal actual fun LocalContext(): Context { return androidx.compose.ui.platform.LocalContext.current } +@Composable +internal actual fun ShowChangelogDialog( + visible: MutableState, + data: ChangelogData, + setup: ChangelogSetup, + onDismiss: () -> Unit +) { + AlertDialog( + onDismissRequest = { + onDismiss() + visible.value = false + }, + title = { + Text(text = setup.texts.dialogTitle) + }, + text = { + Changelog(data, setup) + }, + confirmButton = { + TextButton( + onClick = { + onDismiss() + visible.value = false + }) { + Text(setup.texts.dialogButtonDismiss) + } + } + ) +} + +@Composable +internal actual fun LazyScrollContainer(state: LazyListState, content: LazyListScope.() -> Unit) { + LazyColumn(state = state) { + content() + } +} + internal actual suspend fun ChangelogUtil.read( context: Context, changelogID: ChangelogID, diff --git a/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/Platform.kt b/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/Platform.kt index a7843b3..7097534 100644 --- a/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/Platform.kt +++ b/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/Platform.kt @@ -1,6 +1,9 @@ package com.michaelflisar.composechangelog +import androidx.compose.foundation.lazy.LazyListScope +import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import com.michaelflisar.composechangelog.classes.ChangelogData import com.michaelflisar.composechangelog.classes.DataItemRelease @@ -13,6 +16,17 @@ expect fun stringOk() : String @Composable internal expect fun LocalContext(): Context +@Composable +internal expect fun ShowChangelogDialog( + visible: MutableState, + data: ChangelogData, + setup: ChangelogSetup, + onDismiss: () -> Unit +) + +@Composable +internal expect fun LazyScrollContainer(state: LazyListState, content: LazyListScope.() -> Unit) + internal expect suspend fun ChangelogUtil.read( context: Context, changelogID: ChangelogID, diff --git a/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/ShowChangelogDialog.kt b/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/ShowChangelogDialog.kt index e454300..533be58 100644 --- a/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/ShowChangelogDialog.kt +++ b/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/ShowChangelogDialog.kt @@ -1,8 +1,5 @@ package com.michaelflisar.composechangelog -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -15,7 +12,6 @@ import com.michaelflisar.composechangelog.classes.ChangelogData import com.michaelflisar.composechangelog.classes.DataItem import com.michaelflisar.composechangelog.classes.DataItemRelease import com.michaelflisar.composechangelog.classes.ShowChangelog -import com.michaelflisar.composechangelog.composables.Changelog import com.michaelflisar.composechangelog.interfaces.IChangelogFilter import com.michaelflisar.composechangelog.interfaces.IChangelogStateSaver import kotlinx.coroutines.Dispatchers @@ -40,25 +36,13 @@ fun ShowChangelogDialog( if (data != null && !data.isEmpty()) { val openDialog = remember { mutableStateOf(true) } if (openDialog.value) { - AlertDialog( - onDismissRequest = { + ShowChangelogDialog( + visible = openDialog, + data = data, + setup = setup, + onDismiss = { onDismiss() openDialog.value = false - }, - title = { - Text(text = setup.texts.dialogTitle) - }, - text = { - Changelog(data, setup) - }, - confirmButton = { - TextButton( - onClick = { - onDismiss() - openDialog.value = false - }) { - Text(setup.texts.dialogButtonDismiss) - } } ) } diff --git a/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/composables/Changelog.kt b/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/composables/Changelog.kt index c024993..7930b18 100644 --- a/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/composables/Changelog.kt +++ b/library/core/src/commonMain/kotlin/com/michaelflisar/composechangelog/composables/Changelog.kt @@ -1,12 +1,12 @@ package com.michaelflisar.composechangelog.composables -import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import com.michaelflisar.composechangelog.ChangelogSetup +import com.michaelflisar.composechangelog.LazyScrollContainer import com.michaelflisar.composechangelog.classes.ChangelogData @Composable @@ -18,7 +18,7 @@ fun Changelog( val releases = changelog.releases var idMore = -1 - LazyColumn( + LazyScrollContainer( state = rememberLazyListState() ) { releases.forEachIndexed { index, item -> diff --git a/library/core/src/jvmMain/kotlin/com/michaelflisar/composechangelog/Platform.jvm.kt b/library/core/src/jvmMain/kotlin/com/michaelflisar/composechangelog/Platform.jvm.kt index cbcd7fd..d883b6d 100644 --- a/library/core/src/jvmMain/kotlin/com/michaelflisar/composechangelog/Platform.jvm.kt +++ b/library/core/src/jvmMain/kotlin/com/michaelflisar/composechangelog/Platform.jvm.kt @@ -1,8 +1,26 @@ package com.michaelflisar.composechangelog +import androidx.compose.foundation.VerticalScrollbar +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListScope +import androidx.compose.foundation.lazy.LazyListState +import androidx.compose.foundation.rememberScrollbarAdapter import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.DialogWindow +import androidx.compose.ui.window.WindowPosition +import androidx.compose.ui.window.rememberDialogState import com.michaelflisar.composechangelog.classes.ChangelogData import com.michaelflisar.composechangelog.classes.DataItemRelease +import com.michaelflisar.composechangelog.composables.Changelog import com.michaelflisar.composechangelog.internal.ChangelogParserUtil import java.io.File @@ -19,6 +37,49 @@ internal actual fun LocalContext(): Context { return NoContext } +@Composable +internal actual fun ShowChangelogDialog( + visible: MutableState, + data: ChangelogData, + setup: ChangelogSetup, + onDismiss: () -> Unit +) { + DialogWindow( + visible = visible.value, + title = setup.texts.dialogTitle, + onCloseRequest = { visible.value = false }, + state = rememberDialogState( + position = WindowPosition(Alignment.Center), + width = 600.dp, + height = 400.dp + ) + ) { + Column( + modifier = Modifier.padding(16.dp) + ) { + Changelog(data, setup) + } + } +} + +@Composable +internal actual fun LazyScrollContainer(state: LazyListState, content: LazyListScope.() -> Unit) { + Box { + LazyColumn( + modifier = Modifier + .fillMaxWidth() + .padding(end = 8.dp), + state = state + ) { + content() + } + VerticalScrollbar( + modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), + adapter = rememberScrollbarAdapter(state) + ) + } +} + internal actual suspend fun ChangelogUtil.read( context: Context, changelogID: ChangelogID,