forked from upstream-mirrors/quik
Move packages to com.moez.QKSMS
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.support.constraint.ConstraintLayout
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.within
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.hsv_picker_view.view.*
|
||||
|
||||
class HSVPickerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ConstraintLayout(context, attrs) {
|
||||
|
||||
val selectedColor: Subject<Int> = BehaviorSubject.create()
|
||||
|
||||
private val hues = arrayOf(0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF, 0xFFFF0000)
|
||||
.map { it.toInt() }.toIntArray()
|
||||
|
||||
private var min: Float = 0f
|
||||
private var max = 0f
|
||||
|
||||
private var hue = 0f
|
||||
set(value) {
|
||||
field = value
|
||||
updateHue()
|
||||
}
|
||||
|
||||
init {
|
||||
View.inflate(context, R.layout.hsv_picker_view, this)
|
||||
|
||||
var swatchX = 0f
|
||||
var swatchY = 0f
|
||||
|
||||
saturation.setOnTouchListener { _, event ->
|
||||
setupBounds()
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
swatchX = event.x - event.rawX
|
||||
swatchY = event.y - event.rawY
|
||||
parent.requestDisallowInterceptTouchEvent(true)
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
// Calculate the new x/y position
|
||||
swatch.x = (event.rawX + swatchX + min).within(min, max)
|
||||
swatch.y = (event.rawY + swatchY + min).within(min, max)
|
||||
|
||||
updateSelectedColor()
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP -> {
|
||||
parent.requestDisallowInterceptTouchEvent(false)
|
||||
}
|
||||
|
||||
else -> return@setOnTouchListener false
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
var hueThumbX = 0f
|
||||
|
||||
hueGroup.setOnTouchListener { _, event ->
|
||||
setupBounds()
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
hueThumbX = event.x - event.rawX
|
||||
parent.requestDisallowInterceptTouchEvent(true)
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val x = (event.rawX + hueThumbX + min).within(min, max)
|
||||
|
||||
hueThumb.x = x
|
||||
hue = (hueThumb.x - min) / (max - min) * 360
|
||||
|
||||
updateSelectedColor()
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP -> {
|
||||
parent.requestDisallowInterceptTouchEvent(false)
|
||||
}
|
||||
|
||||
else -> return@setOnTouchListener false
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
hueTrack.clipToOutline = true
|
||||
hueTrack.setImageDrawable(GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, hues))
|
||||
}
|
||||
|
||||
private fun setupBounds() {
|
||||
if (min == 0f || max == 0f) {
|
||||
min = saturation.x - swatch.width / 2
|
||||
max = min + saturation.width
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSelectedColor() {
|
||||
setupBounds()
|
||||
|
||||
val range = max - min
|
||||
val hsv = floatArrayOf(hue, (swatch.x - min) / range, 1 - (swatch.y - min) / range)
|
||||
val color = Color.HSVToColor(hsv)
|
||||
|
||||
swatch.setTint(color)
|
||||
selectedColor.onNext(color)
|
||||
}
|
||||
|
||||
fun setColor(color: Int) {
|
||||
// Convert the rgb color to HSV
|
||||
val hsv = FloatArray(3).apply {
|
||||
Color.colorToHSV(color, this)
|
||||
hue = this[0]
|
||||
}
|
||||
|
||||
// Set the position of the swatch
|
||||
post {
|
||||
setupBounds()
|
||||
val range = max - min
|
||||
|
||||
hueThumb.x = range * hsv[0] / 360 + min
|
||||
swatch.x = range * hsv[1] + min
|
||||
swatch.y = range * (1 - hsv[2]) + min
|
||||
|
||||
updateSelectedColor()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateHue() {
|
||||
val hsv = floatArrayOf(hue, 1f, 1f)
|
||||
val tint = Color.HSVToColor(hsv)
|
||||
saturation.setBackgroundTint(tint)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.flexbox.FlexDirection
|
||||
import com.google.android.flexbox.FlexWrap
|
||||
import com.google.android.flexbox.FlexboxLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.theme_list_item.view.*
|
||||
import kotlinx.android.synthetic.main.theme_palette_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ThemeAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors
|
||||
) : QkAdapter<List<Int>>() {
|
||||
|
||||
val colorSelected: Subject<Int> = PublishSubject.create()
|
||||
|
||||
var selectedColor: Int = -1
|
||||
set(value) {
|
||||
val oldPosition = data.indexOfFirst { it.contains(field) }
|
||||
val newPosition = data.indexOfFirst { it.contains(value) }
|
||||
|
||||
field = value
|
||||
iconTint = colors.textPrimaryOnThemeForColor(value)
|
||||
|
||||
oldPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
|
||||
newPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
|
||||
}
|
||||
|
||||
private var iconTint = 0
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.theme_palette_list_item, parent, false)
|
||||
view.palette.flexWrap = FlexWrap.WRAP
|
||||
view.palette.flexDirection = FlexDirection.ROW
|
||||
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val palette = getItem(position)
|
||||
val view = holder.itemView
|
||||
|
||||
val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
||||
val minPadding = (16 * 6).dpToPx(context)
|
||||
val size = if (screenWidth - minPadding > (56 * 5).dpToPx(context)) {
|
||||
56.dpToPx(context)
|
||||
} else {
|
||||
(screenWidth - minPadding) / 5
|
||||
}
|
||||
val swatchPadding = (screenWidth - size * 5) / 12
|
||||
|
||||
view.palette.removeAllViews()
|
||||
view.palette.setPadding(swatchPadding, swatchPadding, swatchPadding, swatchPadding)
|
||||
|
||||
(palette.subList(0, 5) + palette.subList(5, 10).reversed())
|
||||
.mapIndexed { index, color ->
|
||||
LayoutInflater.from(context).inflate(R.layout.theme_list_item, view.palette, false).apply {
|
||||
|
||||
// Send clicks to the selected subject
|
||||
setOnClickListener { colorSelected.onNext(color) }
|
||||
|
||||
// Apply the color to the view
|
||||
theme.setBackgroundTint(color)
|
||||
|
||||
// Control the check visibility and tint
|
||||
check.setVisible(color == selectedColor)
|
||||
check.setTint(iconTint)
|
||||
|
||||
// Update the size so that the spacing is perfectly even
|
||||
layoutParams = (layoutParams as FlexboxLayout.LayoutParams).apply {
|
||||
height = size
|
||||
width = size
|
||||
isWrapBefore = index % 5 == 0
|
||||
setMargins(swatchPadding, swatchPadding, swatchPadding, swatchPadding)
|
||||
}
|
||||
}
|
||||
}
|
||||
.forEach { theme -> view.palette.addView(theme) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.view.PagerAdapter
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import javax.inject.Inject
|
||||
|
||||
class ThemePagerAdapter @Inject constructor(private val context: Context) : PagerAdapter() {
|
||||
|
||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||
return when (position) {
|
||||
1 -> container.findViewById(R.id.hsvPicker)
|
||||
else -> container.findViewById(R.id.materialColors)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
return when (position) {
|
||||
1 -> context.getString(R.string.theme_plus)
|
||||
else -> context.getString(R.string.theme_material)
|
||||
}
|
||||
}
|
||||
|
||||
override fun isViewFromObject(view: View, `object`: Any): Boolean {
|
||||
return view == `object`
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return 2
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkThemedActivity
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import dagger.android.AndroidInjection
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.theme_picker_activity.*
|
||||
import kotlinx.android.synthetic.main.theme_picker_hsv.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ThemePickerActivity : QkThemedActivity(), ThemePickerView {
|
||||
|
||||
@Inject lateinit var themeAdapter: ThemeAdapter
|
||||
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
override val themeSelectedIntent by lazy { themeAdapter.colorSelected }
|
||||
override val hsvThemeSelectedIntent by lazy { picker.selectedColor }
|
||||
override val hsvThemeClearedIntent by lazy { clear.clicks() }
|
||||
override val hsvThemeAppliedIntent by lazy { apply.clicks() }
|
||||
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ThemePickerViewModel::class.java] }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.theme_picker_activity)
|
||||
setTitle(R.string.title_theme)
|
||||
showBackButton(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
pager.offscreenPageLimit = 1
|
||||
pager.adapter = themePagerAdapter
|
||||
tabs.pager = pager
|
||||
|
||||
themeAdapter.data = colors.materialColors
|
||||
|
||||
materialColors.layoutManager = LinearLayoutManager(this)
|
||||
materialColors.adapter = themeAdapter
|
||||
}
|
||||
|
||||
override fun showQksmsPlusSnackbar() {
|
||||
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
||||
setAction(R.string.button_more, { viewQksmsPlusIntent.onNext(Unit) })
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(state: ThemePickerState) {
|
||||
tabs.setThreadId(state.threadId)
|
||||
|
||||
hex.setText(Integer.toHexString(state.newColor).takeLast(6))
|
||||
|
||||
applyGroup.setVisible(state.applyThemeVisible)
|
||||
apply.setBackgroundTint(state.newColor)
|
||||
apply.setTextColor(state.newTextColor)
|
||||
}
|
||||
|
||||
override fun setCurrentTheme(color: Int) {
|
||||
picker.setColor(color)
|
||||
themeAdapter.selectedColor = color
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import com.moez.QKSMS.injection.ViewModelKey
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoMap
|
||||
import javax.inject.Named
|
||||
|
||||
@Module
|
||||
class ThemePickerActivityModule {
|
||||
|
||||
@Provides
|
||||
@Named("threadId")
|
||||
fun provideThreadId(activity: ThemePickerActivity): Long = activity.intent.extras?.getLong("threadId") ?: 0L
|
||||
|
||||
@Provides
|
||||
@IntoMap
|
||||
@ViewModelKey(ThemePickerViewModel::class)
|
||||
fun provideThemePickerViewModel(viewModel: ThemePickerViewModel): ViewModel = viewModel
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
data class ThemePickerState(
|
||||
val threadId: Long = 0,
|
||||
val applyThemeVisible: Boolean = false,
|
||||
val newColor: Int = -1,
|
||||
val newTextColor: Int = -1
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
import com.moez.QKSMS.common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
interface ThemePickerView : QkView<ThemePickerState> {
|
||||
|
||||
val themeSelectedIntent: Observable<Int>
|
||||
val hsvThemeSelectedIntent: Observable<Int>
|
||||
val hsvThemeClearedIntent: Observable<*>
|
||||
val hsvThemeAppliedIntent: Observable<*>
|
||||
val viewQksmsPlusIntent: Subject<Unit>
|
||||
|
||||
fun setCurrentTheme(color: Int)
|
||||
fun showQksmsPlusSnackbar()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.themepicker
|
||||
|
||||
import com.f2prateek.rx.preferences2.Preference
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkViewModel
|
||||
import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class ThemePickerViewModel @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
private val billingManager: BillingManager,
|
||||
private val colors: Colors,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
) : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = threadId)) {
|
||||
|
||||
private val theme: Preference<Int> = prefs.theme(threadId)
|
||||
|
||||
override fun bindView(view: ThemePickerView) {
|
||||
super.bindView(view)
|
||||
|
||||
theme.asObservable()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { color -> view.setCurrentTheme(color) }
|
||||
|
||||
// Update the theme when a material theme is clicked
|
||||
view.themeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { color -> theme.set(color) }
|
||||
|
||||
// Update the color of the apply button
|
||||
view.hsvThemeSelectedIntent
|
||||
.doOnNext { color -> newState { copy(newColor = color) } }
|
||||
.map { color -> colors.textPrimaryOnThemeForColor(color) }
|
||||
.doOnNext { color -> newState { copy(newTextColor = color) } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Toggle the visibility of the apply group
|
||||
Observables.combineLatest(theme.asObservable(), view.hsvThemeSelectedIntent, { old, new -> old != new })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { themeChanged -> newState { copy(applyThemeVisible = themeChanged) } }
|
||||
|
||||
// Update the theme, when apply is clicked
|
||||
view.hsvThemeAppliedIntent
|
||||
.withLatestFrom(view.hsvThemeSelectedIntent, { _, color -> color })
|
||||
.withLatestFrom(billingManager.upgradeStatus, { color, upgraded ->
|
||||
if (!upgraded) {
|
||||
view.showQksmsPlusSnackbar()
|
||||
} else {
|
||||
theme.set(color)
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Show QKSMS+ activity
|
||||
view.viewQksmsPlusIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showQksmsPlusActivity() }
|
||||
|
||||
// Reset the theme
|
||||
view.hsvThemeClearedIntent
|
||||
.withLatestFrom(theme.asObservable(), { _, color -> color })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { color -> view.setCurrentTheme(color) }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user