Skip to content

Commit

Permalink
improve subscription handling in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Oct 23, 2024
1 parent 1aa3f66 commit 92a9292
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 39 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Habitica/res/drawable/g1g1_vertical_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#925CF3"
android:endColor="#50B5E9"
android:angle="90"/>
</shape>
6 changes: 4 additions & 2 deletions Habitica/res/layout/activity_gift_subscription.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,17 @@
</LinearLayout>

<ImageView
android:id="@+id/hills_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/subscription_bg" />
android:src="@drawable/gift_subscription_bg"
android:scaleType="centerCrop"/>

<LinearLayout
android:id="@+id/gift_subscription_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/g1g1_menu_background"
android:background="@drawable/g1g1_vertical_background"
android:paddingHorizontal="32dp"
android:paddingVertical="16dp"
android:gravity="center_horizontal"
Expand Down
15 changes: 14 additions & 1 deletion Habitica/res/layout/fragment_gem_purchase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<RelativeLayout
android:id="@+id/promo_banner"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_height="96dp"
android:background="@drawable/g1g1_box"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
Expand Down Expand Up @@ -70,6 +70,19 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="22sp"
android:textStyle="bold"
android:layout_marginStart="84dp"
android:layout_marginEnd="84dp"
android:gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="6dp" />

<TextView
android:id="@+id/promo_banner_subtitle_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginStart="84dp"
Expand Down
25 changes: 18 additions & 7 deletions Habitica/res/layout/fragment_subscription_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<RelativeLayout
android:id="@+id/promo_banner"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_height="96dp"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="8dp"
android:background="@drawable/g1g1_box"
Expand Down Expand Up @@ -102,25 +102,36 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:layout_marginStart="84dp"
android:layout_marginEnd="84dp"
android:orientation="vertical">

<ImageView
android:id="@+id/promo_banner_title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp" />

<TextView
android:id="@+id/promo_banner_title_text"
style="@style/SubHeader1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="84dp"
android:layout_marginEnd="84dp"
android:layout_marginBottom="6dp"
android:visibility="gone"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="6dp" />

<TextView
android:id="@+id/promo_banner_subtitle_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="center"
android:textColor="@color/white"
android:visibility="gone" />
android:layout_marginBottom="6dp" />

<TextView
android:id="@+id/promo_banner_duration_view"
Expand Down
4 changes: 1 addition & 3 deletions Habitica/res/layout/subscription_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@
android:layout_centerHorizontal="true"
android:text="@string/next_hourglass"
android:gravity="center"
android:fontFamily="sans-serif"
android:textStyle="bold"
android:textSize="12sp"
style="@style/subscriptionBoxCompactText"
android:layout_marginHorizontal="64dp"
android:textColor="@color/white" />

Expand Down
4 changes: 2 additions & 2 deletions Habitica/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@
<string name="gift_subscription">Gift Subscription</string>
<string name="gift_one_get_one_description">Gift a sub and get a sub free event going on now!</string>
<string name="gift_title">Who would you like to gift to?</string>
<string name="gift_one_get_one">Gift one, Get one!</string>
<string name="gift_one_get_one">Gift one, Get one</string>
<string name="gift_one_get_one_detailed_description">While this promotion is active, you’ll receive a matching subscription automatically after sending your gift.</string>
<string name="gift_subscription_subtitle">Choose the subscription you’d like to gift! This purchase won’t renew.</string>
<string name="gift_gems_subtitle">Choose the gem packet you’d like to gift below!</string>
Expand Down Expand Up @@ -1170,7 +1170,7 @@
<string name="claim_x_gems">Claim %d Gems</string>
<string name="g1g1_promo_info_prompt">In honor of the season of giving we\'re bringing back a very special promotion. Now when you gift somebody a subscription, you get the same sub for yourself for free!</string>
<string name="g1g1_promo_info_instructions">Tap ‘Gift a Subscription’ and type in the username of the account you’d like to gift to. From there, pick the sub length you’d like to gift and check out. Your account will automatically be rewarded with the same level of subscription you just gifted.</string>
<string name="g1g1_promo_info_limitations_fixed">This is a limited time event that starts on %1$s (%2$s) and will end %3$s (%4$s). This promotion only applies when you gift to another Habitican. If you or your gift recipient already have a subscription, the gifted subscription will add months of credit that will only be used after the current subscription is cancelled or expires.</string>
<string name="g1g1_promo_info_limitations_noutc">This is a limited time event that starts on %1$s and will end %2$s. This promotion only applies when you gift to another Habitican. If you or your gift recipient already have a subscription, the gifted subscription will add months of credit that will only be used after the current subscription is cancelled or expires.</string>
<string name="gift_one_get_one_purchase_banner">Gift a sub and get a sub for free until %s</string>
<string name="one_month_one_time">1 Month</string>
<string name="three_months_one_time">3 Months</string>
Expand Down
2 changes: 1 addition & 1 deletion Habitica/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@

<style name="Pill.Selected.Yellow.Bright">
<item name="android:background">@drawable/pill_bg_yellow_100</item>
<item name="textColor">@color/brand_100</item>
<item name="android:textColor">@color/brand_100</item>
</style>

<style name="Pill.Selected.Red">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ class AppConfigManager(contentRepository: ContentRepository) :
if (promo is HabiticaWebPromotion) {
promo.url = surveyURL()
}
return promo
if (promo?.isActive == true) {
return promo
}
return null
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,15 @@ class PurchaseHandler(
val validationRequest = buildValidationRequest(purchase)
MainScope().launchCatching {
try {
apiClient.validatePurchase(validationRequest)
val response = apiClient.validatePurchase(validationRequest)
processedPurchase(purchase)
val gift = removeGift(sku)
withContext(Dispatchers.IO) {
consume(purchase)
}
displayConfirmationDialog(purchase, gift?.third)
if (response != null) {
displayConfirmationDialog(purchase, gift?.third)
}
} catch (throwable: Throwable) {
handleError(throwable, purchase)
}
Expand All @@ -393,13 +395,15 @@ class PurchaseHandler(
val validationRequest = buildValidationRequest(purchase)
MainScope().launchCatching {
try {
apiClient.validateNoRenewSubscription(validationRequest)
val response = apiClient.validateNoRenewSubscription(validationRequest)
processedPurchase(purchase)
val gift = removeGift(sku)
withContext(Dispatchers.IO) {
consume(purchase)
}
displayConfirmationDialog(purchase, gift?.third)
if (response != null) {
displayConfirmationDialog(purchase, gift?.third)
}
} catch (throwable: Throwable) {
handleError(throwable, purchase)
}
Expand All @@ -410,12 +414,14 @@ class PurchaseHandler(
val validationRequest = buildValidationRequest(purchase)
MainScope().launchCatching {
try {
apiClient.validateSubscription(validationRequest)
val response = apiClient.validateSubscription(validationRequest)
processedPurchase(purchase)
CoroutineScope(Dispatchers.IO).launch(ExceptionHandler.coroutine()) {
acknowledgePurchase(purchase)
}
displayConfirmationDialog(purchase)
if (response != null) {
displayConfirmationDialog(purchase)
}
} catch (throwable: Throwable) {
handleError(throwable, purchase)
}
Expand Down Expand Up @@ -623,9 +629,6 @@ class PurchaseHandler(
message?.let { alert.setMessage(it) }
alert.addOkButton { dialog, _ ->
dialog.dismiss()
if (activity is PurchaseActivity) {
activity.finish()
}
}
alert.enqueue()
}
Expand Down Expand Up @@ -653,9 +656,6 @@ class PurchaseHandler(
alert.setMessage(message)
alert.addOkButton { dialog, _ ->
dialog.dismiss()
if (activity is PurchaseActivity) {
activity.finish()
}
}
alert.enqueue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ class GiftOneGetOneHabiticaPromotion(startDate: Date?, endDate: Date?) : Habitic
binding.promoBannerTitleImage.visibility = View.GONE
binding.promoBannerDurationView.visibility = View.GONE
binding.promoBannerTitleText.visibility = View.VISIBLE
binding.promoBannerSubtitleText.text = context.getString(R.string.gift_one_get_one)
binding.promoBannerSubtitleText.visibility = View.VISIBLE
val formatter = SimpleDateFormat("MMM d", Locale.getDefault())
binding.promoBannerTitleText.text =
binding.promoBannerSubtitleText.text =
context.getString(R.string.gift_one_get_one_purchase_banner, formatter.format(endDate))
}

Expand All @@ -117,8 +119,10 @@ class GiftOneGetOneHabiticaPromotion(startDate: Date?, endDate: Date?) : Habitic
binding.content.promoBannerTitleImage.visibility = View.GONE
binding.content.promoBannerDurationView.visibility = View.GONE
binding.content.promoBannerTitleText.visibility = View.VISIBLE
binding.content.promoBannerSubtitleText.text = context.getString(R.string.gift_one_get_one)
binding.content.promoBannerSubtitleText.visibility = View.VISIBLE
val formatter = SimpleDateFormat("MMM d", Locale.getDefault())
binding.content.promoBannerTitleText.text =
binding.content.promoBannerSubtitleText.text =
context.getString(R.string.gift_one_get_one_purchase_banner, formatter.format(endDate))
}

Expand Down Expand Up @@ -183,15 +187,11 @@ class GiftOneGetOneHabiticaPromotion(startDate: Date?, endDate: Date?) : Habitic
context.getString(R.string.g1g1_promo_info_instructions)
val limitationsFormatter =
SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG)
val utcTimeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.LONG)
utcTimeFormatter.timeZone = TimeZone.getTimeZone("UTC")
fragment.binding?.limitationsDescriptionView?.text =
context.getString(
R.string.g1g1_promo_info_limitations_fixed,
R.string.g1g1_promo_info_limitations_noutc,
limitationsFormatter.format(startDate),
utcTimeFormatter.format(startDate),
limitationsFormatter.format(endDate),
utcTimeFormatter.format(endDate),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.models.promotions

import android.content.Context
import android.graphics.drawable.Drawable
import com.habitrpg.android.habitica.BuildConfig
import com.habitrpg.android.habitica.databinding.FragmentGemPurchaseBinding
import com.habitrpg.android.habitica.databinding.FragmentSubscriptionBinding
import com.habitrpg.android.habitica.databinding.PurchaseGemViewBinding
Expand All @@ -20,6 +21,9 @@ abstract class HabiticaPromotion {
val isActive: Boolean
get() {
val now = Date()
if (BuildConfig.TESTING_LEVEL == "staff") {
return startDate.before(now)
}
return startDate.before(now) && endDate.after(now)
}
abstract val identifier: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ class GiftSubscriptionActivity : PurchaseActivity() {

if (appConfigManager.activePromo()?.identifier == "g1g1") {
binding.giftSubscriptionContainer.visibility = View.VISIBLE
binding.hillsBg.setImageResource(R.drawable.gift_subscription_bg)
} else {
binding.giftSubscriptionContainer.visibility = View.GONE
binding.hillsBg.setImageResource(R.drawable.subscription_bg)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class GemsPurchaseFragment : BaseFragment<FragmentGemPurchaseBinding>() {
val fragment = PromoInfoFragment()
parentFragmentManager
.beginTransaction()
.replace(R.id.fragment_container, fragment as Fragment)
.add(R.id.fragment_container, fragment as Fragment)
.commit()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class SubscriptionFragment : BaseFragment<FragmentSubscriptionBinding>() {
val fragment = PromoInfoFragment()
parentFragmentManager
.beginTransaction()
.replace(R.id.fragment_container, fragment as Fragment)
.add(R.id.fragment_container, fragment as Fragment)
.commit()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class PurchaseDialog(
} else {
limitedTextView.text = context.getString(R.string.gems_left_nomax, gemsLeft)
}
item.limitedNumberLeft = gemsLeft
limitedTextView.visibility = View.VISIBLE
if (gemsLeft == 0) {
limitedTextView.setBackgroundColor(ContextCompat.getColor(context, R.color.orange_10))
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NAME=4.5.0
CODE=8651
CODE=8701

0 comments on commit 92a9292

Please sign in to comment.