Skip to content

Commit ca2f1d9

Browse files
authored
Fix issue where Champion information was not considered in the UI (#3356)
1 parent 14d010a commit ca2f1d9

File tree

2 files changed

+106
-85
lines changed

2 files changed

+106
-85
lines changed

modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/AccountDetailsViewModel.kt

+2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ class AccountDetailsViewModel
9797
SubscriptionHeaderState.SupporterRenew(
9898
tier = activeSubscription.tier,
9999
expiresIn = activeSubscription.expiryDate?.toDurationFromNow(),
100+
isChampion = status.isPocketCastsChampion,
100101
)
101102
} else {
102103
SubscriptionHeaderState.SupporterCancel(
103104
tier = activeSubscription.tier,
104105
expiresIn = activeSubscription.expiryDate?.toDurationFromNow(),
106+
isChampion = status.isPocketCastsChampion,
105107
)
106108
}
107109
}

modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/AccountHeader.kt

+104-85
Original file line numberDiff line numberDiff line change
@@ -164,105 +164,103 @@ internal sealed interface SubscriptionHeaderState {
164164
data class SupporterRenew(
165165
override val tier: SubscriptionTier,
166166
override val expiresIn: Duration?,
167-
) : SubscriptionHeaderState {
168-
override val isChampion = false
169-
}
167+
override val isChampion: Boolean,
168+
) : SubscriptionHeaderState
170169

171170
data class SupporterCancel(
172171
override val tier: SubscriptionTier,
173172
override val expiresIn: Duration?,
174-
) : SubscriptionHeaderState {
175-
override val isChampion = false
176-
}
173+
override val isChampion: Boolean,
174+
) : SubscriptionHeaderState
177175
}
178176

179177
@Composable
180178
private fun SubscriptionHeaderState.labels(): Labels {
181179
val context = LocalContext.current
182180
return remember(this) {
183-
when (this) {
184-
is SubscriptionHeaderState.Free -> {
185-
Labels(
186-
start = Label(
187-
text = context.getString(LR.string.profile_free_account),
188-
),
189-
)
190-
}
181+
if (isChampion) {
182+
Labels(
183+
start = Label(
184+
text = context.getString(LR.string.plus_thanks_for_your_support_bang),
185+
),
186+
end = Label(
187+
text = context.getString(LR.string.pocket_casts_champion),
188+
color = { support02 },
189+
),
190+
)
191+
} else {
192+
when (this) {
193+
is SubscriptionHeaderState.Free -> {
194+
Labels(
195+
start = Label(
196+
text = context.getString(LR.string.profile_free_account),
197+
),
198+
)
199+
}
191200

192-
is SubscriptionHeaderState.PaidRenew -> {
193-
val expiryDate = Date(Date().time + expiresIn.inWholeMilliseconds)
194-
Labels(
195-
start = Label(
196-
text = context.getString(LR.string.profile_next_payment, expiryDate.toLocalizedFormatLongStyle()),
197-
),
198-
end = Label(
199-
text = when (frequency) {
200-
SubscriptionFrequency.MONTHLY -> context.getString(LR.string.profile_monthly)
201-
SubscriptionFrequency.YEARLY -> context.getString(LR.string.profile_yearly)
202-
SubscriptionFrequency.NONE -> ""
203-
},
204-
),
205-
)
206-
}
201+
is SubscriptionHeaderState.PaidRenew -> {
202+
val expiryDate = Date(Date().time + expiresIn.inWholeMilliseconds)
203+
Labels(
204+
start = Label(
205+
text = context.getString(LR.string.profile_next_payment, expiryDate.toLocalizedFormatLongStyle()),
206+
),
207+
end = Label(
208+
text = when (frequency) {
209+
SubscriptionFrequency.MONTHLY -> context.getString(LR.string.profile_monthly)
210+
SubscriptionFrequency.YEARLY -> context.getString(LR.string.profile_yearly)
211+
SubscriptionFrequency.NONE -> ""
212+
},
213+
),
214+
)
215+
}
207216

208-
is SubscriptionHeaderState.PaidCancel -> {
209-
Labels(
210-
start = Label(
211-
text = when {
212-
isChampion -> {
213-
context.getString(LR.string.plus_thanks_for_your_support_bang)
214-
}
215-
platform == SubscriptionPlatform.GIFT -> {
216-
val daysString = context.resources.getStringPluralDaysMonthsOrYears(giftDaysLeft)
217-
context.getString(LR.string.profile_time_free, daysString)
218-
}
219-
else -> {
220-
context.getString(LR.string.profile_payment_cancelled)
221-
}
222-
},
223-
),
224-
end = Label(
225-
text = if (isChampion) {
226-
context.getString(LR.string.pocket_casts_champion)
227-
} else {
228-
val expiryDate = Date(Date().time + expiresIn.inWholeMilliseconds)
229-
context.getString(LR.string.profile_plus_expires, expiryDate.toLocalizedFormatLongStyle())
230-
},
231-
color = {
232-
if (isChampion) {
233-
support02
234-
} else {
235-
primaryText02
236-
}
237-
},
238-
),
239-
)
240-
}
217+
is SubscriptionHeaderState.PaidCancel -> {
218+
Labels(
219+
start = Label(
220+
text = when {
221+
platform == SubscriptionPlatform.GIFT -> {
222+
val daysString = context.resources.getStringPluralDaysMonthsOrYears(giftDaysLeft)
223+
context.getString(LR.string.profile_time_free, daysString)
224+
}
225+
else -> {
226+
context.getString(LR.string.profile_payment_cancelled)
227+
}
228+
},
229+
),
230+
end = Label(
231+
text = run {
232+
val expiryDate = Date(Date().time + expiresIn.inWholeMilliseconds)
233+
context.getString(LR.string.profile_plus_expires, expiryDate.toLocalizedFormatLongStyle())
234+
},
235+
),
236+
)
237+
}
241238

242-
is SubscriptionHeaderState.SupporterRenew -> {
243-
Labels(
244-
start = Label(
245-
text = context.getString(LR.string.supporter),
246-
color = { support02 },
247-
),
248-
end = Label(
249-
text = context.getString(LR.string.supporter_check_contributions),
250-
),
251-
)
252-
}
239+
is SubscriptionHeaderState.SupporterRenew -> {
240+
Labels(
241+
start = Label(
242+
text = context.getString(LR.string.supporter),
243+
color = { support02 },
244+
),
245+
end = Label(
246+
text = context.getString(LR.string.supporter_check_contributions),
247+
),
248+
)
249+
}
253250

254-
is SubscriptionHeaderState.SupporterCancel -> {
255-
val expiryDate = expiresIn?.inWholeMilliseconds?.let { Date(Date().time + it) }
256-
val expiryString = expiryDate?.toLocalizedFormatLongStyle() ?: context.getString(LR.string.profile_expiry_date_unknown)
257-
Labels(
258-
start = Label(
259-
text = context.getString(LR.string.supporter_payment_cancelled),
260-
color = { support05 },
261-
),
262-
end = Label(
263-
text = context.getString(LR.string.supporter_subscription_ends, expiryString),
264-
),
265-
)
251+
is SubscriptionHeaderState.SupporterCancel -> {
252+
val expiryDate = expiresIn?.inWholeMilliseconds?.let { Date(Date().time + it) }
253+
val expiryString = expiryDate?.toLocalizedFormatLongStyle() ?: context.getString(LR.string.profile_expiry_date_unknown)
254+
Labels(
255+
start = Label(
256+
text = context.getString(LR.string.supporter_payment_cancelled),
257+
color = { support05 },
258+
),
259+
end = Label(
260+
text = context.getString(LR.string.supporter_subscription_ends, expiryString),
261+
),
262+
)
263+
}
266264
}
267265
}
268266
}
@@ -431,6 +429,16 @@ private class AccountHeaderStateParameterProvider : PreviewParameterProvider<Acc
431429
subscription = SubscriptionHeaderState.SupporterRenew(
432430
tier = SubscriptionTier.PLUS,
433431
expiresIn = null,
432+
isChampion = false,
433+
),
434+
),
435+
AccountHeaderState(
436+
email = "[email protected]",
437+
imageUrl = null,
438+
subscription = SubscriptionHeaderState.SupporterRenew(
439+
tier = SubscriptionTier.PLUS,
440+
expiresIn = null,
441+
isChampion = true,
434442
),
435443
),
436444
AccountHeaderState(
@@ -439,6 +447,16 @@ private class AccountHeaderStateParameterProvider : PreviewParameterProvider<Acc
439447
subscription = SubscriptionHeaderState.SupporterCancel(
440448
tier = SubscriptionTier.PLUS,
441449
expiresIn = 10.days,
450+
isChampion = false,
451+
),
452+
),
453+
AccountHeaderState(
454+
email = "[email protected]",
455+
imageUrl = null,
456+
subscription = SubscriptionHeaderState.SupporterCancel(
457+
tier = SubscriptionTier.PLUS,
458+
expiresIn = 10.days,
459+
isChampion = true,
442460
),
443461
),
444462
AccountHeaderState(
@@ -447,6 +465,7 @@ private class AccountHeaderStateParameterProvider : PreviewParameterProvider<Acc
447465
subscription = SubscriptionHeaderState.SupporterCancel(
448466
tier = SubscriptionTier.PLUS,
449467
expiresIn = null,
468+
isChampion = false,
450469
),
451470
),
452471
)

0 commit comments

Comments
 (0)