|
|
@@ -1,15 +1,8 @@
|
|
|
-import 'dart:io';
|
|
|
import 'dart:math';
|
|
|
|
|
|
-import 'package:classify_photo/classify_photo.dart';
|
|
|
import 'package:clean/data/bean/photos_type.dart';
|
|
|
-import 'package:clean/model/asset_group.dart';
|
|
|
-import 'package:clean/module/locations_photo/locations_photo_controller.dart';
|
|
|
-import 'package:clean/module/locations_photo/locations_single_photo_controller.dart';
|
|
|
-import 'package:clean/module/people_photo/people_photo_controller.dart';
|
|
|
-import 'package:clean/module/people_photo/photo_group.dart';
|
|
|
-import 'package:clean/module/photo_preview/photo_preview_controller.dart';
|
|
|
-import 'package:clean/module/screenshots_blurry/screenshots_controller.dart';
|
|
|
+import 'package:clean/module/locations_photo/locations_photo_state.dart';
|
|
|
+import 'package:clean/module/screenshots_blurry/screenshots_blurry_state.dart';
|
|
|
import 'package:clean/module/similar_photo/similar_photo_controller.dart';
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
@@ -18,7 +11,7 @@ import 'package:photo_manager/photo_manager.dart';
|
|
|
|
|
|
import '../../handler/photo_scan_handler.dart';
|
|
|
import '../calendar/calendar_state.dart';
|
|
|
-import '../home/home_controller.dart';
|
|
|
+import '../people_photo/people_photo_state.dart';
|
|
|
|
|
|
class ImagePickerUtil {
|
|
|
ImagePickerUtil._();
|
|
|
@@ -45,9 +38,9 @@ class ImagePickerUtil {
|
|
|
// 人物图片
|
|
|
static final RxList<AssetEntity> peoplePhotos = <AssetEntity>[].obs;
|
|
|
|
|
|
- // android测试
|
|
|
|
|
|
- static late List<AssetEntity> androidPhotos = <AssetEntity>[];
|
|
|
+
|
|
|
+ static late List<AssetEntity> allPhotos = <AssetEntity>[];
|
|
|
|
|
|
static final RxSet<String> selectedScreenshotPhotosIds = <String>{}.obs;
|
|
|
static final RxSet<String> selectedSimilarPhotosIds = <String>{}.obs;
|
|
|
@@ -76,7 +69,7 @@ class ImagePickerUtil {
|
|
|
peoplePhotos.clear();
|
|
|
}
|
|
|
|
|
|
- static loadData(ClassificationResult result) async {
|
|
|
+ static loadClassifiedPhotoData(ClassificationResult result) async {
|
|
|
if (result.similarGroups != null) {
|
|
|
similarResult.assignAll(result.similarGroups ?? []);
|
|
|
await newUpdatePhotoGroups("similar", similarResult);
|
|
|
@@ -172,20 +165,24 @@ class ImagePickerUtil {
|
|
|
Set<String> selectedPhotosIds = Set.from(selectedPhotosIds1);
|
|
|
screenshotPhotos
|
|
|
.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
+ blurryPhotos
|
|
|
+ .removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
+ ScreenshotsBlurryState.removePhotosData(selectedPhotosIds);
|
|
|
for (var group in similarPhotos) {
|
|
|
group.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
}
|
|
|
locationPhotos.forEach((key, group) =>
|
|
|
group.removeWhere((element) => selectedPhotosIds.contains(element.id)));
|
|
|
+ LocationsPhotoState.removePhotosData(selectedPhotosIds);
|
|
|
peoplePhotos
|
|
|
.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
- blurryPhotos
|
|
|
- .removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
- // 2. 移除空的集合
|
|
|
+ PeoplePhotoState.removePhotosData(selectedPhotosIds);
|
|
|
+
|
|
|
+
|
|
|
similarPhotos.removeWhere((element) => element.isEmpty);
|
|
|
locationPhotos.removeWhere((key, value) => value.isEmpty);
|
|
|
|
|
|
- debugPrint("ImagePickerUtil2 updatePhotoData $selectedPhotosIds");
|
|
|
+ debugPrint("ImagePickerUtil updatePhotoData $selectedPhotosIds");
|
|
|
selectedScreenshotPhotosIds
|
|
|
.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
selectedSimilarPhotosIds
|
|
|
@@ -324,6 +321,13 @@ class ImagePickerUtil {
|
|
|
similarPhotosSize.value += group.groupFileSize;
|
|
|
similarPhotoCount.value += group.groupImageCount;
|
|
|
}
|
|
|
+ for (final group in ImagePickerUtil.similarPhotos) {
|
|
|
+ for (final asset in group) {
|
|
|
+ if (PhotoScanHandler.similarPhotos.length >= 4) break;
|
|
|
+ PhotoScanHandler.similarPhotos.add(asset);
|
|
|
+ }
|
|
|
+ if (PhotoScanHandler.similarPhotos.length >= 4) break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -335,9 +339,10 @@ class ImagePickerUtil {
|
|
|
screenshotPhotos.value = await _newConvertToAssetEntities(photoGroup);
|
|
|
screenshotsSize.value =
|
|
|
photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
-
|
|
|
+ if (ImagePickerUtil.screenshotPhotos.isNotEmpty) {
|
|
|
+ PhotoScanHandler.screenshotPhoto.value = ImagePickerUtil.screenshotPhotos.first;
|
|
|
+ }
|
|
|
break;
|
|
|
-
|
|
|
// case 'location':
|
|
|
// String location = group['name'] as String;
|
|
|
// locationPhotos[location] = await _convertToAssetEntities(photos);
|
|
|
@@ -348,12 +353,20 @@ class ImagePickerUtil {
|
|
|
peoplePhotos.assignAll(await _newConvertToAssetEntities(photoGroup));
|
|
|
peopleSize.value =
|
|
|
photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
+ for (final person in ImagePickerUtil.peoplePhotos) {
|
|
|
+ if (PhotoScanHandler.peoplePhotos.length >= 2) break;
|
|
|
+ PhotoScanHandler.peoplePhotos.add(person);
|
|
|
+ }
|
|
|
+
|
|
|
break;
|
|
|
case 'blurry':
|
|
|
blurryPhotos.clear();
|
|
|
blurryPhotos.value = await _newConvertToAssetEntities(photoGroup);
|
|
|
blurrySize.value =
|
|
|
photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
+ if (ImagePickerUtil.blurryPhotos.isNotEmpty) {
|
|
|
+ PhotoScanHandler.blurryPhoto.value = ImagePickerUtil.blurryPhotos.first;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -512,7 +525,7 @@ class ImagePickerUtil {
|
|
|
final PermissionState result = await PhotoManager.requestPermissionExtend();
|
|
|
if (!result.hasAccess) return [];
|
|
|
|
|
|
- if (androidPhotos.isNotEmpty) return androidPhotos;
|
|
|
+ if (allPhotos.isNotEmpty) return allPhotos;
|
|
|
// 选择相册
|
|
|
final List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(
|
|
|
type: RequestType.common,
|
|
|
@@ -530,11 +543,11 @@ class ImagePickerUtil {
|
|
|
int assetCount = await albums.first.assetCountAsync;
|
|
|
|
|
|
debugPrint("ImagePickerUtil loadAssets assetCount $assetCount");
|
|
|
- androidPhotos = await albums.first.getAssetListPaged(
|
|
|
+ allPhotos = await albums.first.getAssetListPaged(
|
|
|
page: 0,
|
|
|
size: assetCount,
|
|
|
);
|
|
|
|
|
|
- return androidPhotos;
|
|
|
+ return allPhotos;
|
|
|
}
|
|
|
}
|