forked from upstream-mirrors/quik
Squashed commit of the following:
commit 1f890b96beb893c866ed9b47d8e3a9ac6e20662f Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed Jan 31 17:41:22 2018 -0500 Clean up bindView in PlusViewModel commit c71f4853d385df66a79f9372ecf29507cb64152b Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed Jan 31 02:14:37 2018 -0500 Move QKSMS+ to sliding menu commit a23d1dd6d314935cd96c530e3419a3a2ca4cab27 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed Jan 31 00:28:42 2018 -0500 Make selected plan more visible commit 540cda206ede1d3b81d7d42438257f76f9f07cd4 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed Jan 31 00:27:03 2018 -0500 Allow changing dynamic textcolor programatically commit 859325dd5ffa7aa5958ae2eb5c9eac62bcb8f7bd Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Tue Jan 30 22:26:41 2018 -0500 Dark mode support for ripple selected state commit 6a1d5c387fe0a08ef05573f3f07a1cd82b1a37ec Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Tue Jan 30 22:18:27 2018 -0500 Remove explicit upgrade button, click plan to buy commit 4a6e85b0c513c8604f8993f78add2b3910c0b49d Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Tue Jan 30 20:43:09 2018 -0500 Show thank you UI if user has upgraded commit 080fccf40b4461b6a833ba77fce1267bd8251281 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Tue Jan 30 17:52:02 2018 -0500 Allow changing plans commit ac122f138b1840de39f7a7bd1fb36727056233e1 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Tue Jan 30 16:33:59 2018 -0500 Allow purchase of subscription commit 3e689443ec197a929308d9add270ae6777cdeae1 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 23:21:31 2018 -0500 Allow selection of different plans commit d51a90160898b39de5ba4e69fdc8351e2fe7093c Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 19:42:56 2018 -0500 Collapsing toolbar for QKSMS+ activity commit 06c0d5a834884f144ad7e149b7dea3b0ba38b643 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 18:02:05 2018 -0500 Display pricing information in QKSMS+ activity commit c0be51eec5e1b091dbe8ba69f28c48e5379011f3 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 17:26:16 2018 -0500 Add ability to view QKSMS+ activity from settings commit 51e7782a274503401d53a22ccbe55eab2523f200 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 15:41:40 2018 -0500 Indicate currently selected theme commit 0b3bb3e24b3c40ac517cf05404638061f9b520b8 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 15:19:28 2018 -0500 Move ThemeAdapter package commit 828b6fe10afd6493884ee8d1c472dcd39f5371d4 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 15:10:14 2018 -0500 Evenly space theme swatches with other items and borders commit 220499c0676f03c282b201dfd67faa10f20a546d Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Mon Jan 29 14:45:47 2018 -0500 Evenly distribute theme swatches commit 4d0995da773f720411b22091fc58d03497d38438 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun Jan 28 22:53:49 2018 -0500 Use separate activity for Theme picker commit 3886c1890a6320667f9999071213f181e4e2de79 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun Jan 28 20:00:17 2018 -0500 Update more text commit 3e3995fdf58ee849f6fedabd895aff42f521e473 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun Jan 28 19:56:04 2018 -0500 Update text for blocking commit b8ffbf30761105abe1150279994c8d0ebd7a68b7 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun Jan 28 19:49:11 2018 -0500 Build layout for QKSMS+ activity commit 90518ad8291d5028ceb765ca60fe1d36a5edb33a Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun Jan 28 19:48:59 2018 -0500 Improve layout preview support for some custom views commit 3b301b641e1b747d0ac7192bb50e51d494fe6ef8 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun Jan 28 02:22:54 2018 -0500 Use up-to-date material design colors commit e8c9cec67767c8702f1b6ccf7ee89c22e585132c Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun Jan 28 01:21:24 2018 -0500 Add strings and icons for QKSMS+ features
This commit is contained in:
@@ -32,14 +32,17 @@ import common.util.NotificationManager
|
||||
import presentation.feature.compose.ComposeActivity
|
||||
import presentation.feature.compose.ComposeViewModel
|
||||
import presentation.feature.main.MainViewModel
|
||||
import presentation.feature.plus.PlusActivity
|
||||
import presentation.feature.plus.PlusViewModel
|
||||
import presentation.feature.settings.SettingsActivity
|
||||
import presentation.feature.settings.SettingsViewModel
|
||||
import presentation.feature.setup.SetupActivity
|
||||
import presentation.feature.setup.SetupViewModel
|
||||
import presentation.feature.themepicker.ThemePickerActivity
|
||||
import presentation.feature.themepicker.ThemePickerViewModel
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
@Singleton
|
||||
class Navigator @Inject constructor(val context: Context) {
|
||||
|
||||
@@ -53,6 +56,11 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showQksmsPlusActivity() {
|
||||
val intent = Intent(context, PlusActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showDefaultSmsDialog() {
|
||||
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
|
||||
if (Telephony.Sms.getDefaultSmsPackage(context) != context.packageName) {
|
||||
@@ -78,6 +86,11 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showThemePicker() {
|
||||
val intent = Intent(context, ThemePickerActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun makePhoneCall(address: String) {
|
||||
val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:$address"))
|
||||
startActivity(intent)
|
||||
@@ -110,9 +123,11 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
return when (modelClass) {
|
||||
MainViewModel::class.java -> MainViewModel()
|
||||
PlusViewModel::class.java -> PlusViewModel()
|
||||
SetupViewModel::class.java -> SetupViewModel()
|
||||
ComposeViewModel::class.java -> ComposeViewModel(intent)
|
||||
SettingsViewModel::class.java -> SettingsViewModel()
|
||||
ThemePickerViewModel::class.java -> ThemePickerViewModel()
|
||||
else -> throw IllegalArgumentException("Invalid ViewModel class. If this is a new ViewModel, please add it to Navigator.kt")
|
||||
} as T
|
||||
}
|
||||
|
||||
@@ -22,11 +22,13 @@ import android.content.Context
|
||||
import android.support.v7.widget.LinearLayoutCompat
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.Colors
|
||||
import common.util.extensions.getColorCompat
|
||||
import common.util.extensions.setTint
|
||||
import common.util.extensions.setVisible
|
||||
import kotlinx.android.synthetic.main.preference_view.view.*
|
||||
@@ -39,18 +41,34 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
var title: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
titleView.text = value
|
||||
|
||||
if (isInEditMode) {
|
||||
findViewById<TextView>(R.id.titleView).text = value
|
||||
} else {
|
||||
titleView.text = value
|
||||
}
|
||||
}
|
||||
|
||||
var summary: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
summaryView.text = value
|
||||
summaryView.setVisible(value?.isNotEmpty() == true)
|
||||
|
||||
|
||||
if (isInEditMode) {
|
||||
findViewById<TextView>(R.id.summaryView).run {
|
||||
text = value
|
||||
setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
} else {
|
||||
summaryView.text = value
|
||||
summaryView.setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
View.inflate(context, R.layout.preference_view, this)
|
||||
setBackgroundResource(R.drawable.ripple)
|
||||
@@ -77,9 +95,14 @@ class PreferenceView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
colors.textSecondary
|
||||
.autoDisposable(scope())
|
||||
.subscribe { icon.setTint(it) }
|
||||
|
||||
if (isInEditMode) {
|
||||
icon.setTint(context.getColorCompat(R.color.textSecondary))
|
||||
} else {
|
||||
colors.textSecondary
|
||||
.autoDisposable(scope())
|
||||
.subscribe { icon.setTint(it) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,46 +22,101 @@ import android.content.Context
|
||||
import android.support.v7.widget.AppCompatTextView
|
||||
import android.util.AttributeSet
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.Colors
|
||||
import common.util.extensions.getColorCompat
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import javax.inject.Inject
|
||||
|
||||
open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
|
||||
: AppCompatTextView(context, attrs) {
|
||||
|
||||
companion object {
|
||||
const val COLOR_PRIMARY = 0
|
||||
const val COLOR_SECONDARY = 1
|
||||
const val COLOR_TERTIARY = 2
|
||||
const val COLOR_PRIMARY_ON_THEME = 3
|
||||
const val COLOR_SECONDARY_ON_THEME = 4
|
||||
const val COLOR_TERTIARY_ON_THEME = 5
|
||||
}
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
|
||||
private var textColorDisposable: Disposable? = null
|
||||
private var textColorObservable: Observable<Int>? = null
|
||||
set(value) {
|
||||
if (field !== value) {
|
||||
field = value
|
||||
|
||||
if (isAttachedToWindow) {
|
||||
textColorDisposable?.let { disposable ->
|
||||
if (!disposable.isDisposed) {
|
||||
disposable.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
subscribeColorChanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
textColorObservable = when (getInt(R.styleable.QkTextView_textColor, -1)) {
|
||||
0 -> colors.textPrimary
|
||||
1 -> colors.textSecondary
|
||||
2 -> colors.textTertiary
|
||||
3 -> colors.textPrimaryOnTheme
|
||||
4 -> colors.textSecondaryOnTheme
|
||||
5 -> colors.textTertiaryOnTheme
|
||||
else -> null
|
||||
val colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||
if (isInEditMode) {
|
||||
setTextColor(context.getColorCompat(when (colorAttr) {
|
||||
COLOR_PRIMARY -> R.color.textPrimary
|
||||
COLOR_SECONDARY -> R.color.textSecondary
|
||||
COLOR_TERTIARY -> R.color.textTertiary
|
||||
COLOR_PRIMARY_ON_THEME -> R.color.textPrimaryDark
|
||||
COLOR_SECONDARY_ON_THEME -> R.color.textSecondaryDark
|
||||
COLOR_TERTIARY_ON_THEME -> R.color.textTertiaryDark
|
||||
else -> R.color.textPrimary
|
||||
}))
|
||||
} else {
|
||||
setColor(colorAttr)
|
||||
}
|
||||
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
textColorObservable
|
||||
?.autoDisposable(scope())
|
||||
fun setColor(colorAttr: Int) {
|
||||
textColorObservable = when (colorAttr) {
|
||||
COLOR_PRIMARY -> colors.textPrimary
|
||||
COLOR_SECONDARY -> colors.textSecondary
|
||||
COLOR_TERTIARY -> colors.textTertiary
|
||||
COLOR_PRIMARY_ON_THEME -> colors.textPrimaryOnTheme
|
||||
COLOR_SECONDARY_ON_THEME -> colors.textSecondaryOnTheme
|
||||
COLOR_TERTIARY_ON_THEME -> colors.textTertiaryOnTheme
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun subscribeColorChanges() {
|
||||
textColorDisposable = textColorObservable
|
||||
?.subscribe { color ->
|
||||
setTextColor(color)
|
||||
setLinkTextColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
|
||||
if (textColorDisposable?.isDisposed != false) {
|
||||
subscribeColorChanges()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
textColorDisposable?.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,10 +21,12 @@ package presentation.common.widget
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.Colors
|
||||
import common.util.extensions.getColorCompat
|
||||
import javax.inject.Inject
|
||||
|
||||
class Separator @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs) {
|
||||
@@ -32,14 +34,20 @@ class Separator @JvmOverloads constructor(context: Context, attrs: AttributeSet?
|
||||
@Inject lateinit var colors: Colors
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
|
||||
colors.separator
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> setBackgroundColor(color) }
|
||||
if (isInEditMode) {
|
||||
setBackgroundColor(context.getColorCompat(R.color.separatorLight))
|
||||
} else {
|
||||
colors.separator
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> setBackgroundColor(color) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
scheduled.clicks().map { DrawerItem.SCHEDULED },
|
||||
blocked.clicks().map { DrawerItem.BLOCKED },
|
||||
settings.clicks().map { DrawerItem.SETTINGS },
|
||||
plus.clicks().map { DrawerItem.PLUS },
|
||||
help.clicks().map { DrawerItem.HELP }))
|
||||
}
|
||||
override val conversationClickIntent by lazy { conversationsAdapter.clicks }
|
||||
@@ -159,6 +160,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
.doOnNext { tintList -> scheduledIcon.imageTintList = tintList }
|
||||
.doOnNext { tintList -> blockedIcon.imageTintList = tintList }
|
||||
.doOnNext { tintList -> settingsIcon.imageTintList = tintList }
|
||||
.doOnNext { tintList -> plusIcon.imageTintList = tintList }
|
||||
.doOnNext { tintList -> helpIcon.imageTintList = tintList }
|
||||
.autoDisposable(scope())
|
||||
.subscribe()
|
||||
|
||||
@@ -39,4 +39,4 @@ interface MainView : QkView<MainState> {
|
||||
|
||||
}
|
||||
|
||||
enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKED, SETTINGS, HELP }
|
||||
enum class DrawerItem { INBOX, ARCHIVED, SCHEDULED, BLOCKED, SETTINGS, PLUS, HELP }
|
||||
@@ -27,7 +27,6 @@ import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.BillingManager
|
||||
import common.util.extensions.toFlowable
|
||||
import common.util.filter.ConversationFilter
|
||||
import data.model.MenuItem
|
||||
@@ -40,14 +39,12 @@ import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.realm.Realm
|
||||
import presentation.common.Navigator
|
||||
import presentation.common.base.QkViewModel
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var billingManager: BillingManager
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var conversationFilter: ConversationFilter
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@@ -116,10 +113,6 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
}
|
||||
|
||||
markAllSeen.execute(Unit)
|
||||
|
||||
billingManager.purchases.subscribe { purchases -> Timber.v("Purchases: $purchases") }
|
||||
billingManager.iabs.subscribe { iabs -> Timber.v("IABs: $iabs") }
|
||||
billingManager.subs.subscribe { subs -> Timber.v("Subs: $subs") }
|
||||
}
|
||||
|
||||
override fun bindView(view: MainView) {
|
||||
@@ -157,6 +150,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
view.drawerItemIntent
|
||||
.doOnNext { newState { it.copy(drawerOpen = false) } }
|
||||
.doOnNext { if (it == DrawerItem.SETTINGS) navigator.showSettings() }
|
||||
.doOnNext { if (it == DrawerItem.PLUS) navigator.showQksmsPlusActivity() }
|
||||
.doOnNext { if (it == DrawerItem.HELP) navigator.showSupport() }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext {
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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 presentation.feature.plus
|
||||
|
||||
import android.os.Bundle
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.BillingManager
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setTint
|
||||
import common.util.extensions.setVisible
|
||||
import kotlinx.android.synthetic.main.qksms_plus_activity.*
|
||||
import presentation.common.base.QkActivity
|
||||
import presentation.common.widget.QkTextView
|
||||
|
||||
class PlusActivity : QkActivity<PlusViewModel>(), PlusView {
|
||||
|
||||
override val viewModelClass = PlusViewModel::class
|
||||
override val supporterSelectedIntent by lazy { supporter.clicks() }
|
||||
override val donorSelectedIntent by lazy { donor.clicks() }
|
||||
override val philanthropistSelectedIntent by lazy { philanthropist.clicks() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
appComponent.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.qksms_plus_activity)
|
||||
setTitle(R.string.title_qksms_plus)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
colors.textPrimary
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color ->
|
||||
collapsingToolbar.setCollapsedTitleTextColor(color)
|
||||
collapsingToolbar.setExpandedTitleColor(color)
|
||||
}
|
||||
|
||||
colors.background
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
|
||||
colors.separator
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> thanks.setBackgroundTint(color) }
|
||||
|
||||
colors.theme
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color ->
|
||||
thanksIcon.setTint(color)
|
||||
supporter.setBackgroundTint(color)
|
||||
donor.setBackgroundTint(color)
|
||||
philanthropist.setBackgroundTint(color)
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(state: PlusState) {
|
||||
description.text = getString(R.string.qksms_plus_description_summary, state.supporterPrice)
|
||||
|
||||
thanks.setVisible(state.currentPlan != BillingManager.UpgradeStatus.REGULAR)
|
||||
|
||||
val supportedSelected = state.currentPlan == BillingManager.UpgradeStatus.SUPPORTER
|
||||
supporter.isSelected = supportedSelected
|
||||
supporterPrice.text = state.supporterPrice
|
||||
supporterName.setColor(getPrimaryTextColorAttr(supportedSelected))
|
||||
supporterPrice.setColor(getPrimaryTextColorAttr(supportedSelected))
|
||||
supporterPeriod.setColor(getSecondaryTextColorAttr(supportedSelected))
|
||||
|
||||
val donorSelected = state.currentPlan == BillingManager.UpgradeStatus.DONOR
|
||||
donor.isSelected = donorSelected
|
||||
donorPrice.text = state.donorPrice
|
||||
donorName.setColor(getPrimaryTextColorAttr(donorSelected))
|
||||
donorPrice.setColor(getPrimaryTextColorAttr(donorSelected))
|
||||
donorPeriod.setColor(getSecondaryTextColorAttr(donorSelected))
|
||||
|
||||
val philanthropistSelected = state.currentPlan == BillingManager.UpgradeStatus.PHILANTHROPIST
|
||||
philanthropist.isSelected = philanthropistSelected
|
||||
philanthropistPrice.text = state.philanthropistPrice
|
||||
philanthropistName.setColor(getPrimaryTextColorAttr(philanthropistSelected))
|
||||
philanthropistPrice.setColor(getPrimaryTextColorAttr(philanthropistSelected))
|
||||
philanthropistPeriod.setColor(getSecondaryTextColorAttr(philanthropistSelected))
|
||||
}
|
||||
|
||||
private fun getPrimaryTextColorAttr(selected: Boolean): Int {
|
||||
return if (selected) QkTextView.COLOR_PRIMARY_ON_THEME else QkTextView.COLOR_PRIMARY
|
||||
}
|
||||
|
||||
private fun getSecondaryTextColorAttr(selected: Boolean): Int {
|
||||
return if (selected) QkTextView.COLOR_SECONDARY_ON_THEME else QkTextView.COLOR_SECONDARY
|
||||
}
|
||||
|
||||
override fun initiatePurchaseFlow(billingManager: BillingManager, sku: String) {
|
||||
billingManager.initiatePurchaseFlow(this, sku)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 presentation.feature.plus
|
||||
|
||||
import common.util.BillingManager
|
||||
|
||||
data class PlusState(
|
||||
val currentPlan: BillingManager.UpgradeStatus = BillingManager.UpgradeStatus.REGULAR,
|
||||
val supporterPrice: String = "",
|
||||
val donorPrice: String = "",
|
||||
val philanthropistPrice: String = ""
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 presentation.feature.plus
|
||||
|
||||
import common.util.BillingManager
|
||||
import io.reactivex.Observable
|
||||
import presentation.common.base.QkView
|
||||
|
||||
interface PlusView : QkView<PlusState> {
|
||||
|
||||
val supporterSelectedIntent: Observable<Unit>
|
||||
val donorSelectedIntent: Observable<Unit>
|
||||
val philanthropistSelectedIntent: Observable<Unit>
|
||||
|
||||
fun initiatePurchaseFlow(billingManager: BillingManager, sku: String)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 presentation.feature.plus
|
||||
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.BillingManager
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import presentation.common.base.QkViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
class PlusViewModel : QkViewModel<PlusView, PlusState>(PlusState()) {
|
||||
|
||||
@Inject lateinit var billingManager: BillingManager
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
disposables += billingManager.plusStatus
|
||||
.subscribe { plan ->
|
||||
newState { it.copy(currentPlan = plan) }
|
||||
}
|
||||
|
||||
disposables += billingManager.subscriptions
|
||||
.subscribe { subs ->
|
||||
newState {
|
||||
it.copy(
|
||||
supporterPrice = subs.firstOrNull { it.sku == BillingManager.SKU_3 }?.price ?: "",
|
||||
donorPrice = subs.firstOrNull { it.sku == BillingManager.SKU_5 }?.price ?: "",
|
||||
philanthropistPrice = subs.firstOrNull { it.sku == BillingManager.SKU_10 }?.price ?: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun bindView(view: PlusView) {
|
||||
super.bindView(view)
|
||||
|
||||
Observable.merge(
|
||||
view.supporterSelectedIntent.map { BillingManager.SKU_3 },
|
||||
view.donorSelectedIntent.map { BillingManager.SKU_5 },
|
||||
view.philanthropistSelectedIntent.map { BillingManager.SKU_10 })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { sku -> view.initiatePurchaseFlow(billingManager, sku) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import com.google.android.flexbox.FlexboxLayoutManager
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
@@ -37,7 +36,6 @@ import common.di.appComponent
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.setVisible
|
||||
import data.model.MenuItem
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.settings_activity.*
|
||||
@@ -53,7 +51,6 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
||||
|
||||
override val viewModelClass = SettingsViewModel::class
|
||||
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
|
||||
override val themeSelectedIntent: Observable<Int> by lazy { themeAdapter.colorSelected }
|
||||
override val ringtoneSelectedIntent: Subject<String> = PublishSubject.create()
|
||||
override val mmsSizeSelectedIntent: Subject<Int> by lazy { menuItemAdapter.menuItemClicks }
|
||||
|
||||
@@ -66,50 +63,6 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
||||
}
|
||||
}
|
||||
|
||||
private val themeDialog by lazy {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.settings_dialog_theme_title)
|
||||
.setView(themeRecyclerView)
|
||||
.setCancelable(false)
|
||||
.create()
|
||||
}
|
||||
|
||||
private val themeRecyclerView by lazy {
|
||||
RecyclerView(this).apply {
|
||||
val padding = 8.dpToPx(context)
|
||||
setPadding(padding, padding, padding, padding)
|
||||
adapter = themeAdapter
|
||||
clipToPadding = false
|
||||
clipChildren = false
|
||||
layoutManager = FlexboxLayoutManager(this@SettingsActivity)
|
||||
}
|
||||
}
|
||||
|
||||
private val themeAdapter by lazy {
|
||||
ThemeAdapter(this@SettingsActivity).apply {
|
||||
data = listOf(
|
||||
-0x21f24, -0x64245, -0x96678, -0xc93a0, -0x17b1c0, -0x1ae3dd, -0x22e6e3, -0x2fe8ea, -0x3bebef, -0x4fedf6,
|
||||
-0x31b14, -0x74430, -0xb704f, -0xf9d6e, -0x13bf86, -0x16e19d, -0x27e4a0, -0x3de7a5, -0x52eba9, -0x77f1b1,
|
||||
-0xc1a0b, -0x1e4119, -0x316c28, -0x459738, -0x54b844, -0x63d850, -0x71db56, -0x84e05e, -0x95e466, -0xb5eb74,
|
||||
-0x12180a, -0x2e3b17, -0x4c6225, -0x6a8a33, -0x81a83e, -0x98c549, -0xa1ca4f, -0xaed258, -0xbad860, -0xcee46e,
|
||||
-0x17150a, -0x3a3517, -0x605726, -0x867935, -0xa39440, -0xc0ae4b, -0xc6b655, -0xcfc061, -0xd7ca6d, -0xe5dc82,
|
||||
-0x181603, -0x2f2601, -0x504001, -0x6e5801, -0x8c7002, -0xa98804, -0xb19311, -0xbaa122, -0xc4af32, -0xd5c94f,
|
||||
-0x1e0a02, -0x4c1a04, -0x7e2b06, -0xb03c09, -0xd6490a, -0xfc560c, -0xfc641b, -0xfd772f, -0xfd8843, -0xfea865,
|
||||
-0x1f0806, -0x4d140e, -0x7f2116, -0xb22f1f, -0xd93926, -0xff432c, -0xff533f, -0xff6859, -0xff7c71, -0xff9f9c,
|
||||
-0x1f0d0f, -0x4d2025, -0x7f343c, -0xb24954, -0xd95966, -0xff6978, -0xff7685, -0xff8695, -0xff96a4, -0xffb2c0,
|
||||
-0x2f0732, -0x5c165c, -0x8d2a8e, -0xbd42bf, -0xd450d5, -0xda64dc, -0xf570f8, -0xf581f9, -0xfa9100, -0xf2acfe,
|
||||
-0xe0717, -0x231238, -0x3a1e5b, -0x512a7f, -0x63339b, -0x743cb6, -0x834cbe, -0x9760c8, -0xaa74d1, -0xcc96e2,
|
||||
-0x60419, -0xf0b3d, -0x191164, -0x23188b, -0x2b1ea9, -0x3223c7, -0x3f35cd, -0x504bd5, -0x6162dc, -0x7d88e9,
|
||||
-0x219, -0x63c, -0xa63, -0xe8a, -0x11a8, -0x14c5, -0x227cb, -0x43fd3, -0x657db, -0xa80e9,
|
||||
-0x71f, -0x134d, -0x1f7e, -0x2ab1, -0x35d8, -0x3ef9, -0x4d00, -0x6000, -0x7100, -0x9100,
|
||||
-0xc20, -0x1f4e, -0x3380, -0x48b3, -0x58da, -0x6800, -0x47400, -0xa8400, -0x109400, -0x19af00,
|
||||
-0x41619, -0x3344, -0x546f, -0x759b, -0x8fbd, -0xa8de, -0xbaee2, -0x19b5e7, -0x27bceb, -0x40c9f4,
|
||||
-0x101417, -0x283338, -0x43555c, -0x5e7781, -0x72919d, -0x86aab8, -0x92b3bf, -0xa2bfc9, -0xb1cbd2,
|
||||
-0x50506, -0xa0a0b, -0x111112, -0x1f1f20, -0x424243, -0x616162, -0x8a8a8b, -0x9e9e9f, -0xbdbdbe, -0xdededf, -0x1000000, -0x1,
|
||||
-0x13100f, -0x13100f, -0x4f413b, -0x6f5b52, -0x876f64, -0x9f8275, -0xab9186, -0xbaa59c, -0xc8b8b1, -0xd9cdc8)
|
||||
}
|
||||
}
|
||||
|
||||
private val mmsSizeDialog by lazy {
|
||||
menuItemAdapter.data = arrayListOf(
|
||||
MenuItem(R.string.menu_mms_size_100kb, 100),
|
||||
@@ -161,9 +114,6 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
|
||||
}
|
||||
|
||||
override fun render(state: SettingsState) {
|
||||
if (themeDialog.isShowing && !state.selectingTheme) themeDialog.dismiss()
|
||||
else if (!themeDialog.isShowing && state.selectingTheme) themeDialog.show()
|
||||
|
||||
if (progressDialog.isShowing && !state.syncing) progressDialog.dismiss()
|
||||
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package presentation.feature.settings
|
||||
|
||||
data class SettingsState(
|
||||
val selectingTheme: Boolean = false,
|
||||
val syncing: Boolean = false,
|
||||
|
||||
val isDefaultSmsApp: Boolean = false,
|
||||
|
||||
@@ -27,7 +27,6 @@ import presentation.common.widget.PreferenceView
|
||||
interface SettingsView : QkView<SettingsState> {
|
||||
|
||||
val preferenceClickIntent: Subject<PreferenceView>
|
||||
val themeSelectedIntent: Observable<Int>
|
||||
val ringtoneSelectedIntent: Observable<String>
|
||||
val mmsSizeSelectedIntent: Observable<Int>
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
when (it.id) {
|
||||
R.id.defaultSms -> navigator.showDefaultSmsDialog()
|
||||
|
||||
R.id.theme -> newState { it.copy(selectingTheme = true) }
|
||||
R.id.theme -> navigator.showThemePicker()
|
||||
|
||||
R.id.dark -> prefs.dark.set(!prefs.dark.get())
|
||||
|
||||
@@ -125,13 +125,6 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
}
|
||||
}
|
||||
|
||||
view.themeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { color ->
|
||||
prefs.theme.set(color)
|
||||
newState { it.copy(selectingTheme = false) }
|
||||
}
|
||||
|
||||
view.ringtoneSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { ringtone -> prefs.ringtone.set(ringtone) }
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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 presentation.feature.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import presentation.common.base.QkAdapter
|
||||
import presentation.common.base.QkViewHolder
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.theme_list_item.view.*
|
||||
|
||||
class ThemeAdapter(private val context: Context) : QkAdapter<Int>() {
|
||||
|
||||
val colorSelected: Subject<Int> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.theme_list_item, parent, false)
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val theme = getItem(position)
|
||||
val view = holder.itemView
|
||||
|
||||
view.setOnClickListener { colorSelected.onNext(theme) }
|
||||
|
||||
view.theme.setBackgroundTint(theme)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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 presentation.feature.themepicker
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.support.v7.widget.RecyclerView
|
||||
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 common.util.Colors
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setTint
|
||||
import common.util.extensions.setVisible
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
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 presentation.common.base.QkAdapter
|
||||
import presentation.common.base.QkViewHolder
|
||||
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
|
||||
|
||||
oldPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
|
||||
newPosition.takeIf { it != -1 }?.let { position -> notifyItemChanged(position) }
|
||||
}
|
||||
|
||||
private var iconTint = 0
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(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) }
|
||||
}
|
||||
|
||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView?) {
|
||||
disposables += colors.textPrimaryOnTheme
|
||||
.subscribe { color -> iconTint = color }
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView?) {
|
||||
disposables.clear()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 presentation.feature.themepicker
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import io.reactivex.Observable
|
||||
import kotlinx.android.synthetic.main.theme_picker_activity.*
|
||||
import presentation.common.base.QkActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
class ThemePickerActivity : QkActivity<ThemePickerViewModel>(), ThemePickerView {
|
||||
|
||||
override val viewModelClass = ThemePickerViewModel::class
|
||||
override val themeSelectedIntent: Observable<Int> by lazy { themeAdapter.colorSelected }
|
||||
|
||||
@Inject lateinit var themeAdapter: ThemeAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
appComponent.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.theme_picker_activity)
|
||||
setTitle(R.string.title_theme)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
themeAdapter.data = colors.materialColors
|
||||
|
||||
materialColors.layoutManager = LinearLayoutManager(this)
|
||||
materialColors.adapter = themeAdapter
|
||||
|
||||
colors.background
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
}
|
||||
|
||||
override fun render(state: ThemePickerState) {
|
||||
themeAdapter.selectedColor = state.selectedColor
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 presentation.feature.themepicker
|
||||
|
||||
data class ThemePickerState(
|
||||
|
||||
val selectedColor: Int = -1
|
||||
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 presentation.feature.themepicker
|
||||
|
||||
import io.reactivex.Observable
|
||||
import presentation.common.base.QkView
|
||||
|
||||
interface ThemePickerView : QkView<ThemePickerState> {
|
||||
|
||||
val themeSelectedIntent: Observable<Int>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 presentation.feature.themepicker
|
||||
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.Preferences
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import presentation.common.base.QkViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
class ThemePickerViewModel : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState()) {
|
||||
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
disposables += prefs.theme.asObservable()
|
||||
.subscribe { color -> newState { it.copy(selectedColor = color) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: ThemePickerView) {
|
||||
super.bindView(view)
|
||||
|
||||
view.themeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { color -> prefs.theme.set(color) }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user