diff --git a/buildSrc/src/main/kotlin/com/skydoves/powerspinner/Dependencies.kt b/buildSrc/src/main/kotlin/com/skydoves/powerspinner/Dependencies.kt index 7c9bf1a..76fa505 100644 --- a/buildSrc/src/main/kotlin/com/skydoves/powerspinner/Dependencies.kt +++ b/buildSrc/src/main/kotlin/com/skydoves/powerspinner/Dependencies.kt @@ -1,12 +1,12 @@ package com.skydoves.powerspinner object Versions { - internal const val ANDROID_GRADLE_PLUGIN = "7.2.0" - internal const val ANDROID_GRADLE_SPOTLESS = "6.3.0" + internal const val ANDROID_GRADLE_PLUGIN = "7.2.1" + internal const val ANDROID_GRADLE_SPOTLESS = "6.7.0" internal const val GRADLE_NEXUS_PUBLISH_PLUGIN = "1.1.0" - internal const val KOTLIN = "1.6.10" - internal const val KOTLIN_GRADLE_DOKKA = "1.6.21" - internal const val KOTLIN_BINARY_VALIDATOR = "0.8.0" + internal const val KOTLIN = "1.7.10" + internal const val KOTLIN_GRADLE_DOKKA = "1.7.10" + internal const val KOTLIN_BINARY_VALIDATOR = "0.11.0" internal const val APPCOMPAT = "1.4.1" internal const val MATERIAL = "1.6.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 92f06b5..8fad3f5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/powerspinner/api/powerspinner.api b/powerspinner/api/powerspinner.api index 784fb02..c409612 100644 --- a/powerspinner/api/powerspinner.api +++ b/powerspinner/api/powerspinner.api @@ -35,7 +35,7 @@ public final class com/skydoves/powerspinner/IconSpinnerAdapter : androidx/recyc } public final class com/skydoves/powerspinner/IconSpinnerAdapter$IconSpinnerViewHolder : androidx/recyclerview/widget/RecyclerView$ViewHolder { - public fun (Lcom/skydoves/powerspinner/databinding/PowerspinnerItemDefaultPowerBinding;)V + public fun (Lcom/skydoves/powerspinner/IconSpinnerAdapter;Lcom/skydoves/powerspinner/databinding/PowerspinnerItemDefaultPowerBinding;)V } public final class com/skydoves/powerspinner/IconSpinnerItem { diff --git a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/DefaultSpinnerAdapter.kt b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/DefaultSpinnerAdapter.kt index 6370564..e8ccc06 100644 --- a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/DefaultSpinnerAdapter.kt +++ b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/DefaultSpinnerAdapter.kt @@ -39,7 +39,8 @@ public class DefaultSpinnerAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DefaultSpinnerViewHolder { val binding = PowerspinnerItemDefaultPowerBinding.inflate( - LayoutInflater.from(parent.context), parent, + LayoutInflater.from(parent.context), + parent, false ) return DefaultSpinnerViewHolder(binding).apply { diff --git a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerAdapter.kt b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerAdapter.kt index 7c01fdd..593f269 100644 --- a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerAdapter.kt +++ b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerAdapter.kt @@ -22,6 +22,7 @@ import android.util.TypedValue import android.view.Gravity import android.view.LayoutInflater import android.view.ViewGroup +import androidx.appcompat.widget.AppCompatTextView import androidx.core.content.res.ResourcesCompat import androidx.recyclerview.widget.RecyclerView import com.skydoves.powerspinner.databinding.PowerspinnerItemDefaultPowerBinding @@ -48,7 +49,8 @@ public class IconSpinnerAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IconSpinnerViewHolder { val binding = PowerspinnerItemDefaultPowerBinding.inflate( - LayoutInflater.from(parent.context), parent, + LayoutInflater.from(parent.context), + parent, false ) return IconSpinnerViewHolder(binding).apply { @@ -75,19 +77,7 @@ public class IconSpinnerAdapter( if (index == NO_SELECTED_INDEX) return val item = spinnerItems[index] spinnerView.compoundDrawablePadding = item.iconPadding ?: spinnerView.compoundDrawablePadding - val icon = item.iconRes?.let { - ResourcesCompat.getDrawable(spinnerView.resources, it, null) - } ?: item.icon - when (item.iconGravity) { - Gravity.START -> - spinnerView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) - Gravity.END -> - spinnerView.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null) - Gravity.TOP -> - spinnerView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null) - Gravity.BOTTOM -> - spinnerView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, icon) - } + spinnerView.applyCompoundDrawables(spinnerView, item) val oldIndex = this.index this.index = index this.spinnerView.notifyItemSelected(index, item.text) @@ -101,7 +91,7 @@ public class IconSpinnerAdapter( override fun getItemCount(): Int = this.spinnerItems.size - public class IconSpinnerViewHolder(private val binding: PowerspinnerItemDefaultPowerBinding) : + public inner class IconSpinnerViewHolder(private val binding: PowerspinnerItemDefaultPowerBinding) : RecyclerView.ViewHolder(binding.root) { internal fun bind(item: IconSpinnerItem, spinnerView: PowerSpinnerView) { @@ -112,29 +102,41 @@ public class IconSpinnerAdapter( setTextSize(TypedValue.COMPLEX_UNIT_PX, item.textSize ?: spinnerView.textSize) setTextColor(item.textColor ?: spinnerView.currentTextColor) compoundDrawablePadding = item.iconPadding ?: spinnerView.compoundDrawablePadding - val icon = item.iconRes?.let { - ResourcesCompat.getDrawable(spinnerView.resources, it, null) - } ?: item.icon - when (item.iconGravity) { - Gravity.START -> - setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) - Gravity.END -> - setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null) - Gravity.TOP -> - setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null) - Gravity.BOTTOM -> - setCompoundDrawablesWithIntrinsicBounds(null, null, null, icon) + applyCompoundDrawables(spinnerView, item) + binding.root.setPadding( + spinnerView.paddingLeft, + spinnerView.paddingTop, + spinnerView.paddingRight, + spinnerView.paddingBottom + ) + if (spinnerView.spinnerItemHeight != NO_INT_VALUE) { + binding.root.height = spinnerView.spinnerItemHeight } } - binding.root.setPadding( - spinnerView.paddingLeft, - spinnerView.paddingTop, - spinnerView.paddingRight, - spinnerView.paddingBottom - ) - if (spinnerView.spinnerItemHeight != NO_INT_VALUE) { - binding.root.height = spinnerView.spinnerItemHeight - } + } + } + + @JvmSynthetic + internal fun AppCompatTextView.applyCompoundDrawables( + spinnerView: PowerSpinnerView, + item: IconSpinnerItem + ) { + val icon = item.iconRes?.let { + ResourcesCompat.getDrawable(spinnerView.resources, it, null) + } ?: item.icon + val start = compoundDrawablesRelative[0] + val top = compoundDrawablesRelative[1] + val end = compoundDrawablesRelative[2] + val bottom = compoundDrawablesRelative[3] + when (item.iconGravity) { + Gravity.START -> + setCompoundDrawablesRelativeWithIntrinsicBounds(icon, top, end, bottom) + Gravity.END -> + setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, icon, bottom) + Gravity.TOP -> + setCompoundDrawablesRelativeWithIntrinsicBounds(start, icon, end, bottom) + Gravity.BOTTOM -> + setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, icon) } } } diff --git a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerItem.kt b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerItem.kt index 008b648..83fc931 100644 --- a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerItem.kt +++ b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/IconSpinnerItem.kt @@ -46,5 +46,5 @@ public data class IconSpinnerItem @JvmOverloads constructor( val textTypeface: Typeface? = null, val gravity: Int? = null, val textSize: Float? = null, - @ColorInt val textColor: Int? = null, + @ColorInt val textColor: Int? = null ) diff --git a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerPersistence.kt b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerPersistence.kt index 3c78b0b..dc5a626 100644 --- a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerPersistence.kt +++ b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerPersistence.kt @@ -27,7 +27,8 @@ internal class PowerSpinnerPersistence private constructor() { /** gets selected index from the preference. */ fun getSelectedIndex(name: String): Int = sharedPreferenceManager.getInt( - INDEX + name, NO_SELECTED_INDEX + INDEX + name, + NO_SELECTED_INDEX ) /** puts selected index from the preference. */ diff --git a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerView.kt b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerView.kt index 3b56f1f..38a93d9 100644 --- a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerView.kt +++ b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/PowerSpinnerView.kt @@ -568,13 +568,33 @@ public class PowerSpinnerView : AppCompatTextView, DefaultLifecycleObserver { } } when (this.arrowGravity) { - SpinnerGravity.START -> setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) - SpinnerGravity.TOP -> setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null) - SpinnerGravity.END -> setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null) - SpinnerGravity.BOTTOM -> setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable) + SpinnerGravity.START -> setCompoundDrawablesRelativeWithIntrinsicBounds( + drawable, + null, + null, + null + ) + SpinnerGravity.TOP -> setCompoundDrawablesRelativeWithIntrinsicBounds( + null, + drawable, + null, + null + ) + SpinnerGravity.END -> setCompoundDrawablesRelativeWithIntrinsicBounds( + null, + null, + drawable, + null + ) + SpinnerGravity.BOTTOM -> setCompoundDrawablesRelativeWithIntrinsicBounds( + null, + null, + null, + drawable + ) } } else { - setCompoundDrawablesWithIntrinsicBounds(null, null, null, null) + setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, null, null) } } diff --git a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/internals/WhatIfExtension.kt b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/internals/WhatIfExtension.kt index 9dc3ff3..65bf296 100644 --- a/powerspinner/src/main/kotlin/com/skydoves/powerspinner/internals/WhatIfExtension.kt +++ b/powerspinner/src/main/kotlin/com/skydoves/powerspinner/internals/WhatIfExtension.kt @@ -28,7 +28,6 @@ package com.skydoves.powerspinner.internals internal inline fun String?.whatIfNotNullOrEmpty( whatIf: (String) -> Unit ) { - this.whatIfNotNullOrEmpty( whatIf = whatIf, whatIfNot = { } @@ -44,7 +43,6 @@ internal inline fun String?.whatIfNotNullOrEmpty( whatIf: (String) -> Unit, whatIfNot: () -> Unit ) { - if (!this.isNullOrEmpty()) { whatIf(this) } else { diff --git a/spotless/spotless.gradle b/spotless/spotless.gradle index aba0b23..176eac1 100644 --- a/spotless/spotless.gradle +++ b/spotless/spotless.gradle @@ -18,7 +18,7 @@ spotless { kotlin { target "**/*.kt" targetExclude "**/build/**/*.kt" - ktlint().userData(['indent_size': '2', 'continuation_indent_size': '2']) + ktlint().setUseExperimental(true).editorConfigOverride(['indent_size': '2', 'continuation_indent_size': '2']) licenseHeaderFile "$rootDir/spotless/spotless.license.kt" trimTrailingWhitespace() endWithNewline()