Skip to content

Latest commit

 

History

History
127 lines (91 loc) · 3.42 KB

File metadata and controls

127 lines (91 loc) · 3.42 KB

Module common-enums

Common enums utilities for androidx-ktx-extras' modules.

Usage

Common Enums on Maven Central

Common Enums is available on Maven Central as the Maven coordinate io.github.edricchan03.androidx.common:common-enums:

settings.gradle.kts

dependencyResolutionManagement {
  // ...
  repositories {
    mavenCentral()
  }
}

Kotlin/Groovy

build.gradle.kts

implementation("io.github.edricchan03.androidx.common:common-enums:0.2.0")

TOML

gradle/libs.versions.toml:

[libraries]
androidxtra-common-enums = "io.github.edricchan03.androidx.common:common-enums:0.2.0"

build.gradle.kts:

implementation(libs.androidxtra.common.enums)

Snapshots

Common Enums on Maven Central (snapshot)

Alternatively, you can grab the latest built snapshot from Maven Central's snapshots repository:

settings.gradle.kts

dependencyResolutionManagement {
  // ...
  repositories {
    maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
      // Optionally, you can specify that only snapshots are to be used
      mavenContent {
        snapshotsOnly()
      }
    }
  }
}

Kotlin

build.gradle.kts:

implementation("io.github.edricchan03.androidx.common:common-enums:0.2.1-SNAPSHOT")

TOML

gradle/libs.versions.toml:

[libaries]
androidxtra-common-enums = "io.github.edricchan03.androidx.common:common-enums:0.2.1-SNAPSHOT"

build.gradle.kts:

implementation(libs.androidxtra.common.enums)

Package io.github.edricchan03.androidx.common.enums

Common enum utilities such as [EnumFromValue][io.github.edricchan03.androidx.common.enums.EnumFromValue]:

enum class Example(val value: String) {
    One("one"),
    Two("two"),
    Three("abc");

    companion object : EnumFromValue<String, Example>(default = Three) {
        override fun fromValueOrNull(value: String) = when (value) {
            "one" -> One
            "two" -> Two
            "abc", "other value" -> Three
            else -> null
  }
}

Package io.github.edricchan03.androidx.common.enums.impl

Implementations of utilities from the parent package, such as [ValueEnumFromValue][io.github.edricchan03.androidx.common.enums.impl.ValueEnumFromValue]:

enum class ExampleValue(override val value: String): ValueEnum<String> {
  One("one"),
  Two("two"),
  Three("three");

  companion object : ValueEnumFromValue<String, ExampleValue>(default = One, entries)
}

println(ExampleValue.fromValueOrNull("four")) // null
println(ExampleValue.fromValueOrNull("one")) // One