Skip to content

Commit

Permalink
subscription display fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Oct 31, 2024
1 parent f46b1f8 commit e4bf648
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Habitica/res/layout/fragment_gem_purchase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
android:layout_marginEnd="84dp"
android:gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="6dp" />
android:layout_marginBottom="4dp" />

<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:fontFamily="@string/font_family_medium"
android:layout_marginStart="84dp"
android:layout_marginEnd="84dp"
android:gravity="center"
Expand Down
3 changes: 2 additions & 1 deletion Habitica/res/layout/fragment_promo_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
android:background="?colorContentBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
4 changes: 2 additions & 2 deletions Habitica/res/layout/fragment_subscription_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@
android:textStyle="bold"
android:gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="6dp" />
android:layout_marginBottom="4dp" />

<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:fontFamily="@string/font_family_medium"
android:gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="6dp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ open class RealmContentLocalRepository(realm: Realm) :
realm1.insertOrUpdate(contentResult.appearances)
realm1.insertOrUpdate(contentResult.backgrounds)
realm1.insertOrUpdate(contentResult.faq)
realm1.insertOrUpdate(contentResult.mystery)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ class RealmInventoryLocalRepository(realm: Realm) :

private fun getLatestMysterySet(): Flow<EquipmentSet?> {
return realm.where(EquipmentSet::class.java)
.equalTo("pinType", "mystery_set")
.sort("key", Sort.DESCENDING)
.findAll()
.toFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PurchaseHandler(
private val context: Context,
private val apiClient: ApiClient,
private val userViewModel: MainUserViewModel,
private val configManager: AppConfigManager
) : PurchasesUpdatedListener, PurchasesResponseListener {
private var billingClient =
BillingClient.newBuilder(context).setListener(this).enablePendingPurchases().build()
Expand Down Expand Up @@ -383,7 +384,7 @@ class PurchaseHandler(
consume(purchase)
}
if (response != null) {
displayConfirmationDialog(purchase, gift?.third)
displayConfirmationDialog(purchase, gift?.second, gift?.third)
}
} catch (throwable: Throwable) {
handleError(throwable, purchase)
Expand All @@ -402,7 +403,7 @@ class PurchaseHandler(
consume(purchase)
}
if (response != null) {
displayConfirmationDialog(purchase, gift?.third)
displayConfirmationDialog(purchase, gift?.second, gift?.third)
}
} catch (throwable: Throwable) {
handleError(throwable, purchase)
Expand Down Expand Up @@ -574,6 +575,7 @@ class PurchaseHandler(

private fun displayConfirmationDialog(
purchase: Purchase,
giftedToID: String? = null,
giftedTo: String? = null,
) {
if (displayedConfirmations.contains(purchase.orderId)) {
Expand All @@ -591,7 +593,11 @@ class PurchaseHandler(
PurchaseTypes.allSubscriptionNoRenewTypes.contains(sku) -> {
title = context.getString(R.string.gift_confirmation_title)
context.getString(
R.string.gift_confirmation_text_sub,
if (configManager.activePromo()?.identifier == "g1g1" && giftedToID != userViewModel.user.value?.id) {
R.string.gift_confirmation_text_sub_g1g1
} else {
R.string.gift_confirmation_text_sub
},
giftedTo,
durationString(sku),
)
Expand Down Expand Up @@ -629,6 +635,11 @@ class PurchaseHandler(
message?.let { alert.setMessage(it) }
alert.addOkButton { dialog, _ ->
dialog.dismiss()
if (giftedTo != null) {
if (activity is PurchaseActivity) {
activity.finish()
}
}
}
alert.enqueue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.models
import com.habitrpg.android.habitica.models.inventory.Customization
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.Mount
Expand All @@ -29,4 +30,5 @@ class ContentResult {
var backgrounds = RealmList<Customization>()
var faq = RealmList<FAQArticle>()
var special = RealmList<SpecialItem>()
var mystery = RealmList<EquipmentSet>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class GiftOneGetOneHabiticaPromotion(startDate: Date?, endDate: Date?) : Habitic
binding.promoBannerLeftImage.setImageDrawable(
ContextCompat.getDrawable(
context,
R.drawable.g1g1_promo_left_small,
R.drawable.g1g1_promo_left,
),
)
binding.promoBannerRightImage.setImageDrawable(
ContextCompat.getDrawable(
context,
R.drawable.g1g1_promo_right_small,
R.drawable.g1g1_promo_right,
),
)
binding.promoBannerTitleImage.visibility = View.GONE
Expand All @@ -107,13 +107,13 @@ class GiftOneGetOneHabiticaPromotion(startDate: Date?, endDate: Date?) : Habitic
binding.content.promoBannerLeftImage.setImageDrawable(
ContextCompat.getDrawable(
context,
R.drawable.g1g1_promo_left_small,
R.drawable.g1g1_promo_left,
),
)
binding.content.promoBannerRightImage.setImageDrawable(
ContextCompat.getDrawable(
context,
R.drawable.g1g1_promo_right_small,
R.drawable.g1g1_promo_right,
),
)
binding.content.promoBannerTitleImage.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ class UserRepositoryModule {
@ApplicationContext context: Context,
apiClient: ApiClient,
userViewModel: MainUserViewModel,
appConfigManager: AppConfigManager
): PurchaseHandler {
return PurchaseHandler(context, apiClient, userViewModel)
return PurchaseHandler(context, apiClient, userViewModel, appConfigManager)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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.hideKeyboard
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,17 @@ class TaskFormActivity : BaseActivity() {
setSupportActionBar(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
tintColor = getThemeColor(R.attr.taskFormTint)
val upperTintColor =
if (forcedTheme == "taskform") getThemeColor(R.attr.taskFormTint) else getThemeColor(R.attr.colorAccent)
if (forcedTheme == "taskform" || forcedTheme == "maroon") {
ToolbarColorHelper.colorizeToolbar(
binding.toolbar,
this,
ContextCompat.getColor(this, R.color.white),
upperTintColor
)
}
tintColor = getThemeColor(R.attr.taskFormTint)
val upperTintColor =
if (forcedTheme == "taskform") getThemeColor(R.attr.taskFormTint) else getThemeColor(R.attr.colorAccent)
supportActionBar?.setBackgroundDrawable(ColorDrawable(upperTintColor))
binding.upperTextWrapper.setBackgroundColor(upperTintColor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.replace
import androidx.lifecycle.lifecycleScope
import com.android.billingclient.api.ProductDetails
import com.habitrpg.android.habitica.R
Expand Down Expand Up @@ -98,7 +99,8 @@ class GemsPurchaseFragment : BaseFragment<FragmentGemPurchaseBinding>() {
val fragment = PromoInfoFragment()
parentFragmentManager
.beginTransaction()
.add(R.id.fragment_container, fragment as Fragment)
.replace(R.id.fragment_container, fragment as Fragment)
.addToBackStack(null)
.commit()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.replace
import androidx.lifecycle.lifecycleScope
import com.android.billingclient.api.ProductDetails
import com.habitrpg.android.habitica.R
Expand Down Expand Up @@ -121,7 +122,8 @@ class SubscriptionFragment : BaseFragment<FragmentSubscriptionBinding>() {
val fragment = PromoInfoFragment()
parentFragmentManager
.beginTransaction()
.add(R.id.fragment_container, fragment as Fragment)
.replace(R.id.fragment_container, fragment as Fragment)
.addToBackStack(null)
.commit()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.models.Skill
import com.habitrpg.android.habitica.models.inventory.Customization
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.Mount
Expand Down Expand Up @@ -112,6 +113,12 @@ class ContentDeserializer : JsonDeserializer<ContentResult> {
}
}

if (obj.has("mystery")) {
for (entry in obj.get("mystery").asJsonObject.entrySet()) {
result.mystery.add(context.deserialize(entry.value, EquipmentSet::class.java))
}
}

result.appearances =
context.deserialize(
obj.get("appearances"),
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=8711
CODE=8771

0 comments on commit e4bf648

Please sign in to comment.