forked from upstream-mirrors/quik
Move packages to com.moez.QKSMS
This commit is contained in:
@@ -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.plus
|
||||
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.BuildConfig
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkThemedActivity
|
||||
import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.common.util.FontProvider
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
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 dagger.android.AndroidInjection
|
||||
import kotlinx.android.synthetic.main.qksms_plus_activity.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PlusActivity : QkThemedActivity(), PlusView {
|
||||
|
||||
@Inject lateinit var fontProvider: FontProvider
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[PlusViewModel::class.java] }
|
||||
|
||||
override val upgradeIntent by lazy { upgrade.clicks() }
|
||||
override val upgradeDonateIntent by lazy { upgradeDonate.clicks() }
|
||||
override val donateIntent by lazy { donate.clicks() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.qksms_plus_activity)
|
||||
setTitle(R.string.title_qksms_plus)
|
||||
showBackButton(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
free.setVisible(false)
|
||||
|
||||
if (!prefs.systemFont.get()) {
|
||||
fontProvider.getLato { lato ->
|
||||
val typeface = Typeface.create(lato, Typeface.BOLD)
|
||||
collapsingToolbar.setCollapsedTitleTypeface(typeface)
|
||||
collapsingToolbar.setExpandedTitleTypeface(typeface)
|
||||
}
|
||||
}
|
||||
|
||||
val textPrimary = resolveThemeColor(android.R.attr.textColorPrimary)
|
||||
collapsingToolbar.setCollapsedTitleTextColor(textPrimary)
|
||||
collapsingToolbar.setExpandedTitleColor(textPrimary)
|
||||
|
||||
val theme = colors.theme().theme
|
||||
donate.setBackgroundTint(theme)
|
||||
upgrade.setBackgroundTint(theme)
|
||||
thanksIcon.setTint(theme)
|
||||
}
|
||||
|
||||
override fun render(state: PlusState) {
|
||||
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)
|
||||
|
||||
val fdroid = BuildConfig.FLAVOR == "noAnalytics"
|
||||
|
||||
free.setVisible(fdroid)
|
||||
toUpgrade.setVisible(!fdroid && !state.upgraded)
|
||||
upgraded.setVisible(!fdroid && state.upgraded)
|
||||
}
|
||||
|
||||
override fun initiatePurchaseFlow(billingManager: BillingManager, sku: String) {
|
||||
billingManager.initiatePurchaseFlow(this, sku)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.moez.QKSMS.feature.plus
|
||||
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import com.moez.QKSMS.injection.ViewModelKey
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoMap
|
||||
|
||||
@Module
|
||||
class PlusActivityModule {
|
||||
|
||||
@Provides
|
||||
@IntoMap
|
||||
@ViewModelKey(PlusViewModel::class)
|
||||
fun providePlusViewModel(viewModel: PlusViewModel): 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.plus
|
||||
|
||||
data class PlusState(
|
||||
val upgraded: Boolean = false,
|
||||
val upgradePrice: String = "",
|
||||
val upgradeDonatePrice: String = "",
|
||||
val currency: 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 com.moez.QKSMS.feature.plus
|
||||
|
||||
import com.moez.QKSMS.common.base.QkView
|
||||
import com.moez.QKSMS.common.util.BillingManager
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface PlusView : QkView<PlusState> {
|
||||
|
||||
val upgradeIntent: Observable<Unit>
|
||||
val upgradeDonateIntent: Observable<Unit>
|
||||
val donateIntent: Observable<*>
|
||||
|
||||
fun initiatePurchaseFlow(billingManager: BillingManager, sku: String)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.plus
|
||||
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkViewModel
|
||||
import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.manager.AnalyticsManager
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
|
||||
class PlusViewModel @Inject constructor(
|
||||
private val analyticsManager: AnalyticsManager,
|
||||
private val billingManager: BillingManager,
|
||||
private val navigator: Navigator
|
||||
) : QkViewModel<PlusView, PlusState>(PlusState()) {
|
||||
|
||||
init {
|
||||
analyticsManager.track("Viewed QKSMS+")
|
||||
|
||||
disposables += billingManager.upgradeStatus
|
||||
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
|
||||
|
||||
disposables += billingManager.products
|
||||
.subscribe { products ->
|
||||
newState {
|
||||
val upgrade = products.firstOrNull { it.sku == BillingManager.SKU_PLUS }
|
||||
val upgradeDonate = products.firstOrNull { it.sku == BillingManager.SKU_PLUS_DONATE }
|
||||
copy(upgradePrice = upgrade?.price ?: "", upgradeDonatePrice = upgradeDonate?.price ?: "",
|
||||
currency = upgrade?.priceCurrencyCode ?: upgradeDonate?.priceCurrencyCode ?: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun bindView(view: PlusView) {
|
||||
super.bindView(view)
|
||||
|
||||
Observable.merge(
|
||||
view.upgradeIntent.map { BillingManager.SKU_PLUS },
|
||||
view.upgradeDonateIntent.map { BillingManager.SKU_PLUS_DONATE })
|
||||
.doOnNext { sku -> analyticsManager.track("Clicked Upgrade", Pair("sku", sku)) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { sku -> view.initiatePurchaseFlow(billingManager, sku) }
|
||||
|
||||
view.donateIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showDonation() }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user