diff --git a/Habitica/build.gradle b/Habitica/build.gradle
index e9c7e11fa..ff862e19d 100644
--- a/Habitica/build.gradle
+++ b/Habitica/build.gradle
@@ -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
diff --git a/Habitica/res/layout/subscription_details.xml b/Habitica/res/layout/subscription_details.xml
index a75136aa7..253fd7434 100644
--- a/Habitica/res/layout/subscription_details.xml
+++ b/Habitica/res/layout/subscription_details.xml
@@ -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" />
diff --git a/Habitica/res/values/strings.xml b/Habitica/res/values/strings.xml
index 3a8683b4a..970c1cb5e 100644
--- a/Habitica/res/values/strings.xml
+++ b/Habitica/res/values/strings.xml
@@ -432,6 +432,7 @@
Current Bonuses
Months subscribed
Current Mystic Hourglasses
+ Next Hourglass
Monthly gem cap
Inactive
1 Month
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlan.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlan.kt
index 9fd860ed1..ea478b96e 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlan.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlan.kt
@@ -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"
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/subscriptions/SubscriptionDetailsView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/subscriptions/SubscriptionDetailsView.kt
index 9564680a1..04ee559f0 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/subscriptions/SubscriptionDetailsView.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/subscriptions/SubscriptionDetailsView.kt
@@ -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) {
diff --git a/Habitica/src/test/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanTest.kt b/Habitica/src/test/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanTest.kt
index c16dd757f..67ea29465 100644
--- a/Habitica/src/test/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanTest.kt
+++ b/Habitica/src/test/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanTest.kt
@@ -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
+ }
+ }
})