diff --git a/lib/api/dashboard_api_client.dart b/lib/api/dashboard_api_client.dart index 6576100c..5af1730e 100644 --- a/lib/api/dashboard_api_client.dart +++ b/lib/api/dashboard_api_client.dart @@ -7,6 +7,7 @@ import 'package:android_id/android_id.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:http/http.dart' as http; import 'package:device_info_plus/device_info_plus.dart'; +import 'package:mobile_device_identifier/mobile_device_identifier.dart'; import 'package:mohem_flutter_app/api/api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; @@ -276,7 +277,7 @@ class DashboardApiClient { String QRValue = "", String payrollCode = "", }) async { - + var _mobileDeviceIdentifierPlugin = MobileDeviceIdentifier(); Codec stringToBase64 = utf8.fuse(base64); String url = "${ApiConsts.swpRest}AuthenticateAndSwipeUserSupportNFC"; Uuid uuid = Uuid(); @@ -292,8 +293,16 @@ class DashboardApiClient { deviceId = deviceId.length >= 50 ? deviceId.substring(0, 48) : deviceId; } else if (Platform.isIOS) { IosDeviceInfo iosInfo = await DeviceInfoPlugin().iosInfo; - deviceId = iosInfo.identifierForVendor; + try { + deviceId = await _mobileDeviceIdentifierPlugin.getDeviceId() ?? + "Unknown"; + } catch (ex) { + deviceId = iosInfo.identifierForVendor; + } } + + print("the DeviceID is $deviceId"); + Map postParams = { "UID": deviceId, //uuid.v4(), //Mobile Id // "UID": uuid.v4(), //Mobile Id diff --git a/lib/api/offers_and_discounts_api_client.dart b/lib/api/offers_and_discounts_api_client.dart index 5c1eaab8..34a5709b 100644 --- a/lib/api/offers_and_discounts_api_client.dart +++ b/lib/api/offers_and_discounts_api_client.dart @@ -68,7 +68,7 @@ class OffersAndDiscountsApiClient { String url = "${ApiConsts.cocRest}GetOfferDiscountsConfigData"; Map postParams = { - "EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, + "EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER ?? "217869", "ItgPageSize": pageSize, "ItgPageNo": 1, "ItgCategoryID": categoryID, diff --git a/lib/app_state/app_state.dart b/lib/app_state/app_state.dart index 624336be..3c0a7eda 100644 --- a/lib/app_state/app_state.dart +++ b/lib/app_state/app_state.dart @@ -92,7 +92,7 @@ class AppState { String get getHuaweiPushToken => _huaweiPushToken; - final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 33, versionID: 10.3, mobileType: Platform.isAndroid ? "android" : "ios"); + final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 33, versionID: 10.4, mobileType: Platform.isAndroid ? "android" : "ios"); PostParamsModel get postParamsInitConfig { if (_postParamsInitConfig.pLegislationCode == null) { diff --git a/lib/ui/mazaya/mazaya_discover_screen.dart b/lib/ui/mazaya/mazaya_discover_screen.dart index 34c3df41..0c67dea7 100644 --- a/lib/ui/mazaya/mazaya_discover_screen.dart +++ b/lib/ui/mazaya/mazaya_discover_screen.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:mohem_flutter_app/api/login_api_client.dart'; import 'package:mohem_flutter_app/api/offers_and_discounts_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; @@ -11,6 +12,7 @@ import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; +import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart'; import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_category_model.dart'; @@ -48,7 +50,7 @@ class _MazayaDiscoverScreenState extends State { bool _isLoadingCategories = true; List _categories = []; - + bool _hasRegisteredMobileLoginInfo = false; bool _isLoadingExclusiveOffers = true; List _exclusiveOffers = []; @@ -70,6 +72,7 @@ class _MazayaDiscoverScreenState extends State { _fetchCategories(); _fetchExclusiveOffers(); _initCityAndFetchSections(); + _registerMobileLoginInfo(); } Future _initCityAndFetchSections() async { @@ -101,10 +104,63 @@ class _MazayaDiscoverScreenState extends State { super.dispose(); } - // Only drives the benefits strip now - Travel Essentials/Home & Kitchen/Latest on Mazaya each - // fetch independently (see _fetchCategorySection/_fetchLatestOnMazaya). Still fetched in - // parallel with those though, since it also feeds each fixed-category section's title (the - // top-level categories list is the primary source there - see _sectionTitle). + Future _registerMobileLoginInfo() async { + if (_hasRegisteredMobileLoginInfo) return; + if (!ApiConsts.isDependetLogin) return; + _hasRegisteredMobileLoginInfo = true; + + try { + int loginType = AppState().dependentLoginType ?? 1; + String nationalId = AppState().getUserName ?? ""; + String dob = AppState().dependentDob ?? ""; + String name = AppState().dependentName ?? ""; + String mobile = AppState().postParamsObject?.mobileNumber ?? ""; + String tokenID = + (AppState().postParamsObject?.tokenID != null && + AppState().postParamsObject!.tokenID!.isNotEmpty) + ? AppState().postParamsObject!.tokenID! + : (AppState().authenticationTokenID ?? ""); + if (tokenID.isEmpty) { + tokenID = await Utils.getStringFromPrefs("P_DEP_TOKEN_ID"); + } + int sessionId = AppState().postParamsObject?.pSessionId ?? 0; + String email = AppState().postParamsObject?.pEmailAddress ?? ""; + String deviceToken = + AppState().getIsHuawei + ? AppState().getHuaweiPushToken + : ((AppState().getDeviceToken != null && + AppState().getDeviceToken!.isNotEmpty && + AppState().getDeviceToken != "null") + ? AppState().getDeviceToken! + : ""); + if (deviceToken.isEmpty || deviceToken == "null") { + String savedToken = await Utils.getStringFromPrefs( + "P_DEP_DEVICE_TOKEN", + ); + if (savedToken.isNotEmpty && savedToken != "null") { + deviceToken = savedToken; + } + } + + await LoginApiClient().insertMobileLoginInfoDependent( + loginType: loginType, + nationalId: nationalId, + dob: dob, + dependentName: name, + mobileNumber: mobile, + tokenID: tokenID, + sessionId: sessionId, + email: email, + deviceToken: deviceToken, + channel: AppState().postParamsObject?.channel, + context: context, + ); + } catch (e) { + // if (kDebugMode) { + print("Error calling insertMobileLoginInfoDependent: $e"); + // } + } + } Future _fetchCategories() async { setState(() => _isLoadingCategories = true); try { @@ -458,7 +514,7 @@ class _MazayaDiscoverScreenState extends State { appBar: AppBarWidget( context, title: LocaleKeys.mazayaDeals.tr(), - showHomeButton: true, + showHomeButton: ApiConsts.isDependetLogin ? false : true, // Discover is the dependent-login landing page - no back button there (logout is still // reachable via the explicit logout action below). Employees reaching Discover from the // regular dashboard can still pop back normally. @@ -1023,7 +1079,7 @@ class _MazayaDiscoverScreenState extends State { title.toText20( color: const Color(0xFF202F32), weight: FontWeight.w600, - ), + ).toShimmer(isShow: isLoading), InkWell( onTap: onSeeAll, child: Row( @@ -1055,7 +1111,7 @@ class _MazayaDiscoverScreenState extends State { subtitle.toText11( color: const Color(0xFF78817F), weight: FontWeight.w400, - ), + ).toShimmer(isShow: isLoading), ], ), ), diff --git a/lib/ui/mazaya/retailers_list_screen.dart b/lib/ui/mazaya/retailers_list_screen.dart index 64156e3a..e39f9b85 100644 --- a/lib/ui/mazaya/retailers_list_screen.dart +++ b/lib/ui/mazaya/retailers_list_screen.dart @@ -100,7 +100,7 @@ class _RetailersListScreenState extends State { WidgetsBinding.instance.addPostFrameCallback((_) async { if (mounted) { await _saveDependentSessionToPrefs(); - await _registerMobileLoginInfo(); + await fetchCategories(); } }); diff --git a/lib/ui/mazaya/widgets/mazaya_bottom_nav.dart b/lib/ui/mazaya/widgets/mazaya_bottom_nav.dart index 898478a3..f6d85c01 100644 --- a/lib/ui/mazaya/widgets/mazaya_bottom_nav.dart +++ b/lib/ui/mazaya/widgets/mazaya_bottom_nav.dart @@ -105,13 +105,13 @@ class MazayaBottomNav extends StatelessWidget { context, tab: MazayaTab.discover, svgAsset: "assets/icons/mazaya_compass.svg", - label: LocaleKeys.discover.tr(), + label: LocaleKeys.discover.tr(context: context), ), _buildItem( context, tab: MazayaTab.saved, svgAsset: "assets/icons/mazaya_heart_outline.svg", - label: LocaleKeys.saved.tr(), + label: LocaleKeys.saved.tr(context: context), ), // My Family lets the account holder manage their dependents' Mazaya access - not // applicable (and not shown) when a dependent is the one logged in. @@ -120,7 +120,7 @@ class MazayaBottomNav extends StatelessWidget { context, tab: MazayaTab.myFamily, svgAsset: "assets/icons/mazaya_user_round.svg", - label: LocaleKeys.myFamily.tr(), + label: LocaleKeys.myFamily.tr(context: context), ), ], ),