π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Use service locator for locationService
Neeraj Gupta6df4825f8419
diff --git a/mobile/lib/main.dart b/mobile/lib/main.dartindex c683ac950b..2b3e1dd6ee 100644--- a/mobile/lib/main.dart+++ b/mobile/lib/main.dart@@ -35,7 +35,6 @@ import "package:photos/services/filedata/filedata_service.dart";import 'package:photos/services/home_widget_service.dart';import 'package:photos/services/local_file_update_service.dart';import 'package:photos/services/local_sync_service.dart';-import "package:photos/services/location_service.dart";import "package:photos/services/machine_learning/face_ml/person/person_service.dart";import "package:photos/services/machine_learning/machine_learning_controller.dart";import 'package:photos/services/machine_learning/ml_service.dart';@@ -246,10 +245,6 @@ Future<void> _init(bool isBackground, {String via = ''}) async {await UserService.instance.init();_logger.info("UserService init done $tlog");- _logger.info("LocationService init $tlog");- LocationService.instance.init(preferences);- _logger.info("LocationService init done $tlog");-_logger.info("UserRemoteFlagService init $tlog");await UserRemoteFlagService.instance.init();_logger.info("UserRemoteFlagService init done $tlog");diff --git a/mobile/lib/service_locator.dart b/mobile/lib/service_locator.dartindex a1fd77ae93..5191ab8f8a 100644--- a/mobile/lib/service_locator.dart+++ b/mobile/lib/service_locator.dart@@ -5,6 +5,7 @@ import "package:ente_feature_flag/ente_feature_flag.dart";import "package:package_info_plus/package_info_plus.dart";import "package:photos/gateways/entity_gw.dart";import "package:photos/services/entity_service.dart";+import "package:photos/services/location_service.dart";import "package:photos/services/storage_bonus_service.dart";import "package:photos/services/update_service.dart";import "package:photos/utils/local_settings.dart";@@ -78,3 +79,9 @@ EntityService get entityService {);return _entityService!;}++LocationService? _locationService;+LocationService get locationService {+ _locationService ??= LocationService(ServiceLocator.instance.prefs);+ return _locationService!;+}diff --git a/mobile/lib/services/location_service.dart b/mobile/lib/services/location_service.dartindex 09ec26c6f4..6c90408950 100644--- a/mobile/lib/services/location_service.dart+++ b/mobile/lib/services/location_service.dart@@ -3,6 +3,7 @@ import "dart:io";import "dart:math";import "package:computer/computer.dart";+import "package:flutter/foundation.dart";import "package:logging/logging.dart";import "package:photos/core/constants.dart";import "package:photos/core/event_bus.dart";@@ -18,23 +19,20 @@ import "package:photos/services/remote_assets_service.dart";import "package:shared_preferences/shared_preferences.dart";class LocationService {- late SharedPreferences prefs;+ final SharedPreferences prefs;final Logger _logger = Logger((LocationService).toString());final Computer _computer = Computer.shared();- LocationService._privateConstructor();// If the discovery section is loaded before the cities are loaded, then we// need to refresh the discovery section after the cities are loaded.bool reloadLocationDiscoverySection = false;- static final LocationService instance = LocationService._privateConstructor();-static const kCitiesRemotePath = "https://static.ente.io/world_cities.json";List<City> _cities = [];- void init(SharedPreferences preferences) {- prefs = preferences;+ LocationService(this.prefs) {+ debugPrint('LocationService constructor');Future.delayed(const Duration(seconds: 3), () {_loadCities();});diff --git a/mobile/lib/services/search_service.dart b/mobile/lib/services/search_service.dartindex f45f599bbb..c0f81e2db4 100644--- a/mobile/lib/services/search_service.dart+++ b/mobile/lib/services/search_service.dart@@ -634,8 +634,7 @@ class SearchService {}Future<List<GenericSearchResult>> getLocationResults(String query) async {- final locationTagEntities =- (await LocationService.instance.getLocationTags());+ final locationTagEntities = (await locationService.getLocationTags());final Map<LocalEntity<LocationTag>, List<EnteFile>> result = {};final bool showNoLocationTag = query.length > 2 &&"No Location Tag".toLowerCase().startsWith(query.toLowerCase());@@ -720,8 +719,7 @@ class SearchService {if (allCitiesSearch) {query = '';}- final results =- await LocationService.instance.getFilesInCity(allFiles, query);+ final results = await locationService.getFilesInCity(allFiles, query);final List<City> sortedByResultCount = results.keys.toList()..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));for (final city in sortedByResultCount) {@@ -898,8 +896,7 @@ class SearchService {try {final Map<LocalEntity<LocationTag>, List<EnteFile>> tagToItemsMap = {};final List<GenericSearchResult> tagSearchResults = [];- final locationTagEntities =- (await LocationService.instance.getLocationTags());+ final locationTagEntities = (await locationService.getLocationTags());final allFiles = await getAllFiles();final List<EnteFile> filesWithNoLocTag = [];@@ -955,8 +952,8 @@ class SearchService {}}if (limit == null || tagSearchResults.length < limit) {- final results = await LocationService.instance- .getFilesInCity(filesWithNoLocTag, '');+ final results =+ await locationService.getFilesInCity(filesWithNoLocTag, '');final List<City> sortedByResultCount = results.keys.toList()..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));for (final city in sortedByResultCount) {diff --git a/mobile/lib/ui/viewer/file_details/location_tags_widget.dart b/mobile/lib/ui/viewer/file_details/location_tags_widget.dartindex 3544eeb127..4436fcb5e1 100644--- a/mobile/lib/ui/viewer/file_details/location_tags_widget.dart+++ b/mobile/lib/ui/viewer/file_details/location_tags_widget.dart@@ -9,7 +9,7 @@ import "package:photos/core/event_bus.dart";import "package:photos/events/location_tag_updated_event.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/file/file.dart";-import "package:photos/services/location_service.dart";+import "package:photos/service_locator.dart";import "package:photos/services/search_service.dart";import "package:photos/services/user_remote_flag_service.dart";import "package:photos/states/location_screen_state.dart";@@ -105,8 +105,8 @@ class _LocationTagsWidgetState extends State<LocationTagsWidget> {Future<List<Widget>> _getLocationTags() async {// await Future.delayed(const Duration(seconds: 1));- final locationTags = await LocationService.instance- .enclosingLocationTags(widget.file.location!);+ final locationTags =+ await locationService.enclosingLocationTags(widget.file.location!);if (locationTags.isEmpty) {if (mounted) {setState(() {diff --git a/mobile/lib/ui/viewer/location/add_location_sheet.dart b/mobile/lib/ui/viewer/location/add_location_sheet.dartindex 9e1345dc04..29c79babad 100644--- a/mobile/lib/ui/viewer/location/add_location_sheet.dart+++ b/mobile/lib/ui/viewer/location/add_location_sheet.dart@@ -4,7 +4,7 @@ import "package:modal_bottom_sheet/modal_bottom_sheet.dart";import "package:photos/core/constants.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/location/location.dart";-import "package:photos/services/location_service.dart";+import "package:photos/service_locator.dart";import 'package:photos/states/location_state.dart';import "package:photos/theme/colors.dart";import "package:photos/theme/ente_theme.dart";@@ -255,7 +255,7 @@ class _AddLocationSheetState extends State<AddLocationSheet> {final coordinates = locationData.centerPoint;final radius = locationData.selectedRadius;- await LocationService.instance.addLocation(+ await locationService.addLocation(_textEditingController.text.trim(),coordinates,radius,diff --git a/mobile/lib/ui/viewer/location/edit_center_point_tile_widget.dart b/mobile/lib/ui/viewer/location/edit_center_point_tile_widget.dartindex f78009b87f..07fe0cf489 100644--- a/mobile/lib/ui/viewer/location/edit_center_point_tile_widget.dart+++ b/mobile/lib/ui/viewer/location/edit_center_point_tile_widget.dart@@ -1,7 +1,7 @@import "package:flutter/material.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/location/location.dart";-import "package:photos/services/location_service.dart";+import "package:photos/service_locator.dart";import "package:photos/states/location_state.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/components/buttons/icon_button_widget.dart";@@ -14,7 +14,7 @@ class EditCenterPointTileWidget extends StatelessWidget {Widget build(BuildContext context) {final textTheme = getEnteTextTheme(context);final colorScheme = getEnteColorScheme(context);- final centerPointInDMS = LocationService.instance.convertLocationToDMS(+ final centerPointInDMS = locationService.convertLocationToDMS(InheritedLocationTagData.of(context).centerPoint,);return Row(diff --git a/mobile/lib/ui/viewer/location/edit_location_sheet.dart b/mobile/lib/ui/viewer/location/edit_location_sheet.dartindex 66df52e909..fce0765e62 100644--- a/mobile/lib/ui/viewer/location/edit_location_sheet.dart+++ b/mobile/lib/ui/viewer/location/edit_location_sheet.dart@@ -244,7 +244,7 @@ class _EditLocationSheetState extends State<EditLocationSheet> {Future<void> _editLocation() async {final locationTagState = InheritedLocationTagData.of(context);- await LocationService.instance.updateLocationTag(+ await locationService.updateLocationTag(locationTagEntity: locationTagState.locationTagEntity!,newRadius: locationTagState.selectedRadius,newName: _textEditingController.text.trim(),diff --git a/mobile/lib/ui/viewer/location/location_screen.dart b/mobile/lib/ui/viewer/location/location_screen.dartindex 6755aa9223..d2efe4971b 100644--- a/mobile/lib/ui/viewer/location/location_screen.dart+++ b/mobile/lib/ui/viewer/location/location_screen.dart@@ -118,7 +118,7 @@ class LocationScreenPopUpMenu extends StatelessWidget {);} else if (value == "delete") {try {- await LocationService.instance.deleteLocationTag(+ await locationService.deleteLocationTag(InheritedLocationScreenState.of(context).locationTagEntity.id,);Navigator.of(context).pop();diff --git a/mobile/lib/ui/viewer/location/update_location_data_widget.dart b/mobile/lib/ui/viewer/location/update_location_data_widget.dartindex 780cf432eb..f2bdccef60 100644--- a/mobile/lib/ui/viewer/location/update_location_data_widget.dart+++ b/mobile/lib/ui/viewer/location/update_location_data_widget.dart@@ -97,8 +97,7 @@ class _UpdateLocationDataWidgetState extends State<UpdateLocationDataWidget> {child: ValueListenableBuilder(valueListenable: selectedLocation,builder: (context, value, _) {- final locationInDMS =- LocationService.instance.convertLocationToDMS(+ final locationInDMS = locationService.convertLocationToDMS(Location(latitude: value?.latitude,longitude: value?.longitude,