diff --git a/lib/api/dashboard_api_client.dart b/lib/api/dashboard_api_client.dart index 9747e5c..69c2e82 100644 --- a/lib/api/dashboard_api_client.dart +++ b/lib/api/dashboard_api_client.dart @@ -186,4 +186,18 @@ class DashboardApiClient { ); return chatUnreadCovnCountModelFromJson(response.body); } + + // Future setAdvertisementViewed(String masterID, int advertisementId) async { + // String url = "${ApiConsts.cocRest}Mohemm_ITG_UpdateAdvertisementAsViewed"; + // + // Map postParams = { + // "ItgNotificationMasterId": masterID, + // "ItgAdvertisement": {"advertisementId": advertisementId, "acknowledgment": true} //Mobile Id + // }; + // postParams.addAll(AppState().postParamsJson); + // return await ApiClient().postJsonForObject((json) { + // // ItgMainRes responseData = ItgMainRes.fromJson(json); + // return json; + // }, url, postParams); + // } } diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index d433e09..c8cdcef 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -100,41 +100,39 @@ class _DashboardScreenState extends State { Widget build(BuildContext context) { return Scaffold( key: _scaffoldState, - appBar: AppBar( - actions: [ - IconButton( - onPressed: () { - data.getITGNotification().then((value) { - if (value!.result!.data != null) { - if (value.result!.data!.notificationType == "Survey") { - Navigator.pushNamed(context, AppRoutes.survey, arguments: value.result!.data); - } else { - DashboardApiClient().getAdvertisementDetail(value.result!.data!.notificationMasterId ?? "").then( - (value) { - if (value!.mohemmItgResponseItem!.statusCode == 200) { - if (value.mohemmItgResponseItem!.result!.data != null) { - String? rFile = value.mohemmItgResponseItem!.result!.data!.advertisement!.viewAttachFileColl!.first.base64String; - String? rFileExt = value.mohemmItgResponseItem!.result!.data!.advertisement!.viewAttachFileColl!.first.fileName; - Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => ITGAdsScreen( - encodedBytes: rFile!, - fileExtenshion: rFileExt!, - ), - ), - ); - } - } - }, - ); - } - } - }); - }, - icon: Icon(Icons.add)) - ], - ), + // appBar: AppBar( + // actions: [ + // IconButton( + // onPressed: () { + // data.getITGNotification().then((val) { + // if (val!.result!.data != null) { + // if (val.result!.data!.notificationType == "Survey") { + // Navigator.pushNamed(context, AppRoutes.survey, arguments: val.result!.data); + // } else { + // DashboardApiClient().getAdvertisementDetail(val.result!.data!.notificationMasterId ?? "").then( + // (value) { + // if (value!.mohemmItgResponseItem!.statusCode == 200) { + // if (value.mohemmItgResponseItem!.result!.data != null) { + // Navigator.push( + // context, + // MaterialPageRoute( + // builder: (BuildContext context) => ITGAdsScreen( + // addMasterId: val.result!.data!.notificationMasterId!, + // advertisement: value.mohemmItgResponseItem!.result!.data!.advertisement!, + // ), + // ), + // ); + // } + // } + // }, + // ); + // } + // } + // }); + // }, + // icon: Icon(Icons.add)) + // ], + // ), body: Column( children: [ Row( 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 1d9c41f..4b2e358 100644 --- a/lib/ui/landing/itg/its_add_screen_video_image.dart +++ b/lib/ui/landing/itg/its_add_screen_video_image.dart @@ -2,17 +2,20 @@ import 'dart:convert'; import 'dart:io' as Io; import 'dart:io'; import 'dart:typed_data'; - import 'package:flutter/material.dart'; +import 'package:just_audio/just_audio.dart'; +import 'package:mohem_flutter_app/api/dashboard_api_client.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; +import 'package:mohem_flutter_app/main.dart'; +import 'package:mohem_flutter_app/models/itg/advertisement.dart' as ads; import 'package:path_provider/path_provider.dart'; import 'package:video_player/video_player.dart'; class ITGAdsScreen extends StatefulWidget { - final String encodedBytes; - final String fileExtension; + final String addMasterId; + final ads.Advertisement advertisement; - const ITGAdsScreen({required this.encodedBytes, required this.fileExtension}); + const ITGAdsScreen({required this.addMasterId, required this.advertisement}); @override _ITGAdsScreenState createState() => _ITGAdsScreenState(); @@ -22,10 +25,39 @@ class _ITGAdsScreenState extends State { late Future _futureController; late VideoPlayerController _controller; bool skip = false; + bool isVideo = false; + bool isImage = false; + String ext = ''; + late File imageFile; + + void checkFileType() async { + String? rFile = widget.advertisement!.viewAttachFileColl!.first.base64String; + String? rFileExt = widget.advertisement!.viewAttachFileColl!.first.fileName; + ext = "." + rFileExt!.split(".").last.toLowerCase(); + if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif") { + await processImage(rFile!); + isImage = true; + } else { + isVideo = true; + _futureController = createVideoPlayer(rFile!); + } + setState(() {}); + } + + Future processImage(String encodedBytes) async { + try { + Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last); + Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1 + imageFile = Io.File("${appDocumentsDirectory.path}/addImage$ext"); + imageFile.writeAsBytesSync(decodedBytes); + } catch (e) { + logger.d(e); + } + } - Future createVideoPlayer() async { + Future createVideoPlayer(String encodedBytes) async { try { - Uint8List decodedBytes = base64Decode(widget.encodedBytes.split("base64,").last); + Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last); Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1 File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4"); file.writeAsBytesSync(decodedBytes); @@ -40,55 +72,15 @@ class _ITGAdsScreenState extends State { } } - void checkType(){ - - // getFileTypeDescription(value); - - - } - - String getFileTypeDescription(String value) { - switch (value) { - case ".pdf": - return "application/pdf"; - case ".png": - return "image/png"; - case ".txt": - return "text/plain"; - case ".jpg": - return "image/jpg"; - case ".jpeg": - return "image/jpeg"; - case ".ppt": - return "application/vnd.openxmlformats-officedocument.presentationml.presentation"; - case ".pptx": - return "application/vnd.openxmlformats-officedocument.presentationml.presentation"; - case ".doc": - return "application/vnd.openxmlformats-officedocument.wordprocessingm"; - case ".docx": - return "application/vnd.openxmlformats-officedocument.wordprocessingm"; - case ".xls": - return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - case ".xlsx": - return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - case ".zip": - return "application/octet-stream"; - case ".rar": - return "application/octet-stream"; - default: - return ""; - } - } - @override void initState() { - _futureController = createVideoPlayer(); + checkFileType(); initTimer(); super.initState(); } void initTimer() { - Future.delayed(const Duration(milliseconds: 500), () { + Future.delayed(const Duration(seconds: 5), () { setState(() { skip = true; }); @@ -107,28 +99,34 @@ class _ITGAdsScreenState extends State { return Scaffold( body: Column( children: [ - SizedBox( - height: MediaQuery.of(context).size.height * .3, - child: FutureBuilder( - future: _futureController, - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) { - _controller = snapshot.data as VideoPlayerController; - return AspectRatio( - aspectRatio: _controller.value.aspectRatio, - child: VideoPlayer(_controller), - ); - } else { - return const Center( - child: CircularProgressIndicator(), - ); - } - }, + if (isVideo) + SizedBox( + height: MediaQuery.of(context).size.height * .3, + child: FutureBuilder( + future: _futureController, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) { + _controller = snapshot.data as VideoPlayerController; + return AspectRatio( + aspectRatio: _controller.value.aspectRatio, + child: VideoPlayer(_controller), + ); + } else { + return const Center( + child: CircularProgressIndicator(), + ); + } + }, + ), ), - ), + if (isImage) Image.file(imageFile), if (skip) ElevatedButton( - onPressed: () {}, + onPressed: () async { + // DashboardApiClient().setAdvertisementViewed(widget.addMasterId, widget.advertisement!.advertisementId!).then((value) { + // logger.d(value); + // }); + }, child: const Text("Go To Dashboard"), ) ],