From a48d70364296b63cffbaba2bc7a770ae0650ddf5 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Thu, 24 Aug 2023 18:19:46 +0300 Subject: [PATCH] ITG ADs update --- lib/api/dashboard_api_client.dart | 2 +- lib/classes/consts.dart | 4 +- lib/models/itg/advertisement.dart | 220 +++++++++++------- lib/models/itg/survey_model.dart | 30 +-- .../itg_forms_models/itg_request_model.dart | 2 +- lib/ui/landing/dashboard_screen.dart | 2 +- .../itg/its_add_screen_video_image.dart | 127 +++++++--- 7 files changed, 243 insertions(+), 144 deletions(-) diff --git a/lib/api/dashboard_api_client.dart b/lib/api/dashboard_api_client.dart index 544ba71..77cc37d 100644 --- a/lib/api/dashboard_api_client.dart +++ b/lib/api/dashboard_api_client.dart @@ -201,7 +201,7 @@ class DashboardApiClient { }, url, postParams); } - Future setAdvertisementViewed(String masterID, int advertisementId, String ackValue) async { + Future setAdvertisementViewed(String masterID, int advertisementId, String? ackValue) async { String url = "${ApiConsts.cocRest}Mohemm_ITG_UpdateAdvertisementAsViewed"; Map postParams = { diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 45ef661..32b3fc7 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -3,8 +3,8 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server // static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server - // static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - static String baseUrl = "https://hmgwebservices.com"; // Live server + static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server + // static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; diff --git a/lib/models/itg/advertisement.dart b/lib/models/itg/advertisement.dart index 96f4037..ebcf704 100644 --- a/lib/models/itg/advertisement.dart +++ b/lib/models/itg/advertisement.dart @@ -1,108 +1,156 @@ class Advertisement { + int? advertisementId; + String? advertisementTitle; + int? durationInSeconds; + bool? showDelete; + dynamic acknowledgment; + late bool isOptional; + List? viewAttachFileColl; + int? skipButtonId; + List? actionButtonsColl; + bool? isActive; + num? pageSize; + num? pageNo; + num? languageId; + Advertisement({ this.advertisementId, this.advertisementTitle, this.durationInSeconds, this.showDelete, this.acknowledgment, + required this.isOptional, + // this.skipBtnTextEn, + // this.skipBtnTextAr, this.viewAttachFileColl, + this.skipButtonId, + this.actionButtonsColl, this.isActive, this.pageSize, this.pageNo, this.languageId, - this.isOptional, - this.skipButtonTextEn, - this.skipButtonTextAr, }); - final int? advertisementId; - final String? advertisementTitle; - final int? durationInSeconds; - final bool? showDelete; - final dynamic acknowledgment; - final List? viewAttachFileColl; - final bool? isActive; - final dynamic pageSize; - final dynamic pageNo; - final dynamic languageId; - final bool? isOptional; - final String? skipButtonTextEn; - final String? skipButtonTextAr; - - factory Advertisement.fromJson(Map json) => Advertisement( - advertisementId: json["advertisementId"] == null ? null : json["advertisementId"], - advertisementTitle: json["advertisementTitle"] == null ? null : json["advertisementTitle"], - durationInSeconds: json["durationInSeconds"] == null ? null : json["durationInSeconds"], - showDelete: json["showDelete"] == null ? null : json["showDelete"], - acknowledgment: json["acknowledgment"], - viewAttachFileColl: json["viewAttachFileColl"] == null ? null : List.from(json["viewAttachFileColl"].map((x) => ViewAttachFileColl.fromJson(x))), - isActive: json["isActive"] == null ? null : json["isActive"], - pageSize: json["pageSize"], - pageNo: json["pageNo"], - languageId: json["languageId"], - isOptional: json["isOptional"] == null ? null : json["isOptional"], - skipButtonTextEn: json["skipBtnTextEn"] == null ? null : json["skipBtnTextEn"], - skipButtonTextAr: json["skipBtnTextAr"] == null ? null : json["skipBtnTextAr"], - ); + Advertisement.fromJson(Map json) { + advertisementId = json['advertisementId']; + advertisementTitle = json['advertisementTitle']; + durationInSeconds = json['durationInSeconds']; + showDelete = json['showDelete']; + acknowledgment = json['acknowledgment']; + isOptional = json['isOptional']; + // skipBtnTextEn = json['skipBtnTextEn']; + // skipBtnTextAr = json['skipBtnTextAr']; + if (json['viewAttachFileColl'] != null) { + viewAttachFileColl = []; + json['viewAttachFileColl'].forEach((v) { + viewAttachFileColl!.add(ViewAttachFileColl.fromJson(v)); + }); + } + skipButtonId = json['skipButtonId']; + if (json['actionButtonsColl'] != null) { + actionButtonsColl = []; + json['actionButtonsColl'].forEach((v) { + actionButtonsColl!.add(ActionButtonsColl.fromJson(v)); + }); + } + isActive = json['isActive']; + pageSize = json['pageSize']; + pageNo = json['pageNo']; + languageId = json['languageId']; + } - Map toJson() => { - "advertisementId": advertisementId == null ? null : advertisementId, - "advertisementTitle": advertisementTitle == null ? null : advertisementTitle, - "durationInSeconds": durationInSeconds == null ? null : durationInSeconds, - "showDelete": showDelete == null ? null : showDelete, - "acknowledgment": acknowledgment, - "viewAttachFileColl": viewAttachFileColl == null ? null : List.from(viewAttachFileColl!.map((x) => x.toJson())), - "isActive": isActive == null ? null : isActive, - "pageSize": pageSize, - "pageNo": pageNo, - "languageId": languageId, - }; + Map toJson() { + Map data = Map(); + data['advertisementId'] = this.advertisementId; + data['advertisementTitle'] = this.advertisementTitle; + data['durationInSeconds'] = this.durationInSeconds; + data['showDelete'] = this.showDelete; + data['acknowledgment'] = this.acknowledgment; + data['isOptional'] = this.isOptional; + // data['skipBtnTextEn'] = this.skipBtnTextEn; + // data['skipBtnTextAr'] = this.skipBtnTextAr; + if (this.viewAttachFileColl != null) { + data['viewAttachFileColl'] = this.viewAttachFileColl!.map((v) => v.toJson()).toList(); + } + data['skipButtonId'] = this.skipButtonId; + if (this.actionButtonsColl != null) { + data['actionButtonsColl'] = this.actionButtonsColl!.map((v) => v.toJson()).toList(); + } + data['isActive'] = this.isActive; + data['pageSize'] = this.pageSize; + data['pageNo'] = this.pageNo; + data['languageId'] = this.languageId; + return data; + } } class ViewAttachFileColl { - ViewAttachFileColl({ - this.attachmentId, - this.fileName, - this.contentType, - this.attachFileStream, - this.base64String, - this.isActive, - this.referenceItemId, - this.content, - this.filePath, - }); + dynamic attachmentId; + String? fileName; + String? contentType; + dynamic attachFileStream; + String? base64String; + dynamic isActive; + dynamic referenceItemId; + dynamic content; + dynamic filePath; + + ViewAttachFileColl({this.attachmentId, this.fileName, this.contentType, this.attachFileStream, this.base64String, this.isActive, this.referenceItemId, this.content, this.filePath}); + + ViewAttachFileColl.fromJson(Map json) { + attachmentId = json['attachmentId']; + fileName = json['fileName']; + contentType = json['contentType']; + attachFileStream = json['attachFileStream']; + base64String = json['base64String']; + isActive = json['isActive']; + referenceItemId = json['referenceItemId']; + content = json['content']; + filePath = json['filePath']; + } + + Map toJson() { + Map data = new Map(); + data['attachmentId'] = this.attachmentId; + data['fileName'] = this.fileName; + data['contentType'] = this.contentType; + data['attachFileStream'] = this.attachFileStream; + data['base64String'] = this.base64String; + data['isActive'] = this.isActive; + data['referenceItemId'] = this.referenceItemId; + data['content'] = this.content; + data['filePath'] = this.filePath; + return data; + } +} + +class ActionButtonsColl { + late int actionButtonId; + late String btnTextEn; + late String btnTextAr; + late String actionValue; + late dynamic iconOrImage; + late int orderNo; - final dynamic attachmentId; - final String? fileName; - final String? contentType; - final dynamic attachFileStream; - final String? base64String; - final dynamic isActive; - final dynamic referenceItemId; - final dynamic content; - final dynamic filePath; + ActionButtonsColl({required this.actionButtonId, required this.btnTextEn, required this.btnTextAr, required this.actionValue, required this.iconOrImage, required this.orderNo}); - factory ViewAttachFileColl.fromJson(Map json) => ViewAttachFileColl( - attachmentId: json["attachmentId"], - fileName: json["fileName"] == null ? null : json["fileName"], - contentType: json["contentType"] == null ? null : json["contentType"], - attachFileStream: json["attachFileStream"], - base64String: json["base64String"] == null ? null : json["base64String"], - isActive: json["isActive"], - referenceItemId: json["referenceItemId"], - content: json["content"], - filePath: json["filePath"], - ); + ActionButtonsColl.fromJson(Map json) { + actionButtonId = json['actionButtonId']; + btnTextEn = json['btnTextEn']; + btnTextAr = json['btnTextAr']; + actionValue = json['actionValue']; + iconOrImage = json['iconOrImage']; + orderNo = json['orderNo']; + } - Map toJson() => { - "attachmentId": attachmentId, - "fileName": fileName == null ? null : fileName, - "contentType": contentType == null ? null : contentType, - "attachFileStream": attachFileStream, - "base64String": base64String == null ? null : base64String, - "isActive": isActive, - "referenceItemId": referenceItemId, - "content": content, - "filePath": filePath, - }; + Map toJson() { + Map data = new Map(); + data['actionButtonId'] = this.actionButtonId; + data['btnTextEn'] = this.btnTextEn; + data['btnTextAr'] = this.btnTextAr; + data['actionValue'] = this.actionValue; + data['iconOrImage'] = this.iconOrImage; + data['orderNo'] = this.orderNo; + return data; + } } diff --git a/lib/models/itg/survey_model.dart b/lib/models/itg/survey_model.dart index 7cdbbdd..f9ac415 100644 --- a/lib/models/itg/survey_model.dart +++ b/lib/models/itg/survey_model.dart @@ -5,9 +5,9 @@ class SurveyModel { String? description; List? questions; bool? isActive; - Null? pageSize; - Null? pageNo; - Null? languageId; + dynamic pageSize; + dynamic pageNo; + dynamic languageId; SurveyModel({this.surveyId, this.referenceNo, this.title, this.description, this.questions, this.isActive, this.pageSize, this.pageNo, this.languageId}); @@ -51,13 +51,13 @@ class Questions { bool? isRequired; String? type; int? sequenceNo; - Null? surveyId; + dynamic surveyId; List? options; - Null? rspPercentage; - Null? isActive; - Null? pageSize; - Null? pageNo; - Null? languageId; + dynamic rspPercentage; + dynamic isActive; + dynamic pageSize; + dynamic pageNo; + dynamic languageId; Questions({this.questionId, this.title, this.isRequired, this.type, this.sequenceNo, this.surveyId, this.options, this.rspPercentage, this.isActive, this.pageSize, this.pageNo, this.languageId}); @@ -107,12 +107,12 @@ class Options { bool? isCommentsRequired; int? sequenceNo; int? questionId; - Null? rspPercentage; - Null? count; - Null? isActive; - Null? pageSize; - Null? pageNo; - Null? languageId; + dynamic rspPercentage; + dynamic count; + dynamic isActive; + dynamic pageSize; + dynamic pageNo; + dynamic languageId; Options({this.optionId, this.title, this.isCommentsRequired, this.sequenceNo, this.questionId, this.rspPercentage, this.count, this.isActive, this.pageSize, this.pageNo, this.languageId}); diff --git a/lib/models/itg_forms_models/itg_request_model.dart b/lib/models/itg_forms_models/itg_request_model.dart index ba10305..87d8280 100644 --- a/lib/models/itg_forms_models/itg_request_model.dart +++ b/lib/models/itg_forms_models/itg_request_model.dart @@ -6,7 +6,7 @@ class ITGRequest { List? allowedActions; List? attachments; List? fieldGoups; - Null? grantFields; + dynamic grantFields; List? wFHistory; ITGRequest({this.allowedActions, this.attachments, this.fieldGoups, this.grantFields, this.wFHistory}); diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 2db09d0..4116594 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -163,7 +163,7 @@ class _DashboardScreenState extends State with WidgetsBindingOb print("-------------------- Survey ----------------------------"); if (val.result!.data!.notificationType == "Survey") { DashboardApiClient().getAdvertisementDetail(val.result!.data!.notificationMasterId ?? "").then( - (value) { + (value) { if (value!.mohemmItgResponseItem!.statusCode == 200) { if (value.mohemmItgResponseItem!.result!.data != null) { // Navigator.pushNamed(context, AppRoutes.survey, arguments: val.result!.data); diff --git a/lib/ui/landing/itg/its_add_screen_video_image.dart b/lib/ui/landing/itg/its_add_screen_video_image.dart index 1e280d8..8ce89d0 100644 --- a/lib/ui/landing/itg/its_add_screen_video_image.dart +++ b/lib/ui/landing/itg/its_add_screen_video_image.dart @@ -61,6 +61,11 @@ class _ITGAdsScreenState extends State { isVideo = true; _futureController = createVideoPlayer(rFile!); } + + advertisementData?.actionButtonsColl!.forEach((element) { + advertisementData?.actionButtonsColl!.removeWhere((element1) => element1.actionButtonId == advertisementData?.skipButtonId); + }); + setState(() {}); } @@ -152,55 +157,101 @@ class _ITGAdsScreenState extends State { textStyle: const TextStyle(color: Colors.white, fontSize: 16, letterSpacing: -0.48, fontWeight: FontWeight.bold), ), 50.height, + if (advertisementData?.isOptional ?? false) + DefaultButton(AppState().isArabic(context) ? "يتخطى" : "Skip", () async { + Navigator.pop(context); + DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, "Skip").then((value) { + logger.d(value); + }); + }).paddingOnly(left: 60.0, right: 60.0, top: 8, bottom: 8), ValueListenableBuilder( valueListenable: hasTimerEnded, builder: (context, val, child) { if (hasTimerEndedBool) { - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_up, color: MyColors.gradiantEndColor)) - .onPress(() { - try { - Navigator.pop(context); - DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, "Like").then((value) { - logger.d(value); - }); - } catch (ex) { - logger.wtf(ex); - Utils.handleException(ex, context, null); - } - }), - 20.width, - Container( - padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_down, color: MyColors.gradiantEndColor)) - .onPress(() { - try { - Navigator.pop(context); - DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, "Dislike").then((value) { - logger.d(value); - }); - } catch (ex) { - logger.wtf(ex); - Utils.handleException(ex, context, null); - } - }), - ], + return GridView.builder( + padding: EdgeInsets.zero, + itemCount: advertisementData?.actionButtonsColl!.length, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + String? btnText = AppState().isArabic(context) ? advertisementData?.actionButtonsColl![index].btnTextAr : advertisementData?.actionButtonsColl![index].btnTextEn; + return DefaultButton(btnText!, () async { + Navigator.pop(context); + DashboardApiClient() + .setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, advertisementData?.actionButtonsColl![index].actionValue) + .then((value) { + logger.d(value); + }); + }).paddingOnly(left: 60.0, right: 60.0, top: 8, bottom: 8); + }, + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 1, + childAspectRatio: (7.0), + ), ); + // Row( + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // Container(padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_up, color: MyColors.gradiantEndColor)) + // .onPress(() { + // try { + // Navigator.pop(context); + // DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, "Like").then((value) { + // logger.d(value); + // }); + // } catch (ex) { + // logger.wtf(ex); + // Utils.handleException(ex, context, null); + // } + // }), + // 20.width, + // Container( + // padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_down, color: MyColors.gradiantEndColor)) + // .onPress(() { + // try { + // Navigator.pop(context); + // DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, "Dislike").then((value) { + // logger.d(value); + // }); + // } catch (ex) { + // logger.wtf(ex); + // Utils.handleException(ex, context, null); + // } + // }), + // ], + // ); } else { return Container(); } }, ), 20.height, - if (advertisementData?.isOptional ?? false) - DefaultButton(AppState().isArabic(context) ? advertisementData?.skipButtonTextAr ?? "Skip" : advertisementData?.skipButtonTextEn ?? "Skip", () async { - Navigator.pop(context); - DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, "Skip").then((value) { - logger.d(value); - }); - }).paddingOnly(left: 100, right: 100) + // if (advertisementData?.isOptional ?? false) + // GridView.builder( + // padding: EdgeInsets.zero, + // itemCount: advertisementData?.actionButtonsColl!.length, + // shrinkWrap: true, + // physics: const NeverScrollableScrollPhysics(), + // itemBuilder: (context, index) { + // String? btnText = AppState().isArabic(context) ? advertisementData?.actionButtonsColl![index].btnTextAr : advertisementData?.actionButtonsColl![index].btnTextEn; + // return DefaultButton(btnText!, () async { + // Navigator.pop(context); + // DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, advertisementData?.actionButtonsColl![index].actionValue).then((value) { + // logger.d(value); + // }); + // }).paddingAll(8); + // }, + // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + // crossAxisCount: 2, + // childAspectRatio: (4.0), + // ), + // ) + // DefaultButton(AppState().isArabic(context) ? advertisementData?.skipButtonTextAr ?? "Skip" : advertisementData?.skipButtonTextEn ?? "Skip", () async { + // Navigator.pop(context); + // DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!, "Skip").then((value) { + // logger.d(value); + // }); + // }).paddingOnly(left: 100, right: 100) ], ); } else {