π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Use service locator for storage bonus
Neeraj Guptab9e5b10ed637
diff --git a/mobile/lib/main.dart b/mobile/lib/main.dartindex f091af6fef..f355f6f6e8 100644--- a/mobile/lib/main.dart+++ b/mobile/lib/main.dart@@ -45,7 +45,6 @@ import "package:photos/services/notification_service.dart";import 'package:photos/services/push_service.dart';import 'package:photos/services/remote_sync_service.dart';import 'package:photos/services/search_service.dart';-import "package:photos/services/storage_bonus_service.dart";import 'package:photos/services/sync_service.dart';import 'package:photos/services/trash_sync_service.dart';import 'package:photos/services/update_service.dart';@@ -288,7 +287,6 @@ Future<void> _init(bool isBackground, {String via = ''}) async {MemoriesService.instance.init(preferences);LocalFileUpdateService.instance.init(preferences);SearchService.instance.init();- StorageBonusService.instance.init(preferences);FileDataService.instance.init(preferences);_logger.info("RemoteFileMLService done");if (!isBackground &&diff --git a/mobile/lib/service_locator.dart b/mobile/lib/service_locator.dartindex 053be4784e..ee829e961c 100644--- a/mobile/lib/service_locator.dart+++ b/mobile/lib/service_locator.dart@@ -2,6 +2,7 @@ import "package:dio/dio.dart";import "package:ente_cast/ente_cast.dart";import "package:ente_cast_normal/ente_cast_normal.dart";import "package:ente_feature_flag/ente_feature_flag.dart";+import "package:photos/services/storage_bonus_service.dart";import "package:photos/utils/local_settings.dart";import "package:shared_preferences/shared_preferences.dart";@@ -40,3 +41,12 @@ LocalSettings get localSettings {_localSettings ??= LocalSettings(ServiceLocator.instance.prefs);return _localSettings!;}++StorageBonusService? _storageBonusService;+StorageBonusService get storageBonusService {+ _storageBonusService ??= StorageBonusService(+ ServiceLocator.instance.prefs,+ ServiceLocator.instance.enteDio,+ );+ return _storageBonusService!;+}diff --git a/mobile/lib/services/storage_bonus_service.dart b/mobile/lib/services/storage_bonus_service.dartindex 520d9b7de2..7881fd11ef 100644--- a/mobile/lib/services/storage_bonus_service.dart+++ b/mobile/lib/services/storage_bonus_service.dart@@ -1,23 +1,17 @@-import "package:photos/core/network/network.dart";+import "package:dio/dio.dart";import "package:photos/gateways/storage_bonus_gw.dart";+import "package:photos/models/api/storage_bonus/storage_bonus.dart";import "package:shared_preferences/shared_preferences.dart";class StorageBonusService {- late StorageBonusGateway gateway;- late SharedPreferences prefs;+ final StorageBonusGateway gateway;+ final SharedPreferences prefs;final int minTapCountBeforeHidingBanner = 1;final String _showStorageBonusTapCount = "showStorageBonus.tap_count";- void init(SharedPreferences preferences) {- prefs = preferences;- gateway = StorageBonusGateway(NetworkClient.instance.enteDio);- }-- StorageBonusService._privateConstructor();-- static StorageBonusService instance =- StorageBonusService._privateConstructor();+ StorageBonusService(this.prefs, Dio enteDio)+ : gateway = StorageBonusGateway(enteDio);// returns true if _showStorageBonusTapCount value is less than minTapCountBeforeHidingBannerbool shouldShowStorageBonus() {@@ -30,8 +24,19 @@ class StorageBonusService {prefs.setInt(_showStorageBonusTapCount, tapCount + 1).ignore();}- // getter for gateway- StorageBonusGateway getGateway() {- return gateway;+ Future<void> applyCode(String code) {+ return gateway.claimReferralCode(code.trim().toUpperCase());+ }++ Future<void> updateCode(String code) {+ return gateway.updateCode(code.trim().toUpperCase());+ }++ Future<ReferralView> getReferralView() {+ return gateway.getReferralView();+ }++ Future<BonusDetails> getBonusDetails() {+ return gateway.getBonusDetails();}}diff --git a/mobile/lib/ui/growth/apply_code_screen.dart b/mobile/lib/ui/growth/apply_code_screen.dartindex 2473479dd0..789a7778d7 100644--- a/mobile/lib/ui/growth/apply_code_screen.dart+++ b/mobile/lib/ui/growth/apply_code_screen.dart@@ -4,7 +4,7 @@ import "package:photos/extensions/input_formatter.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/storage_bonus/storage_bonus.dart";import "package:photos/models/user_details.dart";-import "package:photos/services/storage_bonus_service.dart";+import "package:photos/service_locator.dart";import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/components/buttons/button_widget.dart';import 'package:photos/ui/components/buttons/icon_button_widget.dart';@@ -119,9 +119,7 @@ class _ApplyCodeScreenState extends State<ApplyCodeScreen> {isDisabled: code.trim().length < 4,onTap: () async {try {- await StorageBonusService.instance- .getGateway()- .claimReferralCode(code.trim().toUpperCase());+ await storageBonusService.applyCode(code);// ignore: unawaited_futuresNavigator.of(context).pushReplacement(MaterialPageRoute(diff --git a/mobile/lib/ui/growth/referral_code_widget.dart b/mobile/lib/ui/growth/referral_code_widget.dartindex a314360be8..cb139c7263 100644--- a/mobile/lib/ui/growth/referral_code_widget.dart+++ b/mobile/lib/ui/growth/referral_code_widget.dart@@ -4,7 +4,7 @@ import "package:flutter/material.dart";import "package:logging/logging.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/user_details.dart";-import "package:photos/services/storage_bonus_service.dart";+import "package:photos/service_locator.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/utils/dialog_util.dart";@@ -104,9 +104,7 @@ class ReferralCodeWidget extends StatelessWidget {}try {- await StorageBonusService.instance- .getGateway()- .updateCode(text.trim().toUpperCase());+ await storageBonusService.updateCode(text);notifyParent?.call();} catch (e, s) {Logger("ReferralCodeWidget").severe("Failed to update code", e, s);diff --git a/mobile/lib/ui/growth/referral_screen.dart b/mobile/lib/ui/growth/referral_screen.dartindex 7e8cdef434..6a913415bd 100644--- a/mobile/lib/ui/growth/referral_screen.dart+++ b/mobile/lib/ui/growth/referral_screen.dart@@ -2,7 +2,7 @@ import "package:flutter/material.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/storage_bonus/storage_bonus.dart";import "package:photos/models/user_details.dart";-import "package:photos/services/storage_bonus_service.dart";+import "package:photos/service_locator.dart";import "package:photos/services/user_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/loading_widget.dart";@@ -42,8 +42,7 @@ class _ReferralScreenState extends State<ReferralScreen> {UserService.instance.getCachedUserDetails();cachedUserDetails ??=await UserService.instance.getUserDetailsV2(memoryCount: false);- final referralView =- await StorageBonusService.instance.getGateway().getReferralView();+ final referralView = await storageBonusService.getReferralView();return Tuple2(referralView, cachedUserDetails);}diff --git a/mobile/lib/ui/growth/storage_details_screen.dart b/mobile/lib/ui/growth/storage_details_screen.dartindex 941f9f359d..286772593c 100644--- a/mobile/lib/ui/growth/storage_details_screen.dart+++ b/mobile/lib/ui/growth/storage_details_screen.dart@@ -4,7 +4,7 @@ import "package:flutter/material.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/storage_bonus/storage_bonus.dart";import "package:photos/models/user_details.dart";-import "package:photos/services/storage_bonus_service.dart";+import "package:photos/service_locator.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/loading_widget.dart";import 'package:photos/ui/components/buttons/icon_button_widget.dart';@@ -66,9 +66,7 @@ class _StorageDetailsScreenState extends State<StorageDetailsScreen> {// wrap the child inside a FutureBuilder to get the// current state of the TextFieldchild: FutureBuilder<BonusDetails>(- future: StorageBonusService.instance- .getGateway()- .getBonusDetails(),+ future: storageBonusService.getBonusDetails(),builder: (context, snapshot) {if (snapshot.connectionState ==ConnectionState.waiting) {diff --git a/mobile/lib/ui/settings_page.dart b/mobile/lib/ui/settings_page.dartindex 88251fc635..274e2c785f 100644--- a/mobile/lib/ui/settings_page.dart+++ b/mobile/lib/ui/settings_page.dart@@ -8,7 +8,6 @@ import 'package:photos/core/event_bus.dart';import 'package:photos/events/opened_settings_event.dart';import "package:photos/generated/l10n.dart";import "package:photos/service_locator.dart";-import "package:photos/services/storage_bonus_service.dart";import 'package:photos/theme/colors.dart';import 'package:photos/theme/ente_theme.dart';import "package:photos/ui/components/notification_widget.dart";@@ -88,7 +87,7 @@ class SettingsPage extends StatelessWidget {contents.add(const SizedBox(height: 8));if (hasLoggedIn) {final showStorageBonusBanner =- StorageBonusService.instance.shouldShowStorageBonus();+ storageBonusService.shouldShowStorageBonus();contents.addAll([const StorageCardWidget(),(showStorageBonusBanner)@@ -102,7 +101,7 @@ class SettingsPage extends StatelessWidget {subText: S.of(context).referFriendsAnd2xYourPlan,type: NotificationType.goldenBanner,onTap: () async {- StorageBonusService.instance.markStorageBonusAsDone();+ storageBonusService.markStorageBonusAsDone();// ignore: unawaited_futuresrouteToPage(context, const ReferralScreen());},