|
|
@@ -23,6 +23,7 @@ import '../../data/api/response/user_info_response.dart';
|
|
|
import '../../data/consts/event_report_id.dart';
|
|
|
import '../../data/repositories/config_repository.dart';
|
|
|
import '../../handler/event_handler.dart';
|
|
|
+import '../../handler/photo_scan_handler.dart';
|
|
|
import '../../widget/multi_segment_circle_indicator.dart';
|
|
|
|
|
|
class HomeController extends BaseController {
|
|
|
@@ -51,31 +52,31 @@ class HomeController extends BaseController {
|
|
|
RxInt imageCount = 0.obs;
|
|
|
|
|
|
// 相似图片
|
|
|
- RxList<AssetEntity> similarPhotos = <AssetEntity>[].obs;
|
|
|
+ RxList<AssetEntity> similarPhotos = PhotoScanHandler.similarPhotos;
|
|
|
|
|
|
// 人物图片
|
|
|
- RxList<AssetEntity> peoplePhotos = <AssetEntity>[].obs;
|
|
|
+ RxList<AssetEntity> peoplePhotos = PhotoScanHandler.peoplePhotos;
|
|
|
|
|
|
// 地点图片
|
|
|
- Rx<AssetEntity?> locationPhoto = Rx<AssetEntity?>(null);
|
|
|
+ Rx<AssetEntity?> locationPhoto = PhotoScanHandler.locationPhoto;
|
|
|
|
|
|
// 截图照片
|
|
|
- Rx<AssetEntity?> screenshotPhoto = Rx<AssetEntity?>(null);
|
|
|
+ Rx<AssetEntity?> screenshotPhoto = PhotoScanHandler.screenshotPhoto;
|
|
|
|
|
|
// 模糊照片
|
|
|
- Rx<AssetEntity?> blurryPhoto = Rx<AssetEntity?>(null);
|
|
|
+ Rx<AssetEntity?> blurryPhoto = PhotoScanHandler.blurryPhoto;
|
|
|
|
|
|
// 是否扫描完成
|
|
|
- RxBool isSimilarScanned = false.obs;
|
|
|
+ RxBool isSimilarScanned = PhotoScanHandler.isSimilarScanned;
|
|
|
|
|
|
// 是否扫描完成
|
|
|
- RxBool isPeopleScanned = false.obs;
|
|
|
+ RxBool isPeopleScanned = PhotoScanHandler.isPeopleScanned;
|
|
|
|
|
|
// 是否扫描完成
|
|
|
- RxBool isScreenShotScanned = false.obs;
|
|
|
+ RxBool isScreenShotScanned = PhotoScanHandler.isScreenShotScanned;
|
|
|
|
|
|
// 是否扫描完成
|
|
|
- RxBool isBlurryScanned = false.obs;
|
|
|
+ RxBool isBlurryScanned = PhotoScanHandler.isBlurryScanned;
|
|
|
|
|
|
// 存储是否扫描完成
|
|
|
RxBool isStorageScanned = false.obs;
|
|
|
@@ -95,7 +96,6 @@ class HomeController extends BaseController {
|
|
|
super.onInit();
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
- await loadPhotosFromDirectory();
|
|
|
// 延迟3秒
|
|
|
Future.delayed(const Duration(seconds: 3), () {
|
|
|
isStorageScanned.value = true;
|
|
|
@@ -103,22 +103,9 @@ class HomeController extends BaseController {
|
|
|
usedSpace.value = 50.0;
|
|
|
photoSpace.value = 30.0;
|
|
|
freeSpace.value = 150.0;
|
|
|
- isScreenShotScanned.value = true;
|
|
|
- isBlurryScanned.value = true;
|
|
|
- isPeopleScanned.value = true;
|
|
|
- isSimilarScanned.value = true;
|
|
|
- isStorageScanned.value = true;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- // if (await Permission.photos.request().isGranted) {
|
|
|
- // PhotoManager.clearFileCache();
|
|
|
- // getStorageInfo();
|
|
|
- // handlePhotos();
|
|
|
- // } else {
|
|
|
- // ToastUtil.show("Please enable the album permission");
|
|
|
- // }
|
|
|
-
|
|
|
configRepository.refreshConfig();
|
|
|
await userRepository.getUserInfo();
|
|
|
|
|
|
@@ -143,20 +130,11 @@ class HomeController extends BaseController {
|
|
|
}
|
|
|
setFirstIntoApp(false);
|
|
|
|
|
|
- if (Platform.isAndroid) {
|
|
|
- loadPhotosFromDirectory();
|
|
|
- }
|
|
|
- var result= await Permission.photos.request();
|
|
|
- if (result.isGranted) {
|
|
|
- PhotoManager.clearFileCache();
|
|
|
- getStorageInfo();
|
|
|
+ var status = await Permission.photos.status;
|
|
|
+ if (status.isGranted) {
|
|
|
|
|
|
- // handlePhotos();
|
|
|
- await handleScreenPhotos();
|
|
|
- await handleBlurryPhotos();
|
|
|
- await handlePeoplePhotos();
|
|
|
- await handleSimilarPhotos();
|
|
|
- } else if (result.isPermanentlyDenied) {
|
|
|
+ getStorageInfo();
|
|
|
+ } else if (status.isPermanentlyDenied) {
|
|
|
ToastUtil.show("Please enable the album permission");
|
|
|
openAppSettings();
|
|
|
} else {
|
|
|
@@ -170,60 +148,6 @@ class HomeController extends BaseController {
|
|
|
// EventHandler.report(EventId.event_03000);
|
|
|
}
|
|
|
|
|
|
- Future<void> loadPhotosFromDirectory() async {
|
|
|
- if (ImagePickerUtil.peoplePhotos.isEmpty ||
|
|
|
- ImagePickerUtil.similarPhotos.isEmpty ||
|
|
|
- ImagePickerUtil.locationPhotos.isEmpty ||
|
|
|
- ImagePickerUtil.screenshotPhotos.isEmpty) {
|
|
|
- try {
|
|
|
- final List<AssetEntity> result = await ImagePickerUtil.loadAssets();
|
|
|
- ImagePickerUtil.peoplePhotos.value = result ?? [];
|
|
|
- if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
|
|
|
- for (var personPhotos in ImagePickerUtil.peoplePhotos) {
|
|
|
- peoplePhotos.add(personPhotos);
|
|
|
- if (peoplePhotos.length == 2) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ImagePickerUtil.locationPhotos['location'] = result ?? [];
|
|
|
- if (ImagePickerUtil.locationPhotos.isNotEmpty) {
|
|
|
- // 获取第一个地点的第一张照片
|
|
|
- final firstLocationPhotos =
|
|
|
- ImagePickerUtil.locationPhotos.values.first;
|
|
|
- if (firstLocationPhotos.isNotEmpty) {
|
|
|
- var asset = firstLocationPhotos.first;
|
|
|
- locationPhoto.value = asset;
|
|
|
- }
|
|
|
- }
|
|
|
- ImagePickerUtil.screenshotPhotos.value = result ?? [];
|
|
|
- if (ImagePickerUtil.screenshotPhotos.isNotEmpty) {
|
|
|
- var asset = ImagePickerUtil.screenshotPhotos.first;
|
|
|
- screenshotPhoto.value = asset;
|
|
|
- }
|
|
|
-
|
|
|
- ImagePickerUtil.similarPhotos.add(result ?? []);
|
|
|
- if (ImagePickerUtil.similarPhotos.isNotEmpty) {
|
|
|
- for (var group in ImagePickerUtil.similarPhotos) {
|
|
|
- for (var asset in group) {
|
|
|
- similarPhotos.add(asset);
|
|
|
- if (similarPhotos.length == 4) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ImagePickerUtil.blurryPhotos.value = result ?? [];
|
|
|
- if (ImagePickerUtil.blurryPhotos.isNotEmpty) {
|
|
|
- var asset = ImagePickerUtil.blurryPhotos.first;
|
|
|
- blurryPhoto.value = asset;
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- print('Error loading photos: $e');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
Future<void> getStorageInfo() async {
|
|
|
final classifyPhoto = ClassifyPhoto();
|
|
|
|
|
|
@@ -264,164 +188,164 @@ class HomeController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Future<void> handleScreenPhotos() async {
|
|
|
- final photoClassify = ClassifyPhoto();
|
|
|
- try {
|
|
|
- print('开始获取截图照片');
|
|
|
- final photos = await photoClassify.getScreenshots();
|
|
|
- print('获取截图照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
- isScreenShotScanned.value = true;
|
|
|
- if (photos != null) {
|
|
|
- await ImagePickerUtil.updatePhotos(photos);
|
|
|
- if (ImagePickerUtil.screenshotPhotos.isNotEmpty) {
|
|
|
- var asset = ImagePickerUtil.screenshotPhotos.first;
|
|
|
- screenshotPhoto.value = asset;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e, stackTrace) {
|
|
|
- print('获取照片失败: $e');
|
|
|
- print('Stack trace: $stackTrace');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Future<void> handleBlurryPhotos() async {
|
|
|
- final photoClassify = ClassifyPhoto();
|
|
|
- try {
|
|
|
- print('开始获取模糊照片');
|
|
|
- final photos = await photoClassify.getBlurryPhotos();
|
|
|
- print('获取模糊照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
- isBlurryScanned.value = true;
|
|
|
- if (photos != null) {
|
|
|
- await ImagePickerUtil.updatePhotos(photos);
|
|
|
- if (ImagePickerUtil.blurryPhotos.isNotEmpty) {
|
|
|
- var asset = ImagePickerUtil.blurryPhotos.first;
|
|
|
- blurryPhoto.value = asset;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e, stackTrace) {
|
|
|
- print('获取照片失败: $e');
|
|
|
- print('Stack trace: $stackTrace');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Future<void> handlePeoplePhotos() async {
|
|
|
- final photoClassify = ClassifyPhoto();
|
|
|
- try {
|
|
|
- print('开始获取人物照片');
|
|
|
- final photos = await photoClassify.getPeoplePhotos();
|
|
|
- print('获取人物照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
- isPeopleScanned.value = true;
|
|
|
- if (photos != null) {
|
|
|
- await ImagePickerUtil.updatePhotos(photos);
|
|
|
-
|
|
|
- // 处理人物照片
|
|
|
- peoplePhotos.clear();
|
|
|
- if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
|
|
|
- for (var personPhotos in ImagePickerUtil.peoplePhotos) {
|
|
|
- peoplePhotos.add(personPhotos);
|
|
|
- if (peoplePhotos.length == 2) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e, stackTrace) {
|
|
|
- print('获取照片失败: $e');
|
|
|
- print('Stack trace: $stackTrace');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Future<void> handleSimilarPhotos() async {
|
|
|
- final photoClassify = ClassifyPhoto();
|
|
|
- try {
|
|
|
- print('开始获取相似照片');
|
|
|
- final photos = await photoClassify.getSimilarPhotos();
|
|
|
- print('获取相似照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
- isSimilarScanned.value = true;
|
|
|
- if (photos != null) {
|
|
|
- await ImagePickerUtil.updatePhotos(photos);
|
|
|
-
|
|
|
- similarPhotos.clear();
|
|
|
- if (ImagePickerUtil.similarPhotos.isNotEmpty) {
|
|
|
- for (var group in ImagePickerUtil.similarPhotos) {
|
|
|
- for (var asset in group) {
|
|
|
- similarPhotos.add(asset);
|
|
|
- if (similarPhotos.length == 4) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e, stackTrace) {
|
|
|
- print('获取照片失败: $e');
|
|
|
- print('Stack trace: $stackTrace');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Future<void> handlePhotos() async {
|
|
|
- final photoClassify = ClassifyPhoto();
|
|
|
- try {
|
|
|
- print('开始获取照片');
|
|
|
- final photos = await photoClassify.getPhoto();
|
|
|
- print('获取照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
-
|
|
|
- // 已完成扫描
|
|
|
- // isScanned.value = true;
|
|
|
-
|
|
|
- if (photos != null) {
|
|
|
- await ImagePickerUtil.updatePhotos(photos);
|
|
|
-
|
|
|
- similarPhotos.clear();
|
|
|
- if (ImagePickerUtil.similarPhotos.isNotEmpty) {
|
|
|
- for (var group in ImagePickerUtil.similarPhotos) {
|
|
|
- for (var asset in group) {
|
|
|
- similarPhotos.add(asset);
|
|
|
- if (similarPhotos.length == 4) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 处理地点照片
|
|
|
- locationPhoto.value = null;
|
|
|
- if (ImagePickerUtil.locationPhotos.isNotEmpty) {
|
|
|
- // 获取第一个地点的第一张照片
|
|
|
- final firstLocationPhotos =
|
|
|
- ImagePickerUtil.locationPhotos.values.first;
|
|
|
- if (firstLocationPhotos.isNotEmpty) {
|
|
|
- var asset = firstLocationPhotos.first;
|
|
|
- locationPhoto.value = asset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 处理人物照片
|
|
|
- peoplePhotos.clear();
|
|
|
- if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
|
|
|
- for (var personPhotos in ImagePickerUtil.peoplePhotos) {
|
|
|
- peoplePhotos.add(personPhotos);
|
|
|
- if (peoplePhotos.length == 2) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (ImagePickerUtil.screenshotPhotos.isNotEmpty) {
|
|
|
- var asset = ImagePickerUtil.screenshotPhotos.first;
|
|
|
- screenshotPhoto.value = asset;
|
|
|
- }
|
|
|
-
|
|
|
- if (ImagePickerUtil.blurryPhotos.isNotEmpty) {
|
|
|
- var asset = ImagePickerUtil.blurryPhotos.first;
|
|
|
- blurryPhoto.value = asset;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (e, stackTrace) {
|
|
|
- print('获取照片失败: $e');
|
|
|
- print('Stack trace: $stackTrace');
|
|
|
- }
|
|
|
- }
|
|
|
+ // Future<void> handleScreenPhotos() async {
|
|
|
+ // final photoClassify = ClassifyPhoto();
|
|
|
+ // try {
|
|
|
+ // print('开始获取截图照片');
|
|
|
+ // final photos = await photoClassify.getScreenshots();
|
|
|
+ // print('获取截图照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
+ // isScreenShotScanned.value = true;
|
|
|
+ // if (photos != null) {
|
|
|
+ // await ImagePickerUtil.updatePhotos(photos);
|
|
|
+ // if (ImagePickerUtil.screenshotPhotos.isNotEmpty) {
|
|
|
+ // var asset = ImagePickerUtil.screenshotPhotos.first;
|
|
|
+ // screenshotPhoto.value = asset;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } catch (e, stackTrace) {
|
|
|
+ // print('获取照片失败: $e');
|
|
|
+ // print('Stack trace: $stackTrace');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // Future<void> handleBlurryPhotos() async {
|
|
|
+ // final photoClassify = ClassifyPhoto();
|
|
|
+ // try {
|
|
|
+ // print('开始获取模糊照片');
|
|
|
+ // final photos = await photoClassify.getBlurryPhotos();
|
|
|
+ // print('获取模糊照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
+ // isBlurryScanned.value = true;
|
|
|
+ // if (photos != null) {
|
|
|
+ // await ImagePickerUtil.updatePhotos(photos);
|
|
|
+ // if (ImagePickerUtil.blurryPhotos.isNotEmpty) {
|
|
|
+ // var asset = ImagePickerUtil.blurryPhotos.first;
|
|
|
+ // blurryPhoto.value = asset;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } catch (e, stackTrace) {
|
|
|
+ // print('获取照片失败: $e');
|
|
|
+ // print('Stack trace: $stackTrace');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // Future<void> handlePeoplePhotos() async {
|
|
|
+ // final photoClassify = ClassifyPhoto();
|
|
|
+ // try {
|
|
|
+ // print('开始获取人物照片');
|
|
|
+ // final photos = await photoClassify.getPeoplePhotos();
|
|
|
+ // print('获取人物照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
+ // isPeopleScanned.value = true;
|
|
|
+ // if (photos != null) {
|
|
|
+ // await ImagePickerUtil.updatePhotos(photos);
|
|
|
+ //
|
|
|
+ // // 处理人物照片
|
|
|
+ // peoplePhotos.clear();
|
|
|
+ // if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
|
|
|
+ // for (var personPhotos in ImagePickerUtil.peoplePhotos) {
|
|
|
+ // peoplePhotos.add(personPhotos);
|
|
|
+ // if (peoplePhotos.length == 2) {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } catch (e, stackTrace) {
|
|
|
+ // print('获取照片失败: $e');
|
|
|
+ // print('Stack trace: $stackTrace');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // Future<void> handleSimilarPhotos() async {
|
|
|
+ // final photoClassify = ClassifyPhoto();
|
|
|
+ // try {
|
|
|
+ // print('开始获取相似照片');
|
|
|
+ // final photos = await photoClassify.getSimilarPhotos();
|
|
|
+ // print('获取相似照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
+ // isSimilarScanned.value = true;
|
|
|
+ // if (photos != null) {
|
|
|
+ // await ImagePickerUtil.updatePhotos(photos);
|
|
|
+ //
|
|
|
+ // similarPhotos.clear();
|
|
|
+ // if (ImagePickerUtil.similarPhotos.isNotEmpty) {
|
|
|
+ // for (var group in ImagePickerUtil.similarPhotos) {
|
|
|
+ // for (var asset in group) {
|
|
|
+ // similarPhotos.add(asset);
|
|
|
+ // if (similarPhotos.length == 4) {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } catch (e, stackTrace) {
|
|
|
+ // print('获取照片失败: $e');
|
|
|
+ // print('Stack trace: $stackTrace');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // Future<void> handlePhotos() async {
|
|
|
+ // final photoClassify = ClassifyPhoto();
|
|
|
+ // try {
|
|
|
+ // print('开始获取照片');
|
|
|
+ // final photos = await photoClassify.getPhoto();
|
|
|
+ // print('获取照片完成: ${photos?.length ?? 0} 组照片');
|
|
|
+ //
|
|
|
+ // // 已完成扫描
|
|
|
+ // // isScanned.value = true;
|
|
|
+ //
|
|
|
+ // if (photos != null) {
|
|
|
+ // await ImagePickerUtil.updatePhotos(photos);
|
|
|
+ //
|
|
|
+ // similarPhotos.clear();
|
|
|
+ // if (ImagePickerUtil.similarPhotos.isNotEmpty) {
|
|
|
+ // for (var group in ImagePickerUtil.similarPhotos) {
|
|
|
+ // for (var asset in group) {
|
|
|
+ // similarPhotos.add(asset);
|
|
|
+ // if (similarPhotos.length == 4) {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 处理地点照片
|
|
|
+ // locationPhoto.value = null;
|
|
|
+ // if (ImagePickerUtil.locationPhotos.isNotEmpty) {
|
|
|
+ // // 获取第一个地点的第一张照片
|
|
|
+ // final firstLocationPhotos =
|
|
|
+ // ImagePickerUtil.locationPhotos.values.first;
|
|
|
+ // if (firstLocationPhotos.isNotEmpty) {
|
|
|
+ // var asset = firstLocationPhotos.first;
|
|
|
+ // locationPhoto.value = asset;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 处理人物照片
|
|
|
+ // peoplePhotos.clear();
|
|
|
+ // if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
|
|
|
+ // for (var personPhotos in ImagePickerUtil.peoplePhotos) {
|
|
|
+ // peoplePhotos.add(personPhotos);
|
|
|
+ // if (peoplePhotos.length == 2) {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (ImagePickerUtil.screenshotPhotos.isNotEmpty) {
|
|
|
+ // var asset = ImagePickerUtil.screenshotPhotos.first;
|
|
|
+ // screenshotPhoto.value = asset;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (ImagePickerUtil.blurryPhotos.isNotEmpty) {
|
|
|
+ // var asset = ImagePickerUtil.blurryPhotos.first;
|
|
|
+ // blurryPhoto.value = asset;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } catch (e, stackTrace) {
|
|
|
+ // print('获取照片失败: $e');
|
|
|
+ // print('Stack trace: $stackTrace');
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
void _navigateAndStartPage(Function pageStartFunction) {
|
|
|
// if (isFirstClickHomeClean()) {
|