ERM Video fixes

pull/3/head
haroon amjad 1 year ago
parent c4dc3e941d
commit 15c8e80799

@ -91,5 +91,7 @@
<array> <array>
<string>TAG</string> <string>TAG</string>
</array> </array>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict> </dict>
</plist> </plist>

@ -401,4 +401,15 @@ class Utils {
} }
return false; return false;
} }
static bool isDate(String input, String format) {
try {
DateTime d = DateFormat(format).parseStrict(input);
//print(d);
return true;
} catch (e) {
//print(e);
return false;
}
}
} }

@ -39,6 +39,12 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
String? masterID; String? masterID;
int videoDuration = 0; int videoDuration = 0;
bool hasTimerEndedBool = false;
final ValueNotifier<bool> hasTimerEnded = ValueNotifier(false);
late CountdownTimerController timerController;
void checkFileType() async { void checkFileType() async {
String? rFile = advertisementData!.viewAttachFileColl!.first.base64String; String? rFile = advertisementData!.viewAttachFileColl!.first.base64String;
String? rFileExt = advertisementData!.viewAttachFileColl!.first.fileName; String? rFileExt = advertisementData!.viewAttachFileColl!.first.fileName;
@ -56,6 +62,17 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
setState(() {}); setState(() {});
} }
void changeTimer(bool isTimerEnd) {
hasTimerEndedBool = isTimerEnd;
hasTimerEnded.value = !hasTimerEnded.value;
}
void onTimerEnd() {
changeTimer(true);
timerController.disposeTimer();
timerController.dispose();
}
Future processImage(String encodedBytes) async { Future processImage(String encodedBytes) async {
try { try {
Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last); Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
@ -69,18 +86,20 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
Future<VideoPlayerController> createVideoPlayer(String encodedBytes) async { Future<VideoPlayerController> createVideoPlayer(String encodedBytes) async {
try { try {
Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last); // Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1 // Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4"); // File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4");
file.writeAsBytesSync(decodedBytes); // file.writeAsBytesSync(decodedBytes);
VideoPlayerController controller = VideoPlayerController.file(file); // VideoPlayerController controller = VideoPlayerController.file(file);
VideoPlayerController controller = VideoPlayerController.network(advertisementData!.viewAttachFileColl!.first.base64String!);
await controller.initialize(); await controller.initialize();
await controller.play(); await controller.play();
await controller.setVolume(1.0); await controller.setVolume(1.0);
await controller.setLooping(false); await controller.setLooping(false);
return controller; return controller;
} catch (e) { } catch (e) {
return VideoPlayerController.asset("dataSource"); print(e);
return VideoPlayerController.network("https://apimohemmweb.cloudsolutions.com.sa/ErmAttachment/compressedvideo.mp4");
} }
} }
@ -107,6 +126,7 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
if (advertisementData != null) { if (advertisementData != null) {
checkFileType(); checkFileType();
videoDuration = advertisementData?.durationInSeconds ?? 0; videoDuration = advertisementData?.durationInSeconds ?? 0;
timerController = CountdownTimerController(endTime: DateTime.now().millisecondsSinceEpoch + 1000 * videoDuration, onEnd: onTimerEnd);
} }
return Scaffold( return Scaffold(
backgroundColor: Colors.black, backgroundColor: Colors.black,
@ -131,24 +151,34 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
), ),
30.height, 30.height,
CountdownTimer( CountdownTimer(
controller: timerController,
endTime: DateTime.now().millisecondsSinceEpoch + 1000 * videoDuration, endTime: DateTime.now().millisecondsSinceEpoch + 1000 * videoDuration,
onEnd: null, endWidget: "00:00:00".toText16(color: Colors.white, isBold: true),
endWidget: "00:00:00".toText14(color: Colors.white, isBold: true),
textStyle: const TextStyle(color: Colors.white, fontSize: 16, letterSpacing: -0.48, fontWeight: FontWeight.bold), textStyle: const TextStyle(color: Colors.white, fontSize: 16, letterSpacing: -0.48, fontWeight: FontWeight.bold),
), ),
50.height, 50.height,
Container(padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_up, color: MyColors.gradiantEndColor)) ValueListenableBuilder<bool>(
.onPress(() { valueListenable: hasTimerEnded,
try { builder: (context, val, child) {
DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!).then((value) { if (hasTimerEndedBool) {
logger.d(value); return Container(
Navigator.pop(context); padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_up, color: MyColors.gradiantEndColor))
}); .onPress(() {
} catch (ex) { try {
logger.wtf(ex); DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!).then((value) {
Utils.handleException(ex, context, null); logger.d(value);
} Navigator.pop(context);
}), });
} catch (ex) {
logger.wtf(ex);
Utils.handleException(ex, context, null);
}
});
} else {
return Container();
}
}),
// DefaultButton(LocaleKeys.home.tr(), () async { // DefaultButton(LocaleKeys.home.tr(), () async {
// DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!).then((value) { // DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!).then((value) {
// logger.d(value); // logger.d(value);

@ -340,10 +340,15 @@ class _DynamicInputScreenState extends State<DynamicInputScreen> {
idColName = val; idColName = val;
if (getEitDffStructureList![j].fORMATTYPE == "X") { if (getEitDffStructureList![j].fORMATTYPE == "X") {
idColName = Utils.formatDateDefault(idColName!); idColName = Utils.reverseFormatDate(idColName!);
// commenting to test if (Utils.isDate(Utils.reverseFormatDate(Utils.formatDateNew(idColName)), "yyyy-MM-dd")) {
// DateTime date = DateFormat('yyyy-MM-dd').parse(idColName!); idColName = Utils.formatStandardDate(Utils.formatStandardDate(Utils.formatDateNew(idColName)));
// idColName = DateFormat('yyyy-MM-dd HH:mm:ss').format(date); // idColName = DateFormat('yyyy/MM/dd HH:mm:ss').format(date);
} else if (Utils.isDate(Utils.reverseFormatDate(idColName), "dd-MM-yyyy")) {
// // change date format on 31/05/2023
DateTime date = DateFormat('dd-MM-yyyy').parse(idColName);
idColName = DateFormat('yyyy-MM-dd HH:mm:ss').format(date);
}
} }
} }

Loading…
Cancel
Save