Skip to content

Commit da62b96

Browse files
committed
Update editorconfig, reformat Kotlin files
1 parent 76a010a commit da62b96

6 files changed

Lines changed: 101 additions & 109 deletions

File tree

.editorconfig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
[*]
2-
31
[*.{java,kt,xml}]
42
charset=utf-8
53
end_of_line=lf
64
insert_final_newline=true
75
trim_trailing_whitespace=true
86
indent_style=space
9-
continuation_indent_size=4
107

118
[*.{java,kt}]
129
max_line_length=100
1310
spaces_around_operators=true
1411
indent_brace_style=K&R
1512

16-
[*.java]
17-
indent_size=4
18-
1913
[*.kt]
2014
indent_size=2
2115

indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerThumbView.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ import androidx.dynamicanimation.animation.SpringForce
3535
* @see FastScrollerView
3636
*/
3737
class FastScrollerThumbView @JvmOverloads constructor(
38-
context: Context,
39-
attrs: AttributeSet? = null,
40-
defStyleAttr: Int = R.attr.indicatorFastScrollerThumbStyle
38+
context: Context,
39+
attrs: AttributeSet? = null,
40+
defStyleAttr: Int = R.attr.indicatorFastScrollerThumbStyle
4141
) : ConstraintLayout(
42-
context,
43-
attrs,
44-
defStyleAttr
42+
context,
43+
attrs,
44+
defStyleAttr
4545
), FastScrollerView.ItemIndicatorSelectedCallback {
4646

4747
var thumbColor: ColorStateList by onUpdate(::applyStyle)
@@ -60,16 +60,17 @@ class FastScrollerThumbView @JvmOverloads constructor(
6060

6161
init {
6262
context.theme.obtainStyledAttributes(
63-
attrs,
64-
R.styleable.FastScrollerThumbView,
65-
defStyleAttr,
66-
R.style.Widget_IndicatorFastScroll_FastScrollerThumb
63+
attrs,
64+
R.styleable.FastScrollerThumbView,
65+
defStyleAttr,
66+
R.style.Widget_IndicatorFastScroll_FastScrollerThumb
6767
).use { attrsArray ->
6868
throwIfMissingAttrs(styleRes = R.style.Widget_IndicatorFastScroll_FastScrollerThumb) {
69-
thumbColor = attrsArray.getColorStateListOrThrow(R.styleable.FastScrollerThumbView_thumbColor)
69+
thumbColor = attrsArray
70+
.getColorStateListOrThrow(R.styleable.FastScrollerThumbView_thumbColor)
7071
iconColor = attrsArray.getColorOrThrow(R.styleable.FastScrollerThumbView_iconColor)
7172
textAppearanceRes = attrsArray.getResourceIdOrThrow(
72-
R.styleable.FastScrollerThumbView_android_textAppearance
73+
R.styleable.FastScrollerThumbView_android_textAppearance
7374
)
7475
textColor = attrsArray.getColorOrThrow(R.styleable.FastScrollerThumbView_android_textColor)
7576
}
@@ -131,9 +132,9 @@ class FastScrollerThumbView @JvmOverloads constructor(
131132
}
132133

133134
override fun onItemIndicatorSelected(
134-
indicator: FastScrollItemIndicator,
135-
indicatorCenterY: Int,
136-
itemPosition: Int
135+
indicator: FastScrollItemIndicator,
136+
indicatorCenterY: Int,
137+
itemPosition: Int
137138
) {
138139
val thumbTargetY = indicatorCenterY.toFloat() - (thumbView.measuredHeight / 2)
139140
thumbAnimation.animateToFinalPosition(thumbTargetY)
@@ -153,5 +154,4 @@ class FastScrollerThumbView @JvmOverloads constructor(
153154
}
154155
}
155156
}
156-
157157
}

indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerView.kt

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ typealias ItemIndicatorWithPosition = Pair<FastScrollItemIndicator, Int>
3434
* @see FastScrollerThumbView
3535
*/
3636
class FastScrollerView @JvmOverloads constructor(
37-
context: Context,
38-
attrs: AttributeSet? = null,
39-
defStyleAttr: Int = R.attr.indicatorFastScrollerStyle,
40-
defStyleRes: Int = R.style.Widget_IndicatorFastScroll_FastScroller
37+
context: Context,
38+
attrs: AttributeSet? = null,
39+
defStyleAttr: Int = R.attr.indicatorFastScrollerStyle,
40+
defStyleRes: Int = R.style.Widget_IndicatorFastScroll_FastScroller
4141
) : LinearLayout(
42-
context,
43-
attrs,
44-
defStyleAttr,
45-
defStyleRes
42+
context,
43+
attrs,
44+
defStyleAttr,
45+
defStyleRes
4646
) {
4747

4848
var iconColor: ColorStateList? by onUpdate(::bindItemIndicatorViews)
@@ -93,17 +93,18 @@ class FastScrollerView @JvmOverloads constructor(
9393

9494
init {
9595
context.theme.obtainStyledAttributes(
96-
attrs,
97-
R.styleable.FastScrollerView,
98-
defStyleAttr,
99-
defStyleRes
96+
attrs,
97+
R.styleable.FastScrollerView,
98+
defStyleAttr,
99+
defStyleRes
100100
).use { attrsArray ->
101101
throwIfMissingAttrs(styleRes = R.style.Widget_IndicatorFastScroll_FastScroller) {
102102
iconColor = attrsArray.getColorStateListOrThrow(R.styleable.FastScrollerView_iconColor)
103103
textAppearanceRes = attrsArray.getResourceIdOrThrow(
104-
R.styleable.FastScrollerView_android_textAppearance
104+
R.styleable.FastScrollerView_android_textAppearance
105105
)
106-
textColor = attrsArray.getColorStateListOrThrow(R.styleable.FastScrollerView_android_textColor)
106+
textColor = attrsArray
107+
.getColorStateListOrThrow(R.styleable.FastScrollerView_android_textColor)
107108
textPadding = attrsArray.getDimensionOrThrow(R.styleable.FastScrollerView_textPadding)
108109
}
109110
}
@@ -115,11 +116,11 @@ class FastScrollerView @JvmOverloads constructor(
115116

116117
if (isInEditMode) {
117118
itemIndicatorsWithPositions += listOf(
118-
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("A"), 0),
119-
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("B"), 1),
120-
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("C"), 2),
121-
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("D"), 3),
122-
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("E"), 4)
119+
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("A"), 0),
120+
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("B"), 1),
121+
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("C"), 2),
122+
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("D"), 3),
123+
ItemIndicatorWithPosition(FastScrollItemIndicator.Text("E"), 4)
123124
)
124125
bindItemIndicatorViews()
125126
}
@@ -149,10 +150,10 @@ class FastScrollerView @JvmOverloads constructor(
149150
*/
150151
@JvmOverloads
151152
fun setupWithRecyclerView(
152-
recyclerView: RecyclerView,
153-
getItemIndicator: (Int) -> FastScrollItemIndicator?,
154-
showIndicator: ((FastScrollItemIndicator, Int, Int) -> Boolean)? = null,
155-
useDefaultScroller: Boolean = true
153+
recyclerView: RecyclerView,
154+
getItemIndicator: (Int) -> FastScrollItemIndicator?,
155+
showIndicator: ((FastScrollItemIndicator, Int, Int) -> Boolean)? = null,
156+
useDefaultScroller: Boolean = true
156157
) {
157158
if (isSetup) throw IllegalStateException("Only set this view's RecyclerView once!")
158159
this.recyclerView = recyclerView
@@ -162,24 +163,24 @@ class FastScrollerView @JvmOverloads constructor(
162163

163164
updateItemIndicators()
164165
val adapter = recyclerView.adapter ?: throw IllegalArgumentException(
165-
"RecyclerView needs to have an adapter before setting up its fast scroller."
166+
"RecyclerView needs to have an adapter before setting up its fast scroller."
166167
)
167168
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
168169
override fun onChanged() {
169170
postUpdateItemIndicators()
170171
}
171172

172173
override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) =
173-
onChanged()
174+
onChanged()
174175

175176
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) =
176-
onChanged()
177+
onChanged()
177178

178179
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) =
179-
onChanged()
180+
onChanged()
180181

181182
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) =
182-
onChanged()
183+
onChanged()
183184
})
184185
}
185186

@@ -198,8 +199,8 @@ class FastScrollerView @JvmOverloads constructor(
198199
private fun updateItemIndicators() {
199200
itemIndicatorsWithPositions.clear()
200201
itemIndicatorsBuilder
201-
.buildItemIndicators(recyclerView!!, getItemIndicator, showIndicator)
202-
.toCollection(itemIndicatorsWithPositions)
202+
.buildItemIndicators(recyclerView!!, getItemIndicator, showIndicator)
203+
.toCollection(itemIndicatorsWithPositions)
203204

204205
bindItemIndicatorViews()
205206
}
@@ -212,25 +213,25 @@ class FastScrollerView @JvmOverloads constructor(
212213
}
213214

214215
fun createIconView(iconIndicator: FastScrollItemIndicator.Icon): ImageView =
215-
(LayoutInflater.from(context).inflate(
216-
R.layout.fast_scroller_indicator_icon, this, false
217-
) as ImageView).apply {
218-
iconColor?.let(::setImageTintList)
219-
setImageResource(iconIndicator.iconRes)
220-
tag = iconIndicator
221-
}
216+
(LayoutInflater.from(context).inflate(
217+
R.layout.fast_scroller_indicator_icon, this, false
218+
) as ImageView).apply {
219+
iconColor?.let(::setImageTintList)
220+
setImageResource(iconIndicator.iconRes)
221+
tag = iconIndicator
222+
}
222223

223224
fun createTextView(textIndicators: List<FastScrollItemIndicator.Text>): TextView =
224-
(LayoutInflater.from(context).inflate(
225-
R.layout.fast_scroller_indicator_text, this, false
226-
) as TextView).apply {
227-
TextViewCompat.setTextAppearance(this, textAppearanceRes)
228-
textColor?.let(::setTextColor)
229-
updatePadding(top = textPadding.toInt(), bottom = textPadding.toInt())
230-
setLineSpacing(textPadding, lineSpacingMultiplier)
231-
text = textIndicators.joinToString(separator = "\n") { it.text }
232-
tag = textIndicators
233-
}
225+
(LayoutInflater.from(context).inflate(
226+
R.layout.fast_scroller_indicator_text, this, false
227+
) as TextView).apply {
228+
TextViewCompat.setTextAppearance(this, textAppearanceRes)
229+
textColor?.let(::setTextColor)
230+
updatePadding(top = textPadding.toInt(), bottom = textPadding.toInt())
231+
setLineSpacing(textPadding, lineSpacingMultiplier)
232+
text = textIndicators.joinToString(separator = "\n") { it.text }
233+
tag = textIndicators
234+
}
234235

235236
// Optimize the views by batching adjacent text indicators into a single TextView
236237
val viewCreators = ArrayList<() -> View>()
@@ -239,8 +240,8 @@ class FastScrollerView @JvmOverloads constructor(
239240
while (index <= lastIndex) {
240241
@Suppress("UNCHECKED_CAST")
241242
val textIndicatorsBatch = subList(index, size)
242-
.takeWhile { it is FastScrollItemIndicator.Text }
243-
as List<FastScrollItemIndicator.Text>
243+
.takeWhile { it is FastScrollItemIndicator.Text }
244+
as List<FastScrollItemIndicator.Text>
244245
if (textIndicatorsBatch.isNotEmpty()) {
245246
viewCreators.add { createTextView(textIndicatorsBatch) }
246247
index += textIndicatorsBatch.size
@@ -264,24 +265,24 @@ class FastScrollerView @JvmOverloads constructor(
264265
}
265266

266267
private fun selectItemIndicator(
267-
indicator: FastScrollItemIndicator,
268-
indicatorCenterY: Int
268+
indicator: FastScrollItemIndicator,
269+
indicatorCenterY: Int
269270
) {
270271
val position = itemIndicatorsWithPositions
271-
.first { it.first == indicator }
272-
.let(ItemIndicatorWithPosition::second)
272+
.first { it.first == indicator }
273+
.let(ItemIndicatorWithPosition::second)
273274
if (position != lastSelectedPosition) {
274275
lastSelectedPosition = position
275276
if (useDefaultScroller) {
276277
scrollToPosition(position)
277278
}
278279
performHapticFeedback(
279-
// Semantically, dragging across the indicators is similar to moving a text handle
280-
if (Build.VERSION.SDK_INT >= 27) {
281-
HapticFeedbackConstants.TEXT_HANDLE_MOVE
282-
} else {
283-
HapticFeedbackConstants.KEYBOARD_TAP
284-
}
280+
// Semantically, dragging across the indicators is similar to moving a text handle
281+
if (Build.VERSION.SDK_INT >= 27) {
282+
HapticFeedbackConstants.TEXT_HANDLE_MOVE
283+
} else {
284+
HapticFeedbackConstants.KEYBOARD_TAP
285+
}
285286
)
286287
itemIndicatorSelectedCallbacks.forEach {
287288
it.onItemIndicatorSelected(indicator, indicatorCenterY, position)
@@ -324,13 +325,13 @@ class FastScrollerView @JvmOverloads constructor(
324325
val textIndicatorsTouchY = touchY - view.top
325326
val textLineHeight = view.height / possibleTouchedIndicators.size
326327
val touchedIndicatorIndex = Math.min(
327-
textIndicatorsTouchY / textLineHeight,
328-
possibleTouchedIndicators.lastIndex
328+
textIndicatorsTouchY / textLineHeight,
329+
possibleTouchedIndicators.lastIndex
329330
)
330331
val touchedIndicator = possibleTouchedIndicators[touchedIndicatorIndex]
331332

332333
val centerY = view.y.toInt() +
333-
(textLineHeight / 2) + (touchedIndicatorIndex * textLineHeight)
334+
(textLineHeight / 2) + (touchedIndicatorIndex * textLineHeight)
334335
selectItemIndicator(touchedIndicator, centerY)
335336
consumed = true
336337
}
@@ -341,15 +342,14 @@ class FastScrollerView @JvmOverloads constructor(
341342
isPressed = consumed
342343

343344
onItemIndicatorTouched?.invoke(consumed)
344-
return consumed;
345+
return consumed
345346
}
346347

347348
interface ItemIndicatorSelectedCallback {
348349
fun onItemIndicatorSelected(
349-
indicator: FastScrollItemIndicator,
350-
indicatorCenterY: Int,
351-
itemPosition: Int
350+
indicator: FastScrollItemIndicator,
351+
indicatorCenterY: Int,
352+
itemPosition: Int
352353
)
353354
}
354-
355355
}

indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/ItemIndicatorsUpdater.kt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ import androidx.recyclerview.widget.RecyclerView
55
internal open class ItemIndicatorsBuilder {
66

77
open fun buildItemIndicators(
8-
recyclerView: RecyclerView,
9-
getItemIndicator: (Int) -> FastScrollItemIndicator?,
10-
showIndicator: ((FastScrollItemIndicator, Int, Int) -> Boolean)?
8+
recyclerView: RecyclerView,
9+
getItemIndicator: (Int) -> FastScrollItemIndicator?,
10+
showIndicator: ((FastScrollItemIndicator, Int, Int) -> Boolean)?
1111
): List<ItemIndicatorWithPosition> {
1212
return (0 until recyclerView.adapter!!.itemCount)
13-
.mapNotNull { position ->
14-
getItemIndicator(position)?.let { ItemIndicatorWithPosition(it, position) }
15-
}
16-
.distinctBy(ItemIndicatorWithPosition::first)
17-
.let { unfilteredIndicators ->
18-
showIndicator?.let {
19-
unfilteredIndicators.filterIndexed { index, (indicator, _) ->
20-
it(indicator, index, unfilteredIndicators.size)
21-
}
22-
} ?: unfilteredIndicators
23-
}
13+
.mapNotNull { position ->
14+
getItemIndicator(position)?.let { ItemIndicatorWithPosition(it, position) }
15+
}
16+
.distinctBy(ItemIndicatorWithPosition::first)
17+
.let { unfilteredIndicators ->
18+
showIndicator?.let {
19+
unfilteredIndicators.filterIndexed { index, (indicator, _) ->
20+
it(indicator, index, unfilteredIndicators.size)
21+
}
22+
} ?: unfilteredIndicators
23+
}
2424
}
25-
2625
}

indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/ResourcesUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ internal fun View.throwIfMissingAttrs(@StyleRes styleRes: Int, block: () -> Unit
3333
block()
3434
} catch (e: IllegalArgumentException) {
3535
throw IllegalArgumentException(
36-
"This ${this::class.java.simpleName} is missing an attribute. " +
37-
"Add it to its style, or make the style inherit from " +
38-
"${resources.getResourceName(styleRes)}.",
39-
e
36+
"This ${this::class.java.simpleName} is missing an attribute. " +
37+
"Add it to its style, or make the style inherit from " +
38+
"${resources.getResourceName(styleRes)}.",
39+
e
4040
)
4141
}
4242
}

indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/UpdateDelegate.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ internal class UpdateDelegate<T>(val update: () -> Unit) : ReadWriteProperty<Any
2424
update()
2525
}
2626
}
27-
2827
}
2928

3029
/**

0 commit comments

Comments
 (0)