mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Allow dragging swatch
This commit is contained in:
@@ -20,6 +20,7 @@ package feature.themepicker
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
|
import android.view.MotionEvent
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.uber.autodispose.android.lifecycle.scope
|
import com.uber.autodispose.android.lifecycle.scope
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
@@ -30,6 +31,7 @@ import kotlinx.android.synthetic.main.theme_picker_activity.*
|
|||||||
import kotlinx.android.synthetic.main.theme_picker_hsl.*
|
import kotlinx.android.synthetic.main.theme_picker_hsl.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePickerView {
|
class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePickerView {
|
||||||
|
|
||||||
override val viewModelClass = ThemePickerViewModel::class
|
override val viewModelClass = ThemePickerViewModel::class
|
||||||
@@ -61,13 +63,41 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
|
|||||||
colors.background
|
colors.background
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||||
|
|
||||||
|
var dX = 0f
|
||||||
|
var dY = 0f
|
||||||
|
|
||||||
|
hue.setOnTouchListener { _, event ->
|
||||||
|
when (event.action) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
dX = swatch.x - event.rawX
|
||||||
|
dY = swatch.y - event.rawY
|
||||||
|
|
||||||
|
swatch.animate()
|
||||||
|
.x(event.rawX + dX)
|
||||||
|
.y(event.rawY + dY)
|
||||||
|
.setDuration(0)
|
||||||
|
.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
MotionEvent.ACTION_MOVE ->
|
||||||
|
swatch.animate()
|
||||||
|
.x(event.rawX + dX)
|
||||||
|
.y(event.rawY + dY)
|
||||||
|
.setDuration(0)
|
||||||
|
.start()
|
||||||
|
|
||||||
|
else -> return@setOnTouchListener false
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(state: ThemePickerState) {
|
override fun render(state: ThemePickerState) {
|
||||||
hue.setBackgroundTint(state.hue)
|
|
||||||
|
|
||||||
themeAdapter.threadId = state.threadId
|
themeAdapter.threadId = state.threadId
|
||||||
themeAdapter.selectedColor = state.selectedColor
|
themeAdapter.selectedColor = state.selectedColor
|
||||||
}
|
|
||||||
|
|
||||||
|
hue.setBackgroundTint(state.hue)
|
||||||
|
swatchPreview.setBackgroundTint(state.selectedColor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -29,4 +29,26 @@
|
|||||||
app:layout_constraintStart_toStartOf="@id/hue"
|
app:layout_constraintStart_toStartOf="@id/hue"
|
||||||
app:layout_constraintTop_toTopOf="@id/hue" />
|
app:layout_constraintTop_toTopOf="@id/hue" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/swatch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="18dp">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="12dp"
|
||||||
|
android:layout_height="12dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/circle" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/swatchPreview"
|
||||||
|
android:layout_width="10dp"
|
||||||
|
android:layout_height="10dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/circle"
|
||||||
|
tools:backgroundTint="@color/tools_theme" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user