Skip to content

Commit 7a064ae

Browse files
committed
reorder methods and fix visibility
1 parent c63d7f5 commit 7a064ae

5 files changed

Lines changed: 51 additions & 54 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ And then the actual library dependency to your module's `build.gradle`:
1919

2020
```groovy
2121
dependencies {
22-
compile 'com.github.transferwise:sequence-layout:1.0.2'
22+
compile 'com.github.transferwise:sequence-layout:1.0.3'
2323
}
2424
```
2525

sequencelayout/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
minSdkVersion 19
1313
targetSdkVersion 27
1414
versionCode 3
15-
versionName "1.0.2"
15+
versionName "1.0.3"
1616
archivesBaseName = "com.transferwise.sequencelayout-${versionName}"
1717
}
1818

sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.transferwise.sequencelayout
33
/**
44
* Adapter to bind data to [com.transferwise.sequencelayout.SequenceStep]s for a [com.transferwise.sequencelayout.SequenceLayout].
55
*/
6-
abstract class SequenceAdapter<T> {
6+
public abstract class SequenceAdapter<T> {
77

88
abstract fun getCount(): Int
99

sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceLayout.kt

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import kotlinx.android.synthetic.main.sequence_step.view.*
3939
public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAttr: Int)
4040
: FrameLayout(context, attrs, defStyleAttr), ViewTreeObserver.OnGlobalLayoutListener {
4141

42-
constructor(context: Context) : this(context, null)
43-
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
42+
public constructor(context: Context) : this(context, null)
43+
public constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
4444

4545
init {
4646
inflate(getContext(), R.layout.sequence_layout, this)
@@ -60,41 +60,14 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
6060
start()
6161
}
6262

63-
@ColorInt
64-
private var progressBackgroundColor: Int = 0
63+
@ColorInt private var progressBackgroundColor: Int = 0
64+
@ColorInt private var progressForegroundColor: Int = 0
6565

66-
@ColorInt
67-
private var progressForegroundColor: Int = 0
68-
69-
override fun addView(child: View, index: Int, params: ViewGroup.LayoutParams) {
70-
if (child is SequenceStep) {
71-
if (child.isActive()) {
72-
child.setPadding(
73-
0,
74-
if (stepsWrapper.childCount == 0) 0 else resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_top), //no paddingTop if first step is active
75-
0,
76-
resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_bottom)
77-
)
78-
}
79-
val dot = child.getDot()
80-
dot.setDotBackground(progressForegroundColor, progressBackgroundColor)
81-
dot.setPulseColor(progressForegroundColor)
82-
stepsWrapper.addView(child, params)
83-
return
84-
}
85-
super.addView(child, index, params)
86-
}
87-
88-
override fun onGlobalLayout() {
89-
if (stepsWrapper.childCount > 0) {
90-
adaptProgressBarHeight()
91-
setProgressBarHorizontalOffset()
92-
animateToActive()
93-
viewTreeObserver.removeOnGlobalLayoutListener(this)
94-
}
66+
public fun start() {
67+
viewTreeObserver.addOnGlobalLayoutListener(this)
9568
}
9669

97-
fun setStyle(@StyleRes defStyleAttr: Int) {
70+
public fun setStyle(@StyleRes defStyleAttr: Int) {
9871
val attributes = context.theme.obtainStyledAttributes(defStyleAttr, R.styleable.SequenceLayout)
9972
applyAttributes(attributes)
10073
attributes.recycle()
@@ -105,7 +78,7 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
10578
*
10679
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_progressForegroundColor
10780
*/
108-
fun setProgressForegroundColor(@ColorInt color: Int) {
81+
public fun setProgressForegroundColor(@ColorInt color: Int) {
10982
this.progressForegroundColor = color
11083
progressBarForeground.setBackgroundColor(color)
11184
//TODO apply to existing steps
@@ -116,7 +89,7 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
11689
*
11790
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceLayout_dotBackground
11891
*/
119-
fun setProgressBackgroundColor(@ColorInt progressBackgroundColor: Int) {
92+
public fun setProgressBackgroundColor(@ColorInt progressBackgroundColor: Int) {
12093
this.progressBackgroundColor = progressBackgroundColor
12194
progressBarBackground.setBackgroundColor(progressBackgroundColor)
12295
//TODO apply to existing steps
@@ -125,14 +98,14 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
12598
/**
12699
* Removes all contained [com.transferwise.sequencelayout.SequenceStep]s
127100
*/
128-
fun removeAllSteps() {
101+
public fun removeAllSteps() {
129102
stepsWrapper.removeAllViews()
130103
}
131104

132105
/**
133106
* Replaces all contained [com.transferwise.sequencelayout.SequenceStep]s with those provided and bound by the adapter
134107
*/
135-
fun setAdapter(adapter: SequenceAdapter<SequenceStep>) {
108+
public fun setAdapter(adapter: SequenceAdapter<SequenceStep>) {
136109
removeAllSteps()
137110
val count = adapter.getCount()
138111
for (i in 0 until count) {
@@ -227,7 +200,31 @@ public class SequenceLayout(context: Context?, attrs: AttributeSet?, defStyleAtt
227200
return stepOffsets
228201
}
229202

230-
fun start() {
231-
viewTreeObserver.addOnGlobalLayoutListener(this)
203+
override fun addView(child: View, index: Int, params: ViewGroup.LayoutParams) {
204+
if (child is SequenceStep) {
205+
if (child.isActive()) {
206+
child.setPadding(
207+
0,
208+
if (stepsWrapper.childCount == 0) 0 else resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_top), //no paddingTop if first step is active
209+
0,
210+
resources.getDimensionPixelSize(R.dimen.sequence_active_step_padding_bottom)
211+
)
212+
}
213+
val dot = child.getDot()
214+
dot.setDotBackground(progressForegroundColor, progressBackgroundColor)
215+
dot.setPulseColor(progressForegroundColor)
216+
stepsWrapper.addView(child, params)
217+
return
218+
}
219+
super.addView(child, index, params)
220+
}
221+
222+
override fun onGlobalLayout() {
223+
if (stepsWrapper.childCount > 0) {
224+
adaptProgressBarHeight()
225+
setProgressBarHorizontalOffset()
226+
animateToActive()
227+
viewTreeObserver.removeOnGlobalLayoutListener(this)
228+
}
232229
}
233230
}

sequencelayout/src/main/java/com/transferwise/sequencelayout/SequenceStep.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import kotlinx.android.synthetic.main.sequence_step.view.*
4141
public class SequenceStep(context: Context?, attrs: AttributeSet?)
4242
: TableRow(context, attrs), ViewTreeObserver.OnGlobalLayoutListener {
4343

44-
constructor(context: Context) : this(context, null)
44+
public constructor(context: Context) : this(context, null)
4545

4646
private var isActive: Boolean = false
4747

@@ -76,7 +76,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
7676
*
7777
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchor
7878
*/
79-
fun setAnchor(anchor: CharSequence?) {
79+
public fun setAnchor(anchor: CharSequence?) {
8080
this.anchor.text = anchor
8181
this.anchor.visibility = View.VISIBLE
8282
this.anchor.minWidth = resources.getDimensionPixelSize(R.dimen.sequence_anchor_min_width)
@@ -87,7 +87,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
8787
*
8888
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_anchorTextAppearance
8989
*/
90-
fun setAnchorTextAppearance(@StyleRes resourceId: Int) {
90+
public fun setAnchorTextAppearance(@StyleRes resourceId: Int) {
9191
TextViewCompat.setTextAppearance(anchor, resourceId)
9292
}
9393

@@ -96,7 +96,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
9696
*
9797
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_title
9898
*/
99-
fun setTitle(title: CharSequence?) {
99+
public fun setTitle(title: CharSequence?) {
100100
this.title.text = title
101101
this.title.visibility = View.VISIBLE
102102
}
@@ -106,7 +106,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
106106
*
107107
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_title
108108
*/
109-
fun setTitle(@StringRes resId: Int) {
109+
public fun setTitle(@StringRes resId: Int) {
110110
setTitle(context.getString(resId))
111111
}
112112

@@ -115,7 +115,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
115115
*
116116
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_titleTextAppearance
117117
*/
118-
fun setTitleTextAppearance(@StyleRes resourceId: Int) {
118+
public fun setTitleTextAppearance(@StyleRes resourceId: Int) {
119119
TextViewCompat.setTextAppearance(title, resourceId)
120120
}
121121

@@ -124,7 +124,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
124124
*
125125
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitle
126126
*/
127-
fun setSubtitle(subtitle: CharSequence?) {
127+
public fun setSubtitle(subtitle: CharSequence?) {
128128
this.subtitle.text = subtitle
129129
this.subtitle.visibility = View.VISIBLE
130130
}
@@ -134,7 +134,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
134134
*
135135
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitle
136136
*/
137-
fun setSubtitle(@StringRes resId: Int) {
137+
public fun setSubtitle(@StringRes resId: Int) {
138138
setSubtitle(context.getString(resId))
139139
}
140140

@@ -143,7 +143,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
143143
*
144144
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_subtitleTextAppearance
145145
*/
146-
fun setSubtitleTextAppearance(@StyleRes resourceId: Int) {
146+
public fun setSubtitleTextAppearance(@StyleRes resourceId: Int) {
147147
TextViewCompat.setTextAppearance(subtitle, resourceId)
148148
}
149149

@@ -152,7 +152,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
152152
*
153153
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_active
154154
*/
155-
fun isActive(): Boolean {
155+
public fun isActive(): Boolean {
156156
return isActive
157157
}
158158

@@ -161,7 +161,7 @@ public class SequenceStep(context: Context?, attrs: AttributeSet?)
161161
*
162162
* @attr ref com.transferwise.sequencelayout.R.styleable#SequenceStep_active
163163
*/
164-
fun setActive(isActive: Boolean) {
164+
public fun setActive(isActive: Boolean) {
165165
this.isActive = isActive
166166
}
167167

0 commit comments

Comments
 (0)