Add alternative buy button labels

This commit is contained in:
Moez Bhatti
2018-08-02 17:27:36 -04:00
parent 8f2a83feaa
commit a68997ba69
7 changed files with 131 additions and 2 deletions
@@ -36,7 +36,7 @@ class AnalyticsManagerImpl @Inject constructor() : AnalyticsManager {
}
override fun setUserProperty(key: String, value: Any) {
// Do nothing
Timber.v("$key: $value")
}
}
@@ -54,6 +54,7 @@ class AnalyticsManagerImpl @Inject constructor(context: Context) : AnalyticsMana
}
override fun setUserProperty(key: String, value: Any) {
Timber.v("$key: $value")
// Set the value in Mixpanel
val properties = JSONObject()
@@ -0,0 +1,58 @@
/*
* 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.experiment
import android.content.Context
import android.preference.PreferenceManager
import com.moez.QKSMS.manager.AnalyticsManager
import java.util.*
abstract class Experiment<T>(val context: Context, val analytics: AnalyticsManager) {
private val prefs by lazy { PreferenceManager.getDefaultSharedPreferences(context) }
private val prefKey: String
get() = "experiment_$key"
protected abstract val key: String
protected abstract val variants: List<Variant<T>>
protected abstract val default: T
/**
* Returns true if the current device qualifies for the experiment
*/
protected open val qualifies: Boolean = Locale.getDefault().language == "en"
val variant: Variant<T> by lazy {
when {
!qualifies -> null // Device doesn't quality for experiment
prefs.contains(prefKey) -> { // Variant already set
variants.firstOrNull { it.key == prefs.getString(prefKey, null) }
}
else -> { // Variant hasn't been set yet
variants[Random().nextInt(variants.size)].also { variant ->
analytics.setUserProperty("Experiment: $key", variant.key)
prefs.edit().putString(prefKey, variant.key).apply()
}
}
} ?: Variant("default", default)
}
}
@@ -0,0 +1,21 @@
/*
* 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.experiment
data class Variant<T>(val key: String, val value: T)
@@ -34,6 +34,7 @@ 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 com.moez.QKSMS.common.widget.PreferenceView
import com.moez.QKSMS.feature.plus.experiment.UpgradeButtonExperiment
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.collapsing_toolbar.*
import kotlinx.android.synthetic.main.preference_view.view.*
@@ -43,6 +44,7 @@ import javax.inject.Inject
class PlusActivity : QkThemedActivity(), PlusView {
@Inject lateinit var fontProvider: FontProvider
@Inject lateinit var upgradeButtonExperiment: UpgradeButtonExperiment
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[PlusViewModel::class.java] }
@@ -87,7 +89,7 @@ class PlusActivity : QkThemedActivity(), PlusView {
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)
upgrade.text = getString(upgradeButtonExperiment.variant.value, state.upgradePrice, state.currency)
upgradeDonate.text = getString(R.string.qksms_plus_upgrade_donate, state.upgradeDonatePrice, state.currency)
val fdroid = BuildConfig.FLAVOR == "noAnalytics"
@@ -0,0 +1,44 @@
/*
* 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.experiment
import android.content.Context
import androidx.annotation.StringRes
import com.moez.QKSMS.R
import com.moez.QKSMS.experiment.Experiment
import com.moez.QKSMS.experiment.Variant
import com.moez.QKSMS.manager.AnalyticsManager
import javax.inject.Inject
class UpgradeButtonExperiment @Inject constructor(
context: Context,
analytics: AnalyticsManager
) : Experiment<@StringRes Int>(context, analytics) {
override val key: String = "Upgrade Button"
override val variants: List<Variant<Int>> = listOf(
Variant("variant_a", R.string.qksms_plus_upgrade),
Variant("variant_b", R.string.qksms_plus_upgrade_b),
Variant("variant_c", R.string.qksms_plus_upgrade_c),
Variant("variant_d", R.string.qksms_plus_upgrade_d))
override val default: Int = R.string.qksms_plus_upgrade
}
@@ -228,6 +228,9 @@
<string name="qksms_plus_description_title">Support development, unlock everything</string>
<string name="qksms_plus_description_summary">You can save a starving developer for just %s</string>
<string name="qksms_plus_upgrade">Lifetime upgrade for %1$s %2$s</string>
<string name="qksms_plus_upgrade_b">Unlock for %1$s %2$s</string>
<string name="qksms_plus_upgrade_c">Unlock forever for %1$s %2$s</string>
<string name="qksms_plus_upgrade_d">One-time purchase of %1$s %2$s</string>
<string name="qksms_plus_upgrade_donate">Unlock + donate for %1$s %2$s</string>
<string name="qksms_plus_thanks_title">Thank you for supporting QKSMS!</string>
<string name="qksms_plus_thanks_summary">You now have access to all QKSMS+ features</string>