forked from upstream-mirrors/quik
Move hsl picker logic to custom view
This commit is contained in:
@@ -20,14 +20,10 @@ package feature.themepicker
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.view.MotionEvent
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.base.QkThemedActivity
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.within
|
||||
import injection.appComponent
|
||||
import kotlinx.android.synthetic.main.theme_picker_activity.*
|
||||
import kotlinx.android.synthetic.main.theme_picker_hsl.*
|
||||
@@ -42,8 +38,6 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
|
||||
@Inject lateinit var themeAdapter: ThemeAdapter
|
||||
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
|
||||
|
||||
private val swatchPadding by lazy { 18.dpToPx(this) }
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
@@ -67,36 +61,12 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
|
||||
colors.background
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
|
||||
var dX = 0f
|
||||
var dY = 0f
|
||||
|
||||
saturation.setOnTouchListener { _, event ->
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
dX = event.x - event.rawX
|
||||
dY = event.y - event.rawY
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val min = saturation.x - swatch.width / 2
|
||||
val max = min + saturation.width
|
||||
|
||||
swatch.x = (event.rawX + dX + swatchPadding).within(min, max)
|
||||
swatch.y = (event.rawY + dY + swatchPadding).within(min, max)
|
||||
}
|
||||
|
||||
else -> return@setOnTouchListener false
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(state: ThemePickerState) {
|
||||
themeAdapter.threadId = state.threadId
|
||||
themeAdapter.selectedColor = state.selectedColor
|
||||
|
||||
saturation.setBackgroundTint(state.hue)
|
||||
swatchPreview.setBackgroundTint(state.selectedColor)
|
||||
picker.setColor(state.selectedColor)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user