diff --git a/sequencelayout/build.gradle.kts b/sequencelayout/build.gradle.kts index 3009694..6841cd1 100644 --- a/sequencelayout/build.gradle.kts +++ b/sequencelayout/build.gradle.kts @@ -5,17 +5,15 @@ plugins { id("com.github.dcendents.android-maven") } -group="com.github.transferwise" - android { compileSdkVersion(Versions.SDK) defaultConfig { minSdkVersion(Versions.MIN_SDK) targetSdkVersion(Versions.SDK) - versionCode = 12 - versionName = "1.1.0" - setProperty("archivesBaseName", "com.transferwise.sequencelayout-${versionName}") + versionCode = 13 + versionName = "1.1.1" + setProperty("archivesBaseName", "com.transferwise.sequencelayout") } buildTypes { @@ -35,6 +33,9 @@ android { } } +group = "com.github.transferwise" +version = android.defaultConfig.versionName.orEmpty() + dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.KOTLIN}") implementation("androidx.appcompat:appcompat:${Versions.ANDROIDX_APPCOMPAT}") diff --git a/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceLayout.kt b/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceLayout.kt index 6a62fbc..6ca4af0 100644 --- a/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceLayout.kt +++ b/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceLayout.kt @@ -12,7 +12,6 @@ import android.widget.FrameLayout import androidx.annotation.ColorInt import androidx.annotation.StyleRes import androidx.core.view.ViewCompat -import androidx.core.view.doOnPreDraw import kotlinx.android.synthetic.main.sequence_layout.view.* /** @@ -38,7 +37,7 @@ import kotlinx.android.synthetic.main.sequence_layout.view.* * @see com.transferwise.sequencelayout.SequenceStep */ public class SequenceLayout(context: Context, attrs: AttributeSet?, defStyleAttr: Int) - : FrameLayout(context, attrs, defStyleAttr) { + : FrameLayout(context, attrs, defStyleAttr), SequenceStep.OnStepChangedListener { public constructor(context: Context) : this(context, null) public constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) @@ -226,15 +225,17 @@ public class SequenceLayout(context: Context, attrs: AttributeSet?, defStyleAttr resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_bottom) ) } + child.onStepChangedListener = this stepsWrapper.addView(child, params) - child.doOnPreDraw { - setProgressBarHorizontalOffset() - placeDots() - removeCallbacks(animateToActive) - post(animateToActive) - } return } super.addView(child, index, params) } + + override fun onStepChanged() { + setProgressBarHorizontalOffset() + placeDots() + removeCallbacks(animateToActive) + post(animateToActive) + } } \ No newline at end of file diff --git a/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceStep.kt b/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceStep.kt index 14dfce0..b3b3a59 100644 --- a/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceStep.kt +++ b/sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceStep.kt @@ -9,6 +9,7 @@ import android.widget.TextView import androidx.annotation.Dimension import androidx.annotation.StringRes import androidx.annotation.StyleRes +import androidx.core.view.doOnPreDraw import androidx.core.widget.TextViewCompat import kotlinx.android.synthetic.main.sequence_step.view.* import kotlin.math.max @@ -50,9 +51,10 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?) public constructor(context: Context) : this(context, null) private var isActive: Boolean = false + internal var onStepChangedListener: OnStepChangedListener? = null init { - View.inflate(getContext(), R.layout.sequence_step, this) + View.inflate(context, R.layout.sequence_step, this) clipToPadding = false clipChildren = false @@ -183,10 +185,16 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?) */ public fun setActive(isActive: Boolean) { this.isActive = isActive + doOnPreDraw { onStepChangedListener?.onStepChanged() } + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + doOnPreDraw { onStepChangedListener?.onStepChanged() } } fun getDotOffset(): Int = - (max(getViewHeight(anchor), getViewHeight(title)) - 8.toPx()) / 2 //TODO dynamic dot height + (max(getViewHeight(anchor), getViewHeight(title)) - 8.toPx()) / 2 //TODO dynamic dot height private fun setupAnchor(attributes: TypedArray) { if (!attributes.hasValue(R.styleable.SequenceStep_anchor)) { @@ -255,4 +263,8 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?) } else { view.measuredHeight } + + internal interface OnStepChangedListener { + fun onStepChanged() + } } \ No newline at end of file