diff --git a/qksms/src/main/java/presentation/common/widget/QkTextView.kt b/qksms/src/main/java/presentation/common/widget/QkTextView.kt index 3ecc653c..6ac316ea 100644 --- a/qksms/src/main/java/presentation/common/widget/QkTextView.kt +++ b/qksms/src/main/java/presentation/common/widget/QkTextView.kt @@ -22,12 +22,13 @@ 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.FontProvider 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) @@ -45,23 +46,7 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu @Inject lateinit var colors: Colors @Inject lateinit var fontProvider: FontProvider - private var textColorDisposable: Disposable? = null private var textColorObservable: Observable? = null - set(value) { - if (field !== value) { - field = value - - if (isAttachedToWindow) { - textColorDisposable?.let { disposable -> - if (!disposable.isDisposed) { - disposable.dispose() - } - } - - subscribeColorChanges() - } - } - } init { if (!isInEditMode) { @@ -82,44 +67,29 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu else -> R.color.textPrimary })) } else { - setColor(colorAttr) + 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 + } } recycle() } } - 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 - } - } + override fun onAttachedToWindow() { + super.onAttachedToWindow() - private fun subscribeColorChanges() { - textColorDisposable = textColorObservable + textColorObservable + ?.autoDisposable(scope()) ?.subscribe { color -> setTextColor(color) setLinkTextColor(color) } } - - override fun onAttachedToWindow() { - super.onAttachedToWindow() - - if (textColorDisposable?.isDisposed != false) { - subscribeColorChanges() - } - } - - override fun onDetachedFromWindow() { - super.onDetachedFromWindow() - textColorDisposable?.dispose() - } - } \ No newline at end of file diff --git a/qksms/src/main/java/presentation/feature/plus/PlusActivity.kt b/qksms/src/main/java/presentation/feature/plus/PlusActivity.kt index 604945eb..8457a9ed 100644 --- a/qksms/src/main/java/presentation/feature/plus/PlusActivity.kt +++ b/qksms/src/main/java/presentation/feature/plus/PlusActivity.kt @@ -18,6 +18,7 @@ */ package presentation.feature.plus +import android.content.res.ColorStateList import android.graphics.Typeface import android.os.Bundle import com.jakewharton.rxbinding2.view.clicks @@ -30,9 +31,9 @@ import common.util.FontProvider import common.util.extensions.setBackgroundTint import common.util.extensions.setTint import common.util.extensions.setVisible +import io.reactivex.rxkotlin.Observables import kotlinx.android.synthetic.main.qksms_plus_activity.* import presentation.common.base.QkActivity -import presentation.common.widget.QkTextView import javax.inject.Inject class PlusActivity : QkActivity(), PlusView { @@ -81,6 +82,35 @@ class PlusActivity : QkActivity(), PlusView { donor.setBackgroundTint(color) philanthropist.setBackgroundTint(color) } + + val states = arrayOf( + intArrayOf(android.R.attr.state_selected), + intArrayOf(-android.R.attr.state_selected)) + + Observables + .combineLatest(colors.textPrimaryOnTheme, colors.textPrimary, { theme, textSecondary -> + ColorStateList(states, intArrayOf(theme, textSecondary)) + }) + .autoDisposable(scope()) + .subscribe { colorStateList -> + supporterName.setTextColor(colorStateList) + supporterPrice.setTextColor(colorStateList) + donorName.setTextColor(colorStateList) + donorPrice.setTextColor(colorStateList) + philanthropistName.setTextColor(colorStateList) + philanthropistPrice.setTextColor(colorStateList) + } + + Observables + .combineLatest(colors.textSecondaryOnTheme, colors.textSecondary, { theme, textSecondary -> + ColorStateList(states, intArrayOf(theme, textSecondary)) + }) + .autoDisposable(scope()) + .subscribe { colorStateList -> + supporterPeriod.setTextColor(colorStateList) + donorPeriod.setTextColor(colorStateList) + philanthropistPeriod.setTextColor(colorStateList) + } } override fun render(state: PlusState) { @@ -91,31 +121,14 @@ class PlusActivity : QkActivity(), PlusView { 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) { diff --git a/qksms/src/main/res/layout/qksms_plus_activity.xml b/qksms/src/main/res/layout/qksms_plus_activity.xml index 4bf2469f..b62cf643 100644 --- a/qksms/src/main/res/layout/qksms_plus_activity.xml +++ b/qksms/src/main/res/layout/qksms_plus_activity.xml @@ -152,7 +152,7 @@ android:textStyle="bold" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:textColor="primary" /> + tools:textColor="@color/textPrimary" /> + tools:text="$2.99" + tools:textColor="@color/textPrimary" /> + tools:textColor="@color/textSecondary" /> @@ -200,7 +200,7 @@ android:textStyle="bold" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:textColor="primary" /> + tools:textColor="@color/textPrimary" /> + tools:text="$2.99" + tools:textColor="@color/textPrimary" /> + tools:textColor="@color/textSecondary" /> @@ -248,7 +248,7 @@ android:textStyle="bold" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:textColor="primary" /> + tools:textColor="@color/textPrimary" /> + tools:text="$2.99" + tools:textColor="@color/textPrimary" /> + tools:textColor="@color/textSecondary" />