Merge pull request #1764 from Hafizzle/Hafiz/Fixes#1722

Fixes#1722 - Show next hourglass month on sub info screen
This commit is contained in:
Phillip Thelen 2022-05-27 10:05:28 +02:00 committed by GitHub
commit 8a1c058fd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 4 deletions

View file

@ -135,6 +135,8 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation 'com.willowtreeapps:signinwithapplebutton:0.3'
implementation project(':shared')
@ -264,6 +266,8 @@ android {
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8

View file

@ -183,13 +183,13 @@
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/current_hourclasses"
android:text="@string/next_hourglass"
style="@style/subscriptionBoxText.Subtitle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Pill"
android:id="@+id/currentHourglassesTextView"
android:id="@+id/next_hourglass_textview"
tools:text="4" />
</LinearLayout>
</LinearLayout>

View file

@ -432,6 +432,7 @@
<string name="current_bonuses">Current Bonuses</string>
<string name="months_subscribed">Months subscribed</string>
<string name="current_hourclasses">Current Mystic Hourglasses</string>
<string name="next_hourglass">Next Hourglass</string>
<string name="monthly_gem_cap">Monthly gem cap</string>
<string name="inactive">Inactive</string>
<string name="one_month">1 Month</string>

View file

@ -11,9 +11,11 @@ open class SubscriptionPlan : RealmObject(), BaseObject {
var customerId: String? = null
var dateCreated: Date? = null
var dateUpdated: Date? = null
@JvmField
var dateTerminated: Date? = null
var paymentMethod: String? = null
@JvmField
var planId: String? = null
var gemsBought: Int? = null
@ -47,6 +49,20 @@ open class SubscriptionPlan : RealmObject(), BaseObject {
return totalNumberOfGems - (gemsBought ?: 0)
}
/*
If user has a initial basic monthly subscription, receive hourglasses on fourth month,
else receive on third month (subtract 1 from total consecutive count)
*/
val monthsUntilNextHourglass: Int?
get() {
return if (consecutive?.offset == 0) {
(3 - (((consecutive?.count ?: 0)) % 3))
} else {
consecutive?.offset
}
}
companion object {
var PLANID_BASIC = "basic"
var PLANID_BASICEARNED = "basic_earned"

View file

@ -13,7 +13,9 @@ import com.habitrpg.android.habitica.extensions.layoutInflater
import com.habitrpg.android.habitica.models.user.SubscriptionPlan
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import java.text.DateFormat
import java.util.Date
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.*
class SubscriptionDetailsView : LinearLayout {
@ -96,8 +98,13 @@ class SubscriptionDetailsView : LinearLayout {
} else {
binding.monthsSubscribedTextView.text = resources.getString(R.string.x_months, plan.consecutive?.count ?: 0)
}
binding.gemCapTextView.text = plan.totalNumberOfGems.toString()
binding.currentHourglassesTextView.text = plan.consecutive?.trinkets.toString()
if (plan.monthsUntilNextHourglass != null){
val nextHourglassMonth = LocalDate.now().plusMonths(plan.monthsUntilNextHourglass!!.toLong()).format(DateTimeFormatter.ofPattern("MMM"))
nextHourglassMonth?.let { binding.nextHourglassTextview.text = it }
}
binding.changeSubscriptionButton.visibility = View.VISIBLE
if (plan.paymentMethod != null) {

View file

@ -67,4 +67,47 @@ class SubscriptionPlanTest : WordSpec({
plan.numberOfGemsLeft shouldBe 25
}
}
"monthsUntilNextHourglass" should {
beforeEach {
plan.consecutive = SubscriptionPlanConsecutive()
plan.consecutive?.count = 0
plan.dateTerminated = null
}
"months until next hourglass with initial basic sub" {
plan.planId = SubscriptionPlan.PLANID_BASIC
plan.monthsUntilNextHourglass shouldBe 3
}
"months until receiving first hourglass with basic sub" {
plan.consecutive?.count = 2
plan.planId = SubscriptionPlan.PLANID_BASIC
plan.monthsUntilNextHourglass shouldBe 1
}
"months until next hourglass with basic sub after receiving initial hourglass" {
plan.consecutive?.count = 3
plan.planId = SubscriptionPlan.PLANID_BASIC
plan.monthsUntilNextHourglass shouldBe 3
}
"months until next hourglass with three month sub" {
plan.consecutive?.offset = 3
plan.planId = SubscriptionPlan.PLANID_BASIC3MONTH
plan.monthsUntilNextHourglass shouldBe 3
}
"months until next hourglass with six month sub" {
plan.consecutive?.offset = 6
plan.planId = SubscriptionPlan.PLANID_BASIC6MONTH
plan.monthsUntilNextHourglass shouldBe 6
}
"months until next hourglass with 12 month sub" {
plan.consecutive?.offset = 12
plan.planId = SubscriptionPlan.PLANID_BASIC12MONTH
plan.monthsUntilNextHourglass shouldBe 12
}
}
})