diff --git a/data/src/noAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt b/data/src/noAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt index 91c1be14..772c3ea3 100644 --- a/data/src/noAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt +++ b/data/src/noAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt @@ -36,7 +36,7 @@ class AnalyticsManagerImpl @Inject constructor() : AnalyticsManager { } override fun setUserProperty(key: String, value: Any) { - // Do nothing + Timber.v("$key: $value") } } diff --git a/data/src/withAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt b/data/src/withAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt index 4fb14b2c..edf36498 100644 --- a/data/src/withAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt +++ b/data/src/withAnalytics/java/com/moez/QKSMS/manager/AnalyticsManagerImpl.kt @@ -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() diff --git a/domain/src/main/java/com/moez/QKSMS/experiment/Experiment.kt b/domain/src/main/java/com/moez/QKSMS/experiment/Experiment.kt new file mode 100644 index 00000000..d8deb23e --- /dev/null +++ b/domain/src/main/java/com/moez/QKSMS/experiment/Experiment.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +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(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> + 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 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) + } + +} \ No newline at end of file diff --git a/domain/src/main/java/com/moez/QKSMS/experiment/Variant.kt b/domain/src/main/java/com/moez/QKSMS/experiment/Variant.kt new file mode 100644 index 00000000..0d7d5df6 --- /dev/null +++ b/domain/src/main/java/com/moez/QKSMS/experiment/Variant.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.experiment + +data class Variant(val key: String, val value: T) \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/plus/PlusActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/plus/PlusActivity.kt index ceb33c9d..d7a8d1f0 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/plus/PlusActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/plus/PlusActivity.kt @@ -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" diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/plus/experiment/UpgradeButtonExperiment.kt b/presentation/src/main/java/com/moez/QKSMS/feature/plus/experiment/UpgradeButtonExperiment.kt new file mode 100644 index 00000000..568e541b --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/plus/experiment/UpgradeButtonExperiment.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +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> = 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 + +} \ No newline at end of file diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 02b6732f..87e98acd 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -228,6 +228,9 @@ Support development, unlock everything You can save a starving developer for just %s Lifetime upgrade for %1$s %2$s + Unlock for %1$s %2$s + Unlock forever for %1$s %2$s + One-time purchase of %1$s %2$s Unlock + donate for %1$s %2$s Thank you for supporting QKSMS! You now have access to all QKSMS+ features