|
|
@@ -1,4 +1,5 @@
|
|
|
import 'dart:async';
|
|
|
+import 'dart:io';
|
|
|
|
|
|
import 'package:clean/base/base_controller.dart';
|
|
|
import 'package:clean/module/calendar/selected_preview/calendar_selected_preview_view.dart';
|
|
|
@@ -6,6 +7,7 @@ import 'package:flutter/Material.dart';
|
|
|
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
+import 'package:url_launcher/url_launcher.dart';
|
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
import '../../../data/repositories/user_repository.dart';
|
|
|
@@ -29,10 +31,50 @@ class CalendarPreviewController extends BaseController
|
|
|
final RxBool isSwiperEnd = false.obs;
|
|
|
RxInt groupIndex = 0.obs;
|
|
|
|
|
|
-
|
|
|
late AnimationController animationController;
|
|
|
RxBool animationIsComplete = false.obs;
|
|
|
|
|
|
+ void playVideo(AssetEntity asset) async {
|
|
|
+ final mediaUrl = await asset.getMediaUrl();
|
|
|
+ if (mediaUrl != null) {
|
|
|
+ final Uri videoUri = Uri.parse(mediaUrl);
|
|
|
+ if (await canLaunchUrl(videoUri)) {
|
|
|
+ await launchUrl(videoUri, mode: LaunchMode.externalApplication);
|
|
|
+ } else {
|
|
|
+ debugPrint("无法打开视频:$mediaUrl");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // void playVideo(AssetEntity asset) async {
|
|
|
+ // final mediaUrl = await asset.getMediaUrl();
|
|
|
+ // if (mediaUrl != null) {
|
|
|
+ // late final VideoPlayerController videoPlayerController;
|
|
|
+ // videoPlayerController =
|
|
|
+ // VideoPlayerController.networkUrl(Uri.parse(mediaUrl))
|
|
|
+ // ..initialize().then((_) {
|
|
|
+ // print('videoPlayerController.value.size ${videoPlayerController.value.reactive}');
|
|
|
+ // videoPlayerController.play();
|
|
|
+ // Get.dialog(AlertDialog(
|
|
|
+ // content: AspectRatio(
|
|
|
+ // aspectRatio: videoPlayerController.value.aspectRatio,
|
|
|
+ // child: VideoPlayer(videoPlayerController),
|
|
|
+ // ),
|
|
|
+ // actions: [
|
|
|
+ // TextButton(
|
|
|
+ // onPressed: () {
|
|
|
+ // videoPlayerController.pause();
|
|
|
+ // videoPlayerController.dispose(); // 释放资源
|
|
|
+ // Get.back();
|
|
|
+ // },
|
|
|
+ // child: Text('Close'),
|
|
|
+ // )
|
|
|
+ // ],
|
|
|
+ // ));
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
@override
|
|
|
void onInit() {
|
|
|
super.onInit();
|
|
|
@@ -46,7 +88,8 @@ class CalendarPreviewController extends BaseController
|
|
|
if (currentImageId != null) {
|
|
|
for (int i = 0; i < photoGroup.value.images.length; i++) {
|
|
|
if (photoGroup.value.images[i].id == currentImageId) {
|
|
|
- debugPrint('photoGroups[i].id ${photoGroup.value.images[i].id},i $i');
|
|
|
+ debugPrint(
|
|
|
+ 'photoGroups[i].id ${photoGroup.value.images[i].id},i $i');
|
|
|
groupIndex.value = i;
|
|
|
cardSwiperController.moveTo(i);
|
|
|
break;
|
|
|
@@ -176,14 +219,13 @@ class CalendarPreviewController extends BaseController
|
|
|
clickDelete() async {
|
|
|
debugPrint('CalendarPreviewController clickDelete');
|
|
|
if (userRepository.isVip()) {
|
|
|
-
|
|
|
if (photoGroup.value.selectedPhotosIds.isNotEmpty) {
|
|
|
photoDeletingDialog();
|
|
|
// 获取要删除的资产
|
|
|
final assetsToDelete = photoGroup.value.images
|
|
|
.where(
|
|
|
(asset) => photoGroup.value.selectedPhotosIds.contains(asset.id),
|
|
|
- )
|
|
|
+ )
|
|
|
.toList();
|
|
|
|
|
|
// 调用方法会返回被删除的资源,如果全部失败会返回空列表。
|
|
|
@@ -191,13 +233,10 @@ class CalendarPreviewController extends BaseController
|
|
|
assetsToDelete.map((e) => e.id).toList(),
|
|
|
);
|
|
|
|
|
|
-
|
|
|
// 比较result和selectedPhotosIds,如果result和selectedPhotosIds相等,说明删除成功,走下面的逻辑
|
|
|
// 如果不相等,说明有删除失败的,走else逻辑
|
|
|
if (result.length == photoGroup.value.selectedPhotosIds.length) {
|
|
|
-
|
|
|
- ImagePickerUtil.updatePhotoData(
|
|
|
- photoGroup.value.selectedPhotosIds);
|
|
|
+ ImagePickerUtil.updatePhotoData(photoGroup.value.selectedPhotosIds);
|
|
|
cleanSelections();
|
|
|
|
|
|
ToastUtil.show('Delete success');
|
|
|
@@ -211,16 +250,15 @@ class CalendarPreviewController extends BaseController
|
|
|
ToastUtil.show("Delete failed");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
StorePage.start();
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
//删除成功清除选中的图片
|
|
|
void cleanSelections() async {
|
|
|
- photoGroup.value.images
|
|
|
- .removeWhere((element) => photoGroup.value.selectedPhotosIds.contains(element.id));
|
|
|
+ photoGroup.value.images.removeWhere(
|
|
|
+ (element) => photoGroup.value.selectedPhotosIds.contains(element.id));
|
|
|
photoGroup.value.selectedPhotosIds.clear();
|
|
|
photoGroup.refresh();
|
|
|
if (photoGroup.value.images.isEmpty) {
|
|
|
@@ -236,19 +274,20 @@ class CalendarPreviewController extends BaseController
|
|
|
});
|
|
|
}
|
|
|
updateSelectedFilesSize();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// 将selectedFilesSize转成String类型,然后单位转换,如果超过1MB,则转成MB,超过1GB,则转成GB,否则KB
|
|
|
String get selectedFilesSizeString {
|
|
|
-
|
|
|
final double sizeInKB = photoGroup.value.selectedTotalSize.value;
|
|
|
|
|
|
- if (sizeInKB >= 1024 * 1024) { // 先检查最大单位(GB)
|
|
|
+ if (sizeInKB >= 1024 * 1024) {
|
|
|
+ // 先检查最大单位(GB)
|
|
|
return "${(sizeInKB / (1024 * 1024)).toStringAsFixed(2)}GB";
|
|
|
- } else if (sizeInKB >= 1024) { // 然后检查MB
|
|
|
+ } else if (sizeInKB >= 1024) {
|
|
|
+ // 然后检查MB
|
|
|
return "${(sizeInKB / 1024).toStringAsFixed(2)}MB";
|
|
|
- } else { // 最后是KB
|
|
|
+ } else {
|
|
|
+ // 最后是KB
|
|
|
return "${sizeInKB.toStringAsFixed(2)}KB";
|
|
|
}
|
|
|
}
|
|
|
@@ -268,12 +307,8 @@ class CalendarPreviewController extends BaseController
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
void restoreSelections() {
|
|
|
-
|
|
|
-
|
|
|
- if(photoGroup.value.images.isEmpty){
|
|
|
+ if (photoGroup.value.images.isEmpty) {
|
|
|
clickBack();
|
|
|
return;
|
|
|
}
|
|
|
@@ -287,8 +322,8 @@ class CalendarPreviewController extends BaseController
|
|
|
});
|
|
|
}
|
|
|
updateSelectedFilesSize();
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
@override
|
|
|
void onClose() {
|
|
|
debugPrint('CalendarPreviewController onClose');
|
|
|
@@ -304,6 +339,4 @@ class CalendarPreviewController extends BaseController
|
|
|
// 清理缓存
|
|
|
PhotoManager.clearFileCache();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|