Skip to content

Commit

Permalink
Update subscription page
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Sep 26, 2024
1 parent b87cb8a commit c61d43b
Show file tree
Hide file tree
Showing 39 changed files with 124 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Habitica/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:label="@string/app_name"
android:theme="@style/MainAppTheme"
android:fullBackupContent="@xml/backup_descriptor"
android:configChanges="orientation"
android:configChanges="orientation|smallestScreenSize|screenLayout"
android:networkSecurityConfig="@xml/network_security_config">
<meta-data
android:name="firebase_performance_logcat_enabled"
Expand Down
Binary file modified Habitica/res/drawable-hdpi/sub_benefits_armoire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Habitica/res/drawable-hdpi/sub_benefits_drops.png
Binary file not shown.
Binary file added Habitica/res/drawable-hdpi/sub_benefits_faint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-hdpi/sub_benefits_gems.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-hdpi/sub_benefits_hourglasses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-hdpi/sub_benefits_pet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-mdpi/sub_benefits_armoire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Habitica/res/drawable-mdpi/sub_benefits_drops.png
Binary file not shown.
Binary file modified Habitica/res/drawable-mdpi/sub_benefits_faint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-mdpi/sub_benefits_gems.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-mdpi/sub_benefits_hourglasses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-mdpi/sub_benefits_pet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xhdpi/sub_benefits_armoire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xhdpi/sub_benefits_faint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xhdpi/sub_benefits_gems.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xhdpi/sub_benefits_hourglasses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xhdpi/sub_benefits_pet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xxhdpi/sub_benefits_armoire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xxhdpi/sub_benefits_faint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xxhdpi/sub_benefits_gems.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xxhdpi/sub_benefits_hourglasses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Habitica/res/drawable-xxhdpi/sub_benefits_pet.png
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/pill_bg_green_10.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">
<solid android:color="@color/green_10"/>
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
15 changes: 8 additions & 7 deletions Habitica/res/layout/fragment_subscription_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@
android:orientation="vertical"
android:padding="24dp">

<com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionDetailsView
android:id="@+id/subscriptionDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ImageView
android:id="@+id/header_image_view"
android:layout_width="wrap_content"
Expand All @@ -119,6 +114,11 @@
android:src="@drawable/subscribe_header_dark"
android:importantForAccessibility="no" />

<com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionDetailsView
android:id="@+id/subscriptionDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" />


<include
android:id="@+id/gift_segment_subscribed"
Expand Down Expand Up @@ -256,6 +256,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/subscription_bg"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
Expand All @@ -270,9 +271,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textColorLink="@color/yellow_100"
android:textSize="13sp"
android:textStyle="italic"
android:gravity="center"/>
android:textStyle="italic"/>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
26 changes: 21 additions & 5 deletions Habitica/res/layout/subscription_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,40 @@
tools:background="@color/content_background"
android:paddingBottom="16dp">

<ImageView
android:id="@+id/heart_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/thanks_for_subscribing"
android:textColor="@color/white"
android:textSize="17sp"
android:layout_gravity="center_horizontal"
android:fontFamily="@string/font_family_medium"
android:layout_marginBottom="14dp"/>

<com.google.android.material.card.MaterialCardView
android:id="@+id/subscription_credit_card"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:cardBackgroundColor="@color/transparent"
app:cardCornerRadius="8dp"
app:strokeColor="@color/green_50"
app:strokeWidth="1dp">
app:strokeColor="@color/green_100"
app:strokeWidth="3dp">

<TextView
android:id="@+id/subscription_credit_text_view"
style="@style/subscriptionBoxText.Subtitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="4dp"
android:textSize="15sp"
android:text="@string/subscription_credit_canceling"
android:textColor="@color/green_50" />
android:textColor="@color/green_500" />

</com.google.android.material.card.MaterialCardView>

Expand Down Expand Up @@ -59,6 +74,7 @@
<TextView
android:id="@+id/subscriptionStatusActive"
style="@style/Pill.Selected.Green"
android:background="@drawable/pill_bg_green_10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
Expand Down
5 changes: 4 additions & 1 deletion Habitica/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@
<string name="belongs_to_challenge">Belongs to Challenge</string>
<string name="has_reminder">Has Reminder</string>
<string name="has_tag">Has Tag</string>
<string name="subscribe_title">Subscribing supports our small team and help keeps Habitica running</string>
<string name="subscribe_title">Subscribing supports our small team and helps keep Habitica running</string>
<string name="subscribe_prompt">Stay motivated with even more rewards when you subscribe</string>
<string name="subscribe_listitem1">Free Monthly Gems</string>
<string name="subscribe_listitem2">Monthly Mystic Hourglass</string>
Expand All @@ -407,6 +407,7 @@
<string name="subscribe_listitem2_description">Never miss an item with 1 Mystic Hourglass a month to use in the Time Travelers Shop!</string>
<string name="subscribe_listitem3_description">Subscribe now to get an exclusive set now and receive new items every month!</string>
<string name="subscribe_listitem3_description_new">Subscribe now to get this %s and receive new items every month!</string>
<string name="subscribe_listitem3_description_alt">Stay decked out in the latest exclusive gear. Subscribe now to get %1$s’s %2$s!</string>
<string name="subscribe_listitem4_description">Receive the Royal Purple Jackalope pet when you become a new subscriber.</string>
<string name="subscribe_listitemFaint_description">Avoid losing your progress with an instant heal when you run out of HP once a day!</string>
<string name="subscribe_listitem5_description">Get a Royal Purple Jackalope plus double the Eggs, Hatching Potions, and Food each day to grow your Pet collection!</string>
Expand Down Expand Up @@ -1550,6 +1551,8 @@
<string name="gem_cap">Gem Cap</string>
<string name="get_12_mystic_hourglasses">Get 12 Mystic Hourglasses immediately after your first 12 month subscription!</string>
<string name="twelve_mystic_hourglasses">12 Mystic Hourglasses</string>
<string name="thanks_for_subscribing">Thanks for subscribing</string>
<string name="set">Set</string>

<plurals name="you_x_others">
<item quantity="zero">You</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.data

import com.habitrpg.android.habitica.models.inventory.Egg
import com.habitrpg.android.habitica.models.inventory.Equipment
import com.habitrpg.android.habitica.models.inventory.EquipmentSet
import com.habitrpg.android.habitica.models.inventory.Food
import com.habitrpg.android.habitica.models.inventory.HatchingPotion
import com.habitrpg.android.habitica.models.inventory.Item
Expand Down Expand Up @@ -153,6 +154,7 @@ interface InventoryRepository : BaseRepository {
fun getItems(itemClass: Class<out Item>): Flow<List<Item>>

fun getLatestMysteryItem(): Flow<Equipment>
fun getLatestMysteryItemAndSet(): Flow<Pair<Equipment, EquipmentSet?>>

fun getItem(
type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.habitrpg.android.habitica.data.local.InventoryLocalRepository
import com.habitrpg.android.habitica.helpers.AppConfigManager
import com.habitrpg.android.habitica.models.inventory.Egg
import com.habitrpg.android.habitica.models.inventory.Equipment
import com.habitrpg.android.habitica.models.inventory.EquipmentSet
import com.habitrpg.android.habitica.models.inventory.Food
import com.habitrpg.android.habitica.models.inventory.HatchingPotion
import com.habitrpg.android.habitica.models.inventory.Item
Expand Down Expand Up @@ -197,6 +198,10 @@ class InventoryRepositoryImpl(
return localRepository.getLatestMysteryItem()
}

override fun getLatestMysteryItemAndSet(): Flow<Pair<Equipment, EquipmentSet?>> {
return localRepository.getLatestMysteryItemAndSet()
}

override fun getItem(
type: String,
key: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.habitrpg.android.habitica.data.local

import com.habitrpg.android.habitica.models.inventory.Equipment
import com.habitrpg.android.habitica.models.inventory.EquipmentSet
import com.habitrpg.android.habitica.models.inventory.Item
import com.habitrpg.android.habitica.models.inventory.Mount
import com.habitrpg.android.habitica.models.inventory.Pet
Expand Down Expand Up @@ -118,6 +119,7 @@ interface InventoryLocalRepository : ContentLocalRepository {
)

fun getLatestMysteryItem(): Flow<Equipment>
fun getLatestMysteryItemAndSet(): Flow<Pair<Equipment, EquipmentSet?>>

fun soldItem(
userID: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.data.local.implementation
import com.habitrpg.android.habitica.data.local.InventoryLocalRepository
import com.habitrpg.android.habitica.models.inventory.Egg
import com.habitrpg.android.habitica.models.inventory.Equipment
import com.habitrpg.android.habitica.models.inventory.EquipmentSet
import com.habitrpg.android.habitica.models.inventory.Food
import com.habitrpg.android.habitica.models.inventory.HatchingPotion
import com.habitrpg.android.habitica.models.inventory.Item
Expand Down Expand Up @@ -455,12 +456,33 @@ class RealmInventoryLocalRepository(realm: Realm) :
.filter { it.isLoaded && it.size > 0 }
.map {
val format = SimpleDateFormat("yyyyMM", Locale.US)
it.first {
it.key?.contains(format.format(Date())) == true
it.first { equipment ->
equipment.key?.contains(format.format(Date())) == true
}
}
}

private fun getLatestMysterySet(): Flow<EquipmentSet?> {
return realm.where(EquipmentSet::class.java)
.equalTo("pinType", "mystery_set")
.sort("key", Sort.DESCENDING)
.findAll()
.toFlow()
.filter { it.isLoaded }
.map {
val format = SimpleDateFormat("yyyyMM", Locale.US)
it.firstOrNull() { set ->
set.key.contains(format.format(Date()))
}
}
}

override fun getLatestMysteryItemAndSet(): Flow<Pair<Equipment, EquipmentSet?>> {
return getLatestMysteryItem().combine(getLatestMysterySet()) { item, set ->
Pair(item, set)
}
}

override fun soldItem(
userID: String,
updatedUser: User,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.habitrpg.android.habitica.models.inventory

import io.realm.RealmObject
import io.realm.annotations.PrimaryKey

open class EquipmentSet: RealmObject() {
@PrimaryKey
var key: String = ""
var text: String = ""
var pinType: String = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open class SubscriptionPlan : RealmObject(), BaseObject {
val totalNumberOfGems: Int
get() {
return if (isActive) {
25 + (consecutive?.gemCapExtra ?: 0)
24 + (consecutive?.gemCapExtra ?: 0)
} else {
0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.updateStatusBarColor
import com.habitrpg.android.habitica.ui.fragments.purchases.GemsPurchaseFragment
import com.habitrpg.android.habitica.ui.fragments.purchases.SubscriptionFragment
import com.habitrpg.android.habitica.ui.helpers.ToolbarColorHelper
import com.habitrpg.common.habitica.extensions.getThemeColor
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -25,7 +27,11 @@ class GemPurchaseActivity : PurchaseActivity() {
showSubscription = !(intent.extras?.containsKey("openSubscription") == true && intent.extras?.getBoolean("openSubscription") == false)

val toolbar = findViewById<Toolbar>(R.id.toolbar)
setupToolbar(toolbar, Color.WHITE, ContextCompat.getColor(this, R.color.brand_300))
if (showSubscription) {
setupToolbar(toolbar, Color.WHITE, ContextCompat.getColor(this, R.color.brand_300))
} else {
setupToolbar(toolbar)
}

supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
Expand All @@ -39,10 +45,10 @@ class GemPurchaseActivity : PurchaseActivity() {
}
}

override fun onStart() {
super.onStart()
override fun onResume() {
super.onResume()
if (showSubscription) {
toolbar?.let { ToolbarColorHelper.colorizeToolbar(it, this,) }
window.updateStatusBarColor(ContextCompat.getColor(this, R.color.brand_300), false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ open class SubscriptionBottomSheetFragment : BottomSheetDialogFragment() {
user?.let { setUser(it) }
}
}

binding.content.subscriptionDetails.visibility = View.GONE
binding.content.subscribeBenefitsFooter.visibility = View.GONE
binding.content.giftSegmentSubscribed.root.visibility = View.GONE
binding.content.giftSegmentUnsubscribed.root.visibility = View.VISIBLE
binding.content.subscriptionDisclaimerView.visibility = View.VISIBLE
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ class SubscriptionFragment : BaseFragment<FragmentSubscriptionBinding>() {
val subscriptions = purchaseHandler.getAllSubscriptionProducts()
skus = subscriptions
withContext(Dispatchers.Main) {
binding?.content?.loadingIndicator?.visibility = View.GONE
if (subscriptions.isEmpty()) {
binding?.content?.loadingIndicator?.visibility = View.GONE
binding?.content?.noBillingSubscriptions?.visibility = View.VISIBLE
binding?.content?.visitHabiticaWebsiteButton?.visibility = View.VISIBLE
if (user?.isSubscribed != true) {
binding?.content?.noBillingSubscriptions?.visibility = View.VISIBLE
binding?.content?.visitHabiticaWebsiteButton?.visibility = View.VISIBLE
}
return@withContext
}
binding?.content?.noBillingSubscriptions?.visibility = View.GONE
Expand All @@ -187,7 +189,7 @@ class SubscriptionFragment : BaseFragment<FragmentSubscriptionBinding>() {
?: "",
)
}
subscriptions.minByOrNull {
subscriptions.maxByOrNull {
it.subscriptionOfferDetails?.firstOrNull()?.pricingPhases?.pricingPhaseList?.firstOrNull()?.priceAmountMicros
?: 0
}?.let { selectSubscription(it) }
Expand Down Expand Up @@ -273,16 +275,19 @@ class SubscriptionFragment : BaseFragment<FragmentSubscriptionBinding>() {
binding?.content?.giftSegmentUnsubscribed?.root?.visibility = View.GONE
binding?.content?.giftSegmentSubscribed?.root?.visibility = View.VISIBLE
binding?.content?.subscribeBenefitsTitle?.visibility = View.GONE
binding?.content?.subscriptionDisclaimerView?.visibility = View.GONE
} else {
binding?.content?.headerImageView?.setImageResource(R.drawable.subscribe_header_dark)
if (!hasLoadedSubscriptionOptions) {
return
}
binding?.content?.subscriptionDetails?.visibility = View.GONE
binding?.content?.subscribeBenefitsTitle?.setText(R.string.subscribe_prompt)
binding?.content?.subscribeBenefitsTitle?.visibility = View.VISIBLE
binding?.content?.subscribeBenefitsFooter?.visibility = View.GONE
binding?.content?.giftSegmentSubscribed?.root?.visibility = View.GONE
binding?.content?.giftSegmentUnsubscribed?.root?.visibility = View.VISIBLE
binding?.content?.subscriptionDisclaimerView?.visibility = View.VISIBLE

binding?.content?.subscription12month?.showHourglassPromo(user?.purchased?.plan?.isEligableForHourglassPromo == true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.firstOrNull
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import javax.inject.Inject

class SubscriberBenefitView
Expand All @@ -27,6 +30,8 @@ class SubscriberBenefitView
) : LinearLayout(context, attrs) {
private val binding: SubscriptionBenefitsBinding = SubscriptionBenefitsBinding.inflate(context.layoutInflater, this)

val monthFormatter = SimpleDateFormat("MMMM", Locale.getDefault())

@Inject
lateinit var configManager: AppConfigManager

Expand All @@ -49,7 +54,9 @@ class SubscriberBenefitView
inventoryRepository = hiltEntryPoint.inventoryRepository()

MainScope().launchCatching {
val item = inventoryRepository.getLatestMysteryItem().firstOrNull()
val pair = inventoryRepository.getLatestMysteryItemAndSet().firstOrNull()
val item = pair?.first
val set = pair?.second
binding.subBenefitsMysteryItemIcon.loadImage(
"shop_set_mystery_${
item?.key?.split(
Expand All @@ -58,8 +65,10 @@ class SubscriberBenefitView
}",
)
binding.subBenefitsMysteryItemText.text =
context.getString(R.string.subscribe_listitem3_description_new, item?.text)
context.getString(R.string.subscribe_listitem3_description_alt, monthFormatter.format(Date()), set?.text ?: context.getString(R.string.set))
}
binding.subBenefitsMysteryItemText.text =
context.getString(R.string.subscribe_listitem3_description_alt, monthFormatter.format(Date()), context.getString(R.string.set))

binding.benefitArmoireWrapper.isVisible = configManager.enableArmoireSubs()
binding.benefitFaintWrapper.isVisible = configManager.enableFaintSubs()
Expand Down
Loading

0 comments on commit c61d43b

Please sign in to comment.