SkillAgentSearch skills...

KotlinExtensions

Extensions for the Kotlin standard library and third-party libraries.

Install / Use

/learn @Woody230/KotlinExtensions
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Kotlin Extensions

Kotlin Multiplatform extensions and implementations for the Kotlin standard library and third-party libraries.

Gradle

Published to Maven Central.

repositories {
    mavenCentral()
}
implementation("io.github.woody230.ktx:$Module:$Version")

Modules

aboutlibraries

Extensions for AboutLibraries. See compose-aboutlibraries for the associated composable.

comparator

  • Nullable string comparator.
  • User friendly string and enum comparators.

Jetpack Compose/Compose Multiplatform

Compose Multiplatform is the compose version used by this project to support both Android and the JVM.

New to Compose?

compose-aboutlibraries

compose-multiplatform composable for AboutLibraries

@Composable
fun Libraries(libraries: List<Library>) = LibraryProjector(
    interactor = LibraryInteractor(
        libraries = libraries
    )
).Projection()

Using the AssetReader from the resource module, you can use the libraries output from AboutLibraries as a moko-resource asset.

First, you will need to add the following to gradle in order to copy it as a resource.

val aboutLibrariesResource = task("aboutLibrariesResource") {
    dependsOn("exportLibraryDefinitions")

    copy {
        from("$buildDir\\generated\\aboutLibraries") {
            include("aboutlibraries.json")
        }
        into("$projectDir\\src\\commonMain\\resources\\MR\\assets")
    }
}

tasks.whenTaskAdded {
    if (name == "generateMRcommonMain") {
        dependsOn(aboutLibrariesResource)
    }
}

Now you can use the AssetReader to read the resource and create the libraries from it.

val libraries = with(AssetReader) {
    val content = MyResources.assets.aboutlibraries.readText()
    Libs.Builder().withJson(content).build().libraries
}

compose-accompanist

A copy of Accompanist modules (v0.23.1 and v0.2.1 Snapper) with multiplatform capability. Currently this only includes the pager and pager indicators.

compose-constraint-layout

A copy of ConstraintLayout (v2.1.3 core and v1.0.0 compose) with multiplatform capability.

compose-resource

Wrappers for strings and images for the compose module using the resource module.

Conversion of image moko-resources:

val painter = MyResources.images.my_resource.painter()
val localized = MyResources.strings.my_resource.localized()

Standardized AlertDialog buttons:

val withConfirmation = AlertDialogInteractor.Builder().uniText().build()
val withConfirmationCancel = AlertDialogInteractor.Builder().biText().build()
val withConfirmationCancelReset = AlertDialogInteractor.Builder().triText().build()

IconInteractor wrappers for common use cases such as:

val delete = deleteIconInteractor()
val language = languageIconInteractor()
val settings = settingsIconInteractor()

Conversion of text moko-resources:

val text = MyResources.strings.my_resource.textInteractor()

compose-serialization

kotlinx.serialization extensions for compose related classes.

  • ColorSerializer for storing the Hex associated with a androidx.compose.ui.graphics.Color

compose-settings

Setting to compose-multiplatform state converters.

@Composable
fun Observe(setting: Setting<Instant>, nullableSetting: Setting<Instant?>) {
    val defaulted: MutableState<Instant> = setting.safeState()
    val nullable: MutableState<Instant?> = setting.nullState()

    // Keep the ability to be nullable, but the value will be defaulted and not null.
    val defaultedNullable: MutableState<Instant?> = nullableSetting.defaultState()
}

ColorSetting for androidx.compose.ui.graphics.Color.

fun color(settings: SuspendSettings): Setting<Color> = ColorSetting(
    settings = settings,
    key = "Color",
    defaultValue = Color.Blue
)

compose-ui

The ShowAlert() composable method is used to send notifications.

  • On Android, a Toast is created. Note that the title is ignored.
  • On Desktop, a notification is sent to the tray.
@Composable
fun SendMessage() = ShowAlert(title = "Important!", "An error occurred.", type = AlertType.ERROR)

The ApplicationSize companion object can be used to get the current size of the Android device or desktop window size.

val size: DpSize = ApplicationSize.current

Conversion of a ByteArray to an androidx.compose.ui.graphics.ImageBitmap.

val content = byteArrayOf()
val bitmap = content.asImageBitmap()

compose-ui-geometry

ArcShape for creating arcs.

compose-ui-graphics

Converting hexadecimal colors in ARGB or RGB string format (with optional # prefix) to androidx.compose.ui.graphics.Color.

val color = Hex("3dab5a").color()
val hex = color.hex()

compose-ui-intl

Converter for the com.bselzer.ktx.intl.Locale to androidx.compose.ui.text.intl.Locale.

LocalLocale composition local that can be provided by the following in order to recompose on Localizer.locale changes:

@Composable
fun Content() {
    ProvideLocale {
        val locale = LocalLocale.current
        // ...
    }
}

compose-ui-layout, compose-ui-layout-common, compose-ui-layout-custom

Wrappers and custom composable components using the content/presentation model and projection concept as described by kirill-grouchnikov's Aurora project.

The common module contains wrappers for official components. The custom module contains completely custom components or special wrappers for official components.

See the compose-layout file for documentation on the custom components provided.

compose-ui-text

AnnotatedString and SpanStyle extensions.

compose-ui-unit

Pixel to Dp and Dp to pixel conversions.

val dp = 50f.toDp()
val pixel = dp.toPx()

coroutine

coroutines

Managing locks by a key:

val lock = LockByKey<Int>()
lock.withLock(1) {
    // Perform
}

datetime

kotlinx.datetime

  • Formatting by pattern or style.
val patternFormatter = PatternDateTimeFormatter("EEEE")
val timeFormatter = FormatStyleDateTimeFormatter(dateStyle = null, timeStyle = FormatStyle.SHORT)

datetime-serialization

  • LenientDurationSerializer using kotlinx.serialization.
    • Uses the more lenient Duration.parse() method instead of Duration.parseIsoString().

function

General Kotlin standard library extensions.

enum class Position {
    FIRST, SECOND
}

val userFriendly: String = Position.FIRST.userFriendly()
val first: Position = "FIRST".enumValue<Position>()

val items: Array<Position> = buildArray {
    add(Position.FIRST)
    add(Position.SECOND)
}

val bytes = "AdsnAAA=".decodeBase64ToByteArray()
val string = bytes.encodeBase64ToString()

geometry

Two and three dimensional geometrical objects.

Two dimensional objects include a digon, quadrilateral, 2D point, 2D size. Three dimensional objects include a 3D point.

geometry-serialization

Serializers for two and three dimensional geometrical objects using kotlinx.serialization.

intent

Based on Android intents. Currently supports browser opening and mailto.

Browser.open("https://google.com")

Emailer.send(
  email = Email(
    to = listOf("foo@bar.com", "fizz@buzz.com"),
    cc = listOf("test@test.com"),
    bcc = listOf("bar@baz.com", "test@test.com"),
    subject = "This is a test subject.",
    body = "This is a test body."
  )
)

intl

Internationalization through locale support.

com.bselzer.ktx.intl.Locale is added as a non-composable way to handle locale changes. However, it can be converted to androidx.compose.ui.text.intl.Locale. See the compose section.

DefaultLocale provides the system's default locale. However, there is no ability to be notified of changes to this locale. Instead, a Localizer should be used to maintain an instance of a locale and to be able to be notified of changes by adding a listener which can then be used to update the DefaultLocale if needed.

intl-serialization

Serializer for the com.bselzer.ktx.intl.Locale using kotlinx.serialization.

kodein-db

Kodein-DB extensions.

Note that Kodein-DB is currently archived but may return under a new name.

If you would still like to use it, then

View on GitHub
GitHub Stars7
CategoryDevelopment
Updated5mo ago
Forks0

Languages

Kotlin

Security Score

87/100

Audited on Oct 10, 2025

No findings