improve subscription handling in some cases

This commit is contained in:
Phillip Thelen 2024-10-23 10:22:37 +02:00
parent 1aa3f66ccb
commit 92a9292c46
20 changed files with 79 additions and 39 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View file

@ -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>

View file

@ -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"

View file

@ -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"
@ -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"

View file

@ -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"
@ -102,6 +102,8 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:layout_marginStart="84dp"
android:layout_marginEnd="84dp"
android:orientation="vertical">
<ImageView
@ -109,18 +111,27 @@
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:visibility="gone" />
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:layout_marginBottom="6dp" />
<TextView
android:id="@+id/promo_banner_duration_view"

View file

@ -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" />

View file

@ -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, youll receive a matching subscription automatically after sending your gift.</string>
<string name="gift_subscription_subtitle">Choose the subscription youd like to gift! This purchase wont renew.</string>
<string name="gift_gems_subtitle">Choose the gem packet youd like to gift below!</string>
@ -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 youd like to gift to. From there, pick the sub length youd 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>

View file

@ -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">

View file

@ -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
}

View file

@ -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)
}
@ -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)
}
@ -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)
}
@ -623,9 +629,6 @@ class PurchaseHandler(
message?.let { alert.setMessage(it) }
alert.addOkButton { dialog, _ ->
dialog.dismiss()
if (activity is PurchaseActivity) {
activity.finish()
}
}
alert.enqueue()
}
@ -653,9 +656,6 @@ class PurchaseHandler(
alert.setMessage(message)
alert.addOkButton { dialog, _ ->
dialog.dismiss()
if (activity is PurchaseActivity) {
activity.finish()
}
}
alert.enqueue()
}

View file

@ -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))
}
@ -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))
}
@ -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),
)
}
}

View file

@ -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
@ -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

View file

@ -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)
}
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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))

View file

@ -1,2 +1,2 @@
NAME=4.5.0
CODE=8651
CODE=8701