Skip to content

Commit

Permalink
Merge pull request #925 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz authored Sep 22, 2023
2 parents 2938549 + 2fa8c11 commit 82f0867
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 497 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

## Latest releases 🛠

- (Next Gen) Kotlin && Multiplatform && Plugin | [v10.8.3](https://github.com/mikepenz/AboutLibraries/tree/v10.8.3)
- (Next Gen) Kotlin && Multiplatform && Plugin | [v10.9.0](https://github.com/mikepenz/AboutLibraries/tree/v10.9.0)
- Kotlin && Gradle Plugin | [v8.9.4](https://github.com/mikepenz/AboutLibraries/tree/v8.9.4)

## Gradle Plugin
Expand Down
25 changes: 4 additions & 21 deletions aboutlibraries-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ android {


compose {
kotlinCompilerPlugin.set(libs.versions.composeCompilerJb.get())
//kotlinCompilerPlugin.set("androidx.compose.compiler:compiler")
kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=${libs.versions.kotlinCore.get()}")
}

kotlin {
targetHierarchy.default()

jvm()

android {
androidTarget {
publishLibraryVariants("release")
}

Expand All @@ -84,25 +86,6 @@ kotlin {
sourceSets {
val commonMain by getting
val commonTest by getting

val nonAndroidMain by creating {
dependsOn(commonMain)
}
val nonAndroidTest by creating {
dependsOn(commonTest)
}

listOf(
"jvm",
"iosX64",
"iosArm64",
"iosSimulatorArm64",
"macosX64",
"macosArm64"
).forEach {
getByName(it + "Main").dependsOn(nonAndroidMain)
getByName(it + "Test").dependsOn(nonAndroidTest)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@ package com.mikepenz.aboutlibraries.ui.compose

import android.content.Context
import android.widget.TextView
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.text.HtmlCompat
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.aboutlibraries.ui.compose.data.fakeData
import com.mikepenz.aboutlibraries.ui.compose.util.StableLibrary
import com.mikepenz.aboutlibraries.ui.compose.util.htmlReadyLicenseContent
Expand All @@ -41,11 +34,11 @@ import kotlinx.coroutines.withContext
@Composable
fun LibrariesContainer(
modifier: Modifier = Modifier,
lazyListState: LazyListState = rememberLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
librariesBlock: (Context) -> Libs = { context ->
Libs.Builder().withContext(context).build()
},
lazyListState: LazyListState = rememberLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
showAuthor: Boolean = true,
showVersion: Boolean = true,
showLicenseBadges: Boolean = true,
Expand All @@ -54,80 +47,35 @@ fun LibrariesContainer(
itemContentPadding: PaddingValues = LibraryDefaults.ContentPadding,
itemSpacing: Dp = LibraryDefaults.LibraryItemSpacing,
header: (LazyListScope.() -> Unit)? = null,
onLibraryClick: ((Library) -> Unit)? = null,
onLibraryClick: ((StableLibrary) -> Unit)? = null,
) {
val context = LocalContext.current
val uriHandler = LocalUriHandler.current

val libraries = produceState<Libs?>(null) {
value = withContext(Dispatchers.IO) {
librariesBlock(context)
}
}

val libs = libraries.value?.libraries?.stable
if (libs != null) {
val openDialog = remember { mutableStateOf<Library?>(null) }
Libraries(
libraries = libs,
modifier = modifier,
lazyListState = lazyListState,
contentPadding = contentPadding,
showAuthor = showAuthor,
showVersion = showVersion,
showLicenseBadges = showLicenseBadges,
colors = colors,
padding = padding,
itemContentPadding = itemContentPadding,
itemSpacing = itemSpacing,
header = header,
onLibraryClick = { library ->
val license = library.licenses.firstOrNull()
if (onLibraryClick != null) {
onLibraryClick(library)
} else if (!license?.htmlReadyLicenseContent.isNullOrBlank()) {
openDialog.value = library
} else if (!license?.url.isNullOrBlank()) {
license?.url?.also { uriHandler.openUri(it) }
}
},
)

val library = openDialog.value
if (library != null) {
LicenseDialog(library = library.stable, colors) {
openDialog.value = null
}
LibrariesContainer(
libraries.value?.stable,
modifier,
lazyListState,
contentPadding,
showAuthor,
showVersion,
showLicenseBadges,
colors,
padding,
itemContentPadding,
itemSpacing,
header,
onLibraryClick,
licenseDialogBody = { library ->
HtmlText(
html = library.library.licenses.firstOrNull()?.htmlReadyLicenseContent.orEmpty(),
color = colors.contentColor,
)
}
}
}

@Composable
fun LicenseDialog(
library: StableLibrary,
colors: LibraryColors = LibraryDefaults.libraryColors(),
onDismiss: () -> Unit,
) {
val scrollState = rememberScrollState()
AlertDialog(
backgroundColor = colors.backgroundColor,
contentColor = colors.contentColor,
onDismissRequest = onDismiss,
confirmButton = {
TextButton(onClick = onDismiss) {
Text(stringResource(id = android.R.string.ok))
}
},
text = {
Column(
modifier = Modifier.verticalScroll(scrollState),
) {
HtmlText(
html = library.library.licenses.firstOrNull()?.htmlReadyLicenseContent.orEmpty(),
color = colors.contentColor,
)
}
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.produceState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.aboutlibraries.ui.compose.util.StableLibrary
import com.mikepenz.aboutlibraries.ui.compose.util.stable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
* Displays all provided libraries in a simple list.
Expand All @@ -32,10 +30,11 @@ fun LibrariesContainer(
itemContentPadding: PaddingValues = LibraryDefaults.ContentPadding,
itemSpacing: Dp = LibraryDefaults.LibraryItemSpacing,
header: (LazyListScope.() -> Unit)? = null,
onLibraryClick: ((Library) -> Unit)? = null,
onLibraryClick: ((StableLibrary) -> Unit)? = null,
) {
val libs = Libs.Builder().withJson(aboutLibsJson).build().stable
LibrariesContainer(
{ Libs.Builder().withJson(aboutLibsJson).build() },
libs,
modifier = modifier,
lazyListState = lazyListState,
contentPadding = contentPadding,
Expand All @@ -47,7 +46,10 @@ fun LibrariesContainer(
itemContentPadding = itemContentPadding,
itemSpacing = itemSpacing,
header = header,
onLibraryClick = onLibraryClick
onLibraryClick = onLibraryClick,
licenseDialogBody = { library ->
Text(library.library.licenses.firstOrNull()?.licenseContent ?: "")
}
)
}

Expand All @@ -68,30 +70,27 @@ fun LibrariesContainer(
itemContentPadding: PaddingValues = LibraryDefaults.ContentPadding,
itemSpacing: Dp = LibraryDefaults.LibraryItemSpacing,
header: (LazyListScope.() -> Unit)? = null,
onLibraryClick: ((Library) -> Unit)? = null,
onLibraryClick: ((StableLibrary) -> Unit)? = null,
) {
val libraries = produceState<Libs?>(null) {
value = withContext(Dispatchers.Default) {
librariesBlock()
val libs = librariesBlock().stable

LibrariesContainer(
libs,
modifier,
lazyListState,
contentPadding,
showAuthor,
showVersion,
showLicenseBadges,
colors,
padding,
itemContentPadding,
itemSpacing,
header,
onLibraryClick,
licenseDialogBody = { library ->
Text(library.library.licenses.firstOrNull()?.licenseContent ?: "")
}
}
)

val libs = libraries.value?.libraries?.stable
if (libs != null) {
Libraries(
libraries = libs,
modifier = modifier,
lazyListState = lazyListState,
contentPadding = contentPadding,
showAuthor = showAuthor,
showVersion = showVersion,
showLicenseBadges = showLicenseBadges,
colors = colors,
padding = padding,
itemContentPadding = itemContentPadding,
itemSpacing = itemSpacing,
header = header,
onLibraryClick = onLibraryClick
)
}
}
}
Loading

0 comments on commit 82f0867

Please sign in to comment.