diff --git a/lib/application/settings/settings_bloc.dart b/lib/application/settings/settings_bloc.dart index ad40322d6..a0f91fc34 100644 --- a/lib/application/settings/settings_bloc.dart +++ b/lib/application/settings/settings_bloc.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:genshindb/application/url_page/url_page_bloc.dart'; import 'package:genshindb/domain/enums/enums.dart'; import 'package:genshindb/domain/services/device_info_service.dart'; import 'package:genshindb/domain/services/settings_service.dart'; @@ -18,8 +19,15 @@ class SettingsBloc extends Bloc { final DeviceInfoService _deviceInfoService; final MainBloc _mainBloc; final HomeBloc _homeBloc; + final UrlPageBloc _urlPageBloc; - SettingsBloc(this._settingsService, this._deviceInfoService, this._mainBloc, this._homeBloc) : super(const SettingsState.loading()); + SettingsBloc( + this._settingsService, + this._deviceInfoService, + this._mainBloc, + this._homeBloc, + this._urlPageBloc, + ) : super(const SettingsState.loading()); _LoadedState get currentState => state as _LoadedState; @@ -39,6 +47,7 @@ class SettingsBloc extends Bloc { showWeaponDetails: settings.showWeaponDetails, serverResetTime: settings.serverResetTime, doubleBackToClose: settings.doubleBackToClose, + useOfficialMap: settings.useOfficialMap, ); }, themeChanged: (event) async { @@ -73,6 +82,11 @@ class SettingsBloc extends Bloc { _settingsService.doubleBackToClose = event.newValue; return currentState.copyWith.call(doubleBackToClose: event.newValue); }, + useOfficialMapChanged: (event) async { + _settingsService.useOfficialMap = event.newValue; + _urlPageBloc.add(const UrlPageEvent.init(loadMap: false, loadWishSimulator: false)); + return currentState.copyWith.call(useOfficialMap: event.newValue); + }, ); yield s; diff --git a/lib/application/settings/settings_event.dart b/lib/application/settings/settings_event.dart index 621a2eb85..a5c3c7840 100644 --- a/lib/application/settings/settings_event.dart +++ b/lib/application/settings/settings_event.dart @@ -31,4 +31,8 @@ abstract class SettingsEvent with _$SettingsEvent { const factory SettingsEvent.doubleBackToCloseChanged({ @required bool newValue, }) = _DoubleBackToCloseChanged; + + const factory SettingsEvent.useOfficialMapChanged({ + @required bool newValue, + }) = _UseOfficialMapChanged; } diff --git a/lib/application/settings/settings_state.dart b/lib/application/settings/settings_state.dart index 1040bdfd7..f7753cdab 100644 --- a/lib/application/settings/settings_state.dart +++ b/lib/application/settings/settings_state.dart @@ -12,5 +12,6 @@ abstract class SettingsState with _$SettingsState { @required bool showWeaponDetails, @required AppServerResetTimeType serverResetTime, @required bool doubleBackToClose, + @required bool useOfficialMap, }) = _LoadedState; } diff --git a/lib/application/url_page/url_page_bloc.dart b/lib/application/url_page/url_page_bloc.dart index 79c249df1..a0122bd62 100644 --- a/lib/application/url_page/url_page_bloc.dart +++ b/lib/application/url_page/url_page_bloc.dart @@ -4,6 +4,7 @@ import 'package:bloc/bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:genshindb/domain/services/device_info_service.dart'; import 'package:genshindb/domain/services/network_service.dart'; +import 'package:genshindb/domain/services/settings_service.dart'; import 'package:genshindb/domain/services/telemetry_service.dart'; part 'url_page_bloc.freezed.dart'; @@ -12,13 +13,20 @@ part 'url_page_state.dart'; class UrlPageBloc extends Bloc { final wishSimulatorUrl = 'https://gi-wish-simulator.uzairashraf.dev'; - final mapUrl = 'https://genshin-impact-map.appsample.com'; + final officialMapUrl = 'https://webstatic-sea.mihoyo.com/app/ys-map-sea/index.html'; + final unofficialMapUrl = 'https://genshin-impact-map.appsample.com'; final NetworkService _networkService; final TelemetryService _telemetryService; final DeviceInfoService _deviceInfoService; + final SettingsService _settingsService; - UrlPageBloc(this._networkService, this._telemetryService, this._deviceInfoService) : super(const UrlPageState.loading()); + UrlPageBloc( + this._networkService, + this._telemetryService, + this._deviceInfoService, + this._settingsService, + ) : super(const UrlPageState.loading()); @override Stream mapEventToState( @@ -26,11 +34,12 @@ class UrlPageBloc extends Bloc { ) async* { final s = await event.map( init: (e) async { + final finalMapUrl = _settingsService.useOfficialMap ? officialMapUrl : unofficialMapUrl; final isInternetAvailable = await _networkService.isInternetAvailable(); await _telemetryService.trackUrlOpened(e.loadMap, e.loadWishSimulator, isInternetAvailable); return UrlPageState.loaded( hasInternetConnection: isInternetAvailable, - mapUrl: mapUrl, + mapUrl: finalMapUrl, wishSimulatorUrl: wishSimulatorUrl, userAgent: _deviceInfoService.userAgent, ); diff --git a/lib/domain/models/settings/app_settings.dart b/lib/domain/models/settings/app_settings.dart index 9ce32853b..b180b0f88 100644 --- a/lib/domain/models/settings/app_settings.dart +++ b/lib/domain/models/settings/app_settings.dart @@ -19,6 +19,7 @@ abstract class AppSettings implements _$AppSettings { @required bool isFirstInstall, @required AppServerResetTimeType serverResetTime, @required bool doubleBackToClose, + @required bool useOfficialMap, }) = _AppSettings; const AppSettings._(); diff --git a/lib/domain/services/settings_service.dart b/lib/domain/services/settings_service.dart index 97baed7d0..f8c806d11 100644 --- a/lib/domain/services/settings_service.dart +++ b/lib/domain/services/settings_service.dart @@ -28,5 +28,8 @@ abstract class SettingsService { bool get doubleBackToClose; set doubleBackToClose(bool value); + bool get useOfficialMap; + set useOfficialMap(bool value); + Future init(); } diff --git a/lib/infrastructure/settings_service.dart b/lib/infrastructure/settings_service.dart index 896f1f483..702b9ce40 100644 --- a/lib/infrastructure/settings_service.dart +++ b/lib/infrastructure/settings_service.dart @@ -15,6 +15,7 @@ class SettingsServiceImpl extends SettingsService { final _showWeaponDetailsKey = 'ShowWeaponDetailsKey'; final _serverResetTimeKey = 'ServerResetTimeKey'; final _doubleBackToCloseKey = 'DoubleBackToCloseKey'; + final _useOfficialMapKey = 'UseOfficialMapKey'; bool _initialized = false; @@ -69,6 +70,12 @@ class SettingsServiceImpl extends SettingsService { @override set doubleBackToClose(bool value) => _prefs.setBool(_doubleBackToCloseKey, value); + @override + bool get useOfficialMap => _prefs.getBool(_useOfficialMapKey); + + @override + set useOfficialMap(bool value) => _prefs.setBool(_useOfficialMapKey, value); + @override AppSettings get appSettings => AppSettings( appTheme: appTheme, @@ -80,6 +87,7 @@ class SettingsServiceImpl extends SettingsService { isFirstInstall: isFirstInstall, serverResetTime: serverResetTime, doubleBackToClose: doubleBackToClose, + useOfficialMap: useOfficialMap, ); SettingsServiceImpl(this._logger); @@ -134,6 +142,11 @@ class SettingsServiceImpl extends SettingsService { doubleBackToClose = false; } + if (_prefs.get(_useOfficialMapKey) == null) { + _logger.info(runtimeType, 'Use the official map will be set to its default (false)'); + useOfficialMap = false; + } + _initialized = true; _logger.info(runtimeType, 'Settings were initialized successfully'); } diff --git a/lib/infrastructure/telemetry/telemetry_service.dart b/lib/infrastructure/telemetry/telemetry_service.dart index 8b0eb816d..418e19a00 100644 --- a/lib/infrastructure/telemetry/telemetry_service.dart +++ b/lib/infrastructure/telemetry/telemetry_service.dart @@ -98,6 +98,7 @@ class TelemetryServiceImpl implements TelemetryService { 'IsFirstInstall': settings.isFirstInstall.toString(), 'ServerResetTime': EnumToString.convertToString(settings.serverResetTime), 'DoubleBackToClose': settings.doubleBackToClose.toString(), + 'UseOfficialMap': settings.useOfficialMap.toString(), }); } diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 94c065bb9..8d38b9b91 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -292,5 +292,6 @@ "pressOnceAgainToExit": "Press once again to exit", "discordServer": "Discord Server", "usedItem": "Used item", - "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}" + "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}", + "useOfficialMap": "Use the official map" } \ No newline at end of file diff --git a/lib/l10n/intl_es_ES.arb b/lib/l10n/intl_es_ES.arb index 629130c30..03f72446a 100644 --- a/lib/l10n/intl_es_ES.arb +++ b/lib/l10n/intl_es_ES.arb @@ -292,5 +292,6 @@ "pressOnceAgainToExit": "Presiona una vez más para salir", "discordServer": "Servidor de Discord", "usedItem": "Item usado", - "itemIsBeingUsedOnACalculation": "Este item está siendo usado en una o más sesiones de la calculadora.\nLa cantidad usada es {quantity}" + "itemIsBeingUsedOnACalculation": "Este item está siendo usado en una o más sesiones de la calculadora.\nLa cantidad usada es {quantity}", + "useOfficialMap": "Usar el mapa oficial" } \ No newline at end of file diff --git a/lib/l10n/intl_pt.arb b/lib/l10n/intl_pt.arb index 604f77e24..1def56513 100644 --- a/lib/l10n/intl_pt.arb +++ b/lib/l10n/intl_pt.arb @@ -292,5 +292,6 @@ "pressOnceAgainToExit": "Press once again to exit", "discordServer": "Discord Server", "usedItem": "Used item", - "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}" + "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}", + "useOfficialMap": "Use the official map" } \ No newline at end of file diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 772768212..fdc0c3f20 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -292,5 +292,6 @@ "pressOnceAgainToExit": "Нажмите еще раз, чтобы выйти", "discordServer": "Discord Server", "usedItem": "Used item", - "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}" + "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}", + "useOfficialMap": "Use the official map" } \ No newline at end of file diff --git a/lib/l10n/intl_zh_CN.arb b/lib/l10n/intl_zh_CN.arb index 4569f4c31..ea6d8286d 100644 --- a/lib/l10n/intl_zh_CN.arb +++ b/lib/l10n/intl_zh_CN.arb @@ -292,5 +292,6 @@ "pressOnceAgainToExit": "再点击一次退出", "discordServer": "Discord 服务器", "usedItem": "Used item", - "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}" + "itemIsBeingUsedOnACalculation": "This item is being used in one or more calculator sessions.\nThe used quantity is {quantity}", + "useOfficialMap": "Use the official map" } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 752454161..8642111d7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -89,7 +89,8 @@ class MyApp extends StatelessWidget { final networkService = getIt(); final telemetryService = getIt(); final deviceInfoService = getIt(); - return UrlPageBloc(networkService, telemetryService, deviceInfoService); + final settingsService = getIt(); + return UrlPageBloc(networkService, telemetryService, deviceInfoService, settingsService); }, ), BlocProvider( @@ -132,7 +133,7 @@ class MyApp extends StatelessWidget { create: (ctx) { final settingsService = getIt(); final deviceInfoService = getIt(); - return SettingsBloc(settingsService, deviceInfoService, ctx.read(), ctx.read()); + return SettingsBloc(settingsService, deviceInfoService, ctx.read(), ctx.read(), ctx.read()); }, ), BlocProvider( diff --git a/lib/presentation/settings/widgets/other_settings.dart b/lib/presentation/settings/widgets/other_settings.dart index 33a9e1bbc..6af6eb15b 100644 --- a/lib/presentation/settings/widgets/other_settings.dart +++ b/lib/presentation/settings/widgets/other_settings.dart @@ -59,6 +59,12 @@ class OtherSettings extends StatelessWidget { value: settingsState.doubleBackToClose, onChanged: (newVal) => context.read().add(SettingsEvent.doubleBackToCloseChanged(newValue: newVal)), ), + SwitchListTile( + activeColor: theme.accentColor, + title: Text(s.useOfficialMap), + value: settingsState.useOfficialMap, + onChanged: (newVal) => context.read().add(SettingsEvent.useOfficialMapChanged(newValue: newVal)), + ), ListTile( dense: true, contentPadding: EdgeInsets.zero,