Prechádzať zdrojové kódy

添加首页首次点击clean按钮跳转会员挽留页

云天逵 1 rok pred
rodič
commit
471d2df1bc

+ 1 - 1
lib/data/consts/constants.dart

@@ -93,7 +93,7 @@ void setPrivacyPolicy(bool isAgree) {
 bool isFirstClickHomeClean() {
   return KVUtil.getBool(Constants.isFirstClickHomeClean, true);
 }
-void setFirstClickClean(bool isFirst) {
+void setFirstClickHomeClean(bool isFirst) {
   KVUtil.putBool(Constants.isFirstClickHomeClean, isFirst);
 }
 

+ 47 - 30
lib/module/home/home_controller.dart

@@ -1,26 +1,21 @@
-import 'dart:io';
-
 import 'package:classify_photo/classify_photo.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/module/image_picker/image_picker_util.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/screenshots_blurry/screenshots_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:disk_space/disk_space.dart';
-import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
 import 'package:get/get.dart';
 import 'package:permission_handler/permission_handler.dart';
-import 'dart:typed_data';
-
 import 'package:wechat_assets_picker/wechat_assets_picker.dart';
 
 import '../../data/api/response/user_info_response.dart';
 
 class HomeController extends BaseController {
-
   Rx<double> totalSpace = 500.0.obs;
   Rx<double> usedSpace = 300.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 photoSpacePercentage => (photoSpace.value / totalSpace.value) * 100;
+  double get photoSpacePercentage =>
+      (photoSpace.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;
 
   // 相似图片
   RxList<AssetEntity> similarPhotos = <AssetEntity>[].obs;
+
   // 人物图片
   RxList<AssetEntity> peoplePhotos = <AssetEntity>[].obs;
+
   // 地点图片
   Rx<AssetEntity?> locationPhoto = Rx<AssetEntity?>(null);
+
   // 截图照片
   Rx<AssetEntity?> screenshotPhoto = Rx<AssetEntity?>(null);
+
   // 模糊照片
   Rx<AssetEntity?> blurryPhoto = Rx<AssetEntity?>(null);
+
   // 是否扫描完成
   RxBool isScanned = false.obs;
 
@@ -74,28 +76,26 @@ class HomeController extends BaseController {
   }
 
   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 {
-
         final List<AssetEntity>? result = await AssetPicker.pickAssets(
           Get.context!,
         );
         ImagePickerUtil.peoplePhotos.value = result ?? [];
 
         if (result == null) {
-
-        }else {
+        } else {
           ImagePickerUtil.locationPhotos['location'] = result ?? [];
         }
 
-
         ImagePickerUtil.screenshotPhotos.value = result ?? [];
 
         ImagePickerUtil.similarPhotos.add(result ?? []);
 
         ImagePickerUtil.blurryPhotos.value = result ?? [];
-
       } catch (e) {
         print('Error loading photos: $e');
       }
@@ -103,7 +103,6 @@ class HomeController extends BaseController {
   }
 
   Future<void> getStorageInfo() async {
-
     final classifyPhoto = ClassifyPhoto();
 
     try {
@@ -115,10 +114,18 @@ class HomeController extends BaseController {
       final usedSpaceGB = storageInfo['usedSpace']! / (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();
       freeSpace.value = freeSpaceGB;
@@ -129,7 +136,6 @@ class HomeController extends BaseController {
       print('可用空间: $freeSpaceStr');
       print('已用空间: $usedSpaceStr');
       print('照片占用: $photoSpaceStr');
-
     } catch (e) {
       print('获取存储信息失败: $e');
     }
@@ -164,7 +170,8 @@ class HomeController extends BaseController {
         locationPhoto.value = null;
         if (ImagePickerUtil.locationPhotos.isNotEmpty) {
           // 获取第一个地点的第一张照片
-          final firstLocationPhotos = ImagePickerUtil.locationPhotos.values.first;
+          final firstLocationPhotos =
+              ImagePickerUtil.locationPhotos.values.first;
           if (firstLocationPhotos.isNotEmpty) {
             var asset = firstLocationPhotos.first;
             locationPhoto.value = asset;
@@ -174,7 +181,7 @@ class HomeController extends BaseController {
         // 处理人物照片
         peoplePhotos.clear();
         if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
-        for (var personPhotos in ImagePickerUtil.peoplePhotos) {
+          for (var personPhotos in ImagePickerUtil.peoplePhotos) {
             peoplePhotos.add(personPhotos);
             if (peoplePhotos.length == 2) {
               break;
@@ -197,29 +204,39 @@ class HomeController extends BaseController {
       print('Stack trace: $stackTrace');
     }
   }
+  void _navigateAndStartPage(Function pageStartFunction) {
+    if (isFirstClickHomeClean()) {
+      setFirstClickHomeClean(false);
+      Get.toNamed(RoutePath.discount)?.then((value) {
+        pageStartFunction();
+      });
+    } else {
+      pageStartFunction();
+    }
+  }
 
   similarCleanClick() {
     print('similarCleanClick');
-    SimilarPhotoPage.start();
+    _navigateAndStartPage(SimilarPhotoPage.start);
   }
 
   peopleCleanClick() {
-    PeoplePhotoPage.start();
     print('peopleCleanClick');
+    _navigateAndStartPage(PeoplePhotoPage.start);
   }
 
   locationCleanClick() {
-    LocationsPhotoPage.start();
     print('locationCleanClick');
+    _navigateAndStartPage(LocationsPhotoPage.start);
   }
 
   screenshotCleanClick() {
-    ScreenshotsPage.start("Screenshots");
     print('screenshotCleanClick');
+    _navigateAndStartPage(() => ScreenshotsPage.start("Screenshots"));
   }
 
   blurryCleanClick() {
-    ScreenshotsPage.start("Blurry");
     print('blurCleanClick');
+    _navigateAndStartPage(() => ScreenshotsPage.start("Blurry"));
   }
-}
+}