Skip to content

Commit

Permalink
Merge pull request #4 from KevinSchildhorn/Maven
Browse files Browse the repository at this point in the history
Maven
  • Loading branch information
KevinSchildhorn committed Apr 11, 2023
2 parents 40ca4e4 + c9b960f commit 7636a4c
Show file tree
Hide file tree
Showing 20 changed files with 332 additions and 175 deletions.
86 changes: 55 additions & 31 deletions atomik/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
import org.jetbrains.compose.ComposeCompilerKotlinSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
kotlin("multiplatform")
id("com.android.library")
id("com.github.ben-manes.versions") version "0.43.0"
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
id("org.jetbrains.dokka") version "1.7.10"
id("com.github.ben-manes.versions")
id("org.jetbrains.compose")
id("org.jetbrains.dokka")
id("org.jlleitschuh.gradle.ktlint")
id("maven-publish")
}

group = "me.kevinschildhorn"
version = "1.0"
// Exclude compose from iOS
plugins.removeAll { it is ComposeCompilerKotlinSupportPlugin }
class ComposeNoNativePlugin : org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin by ComposeCompilerKotlinSupportPlugin() {
override fun isApplicable(kotlinCompilation: org.jetbrains.kotlin.gradle.plugin.KotlinCompilation<*>): Boolean {
return when (kotlinCompilation.target.platformType) {
org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.native -> false
else -> ComposeCompilerKotlinSupportPlugin().isApplicable(kotlinCompilation)
}
}
}
apply<ComposeNoNativePlugin>() // Re-adding Compose Compilers only for non-native environments

group = "com.kevinschildhorn.atomik"
version = "0.0.2"

kotlin {
/*
cocoapods {
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
name = "AtomikShared"
framework {
baseName = "AtomikShared"
isStatic = false
embedBitcode(BITCODE)
publishing {
repositories {
mavenLocal()
}
}*/
}

android()
ios()

ios {
binaries {
framework {
baseName = "atomik"
}
}
}
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
implementation(kotlin("stdlib-common"))
implementation("co.touchlab:kermit:1.2.2")
Expand All @@ -41,11 +58,11 @@ kotlin {
val androidMain by getting {
dependencies {
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.9.0")
implementation("androidx.compose.ui:ui:1.4.0-rc01")
implementation("androidx.compose.foundation:foundation:1.4.0-rc01")
implementation("androidx.compose.material:material:1.4.0-rc01")
implementation("androidx.compose.runtime:runtime:1.4.0-rc01")
api("androidx.core:core-ktx:1.10.0")
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
}
}
val iosMain by getting {
Expand All @@ -57,20 +74,27 @@ kotlin {

@Suppress("UnstableApiUsage")
android {
namespace = "com.kevinschildhorn.atomik"

compileSdk = 33
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")

defaultConfig {
minSdk = 24
minSdk = 26
targetSdk = 33
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_15
targetCompatibility = JavaVersion.VERSION_15
}

buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceSets {
named("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/res")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.kevinschildhorn.atomik.atomic.atoms

import androidx.compose.ui.graphics.Color
import me.kevinschildhorn.atomik.color.base.AtomikColorType
import me.kevinschildhorn.atomik.color.base.composeColor

val AtomikColorType.composeColor: Color
get() = color.composeColor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package me.kevinschildhorn.atomik.atomic.atoms
import androidx.compose.foundation.background
import androidx.compose.ui.Modifier
import me.kevinschildhorn.atomik.atomic.atoms.interfaces.ColorAtom
import me.kevinschildhorn.atomik.color.base.composeColor

fun Modifier.atomikColor(colorAtom: ColorAtom): Modifier =
this.background(colorAtom.color.composeColor)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.sp
import me.kevinschildhorn.atomik.atomic.atoms.interfaces.TextAtom
import me.kevinschildhorn.atomik.color.base.composeColor
import me.kevinschildhorn.atomik.typography.fontWeight

val TextAtom.textStyle: TextStyle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package me.kevinschildhorn.atomik.atomic.atoms.xml

import android.widget.TextView
import me.kevinschildhorn.atomik.atomic.atoms.interfaces.TextAtom
import me.kevinschildhorn.atomik.color.base.hexColor

fun TextView.applyTextAtom(textAtom: TextAtom?) {
textAtom?.let {
setTextColor(it.textColor.hexColor)
setTextColor(it.textColor.viewColor)
textSize = it.typography.typography.size.toFloat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package me.kevinschildhorn.atomik.atomic.atoms.xml

import android.view.View
import me.kevinschildhorn.atomik.atomic.atoms.interfaces.ColorAtom
import me.kevinschildhorn.atomik.color.base.hexColor

fun View.applyColorAtom(colorAtom: ColorAtom?) {
colorAtom?.let {
setBackgroundColor(it.color.hexColor)
setBackgroundColor(it.color.viewColor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,59 @@ package me.kevinschildhorn.atomik.color.base

import androidx.compose.ui.graphics.Color

val AtomikColor.composeColor: Color
get() = Color(
red = r.toFloat() / 255,
green = g.toFloat() / 255,
blue = b.toFloat() / 255,
alpha = a
)

val AtomikColor.hexColor: Int
get() = android.graphics.Color.parseColor(hexString)
actual class AtomikColor {
actual val hexString: String
actual val r: Int
actual val g: Int
actual val b: Int
actual val a: Float

/*
* hex code for color (#AARRGGBB) (alpha optional)
*/
private val androidHexColor: String

/*
* viewColor using parseColor
* https://developer.android.com/reference/android/graphics/Color#parseColor(java.lang.String)
* #RRGGBB
* #AARRGGBB
*/
val viewColor: Int
get() = android.graphics.Color.parseColor(androidHexColor)
val composeColor: Color

actual constructor(hex: Long) {
val data = AtomikColorData(hex)
this.hexString = data.cssHexString
this.androidHexColor= data.hexString
this.r = data.r
this.g = data.g
this.b = data.b
this.a = data.a
this.composeColor = Color(
red = r.toFloat() / 255,
green = g.toFloat() / 255,
blue = b.toFloat() / 255,
alpha = this.a
)
}

actual constructor(r: Int, g: Int, b: Int, a: Float?) {
val data = AtomikColorData(r, g, b, a)
this.hexString = data.cssHexString
this.androidHexColor= data.hexString
this.r = data.r
this.g = data.g
this.b = data.b
this.a = data.a
this.composeColor = Color(
red = r.toFloat() / 255,
green = g.toFloat() / 255,
blue = b.toFloat() / 255,
alpha = this.a
)
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import kotlin.math.roundToInt
*
* This contains platform specific implementations in the actual versions
*/
class AtomikColor {
expect class AtomikColor {

/*
* hex code for color (#RRGGBBAA) (alpha optional)
*/
val hexString: String
val r: Int
val g: Int
Expand All @@ -19,50 +22,18 @@ class AtomikColor {
* Constructor with hex variable
*
* @constructor Creates a color based on the hex value(i.e. 0xFFFFFF)
* @param hex - The Hex Value of the color (#RRGGBBAA)
*/
constructor(hex: Long) {
this.hexString = "#${hex.toString(16)}".uppercase()

if (hexString.isLongForm) {
this.r = (hex and 0xFF000000 shr 24).toInt()
this.g = (hex and 0xFF0000 shr 16).toInt()
this.b = (hex and 0xFF00 shr 8).toInt()
this.a = ((hex and 0xFF).toFloat() / 255).rounded
} else {
this.r = (hex and 0xFF0000 shr 16).toInt()
this.g = (hex and 0xFF00 shr 8).toInt()
this.b = (hex and 0xFF).toInt()
this.a = 1F
}
}
constructor(hex: Long)

/**
* Constructor with r, g, b, a
*
* @constructor Creates a color based on the rgb values. Alpha defaults to 1.
* r - Red value (0-255)
* g - Green Value (0-255)
* b - Blue Value (0-255)
* a - Alpha value (0-1)
* @param r - Red value (0-255)
* @param g - Green Value (0-255)
* @param b - Blue Value (0-255)
* @param a - Alpha value (0-1)
*/
constructor(r: Int, g: Int, b: Int, a: Float? = null) {
this.r = r
this.g = g
this.b = b
this.a = a ?: 1F
val alphaString: String = a?.let { (it * 255).roundToInt().asHexString } ?: ""
this.hexString = "#${
r.asHexString + g.asHexString + b.asHexString + alphaString
}".uppercase()
print(hexString)
}

private val String.isLongForm: Boolean
get() = this.length == 8 + 1

private val Int.asHexString: String
get() = toString(16).padStart(2, '0')

private val Float.rounded: Float
get() = (this * 100).toInt() / 100F
constructor(r: Int, g: Int, b: Int, a: Float? = null)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package me.kevinschildhorn.atomik.color.base

import kotlin.math.roundToInt

internal data class AtomikColorData(
val cssHexString: String,
val hexString: String = cssHexString,
val r: Int,
val g: Int,
val b: Int,
val a: Float,
) {
constructor(hex: Long) : this(
cssHexString = hex.asHexString,
hexString = hex.asHexString,
r = hex.red,
g = hex.green,
b = hex.blue,
a = hex.alpha,
)

constructor(r: Int, g: Int, b: Int, a: Float? = null) : this(
cssHexString = hexFromRGB(r, g, b, a, false),
hexString = hexFromRGB(r, g, b, a, true),
r = r,
g = g,
b = b,
a = a ?: 1F,
)
}

// Hex String to RGBA

private val Long.asHexString: String
get() = "#${this.toString(16)}".uppercase()

private val Long.red: Int
get() = if (this.asHexString.isLongFormHex) (this and 0xFF000000 shr 24).toInt() else (this and 0xFF0000 shr 16).toInt()

private val Long.green: Int
get() = if (this.asHexString.isLongFormHex) (this and 0xFF0000 shr 16).toInt() else (this and 0xFF00 shr 8).toInt()

private val Long.blue: Int
get() = if (this.asHexString.isLongFormHex) (this and 0xFF00 shr 8).toInt() else (this and 0xFF).toInt()

private val Long.alpha: Float
get() = if (this.asHexString.isLongFormHex) ((this and 0xFF).toFloat() / 255).rounded else 1F

private val String.isLongFormHex: Boolean
get() = this.length == 8 + 1

private fun hexFromRGB(r: Int, g: Int, b: Int, a: Float?, alphaIsPrefix: Boolean): String {
val rgbString = (r.asHexString + g.asHexString + b.asHexString)
return if (alphaIsPrefix) "#${a.asAlphaString + rgbString}".uppercase()
else "#${rgbString + a.asAlphaString}".uppercase()
}

// RGBA to String

private val Float.rounded: Float
get() = (this * 100).toInt() / 100F

private val Int.asHexString: String
get() = toString(16).padStart(2, '0')

private val Float?.asAlphaString: String
get() = this?.let { (it * 255).roundToInt().asHexString } ?: ""

This file was deleted.

Loading

0 comments on commit 7636a4c

Please sign in to comment.