|
@@ -1,26 +1,21 @@
|
|
|
-import 'dart:io';
|
|
|
|
|
-
|
|
|
|
|
import 'package:classify_photo/classify_photo.dart';
|
|
import 'package:classify_photo/classify_photo.dart';
|
|
|
import 'package:clean/base/base_controller.dart';
|
|
import 'package:clean/base/base_controller.dart';
|
|
|
|
|
+import 'package:clean/data/consts/constants.dart';
|
|
|
import 'package:clean/data/repositories/user_repository.dart';
|
|
import 'package:clean/data/repositories/user_repository.dart';
|
|
|
import 'package:clean/module/image_picker/image_picker_util.dart';
|
|
import 'package:clean/module/image_picker/image_picker_util.dart';
|
|
|
import 'package:clean/module/locations_photo/locations_photo_view.dart';
|
|
import 'package:clean/module/locations_photo/locations_photo_view.dart';
|
|
|
import 'package:clean/module/people_photo/people_photo_view.dart';
|
|
import 'package:clean/module/people_photo/people_photo_view.dart';
|
|
|
import 'package:clean/module/screenshots_blurry/screenshots_view.dart';
|
|
import 'package:clean/module/screenshots_blurry/screenshots_view.dart';
|
|
|
import 'package:clean/module/similar_photo/similar_photo_view.dart';
|
|
import 'package:clean/module/similar_photo/similar_photo_view.dart';
|
|
|
|
|
+import 'package:clean/router/app_pages.dart';
|
|
|
import 'package:clean/utils/toast_util.dart';
|
|
import 'package:clean/utils/toast_util.dart';
|
|
|
-import 'package:disk_space/disk_space.dart';
|
|
|
|
|
-import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get.dart';
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
-import 'dart:typed_data';
|
|
|
|
|
-
|
|
|
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
|
|
import '../../data/api/response/user_info_response.dart';
|
|
import '../../data/api/response/user_info_response.dart';
|
|
|
|
|
|
|
|
class HomeController extends BaseController {
|
|
class HomeController extends BaseController {
|
|
|
-
|
|
|
|
|
Rx<double> totalSpace = 500.0.obs;
|
|
Rx<double> totalSpace = 500.0.obs;
|
|
|
Rx<double> usedSpace = 300.0.obs;
|
|
Rx<double> usedSpace = 300.0.obs;
|
|
|
Rx<double> photoSpace = 100.0.obs;
|
|
Rx<double> photoSpace = 100.0.obs;
|
|
@@ -35,24 +30,31 @@ class HomeController extends BaseController {
|
|
|
double get usedSpacePercentage => (usedSpace.value / totalSpace.value) * 100;
|
|
double get usedSpacePercentage => (usedSpace.value / totalSpace.value) * 100;
|
|
|
|
|
|
|
|
// 计算照片占用存储百分比
|
|
// 计算照片占用存储百分比
|
|
|
- double get photoSpacePercentage => (photoSpace.value / totalSpace.value) * 100;
|
|
|
|
|
|
|
+ double get photoSpacePercentage =>
|
|
|
|
|
+ (photoSpace.value / totalSpace.value) * 100;
|
|
|
|
|
|
|
|
// 计算可用存储百分比
|
|
// 计算可用存储百分比
|
|
|
double get freeSpacePercentage => (freeSpace.value / totalSpace.value) * 100;
|
|
double get freeSpacePercentage => (freeSpace.value / totalSpace.value) * 100;
|
|
|
|
|
|
|
|
- RxList<String> similarImages = List.generate(4, (index) => 'iconHomeNoPhoto').obs;
|
|
|
|
|
|
|
+ RxList<String> similarImages =
|
|
|
|
|
+ List.generate(4, (index) => 'iconHomeNoPhoto').obs;
|
|
|
RxInt imageCount = 0.obs;
|
|
RxInt imageCount = 0.obs;
|
|
|
|
|
|
|
|
// 相似图片
|
|
// 相似图片
|
|
|
RxList<AssetEntity> similarPhotos = <AssetEntity>[].obs;
|
|
RxList<AssetEntity> similarPhotos = <AssetEntity>[].obs;
|
|
|
|
|
+
|
|
|
// 人物图片
|
|
// 人物图片
|
|
|
RxList<AssetEntity> peoplePhotos = <AssetEntity>[].obs;
|
|
RxList<AssetEntity> peoplePhotos = <AssetEntity>[].obs;
|
|
|
|
|
+
|
|
|
// 地点图片
|
|
// 地点图片
|
|
|
Rx<AssetEntity?> locationPhoto = Rx<AssetEntity?>(null);
|
|
Rx<AssetEntity?> locationPhoto = Rx<AssetEntity?>(null);
|
|
|
|
|
+
|
|
|
// 截图照片
|
|
// 截图照片
|
|
|
Rx<AssetEntity?> screenshotPhoto = Rx<AssetEntity?>(null);
|
|
Rx<AssetEntity?> screenshotPhoto = Rx<AssetEntity?>(null);
|
|
|
|
|
+
|
|
|
// 模糊照片
|
|
// 模糊照片
|
|
|
Rx<AssetEntity?> blurryPhoto = Rx<AssetEntity?>(null);
|
|
Rx<AssetEntity?> blurryPhoto = Rx<AssetEntity?>(null);
|
|
|
|
|
+
|
|
|
// 是否扫描完成
|
|
// 是否扫描完成
|
|
|
RxBool isScanned = false.obs;
|
|
RxBool isScanned = false.obs;
|
|
|
|
|
|
|
@@ -74,28 +76,26 @@ class HomeController extends BaseController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> loadPhotosFromDirectory() async {
|
|
Future<void> loadPhotosFromDirectory() async {
|
|
|
-
|
|
|
|
|
- if(ImagePickerUtil.peoplePhotos.isEmpty||ImagePickerUtil.similarPhotos.isEmpty||ImagePickerUtil.locationPhotos.isEmpty||ImagePickerUtil.screenshotPhotos.isEmpty){
|
|
|
|
|
|
|
+ if (ImagePickerUtil.peoplePhotos.isEmpty ||
|
|
|
|
|
+ ImagePickerUtil.similarPhotos.isEmpty ||
|
|
|
|
|
+ ImagePickerUtil.locationPhotos.isEmpty ||
|
|
|
|
|
+ ImagePickerUtil.screenshotPhotos.isEmpty) {
|
|
|
try {
|
|
try {
|
|
|
-
|
|
|
|
|
final List<AssetEntity>? result = await AssetPicker.pickAssets(
|
|
final List<AssetEntity>? result = await AssetPicker.pickAssets(
|
|
|
Get.context!,
|
|
Get.context!,
|
|
|
);
|
|
);
|
|
|
ImagePickerUtil.peoplePhotos.value = result ?? [];
|
|
ImagePickerUtil.peoplePhotos.value = result ?? [];
|
|
|
|
|
|
|
|
if (result == null) {
|
|
if (result == null) {
|
|
|
-
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
ImagePickerUtil.locationPhotos['location'] = result ?? [];
|
|
ImagePickerUtil.locationPhotos['location'] = result ?? [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
ImagePickerUtil.screenshotPhotos.value = result ?? [];
|
|
ImagePickerUtil.screenshotPhotos.value = result ?? [];
|
|
|
|
|
|
|
|
ImagePickerUtil.similarPhotos.add(result ?? []);
|
|
ImagePickerUtil.similarPhotos.add(result ?? []);
|
|
|
|
|
|
|
|
ImagePickerUtil.blurryPhotos.value = result ?? [];
|
|
ImagePickerUtil.blurryPhotos.value = result ?? [];
|
|
|
-
|
|
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
print('Error loading photos: $e');
|
|
print('Error loading photos: $e');
|
|
|
}
|
|
}
|
|
@@ -103,7 +103,6 @@ class HomeController extends BaseController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> getStorageInfo() async {
|
|
Future<void> getStorageInfo() async {
|
|
|
-
|
|
|
|
|
final classifyPhoto = ClassifyPhoto();
|
|
final classifyPhoto = ClassifyPhoto();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -115,10 +114,18 @@ class HomeController extends BaseController {
|
|
|
final usedSpaceGB = storageInfo['usedSpace']! / (1024 * 1024 * 1024);
|
|
final usedSpaceGB = storageInfo['usedSpace']! / (1024 * 1024 * 1024);
|
|
|
final photoSpaceGB = storageInfo['photoSpace']! / (1024 * 1024 * 1024);
|
|
final photoSpaceGB = storageInfo['photoSpace']! / (1024 * 1024 * 1024);
|
|
|
|
|
|
|
|
- totalSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['totalSpace']!, decimals: 1);
|
|
|
|
|
- freeSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['freeSpace']!, decimals: 1);
|
|
|
|
|
- usedSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['usedSpace']!, decimals: 1);
|
|
|
|
|
- photoSpaceStr.value = ImagePickerUtil.formatFileSize(storageInfo['photoSpace']!, decimals: 1);
|
|
|
|
|
|
|
+ totalSpaceStr.value = ImagePickerUtil.formatFileSize(
|
|
|
|
|
+ storageInfo['totalSpace']!,
|
|
|
|
|
+ decimals: 1);
|
|
|
|
|
+ freeSpaceStr.value = ImagePickerUtil.formatFileSize(
|
|
|
|
|
+ storageInfo['freeSpace']!,
|
|
|
|
|
+ decimals: 1);
|
|
|
|
|
+ usedSpaceStr.value = ImagePickerUtil.formatFileSize(
|
|
|
|
|
+ storageInfo['usedSpace']!,
|
|
|
|
|
+ decimals: 1);
|
|
|
|
|
+ photoSpaceStr.value = ImagePickerUtil.formatFileSize(
|
|
|
|
|
+ storageInfo['photoSpace']!,
|
|
|
|
|
+ decimals: 1);
|
|
|
|
|
|
|
|
totalSpace.value = totalSpaceGB.round().toDouble();
|
|
totalSpace.value = totalSpaceGB.round().toDouble();
|
|
|
freeSpace.value = freeSpaceGB;
|
|
freeSpace.value = freeSpaceGB;
|
|
@@ -129,7 +136,6 @@ class HomeController extends BaseController {
|
|
|
print('可用空间: $freeSpaceStr');
|
|
print('可用空间: $freeSpaceStr');
|
|
|
print('已用空间: $usedSpaceStr');
|
|
print('已用空间: $usedSpaceStr');
|
|
|
print('照片占用: $photoSpaceStr');
|
|
print('照片占用: $photoSpaceStr');
|
|
|
-
|
|
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
print('获取存储信息失败: $e');
|
|
print('获取存储信息失败: $e');
|
|
|
}
|
|
}
|
|
@@ -164,7 +170,8 @@ class HomeController extends BaseController {
|
|
|
locationPhoto.value = null;
|
|
locationPhoto.value = null;
|
|
|
if (ImagePickerUtil.locationPhotos.isNotEmpty) {
|
|
if (ImagePickerUtil.locationPhotos.isNotEmpty) {
|
|
|
// 获取第一个地点的第一张照片
|
|
// 获取第一个地点的第一张照片
|
|
|
- final firstLocationPhotos = ImagePickerUtil.locationPhotos.values.first;
|
|
|
|
|
|
|
+ final firstLocationPhotos =
|
|
|
|
|
+ ImagePickerUtil.locationPhotos.values.first;
|
|
|
if (firstLocationPhotos.isNotEmpty) {
|
|
if (firstLocationPhotos.isNotEmpty) {
|
|
|
var asset = firstLocationPhotos.first;
|
|
var asset = firstLocationPhotos.first;
|
|
|
locationPhoto.value = asset;
|
|
locationPhoto.value = asset;
|
|
@@ -174,7 +181,7 @@ class HomeController extends BaseController {
|
|
|
// 处理人物照片
|
|
// 处理人物照片
|
|
|
peoplePhotos.clear();
|
|
peoplePhotos.clear();
|
|
|
if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
|
|
if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
|
|
|
- for (var personPhotos in ImagePickerUtil.peoplePhotos) {
|
|
|
|
|
|
|
+ for (var personPhotos in ImagePickerUtil.peoplePhotos) {
|
|
|
peoplePhotos.add(personPhotos);
|
|
peoplePhotos.add(personPhotos);
|
|
|
if (peoplePhotos.length == 2) {
|
|
if (peoplePhotos.length == 2) {
|
|
|
break;
|
|
break;
|
|
@@ -197,29 +204,39 @@ class HomeController extends BaseController {
|
|
|
print('Stack trace: $stackTrace');
|
|
print('Stack trace: $stackTrace');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ void _navigateAndStartPage(Function pageStartFunction) {
|
|
|
|
|
+ if (isFirstClickHomeClean()) {
|
|
|
|
|
+ setFirstClickHomeClean(false);
|
|
|
|
|
+ Get.toNamed(RoutePath.discount)?.then((value) {
|
|
|
|
|
+ pageStartFunction();
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pageStartFunction();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
similarCleanClick() {
|
|
similarCleanClick() {
|
|
|
print('similarCleanClick');
|
|
print('similarCleanClick');
|
|
|
- SimilarPhotoPage.start();
|
|
|
|
|
|
|
+ _navigateAndStartPage(SimilarPhotoPage.start);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
peopleCleanClick() {
|
|
peopleCleanClick() {
|
|
|
- PeoplePhotoPage.start();
|
|
|
|
|
print('peopleCleanClick');
|
|
print('peopleCleanClick');
|
|
|
|
|
+ _navigateAndStartPage(PeoplePhotoPage.start);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
locationCleanClick() {
|
|
locationCleanClick() {
|
|
|
- LocationsPhotoPage.start();
|
|
|
|
|
print('locationCleanClick');
|
|
print('locationCleanClick');
|
|
|
|
|
+ _navigateAndStartPage(LocationsPhotoPage.start);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
screenshotCleanClick() {
|
|
screenshotCleanClick() {
|
|
|
- ScreenshotsPage.start("Screenshots");
|
|
|
|
|
print('screenshotCleanClick');
|
|
print('screenshotCleanClick');
|
|
|
|
|
+ _navigateAndStartPage(() => ScreenshotsPage.start("Screenshots"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
blurryCleanClick() {
|
|
blurryCleanClick() {
|
|
|
- ScreenshotsPage.start("Blurry");
|
|
|
|
|
print('blurCleanClick');
|
|
print('blurCleanClick');
|
|
|
|
|
+ _navigateAndStartPage(() => ScreenshotsPage.start("Blurry"));
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|