From 505a63921d6672f0a522a8b4ede171a3011809a7 Mon Sep 17 00:00:00 2001 From: Erick Tijero Date: Sat, 6 Feb 2021 00:06:55 -0500 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=91=B7=20Update=20kotlin=20version=20?= =?UTF-8?q?and=20use=20view=20binding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 8 ++- buildSrc/build.gradle.kts | 9 +++ buildSrc/extra.gradle.kts | 4 ++ .../kotlin/{Commons.kt => Dependencies.kt} | 5 +- gradle.properties | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- koleton-sample/build.gradle.kts | 7 ++- .../sample/detail/JourneyDetailFragment.kt | 55 +++++++++++-------- .../koleton/sample/list/JourneyListAdapter.kt | 31 ++++++----- .../sample/list/JourneyListFragment.kt | 33 ++++++----- .../res/layout/fragment_journey_detail.xml | 2 + 11 files changed, 99 insertions(+), 61 deletions(-) create mode 100644 buildSrc/extra.gradle.kts rename buildSrc/src/main/kotlin/{Commons.kt => Dependencies.kt} (95%) diff --git a/build.gradle.kts b/build.gradle.kts index 3bd3f07..65bc391 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,12 +4,13 @@ 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() @@ -17,6 +18,8 @@ buildscript { jcenter() } dependencies { + classpath(rootProject.extra["androidPlugin"].toString()) + classpath(rootProject.extra["kotlinPlugin"].toString()) classpath(Dependencies.safeArgsPlugin) } } @@ -69,7 +72,6 @@ subprojects { apply { plugin(Android.libPlugin) plugin(Kotlin.androidPlugin) - plugin(Kotlin.androidExtensionsPlugin) } configure { @@ -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"]) } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 5aa40ec..52f5daa 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -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) } \ No newline at end of file diff --git a/buildSrc/extra.gradle.kts b/buildSrc/extra.gradle.kts new file mode 100644 index 0000000..d325ffa --- /dev/null +++ b/buildSrc/extra.gradle.kts @@ -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") +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Commons.kt b/buildSrc/src/main/kotlin/Dependencies.kt similarity index 95% rename from buildSrc/src/main/kotlin/Commons.kt rename to buildSrc/src/main/kotlin/Dependencies.kt index 9fccb1f..4bb3b51 100644 --- a/buildSrc/src/main/kotlin/Commons.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -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 { @@ -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 { diff --git a/gradle.properties b/gradle.properties index 97012be..95f667d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,8 +22,8 @@ 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 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9b7e706..02b0ab8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/koleton-sample/build.gradle.kts b/koleton-sample/build.gradle.kts index 603752b..baa9789 100644 --- a/koleton-sample/build.gradle.kts +++ b/koleton-sample/build.gradle.kts @@ -4,7 +4,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id(Android.appPlugin) id(Kotlin.androidPlugin) - id(Kotlin.androidExtensionsPlugin) id("androidx.navigation.safeargs.kotlin") } @@ -37,12 +36,12 @@ dependencies { } configure { - compileSdkVersion(29) + compileSdkVersion(30) defaultConfig { applicationId = "koleton.sample" minSdkVersion(21) - targetSdkVersion(29) + targetSdkVersion(30) versionCode = 1 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" @@ -80,4 +79,6 @@ configure { exclude("META-INF/LICENSE.txt") exclude("META-INF/NOTICE.txt") } + + android.buildFeatures.viewBinding = true } \ No newline at end of file diff --git a/koleton-sample/src/main/kotlin/koleton/sample/detail/JourneyDetailFragment.kt b/koleton-sample/src/main/kotlin/koleton/sample/detail/JourneyDetailFragment.kt index 1efdb70..ec4a553 100644 --- a/koleton-sample/src/main/kotlin/koleton/sample/detail/JourneyDetailFragment.kt +++ b/koleton-sample/src/main/kotlin/koleton/sample/detail/JourneyDetailFragment.kt @@ -12,18 +12,20 @@ import com.facebook.shimmer.Shimmer import koleton.api.hideSkeleton import koleton.api.loadSkeleton import koleton.sample.R +import koleton.sample.databinding.FragmentJourneyDetailBinding import koleton.sample.model.Journey import koleton.sample.utils.DEFAULT_DELAY import koleton.sample.utils.visible -import kotlinx.android.synthetic.main.fragment_journey_detail.* -import kotlinx.android.synthetic.main.include_journey_body.* -import kotlinx.android.synthetic.main.include_journey_header.* class JourneyDetailFragment : AppCompatDialogFragment() { private val args: JourneyDetailFragmentArgs by navArgs() private val handler by lazy { Handler() } + lateinit var binding: FragmentJourneyDetailBinding + private val headerBinding get() = binding.clHeader + private val bodyBinding get() = binding.clBody + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setStyle(STYLE_NO_TITLE, R.style.FullScreenDialogStyle) @@ -34,15 +36,18 @@ class JourneyDetailFragment : AppCompatDialogFragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - return inflater.inflate(R.layout.fragment_journey_detail, container, false) + binding = FragmentJourneyDetailBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - ivBack?.setOnClickListener { dismiss() } - tvToolbar?.text = args.journey.date - clHeader?.loadSkeleton { - shimmer(getCustomShimmer()) + binding.apply { + ivBack.setOnClickListener { dismiss() } + tvToolbar.text = args.journey.date + headerBinding.clHeader.loadSkeleton { + shimmer(getCustomShimmer()) + } } getJourneyDetail() } @@ -52,8 +57,8 @@ class JourneyDetailFragment : AppCompatDialogFragment() { } private fun onSuccess() { - clBody?.visible() - clHeader?.hideSkeleton() + bodyBinding.clBody.visible() + headerBinding.clHeader.hideSkeleton() showInformation(args.journey) } @@ -72,19 +77,23 @@ class JourneyDetailFragment : AppCompatDialogFragment() { } private fun showInformation(journey: Journey) = with(journey) { - ivMap?.setImageResource(mapImage) - tvPickUpValue?.text = pickUpPoint - tvPickUpTime?.text = pickUpTime - tvDropOffValue?.text = dropOffPoint - tvDropOffTime?.text = dropOffTime - tvDriverName?.text = driverName - ivPicture?.setImageResource(driverImage) - tvCarName?.text = carName - ivCarType?.setImageResource(carIcon) - tvBasePriceValue?.text = basePrice - tvServicePriceValue?.text = servicePrice - tvTotalValue?.text = total - tvPaymentValue?.text = paymentMethod + headerBinding.apply { + ivMap.setImageResource(mapImage) + tvPickUpValue.text = pickUpPoint + tvPickUpTime.text = pickUpTime + tvDropOffValue.text = dropOffPoint + tvDropOffTime.text = dropOffTime + } + bodyBinding.apply { + tvDriverName.text = driverName + ivPicture.setImageResource(driverImage) + tvCarName.text = carName + ivCarType.setImageResource(carIcon) + tvBasePriceValue.text = basePrice + tvServicePriceValue.text = servicePrice + tvTotalValue.text = total + tvPaymentValue.text = paymentMethod + } } override fun onDestroyView() { diff --git a/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListAdapter.kt b/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListAdapter.kt index bb4cd1a..2a3cf7c 100644 --- a/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListAdapter.kt +++ b/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListAdapter.kt @@ -1,18 +1,16 @@ package koleton.sample.list import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import androidx.paging.PagedListAdapter import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import koleton.api.generateSkeleton import koleton.custom.KoletonView -import koleton.sample.R +import koleton.sample.databinding.ItemJourneyBinding import koleton.sample.model.Journey import koleton.sample.utils.State import koleton.sample.utils.visible -import kotlinx.android.synthetic.main.item_journey.view.* class JourneyListAdapter(private val clickListener: (Journey) -> Unit) : PagedListAdapter(POST_COMPARATOR) { @@ -30,10 +28,12 @@ class JourneyListAdapter(private val clickListener: (Journey) -> Unit) : parent: ViewGroup, viewType: Int ): RecyclerView.ViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.item_journey, parent, false) + + val itemBinding = + ItemJourneyBinding.inflate(LayoutInflater.from(parent.context), parent, false) return when (viewType) { - TYPE_VIEW -> JourneyViewHolder(view) - TYPE_SKELETON -> SkeletonViewHolder(view.generateSkeleton()) + TYPE_VIEW -> JourneyViewHolder(itemBinding) + TYPE_SKELETON -> SkeletonViewHolder(itemBinding.root.generateSkeleton()) else -> throw IllegalArgumentException("unknown view type $viewType") } } @@ -69,16 +69,19 @@ class JourneyListAdapter(private val clickListener: (Journey) -> Unit) : } } - class JourneyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + class JourneyViewHolder(private val itemBinding: ItemJourneyBinding) : + RecyclerView.ViewHolder(itemBinding.root) { fun bind(journey: Journey?, clickListener: (Journey) -> Unit) = with(itemView) { journey?.run { - val dateTime = "$date, $pickUpTime" - tvDate?.text = dateTime - tvAddress?.text = dropOffPoint - tvPrice?.text = total - ivCarType?.setImageResource(carIcon) - tvDetails?.visible() - itemView.setOnClickListener { clickListener(journey) } + itemBinding.apply { + val dateTime = "$date, $pickUpTime" + tvDate.text = dateTime + tvAddress.text = dropOffPoint + tvPrice.text = total + ivCarType.setImageResource(carIcon) + tvDetails.visible() + itemView.setOnClickListener { clickListener(journey) } + } } } } diff --git a/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListFragment.kt b/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListFragment.kt index 56eeedf..233c3c1 100644 --- a/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListFragment.kt +++ b/koleton-sample/src/main/kotlin/koleton/sample/list/JourneyListFragment.kt @@ -13,9 +13,9 @@ import androidx.recyclerview.widget.RecyclerView import koleton.api.hideSkeleton import koleton.api.loadSkeleton import koleton.sample.R +import koleton.sample.databinding.FragmentJourneyListBinding import koleton.sample.model.Journey import koleton.sample.utils.* -import kotlinx.android.synthetic.main.fragment_journey_list.* class JourneyListFragment : Fragment() { @@ -23,23 +23,26 @@ class JourneyListFragment : Fragment() { private val viewModel: JourneyViewModel by viewModels { getViewModelFactory() } + lateinit var binding: FragmentJourneyListBinding + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - return inflater.inflate(R.layout.fragment_journey_list, container, false) + binding = FragmentJourneyListBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupRecyclerView() - ivRefresh?.setOnClickListener { onRefreshClickListener() } + binding.ivRefresh.setOnClickListener { onRefreshClickListener() } getJourneyList() } private fun setupRecyclerView() { - rvUsers?.apply { + binding.rvUsers.apply { layoutManager = LinearLayoutManager(context) adapter = journeyListAdapter } @@ -56,10 +59,10 @@ class JourneyListFragment : Fragment() { private val journeyStateObserver = Observer> { list -> journeyListAdapter.submitList(list) { - val layoutManager = (rvUsers.layoutManager as LinearLayoutManager) + val layoutManager = (binding.rvUsers.layoutManager as LinearLayoutManager) val position = layoutManager.findFirstCompletelyVisibleItemPosition() if (position != RecyclerView.NO_POSITION) { - rvUsers.scrollToPosition(position) + binding.rvUsers.scrollToPosition(position) } } } @@ -74,16 +77,20 @@ class JourneyListFragment : Fragment() { } private fun onLoadInitial() { - ivRefresh?.gone() - rvUsers?.loadSkeleton(R.layout.item_journey) - tvSubtitle?.loadSkeleton(length = 20) + binding.apply { + ivRefresh.gone() + rvUsers.loadSkeleton(R.layout.item_journey) + tvSubtitle.loadSkeleton(length = 20) + } } private fun onLoaded() { - ivRefresh?.visible() - rvUsers?.hideSkeleton() - tvSubtitle?.hideSkeleton() - tvSubtitle?.text = requireContext().getString(R.string.label_see_your_journey) + binding.apply { + ivRefresh.visible() + rvUsers.hideSkeleton() + tvSubtitle.hideSkeleton() + tvSubtitle.text = requireContext().getString(R.string.label_see_your_journey) + } } private fun onRefreshClickListener() { diff --git a/koleton-sample/src/main/res/layout/fragment_journey_detail.xml b/koleton-sample/src/main/res/layout/fragment_journey_detail.xml index 073fe31..dd4f987 100644 --- a/koleton-sample/src/main/res/layout/fragment_journey_detail.xml +++ b/koleton-sample/src/main/res/layout/fragment_journey_detail.xml @@ -48,11 +48,13 @@ android:layout_marginEnd="16dp"> From 177313a0cdc68e7245f35a3a1cc9b724b9171ef4 Mon Sep 17 00:00:00 2001 From: Erick Tijero Date: Sat, 6 Feb 2021 20:42:17 -0500 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=8E=A8=20Add=20support=20for=20colorI?= =?UTF-8?q?nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/koleton/DefaultSkeletonOptions.kt | 4 ++- .../main/kotlin/koleton/MainSkeletonLoader.kt | 6 ++-- .../src/main/kotlin/koleton/SkeletonLoader.kt | 13 +++++-- .../main/kotlin/koleton/skeleton/Skeleton.kt | 35 +++++++++---------- .../koleton/skeleton/SkeletonBuilder.kt | 19 +++++++--- 5 files changed, 47 insertions(+), 30 deletions(-) diff --git a/koleton-base/src/main/kotlin/koleton/DefaultSkeletonOptions.kt b/koleton-base/src/main/kotlin/koleton/DefaultSkeletonOptions.kt index 022a676..0e9eee1 100644 --- a/koleton-base/src/main/kotlin/koleton/DefaultSkeletonOptions.kt +++ b/koleton-base/src/main/kotlin/koleton/DefaultSkeletonOptions.kt @@ -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 @@ -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, diff --git a/koleton-base/src/main/kotlin/koleton/MainSkeletonLoader.kt b/koleton-base/src/main/kotlin/koleton/MainSkeletonLoader.kt index 230338c..e0d4974 100644 --- a/koleton-base/src/main/kotlin/koleton/MainSkeletonLoader.kt +++ b/koleton-base/src/main/kotlin/koleton/MainSkeletonLoader.kt @@ -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, @@ -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, @@ -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, diff --git a/koleton-base/src/main/kotlin/koleton/SkeletonLoader.kt b/koleton-base/src/main/kotlin/koleton/SkeletonLoader.kt index ff5ea4c..5c3b4f0 100644 --- a/koleton-base/src/main/kotlin/koleton/SkeletonLoader.kt +++ b/koleton-base/src/main/kotlin/koleton/SkeletonLoader.kt @@ -5,6 +5,7 @@ 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 @@ -12,6 +13,7 @@ import koleton.annotation.ExperimentalKoletonApi import koleton.custom.KoletonView import koleton.skeleton.Skeleton import koleton.target.Target +import koleton.util.getColorCompat interface SkeletonLoader { @@ -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)) } /** diff --git a/koleton-base/src/main/kotlin/koleton/skeleton/Skeleton.kt b/koleton-base/src/main/kotlin/koleton/skeleton/Skeleton.kt index 194a29c..a0088fa 100644 --- a/koleton-base/src/main/kotlin/koleton/skeleton/Skeleton.kt +++ b/koleton-base/src/main/kotlin/koleton/skeleton/Skeleton.kt @@ -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 @@ -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? @@ -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?, @@ -139,7 +136,7 @@ class ViewSkeleton internal constructor( context, target, lifecycle, - colorResId, + color, cornerRadius, isShimmerEnabled, shimmer, @@ -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, @@ -235,7 +232,7 @@ class RecyclerViewSkeleton internal constructor( context, target, lifecycle, - colorResId, + color, cornerRadius, isShimmerEnabled, itemLayoutResId, @@ -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. */ @@ -321,7 +318,7 @@ class TextViewSkeleton internal constructor( context, target, lifecycle, - colorResId, + color, cornerRadius, isShimmerEnabled, shimmer, diff --git a/koleton-base/src/main/kotlin/koleton/skeleton/SkeletonBuilder.kt b/koleton-base/src/main/kotlin/koleton/skeleton/SkeletonBuilder.kt index df62837..b008fb8 100644 --- a/koleton-base/src/main/kotlin/koleton/skeleton/SkeletonBuilder.kt +++ b/koleton-base/src/main/kotlin/koleton/skeleton/SkeletonBuilder.kt @@ -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] */ @@ -13,14 +15,14 @@ open class SkeletonBuilder> { @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 @@ -29,7 +31,7 @@ open class SkeletonBuilder> { 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 @@ -46,8 +48,15 @@ open class SkeletonBuilder> { /** * 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)) } /** From 72a6e9cbdbb6cbbf7c62b9731938874fcd4c0226 Mon Sep 17 00:00:00 2001 From: Erick Tijero Date: Sat, 6 Feb 2021 20:53:09 -0500 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=94=A7=20Reformat=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/koleton/custom/Attributes.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/koleton-base/src/main/kotlin/koleton/custom/Attributes.kt b/koleton-base/src/main/kotlin/koleton/custom/Attributes.kt index 72d2801..16fcce7 100644 --- a/koleton-base/src/main/kotlin/koleton/custom/Attributes.kt +++ b/koleton-base/src/main/kotlin/koleton/custom/Attributes.kt @@ -24,7 +24,7 @@ data class RecyclerViewAttributes( override val lineSpacing: Float, @LayoutRes val itemLayout: Int, val itemCount: Int -): Attributes() +) : Attributes() data class SimpleViewAttributes( @ColorInt override val color: Int, @@ -32,14 +32,14 @@ data class SimpleViewAttributes( 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() From b6bcbded5a62b219d20aba684b15890f85650898 Mon Sep 17 00:00:00 2001 From: Erick Tijero Date: Sat, 6 Feb 2021 21:40:57 -0500 Subject: [PATCH 4/5] =?UTF-8?q?=E2=AC=86=20Increase=20version=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e64da5d..a2e5a03 100644 --- a/README.md +++ b/README.md @@ -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") } ``` diff --git a/gradle.properties b/gradle.properties index 95f667d..978faee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,4 +27,4 @@ compileSdk=30 groupId=com.ericktijerou.koleton vcsUrl=https://github.com/ericktijerou/koleton issueTrackerUrl=https://github.com/ericktijerou/koleton/issues -publishVersion=0.8.5 \ No newline at end of file +publishVersion=0.8.8 \ No newline at end of file From b0963452330e07c5e37d89dcbf0d71d50d4da796 Mon Sep 17 00:00:00 2001 From: Erick Tijero Date: Sun, 7 Feb 2021 07:53:49 -0500 Subject: [PATCH 5/5] =?UTF-8?q?=E2=AC=86=20Update=20kotlin=20version=20in?= =?UTF-8?q?=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2e5a03..ba2f35d 100644 --- a/README.md +++ b/README.md @@ -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.