mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-11 23:06:00 +00:00
Implement AB Testing for subscription screen position
This commit is contained in:
parent
7cfc97cceb
commit
b9e789dd7d
4 changed files with 56 additions and 6 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package com.habitrpg.android.habitica.models.user
|
||||
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
open class ABTest: RealmObject() {
|
||||
|
||||
@PrimaryKey
|
||||
var userID: String? = null
|
||||
|
||||
var name: String = ""
|
||||
var group: String = ""
|
||||
}
|
||||
|
|
@ -52,6 +52,9 @@ open class User : RealmObject(), Avatar {
|
|||
if (this.invitations?.isManaged != true) {
|
||||
this.invitations?.userId = id
|
||||
}
|
||||
for (test in abTests ?: emptyList<ABTest>()) {
|
||||
test.userID = id
|
||||
}
|
||||
}
|
||||
var balance: Double = 0.toDouble()
|
||||
private var stats: Stats? = null
|
||||
|
|
@ -132,6 +135,8 @@ open class User : RealmObject(), Avatar {
|
|||
|
||||
var challenges: RealmList<ChallengeMembership>? = null
|
||||
|
||||
var abTests: RealmList<ABTest>? = null
|
||||
|
||||
var lastCron: Date? = null
|
||||
var needsCron: Boolean = false
|
||||
var loginIncentives: Int = 0
|
||||
|
|
|
|||
|
|
@ -9,18 +9,21 @@ import android.support.v4.app.FragmentPagerAdapter
|
|||
import android.support.v4.view.ViewPager
|
||||
import android.support.v7.widget.Toolbar
|
||||
import android.view.MenuItem
|
||||
import com.habitrpg.android.habitica.HabiticaApplication
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.AppComponent
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.extensions.notNull
|
||||
import com.habitrpg.android.habitica.helpers.PurchaseTypes
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.user.ABTest
|
||||
import com.habitrpg.android.habitica.proxy.CrashlyticsProxy
|
||||
import com.habitrpg.android.habitica.ui.fragments.GemsPurchaseFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.SubscriptionFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.playseeds.android.sdk.Seeds
|
||||
import com.playseeds.android.sdk.inappmessaging.InAppMessageListener
|
||||
import io.reactivex.functions.Consumer
|
||||
import org.solovyev.android.checkout.*
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
|
@ -29,6 +32,8 @@ class GemPurchaseActivity : BaseActivity(), InAppMessageListener {
|
|||
|
||||
@Inject
|
||||
lateinit var crashlyticsProxy: CrashlyticsProxy
|
||||
@Inject
|
||||
lateinit var userRepository: UserRepository
|
||||
|
||||
internal val tabLayout: TabLayout by bindView(R.id.tab_layout)
|
||||
internal val viewPager: ViewPager by bindView(R.id.viewPager)
|
||||
|
|
@ -51,6 +56,8 @@ class GemPurchaseActivity : BaseActivity(), InAppMessageListener {
|
|||
activityCheckout?.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
private var showSubscriptionPageFirst = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
@ -111,6 +118,20 @@ class GemPurchaseActivity : BaseActivity(), InAppMessageListener {
|
|||
|
||||
override fun onReady(billingRequests: BillingRequests, s: String, b: Boolean) {}
|
||||
})
|
||||
|
||||
compositeSubscription.add(userRepository.getUser().subscribe(Consumer { user ->
|
||||
for (test in user.abTests ?: emptyList<ABTest>()) {
|
||||
if (test.name == "subscriptionPageOrder") {
|
||||
if (test.group == "subscriptionFirst") {
|
||||
showSubscriptionPageFirst = true
|
||||
viewPager.adapter?.notifyDataSetChanged()
|
||||
return@Consumer
|
||||
}
|
||||
}
|
||||
}
|
||||
showSubscriptionPageFirst = false
|
||||
viewPager.adapter?.notifyDataSetChanged()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
public override fun onDestroy() {
|
||||
|
|
@ -184,7 +205,8 @@ class GemPurchaseActivity : BaseActivity(), InAppMessageListener {
|
|||
viewPager.adapter = object : FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
val fragment: CheckoutFragment = if (position == 0) {
|
||||
val gemPurchasePosition = if (showSubscriptionPageFirst) 1 else 0
|
||||
val fragment: CheckoutFragment = if (position == gemPurchasePosition) {
|
||||
GemsPurchaseFragment()
|
||||
} else {
|
||||
SubscriptionFragment()
|
||||
|
|
@ -207,11 +229,11 @@ class GemPurchaseActivity : BaseActivity(), InAppMessageListener {
|
|||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
when (position) {
|
||||
0 -> return getString(R.string.gems)
|
||||
1 -> return getString(R.string.subscriptions)
|
||||
val gemPurchasePosition = if (showSubscriptionPageFirst) 1 else 0
|
||||
return when (position) {
|
||||
gemPurchasePosition -> getString(R.string.gems)
|
||||
else -> getString(R.string.subscriptions)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,6 +123,16 @@ class UserDeserializer : JsonDeserializer<User> {
|
|||
}
|
||||
}
|
||||
|
||||
if (obj.has("_ABTests")) {
|
||||
user.abTests = RealmList()
|
||||
for (testJSON in obj.getAsJsonObject("_ABTests").entrySet()) {
|
||||
val test = ABTest()
|
||||
test.name = testJSON.key
|
||||
test.group = testJSON.value.asString
|
||||
user.abTests?.add(test)
|
||||
}
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue