mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Add isInEditMode support for QkSwitch
This commit is contained in:
@@ -35,27 +35,31 @@ class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet?
|
|||||||
@Inject lateinit var colors: Colors
|
@Inject lateinit var colors: Colors
|
||||||
|
|
||||||
init {
|
init {
|
||||||
appComponent.inject(this)
|
if (!isInEditMode) {
|
||||||
|
appComponent.inject(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
|
|
||||||
val states = arrayOf(
|
if (!isInEditMode) {
|
||||||
intArrayOf(-android.R.attr.state_enabled),
|
val states = arrayOf(
|
||||||
intArrayOf(android.R.attr.state_checked),
|
intArrayOf(-android.R.attr.state_enabled),
|
||||||
intArrayOf())
|
intArrayOf(android.R.attr.state_checked),
|
||||||
|
intArrayOf())
|
||||||
|
|
||||||
Observables.combineLatest(colors.theme, colors.switchThumbEnabled, colors.switchThumbDisabled,
|
Observables.combineLatest(colors.theme, colors.switchThumbEnabled, colors.switchThumbDisabled,
|
||||||
{ color, enabled, disabled -> intArrayOf(disabled, color, enabled) })
|
{ color, enabled, disabled -> intArrayOf(disabled, color, enabled) })
|
||||||
.map { values -> ColorStateList(states, values) }
|
.map { values -> ColorStateList(states, values) }
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { tintList -> thumbTintList = tintList }
|
.subscribe { tintList -> thumbTintList = tintList }
|
||||||
|
|
||||||
Observables.combineLatest(colors.theme, colors.switchTrackEnabled, colors.switchTrackDisabled,
|
Observables.combineLatest(colors.theme, colors.switchTrackEnabled, colors.switchTrackDisabled,
|
||||||
{ color, enabled, disabled -> intArrayOf(disabled, color.withAlpha(0x4D), enabled) })
|
{ color, enabled, disabled -> intArrayOf(disabled, color.withAlpha(0x4D), enabled) })
|
||||||
.map { values -> ColorStateList(states, values) }
|
.map { values -> ColorStateList(states, values) }
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { tintList -> trackTintList = tintList }
|
.subscribe { tintList -> trackTintList = tintList }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user