Switch from Subscription to IAP

This commit is contained in:
Moez Bhatti
2018-02-05 17:11:50 -05:00
parent fcf5f2d6e8
commit 228c0e3106
9 changed files with 104 additions and 260 deletions
@@ -18,7 +18,6 @@
*/
package presentation.feature.plus
import android.content.res.ColorStateList
import android.graphics.Typeface
import android.os.Bundle
import com.jakewharton.rxbinding2.view.clicks
@@ -31,7 +30,6 @@ 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 javax.inject.Inject
@@ -41,9 +39,8 @@ class PlusActivity : QkActivity<PlusViewModel>(), PlusView {
@Inject lateinit var fontProvider: FontProvider
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 val upgradeIntent by lazy { upgrade.clicks() }
override val upgradeDonateIntent by lazy { upgradeDonate.clicks() }
override fun onCreate(savedInstanceState: Bundle?) {
appComponent.inject(this)
@@ -72,63 +69,27 @@ class PlusActivity : QkActivity<PlusViewModel>(), PlusView {
colors.separator
.autoDisposable(scope())
.subscribe { color -> thanks.setBackgroundTint(color) }
.subscribe { color ->
upgradeDonate.setBackgroundTint(color)
thanks.setBackgroundTint(color)
}
colors.theme
.autoDisposable(scope())
.subscribe { color ->
upgrade.setBackgroundTint(color)
thanksIcon.setTint(color)
supporter.setBackgroundTint(color)
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) {
description.text = getString(R.string.qksms_plus_description_summary, state.supporterPrice)
description.text = getString(R.string.qksms_plus_description_summary, state.upgradePrice)
upgrade.text = getString(R.string.qksms_plus_upgrade, state.upgradePrice, state.currency)
upgradeDonate.text = getString(R.string.qksms_plus_upgrade_donate, state.upgradeDonatePrice, state.currency)
upgrade.setVisible(state.currentPlan == BillingManager.UpgradeStatus.REGULAR)
upgradeDonate.setVisible(state.currentPlan == BillingManager.UpgradeStatus.REGULAR)
thanks.setVisible(state.currentPlan != BillingManager.UpgradeStatus.REGULAR)
val supportedSelected = state.currentPlan == BillingManager.UpgradeStatus.SUPPORTER
supporter.isSelected = supportedSelected
supporterPrice.text = state.supporterPrice
val donorSelected = state.currentPlan == BillingManager.UpgradeStatus.DONOR
donor.isSelected = donorSelected
donorPrice.text = state.donorPrice
val philanthropistSelected = state.currentPlan == BillingManager.UpgradeStatus.PHILANTHROPIST
philanthropist.isSelected = philanthropistSelected
philanthropistPrice.text = state.philanthropistPrice
}
override fun initiatePurchaseFlow(billingManager: BillingManager, sku: String) {
@@ -22,7 +22,7 @@ import common.util.BillingManager
data class PlusState(
val currentPlan: BillingManager.UpgradeStatus = BillingManager.UpgradeStatus.REGULAR,
val supporterPrice: String = "",
val donorPrice: String = "",
val philanthropistPrice: String = ""
val upgradePrice: String = "",
val upgradeDonatePrice: String = "",
val currency: String = ""
)
@@ -24,9 +24,8 @@ import presentation.common.base.QkView
interface PlusView : QkView<PlusState> {
val supporterSelectedIntent: Observable<Unit>
val donorSelectedIntent: Observable<Unit>
val philanthropistSelectedIntent: Observable<Unit>
val upgradeIntent: Observable<Unit>
val upgradeDonateIntent: Observable<Unit>
fun initiatePurchaseFlow(billingManager: BillingManager, sku: String)
@@ -39,13 +39,13 @@ class PlusViewModel : QkViewModel<PlusView, PlusState>(PlusState()) {
newState { it.copy(currentPlan = plan) }
}
disposables += billingManager.subscriptions
.subscribe { subs ->
disposables += billingManager.products
.subscribe { products ->
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 ?: "")
val upgrade = products.firstOrNull { it.sku == BillingManager.SKU_PLUS }
val upgradeDonate = products.firstOrNull { it.sku == BillingManager.SKU_PLUS_DONATE }
it.copy(upgradePrice = upgrade?.price ?: "", upgradeDonatePrice = upgradeDonate?.price ?: "",
currency = upgrade?.priceCurrencyCode ?: upgradeDonate?.priceCurrencyCode ?: "")
}
}
}
@@ -54,9 +54,8 @@ class PlusViewModel : QkViewModel<PlusView, PlusState>(PlusState()) {
super.bindView(view)
Observable.merge(
view.supporterSelectedIntent.map { BillingManager.SKU_3 },
view.donorSelectedIntent.map { BillingManager.SKU_5 },
view.philanthropistSelectedIntent.map { BillingManager.SKU_10 })
view.upgradeIntent.map { BillingManager.SKU_PLUS },
view.upgradeDonateIntent.map { BillingManager.SKU_PLUS_DONATE })
.autoDisposable(view.scope())
.subscribe { sku -> view.initiatePurchaseFlow(billingManager, sku) }
}