Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Restore free plan option in subscription screens

ashilkn4a84a6623f32
diff --git a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart
index 660facd21f..638f28b080 100644
--- a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart
+++ b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart
@@ -228,6 +228,10 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
freeProductID == _currentSubscription!.productID;
}
+ bool _shouldShowFreePlanCard() {
+ return widget.isOnboarding || _isFreePlanUser();
+ }
+
Future<void> _fetchSubData() async {
try {
final userDetails =
@@ -249,7 +253,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
: Platform.isAndroid
? plan.androidID
: plan.iosID;
- return productID.isNotEmpty;
+ return plan.id != freeProductID && productID.isNotEmpty;
}).toList();
hasYearlyPlans = _plans.any((plan) => plan.period == 'year');
if (showYearlyPlan && hasYearlyPlans) {
@@ -419,13 +423,14 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
Future<void> _filterStorePlansForUi() async {
final billingPlans = await _billingService.getBillingPlans();
+ _freePlan = billingPlans.freePlan;
_plans = billingPlans.plans.where((plan) {
final productID = _isActiveStripeSubscriber
? plan.stripeID
: Platform.isAndroid
? plan.androidID
: plan.iosID;
- return productID.isNotEmpty;
+ return plan.id != freeProductID && productID.isNotEmpty;
}).toList();
hasYearlyPlans = _plans.any((plan) => plan.period == 'year');
if (showYearlyPlan) {
@@ -483,8 +488,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
List<Widget> _getMobilePlanWidgets() {
final List<Widget> planWidgets = [];
- if (_hasActiveSubscription &&
- _currentSubscription!.productID == freeProductID) {
+ if (_shouldShowFreePlanCard()) {
planWidgets.add(
GestureDetector(
onTap: () {
@@ -501,7 +505,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
period: AppLocalizations.of(context).freeTrial,
isActive: widget.isOnboarding
? _selectedProductID == freeProductID
- : true,
+ : _isFreePlanUser(),
isOnboarding: widget.isOnboarding,
),
),
@@ -609,12 +613,9 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
if (!widget.isOnboarding) {
return;
}
- final visibleProductIDs = _plans
- .map(_getPlanProductID)
- .where((id) => id.isNotEmpty)
- .toSet();
- final hasFreeOptionVisible =
- _hasActiveSubscription && _currentSubscription!.productID == freeProductID;
+ final visibleProductIDs =
+ _plans.map(_getPlanProductID).where((id) => id.isNotEmpty).toSet();
+ final hasFreeOptionVisible = _shouldShowFreePlanCard();
if (_selectedProductID == freeProductID && hasFreeOptionVisible) {
return;
@@ -658,8 +659,9 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
return;
}
- final BillingPlan? selectedPlan =
- _plans.where((plan) => _getPlanProductID(plan) == selectedProductID).firstOrNull;
+ final BillingPlan? selectedPlan = _plans
+ .where((plan) => _getPlanProductID(plan) == selectedProductID)
+ .firstOrNull;
if (selectedPlan == null) {
return;
}
@@ -700,7 +702,8 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {
final ProductDetailsResponse response =
await InAppPurchase.instance.queryProductDetails({selectedProductID});
if (response.notFoundIDs.isNotEmpty) {
- final errMsg = "Could not find products: " + response.notFoundIDs.toString();
+ final errMsg =
+ "Could not find products: " + response.notFoundIDs.toString();
_logger.severe(errMsg);
await _dialog.hide();
await showGenericErrorDialog(
diff --git a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart
index f1937c3590..53aae4215f 100644
--- a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart
+++ b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart
@@ -51,6 +51,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
// indicates if user's subscription plan is still active
late bool _hasActiveSubscription;
bool _hideCurrentPlanSelection = false;
+ late FreePlan _freePlan;
List<BillingPlan> _plans = [];
bool _hasLoadedData = false;
bool _isLoading = false;
@@ -89,8 +90,9 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
// _filterPlansForUI is used for initializing initState & plan toggle states
Future<void> _filterStripeForUI() async {
final billingPlans = await _billingService.getBillingPlans();
+ _freePlan = billingPlans.freePlan;
_plans = billingPlans.plans.where((plan) {
- if (plan.stripeID.isEmpty) {
+ if (plan.id == freeProductID || plan.stripeID.isEmpty) {
return false;
}
final isYearlyPlan = plan.period == 'year';
@@ -445,6 +447,30 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
List<Widget> _getStripePlanWidgets() {
final List<Widget> planWidgets = [];
+ if (_shouldShowFreePlanCard()) {
+ planWidgets.add(
+ GestureDetector(
+ onTap: () {
+ if (!widget.isOnboarding) {
+ return;
+ }
+ setState(() {
+ _selectedPlanProductID = freeProductID;
+ });
+ },
+ child: SubscriptionPlanWidget(
+ storage: _freePlan.storage,
+ price: "",
+ period: AppLocalizations.of(context).freeTrial,
+ isActive: widget.isOnboarding
+ ? _selectedPlanProductID == freeProductID
+ : _isFreePlanUser(),
+ isOnboarding: widget.isOnboarding,
+ ),
+ ),
+ );
+ }
+
for (final plan in _plans) {
final productID = plan.stripeID;
if (productID.isEmpty) {
@@ -543,6 +569,15 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
return popularProductIDs.contains(plan.id);
}
+ bool _isFreePlanUser() {
+ return _currentSubscription != null &&
+ _currentSubscription!.productID == freeProductID;
+ }
+
+ bool _shouldShowFreePlanCard() {
+ return widget.isOnboarding || _isFreePlanUser();
+ }
+
void _syncOnboardingSelection() {
if (!widget.isOnboarding) {
return;
@@ -551,6 +586,11 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
.map((plan) => plan.stripeID)
.where((id) => id.isNotEmpty)
.toSet();
+ final hasFreeOptionVisible = _shouldShowFreePlanCard();
+
+ if (_selectedPlanProductID == freeProductID && hasFreeOptionVisible) {
+ return;
+ }
if (_selectedPlanProductID != null &&
visibleProductIDs.contains(_selectedPlanProductID)) {
return;
@@ -561,6 +601,10 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
_selectedPlanProductID = currentProductID;
return;
}
+ if (hasFreeOptionVisible) {
+ _selectedPlanProductID = freeProductID;
+ return;
+ }
_selectedPlanProductID =
visibleProductIDs.isNotEmpty ? visibleProductIDs.first : null;
}