Skip to content

Commit

Permalink
Merge pull request #30 from ericktijerou/feature/color-int
Browse files Browse the repository at this point in the history
Support for ColorInt
  • Loading branch information
ericktijerou authored Feb 7, 2021
2 parents acc5733 + b096345 commit ca5f6b2
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 104 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![bintray](https://api.bintray.com/packages/ericktijerou/maven/koleton/images/download.svg)](https://bintray.com/ericktijerou/maven/koleton/_latestVersion)
[![Build Status](https://travis-ci.com/ericktijerou/koleton.svg?branch=master)](https://travis-ci.com/ericktijerou/koleton)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.3.72-blueviolet.svg)](https://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.4.30-blueviolet.svg)](https://kotlinlang.org)
![Minimum SDK Version](https://img.shields.io/badge/minSdkVersion-14-brightgreen.svg)

An Android library that provides an easy way to show skeleton of any view.
Expand All @@ -23,7 +23,7 @@ You can [download](https://bintray.com/ericktijerou/maven/koleton/_latestVersion
```gradle
// In your module's `build.gradle.kts`
dependencies {
implementation("com.ericktijerou.koleton:koleton:0.8.5")
implementation("com.ericktijerou.koleton:koleton:0.8.8")
}
```

Expand Down
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
kotlin("jvm") version Kotlin.version apply false
kotlin("jvm")
`maven-publish`
id(Release.Bintray.plugin) version Release.Bintray.version
}

buildscript {
apply(from = "buildSrc/extra.gradle.kts")
repositories {
google()
mavenCentral()
gradlePluginPortal()
jcenter()
}
dependencies {
classpath(rootProject.extra["androidPlugin"].toString())
classpath(rootProject.extra["kotlinPlugin"].toString())
classpath(Dependencies.safeArgsPlugin)
}
}
Expand Down Expand Up @@ -69,7 +72,6 @@ subprojects {
apply {
plugin(Android.libPlugin)
plugin(Kotlin.androidPlugin)
plugin(Kotlin.androidExtensionsPlugin)
}

configure<BaseExtension> {
Expand Down Expand Up @@ -115,7 +117,7 @@ subprojects {

val doc by tasks.creating(Javadoc::class) {
isFailOnError = false
source = sourceSets["main"].java.sourceFiles
source = sourceSets["main"].java.getSourceFiles()
classpath += files(bootClasspath.joinToString(File.pathSeparator))
classpath.plus(configurations["compile"])
}
Expand Down
9 changes: 9 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ plugins {
}

repositories {
google()
mavenCentral()
jcenter()
}

apply(from = "extra.gradle.kts")

dependencies {
implementation(rootProject.extra["androidPlugin"].toString())
implementation(rootProject.extra["kotlinPlugin"].toString())
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}
4 changes: 4 additions & 0 deletions buildSrc/extra.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rootProject.extra.apply {
set("androidPlugin", "com.android.tools.build:gradle:4.1.1")
set("kotlinPlugin", "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30")
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object Dependencies {
const val safeArgsPlugin = "androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.navigationVersion}"
const val paging = "androidx.paging:paging-runtime:${Versions.pagingVersion}"
const val liveDataKtx = "androidx.lifecycle:lifecycle-livedata-ktx:${Versions.lifecycleVersion}"
const val gradle = "com.android.tools.build:gradle:${Versions.gradle}"
}

object Versions {
Expand All @@ -29,14 +30,14 @@ object Versions {
internal const val recyclerViewVersion = "1.1.0"
internal const val navigationVersion = "2.3.0-beta01"
internal const val pagingVersion = "2.1.2"
internal const val gradle = "4.1.1"
}

object Kotlin {
const val version = "1.3.72"
const val version = "1.4.30"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
const val plugin = "kotlin"
const val androidPlugin = "kotlin-android"
const val androidExtensionsPlugin = "kotlin-android-extensions"
}

object Android {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ kotlin.code.style=official

# Config
minSdk=14
targetSdk=29
compileSdk=29
targetSdk=30
compileSdk=30
groupId=com.ericktijerou.koleton
vcsUrl=https://github.com/ericktijerou/koleton
issueTrackerUrl=https://github.com/ericktijerou/koleton/issues
publishVersion=0.8.5
publishVersion=0.8.8
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package koleton

import android.graphics.Color
import androidx.annotation.ColorInt
import com.facebook.shimmer.Shimmer
import koleton.base.R
import koleton.util.px
Expand All @@ -10,7 +12,7 @@ import koleton.util.px
* @see SkeletonLoader.defaults
*/
data class DefaultSkeletonOptions(
val colorResId: Int = R.color.colorDefault,
@ColorInt val color: Int = Color.LTGRAY,
val cornerRadius: Float = CORNER_RADIUS.px,
val isShimmerEnabled: Boolean = true,
val itemCount: Int = ITEM_COUNT,
Expand Down
6 changes: 3 additions & 3 deletions koleton-base/src/main/kotlin/koleton/MainSkeletonLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal class MainSkeletonLoader(
return@with if (target is TextViewTarget) {
val attributes = TextViewAttributes(
view = target.view,
color = context.getColorCompat(colorResId ?: defaults.colorResId),
color = color ?: defaults.color,
cornerRadius = cornerRadius ?: defaults.cornerRadius,
isShimmerEnabled = isShimmerEnabled ?: defaults.isShimmerEnabled,
shimmer = shimmer ?: defaults.shimmer,
Expand All @@ -117,7 +117,7 @@ internal class MainSkeletonLoader(
return@with if (target is RecyclerViewTarget) {
val attributes = RecyclerViewAttributes(
view = target.view,
color = context.getColorCompat(colorResId ?: defaults.colorResId),
color = color ?: defaults.color,
cornerRadius = cornerRadius ?: defaults.cornerRadius,
isShimmerEnabled = isShimmerEnabled ?: defaults.isShimmerEnabled,
shimmer = shimmer ?: defaults.shimmer,
Expand All @@ -134,7 +134,7 @@ internal class MainSkeletonLoader(
private fun generateSimpleView(skeleton: ViewSkeleton) = with(skeleton) {
return@with if (target is SimpleViewTarget) {
val attributes = SimpleViewAttributes(
color = context.getColorCompat(colorResId ?: defaults.colorResId),
color = color ?: defaults.color,
cornerRadius = cornerRadius ?: defaults.cornerRadius,
isShimmerEnabled = isShimmerEnabled ?: defaults.isShimmerEnabled,
shimmer = shimmer ?: defaults.shimmer,
Expand Down
13 changes: 11 additions & 2 deletions koleton-base/src/main/kotlin/koleton/SkeletonLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ package koleton

import android.content.Context
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.Px
import com.facebook.shimmer.Shimmer
import koleton.annotation.ExperimentalKoletonApi
import koleton.custom.KoletonView
import koleton.skeleton.Skeleton
import koleton.target.Target
import koleton.util.getColorCompat

interface SkeletonLoader {

Expand Down Expand Up @@ -58,8 +60,15 @@ interface SkeletonLoader {
/**
* Set the skeleton color.
*/
fun color(@ColorRes color: Int) = apply {
this.defaults = this.defaults.copy(colorResId = color)
fun colorInt(@ColorInt color: Int) = apply {
this.defaults = this.defaults.copy(color = color)
}

/**
* Set the skeleton color.
*/
fun color(@ColorRes colorRes: Int) = apply {
colorInt(applicationContext.getColorCompat(colorRes))
}

/**
Expand Down
20 changes: 10 additions & 10 deletions koleton-base/src/main/kotlin/koleton/custom/Attributes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ data class RecyclerViewAttributes(
override val lineSpacing: Float,
@LayoutRes val itemLayout: Int,
val itemCount: Int
): Attributes()
) : Attributes()

data class SimpleViewAttributes(
@ColorInt override val color: Int,
@Px override val cornerRadius: Float,
override val isShimmerEnabled: Boolean,
override val shimmer: Shimmer,
override val lineSpacing: Float
): Attributes()
) : Attributes()

data class TextViewAttributes(
val view: TextView,
@ColorInt override val color: Int,
@Px override val cornerRadius: Float,
override val isShimmerEnabled: Boolean,
override val shimmer: Shimmer,
override val lineSpacing: Float,
val length: Int
): Attributes()
val view: TextView,
@ColorInt override val color: Int,
@Px override val cornerRadius: Float,
override val isShimmerEnabled: Boolean,
override val shimmer: Shimmer,
override val lineSpacing: Float,
val length: Int
) : Attributes()
35 changes: 16 additions & 19 deletions koleton-base/src/main/kotlin/koleton/skeleton/Skeleton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ package koleton.skeleton
import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.annotation.ColorRes
import androidx.annotation.LayoutRes
import androidx.annotation.MainThread
import androidx.annotation.Px
import androidx.annotation.*
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.RecyclerView
import com.facebook.shimmer.Shimmer
Expand All @@ -27,7 +24,7 @@ sealed class Skeleton {

abstract val context: Context
abstract val target: Target?
abstract val colorResId: Int?
abstract val color: Int?
abstract val cornerRadius: Float?
abstract val isShimmerEnabled: Boolean?
abstract val lifecycle: Lifecycle?
Expand Down Expand Up @@ -73,7 +70,7 @@ class ViewSkeleton internal constructor(
override val context: Context,
override val target: Target?,
override val lifecycle: Lifecycle?,
@ColorRes override val colorResId: Int?,
@ColorInt override val color: Int?,
@Px override val cornerRadius: Float?,
override val isShimmerEnabled: Boolean?,
override val shimmer: Shimmer?,
Expand Down Expand Up @@ -139,7 +136,7 @@ class ViewSkeleton internal constructor(
context,
target,
lifecycle,
colorResId,
color,
cornerRadius,
isShimmerEnabled,
shimmer,
Expand All @@ -153,7 +150,7 @@ class RecyclerViewSkeleton internal constructor(
override val context: Context,
override val target: Target?,
override val lifecycle: Lifecycle?,
@ColorRes override val colorResId: Int?,
@ColorInt override val color: Int?,
@Px override val cornerRadius: Float?,
override val isShimmerEnabled: Boolean?,
@LayoutRes internal val itemLayoutResId: Int,
Expand Down Expand Up @@ -235,7 +232,7 @@ class RecyclerViewSkeleton internal constructor(
context,
target,
lifecycle,
colorResId,
color,
cornerRadius,
isShimmerEnabled,
itemLayoutResId,
Expand All @@ -248,15 +245,15 @@ class RecyclerViewSkeleton internal constructor(
}

class TextViewSkeleton internal constructor(
override val context: Context,
override val target: Target?,
override val lifecycle: Lifecycle?,
@ColorRes override val colorResId: Int?,
@Px override val cornerRadius: Float?,
override val isShimmerEnabled: Boolean?,
override val shimmer: Shimmer?,
override val lineSpacing: Float?,
internal val length: Int
override val context: Context,
override val target: Target?,
override val lifecycle: Lifecycle?,
@ColorInt override val color: Int?,
@Px override val cornerRadius: Float?,
override val isShimmerEnabled: Boolean?,
override val shimmer: Shimmer?,
override val lineSpacing: Float?,
internal val length: Int
) : Skeleton() {

/** Create a new [Builder] instance using this as a base. */
Expand Down Expand Up @@ -321,7 +318,7 @@ class TextViewSkeleton internal constructor(
context,
target,
lifecycle,
colorResId,
color,
cornerRadius,
isShimmerEnabled,
shimmer,
Expand Down
19 changes: 14 additions & 5 deletions koleton-base/src/main/kotlin/koleton/skeleton/SkeletonBuilder.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package koleton.skeleton

import android.content.Context
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.Px
import com.facebook.shimmer.Shimmer
import koleton.annotation.BuilderMarker
import koleton.util.getColorCompat
import koleton.util.self

/** Base class for [ViewSkeleton.Builder] and [RecyclerViewSkeleton.Builder] */
Expand All @@ -13,14 +15,14 @@ open class SkeletonBuilder<T : SkeletonBuilder<T>> {

@JvmField protected val context: Context
@JvmField @Px protected var cornerRadius: Float?
@JvmField @ColorRes protected var colorResId: Int?
@JvmField @ColorInt protected var color: Int?
@JvmField protected var isShimmerEnabled: Boolean?
@JvmField protected var shimmer: Shimmer?
@JvmField @Px protected var lineSpacing: Float?

constructor(context: Context) {
this.context = context
this.colorResId = null
this.color = null
this.cornerRadius = null
this.isShimmerEnabled = null
this.shimmer = null
Expand All @@ -29,7 +31,7 @@ open class SkeletonBuilder<T : SkeletonBuilder<T>> {

constructor(skeleton: Skeleton, context: Context) {
this.context = context
this.colorResId = skeleton.colorResId
this.color = skeleton.color
this.cornerRadius = skeleton.cornerRadius
this.isShimmerEnabled = skeleton.isShimmerEnabled
this.shimmer = skeleton.shimmer
Expand All @@ -46,8 +48,15 @@ open class SkeletonBuilder<T : SkeletonBuilder<T>> {
/**
* Set the skeleton color.
*/
fun color(@ColorRes color: Int): T = self {
this.colorResId = color
fun colorInt(@ColorInt color: Int): T = self {
this.color = color
}

/**
* Set the skeleton color res.
*/
fun color(@ColorRes colorRes: Int): T = self {
colorInt(context.getColorCompat(colorRes))
}

/**
Expand Down
Loading

0 comments on commit ca5f6b2

Please sign in to comment.