Browse Source

优化部分代码

zk 1 year ago
parent
commit
34cd721c1f

+ 10 - 24
app/src/main/java/com/datarecovery/master/module/audiorecover/AudioRecoverViewModel.java

@@ -12,7 +12,6 @@ import com.datarecovery.master.R;
 import com.datarecovery.master.data.consts.EventId;
 import com.datarecovery.master.data.repositories.DeviceFuncRepository;
 import com.datarecovery.master.handler.EventHelper;
-import com.datarecovery.master.module.imgrecover.ImageRecoverActivity;
 import com.datarecovery.master.module.member.MemberActivity;
 import com.datarecovery.master.module.member.MemberType;
 import com.datarecovery.master.sdk.bugly.BuglyHelper;
@@ -60,9 +59,7 @@ public class AudioRecoverViewModel extends BaseViewModel {
     private final SingleLiveEvent<?> notifyAudioData = new SingleLiveEvent<>();
     private final SingleLiveEvent<Boolean> showLoadingEvent = new SingleLiveEvent<>();
     private final DeviceFuncRepository deviceFuncRepository;
-    private int totalCount = 0;
     private final MutableLiveData<String> detectedLastFileName = new MutableLiveData<>();
-    private final MutableLiveData<Integer> totalDetectedCount = new MutableLiveData<>();
     private final MutableLiveData<Boolean> isDateFilterArrowUp = new MutableLiveData<>(false);
     private final MutableLiveData<Boolean> isSizeSortArrowUp = new MutableLiveData<>(false);
     private final MutableLiveData<Integer> dataFilterCondition = new MutableLiveData<>();
@@ -148,9 +145,6 @@ public class AudioRecoverViewModel extends BaseViewModel {
         return showLoadingEvent;
     }
 
-    public LiveData<Integer> getTotalDetectedCount() {
-        return totalDetectedCount;
-    }
 
     public LiveData<Boolean> getCheckAll() {
         return checkAll;
@@ -182,8 +176,6 @@ public class AudioRecoverViewModel extends BaseViewModel {
                         scanDisposable = Disposable.fromSubscription(s);
                         addDisposable(scanDisposable);
                         showScanDialogEvent.setValue(true);
-                        totalCount = 0;
-                        totalDetectedCount.setValue(0);
                         getList(detectedVideoList).clear();
                         originalDetectedList.clear();
                     }
@@ -193,8 +185,6 @@ public class AudioRecoverViewModel extends BaseViewModel {
                         if (documentFiles == null) {
                             return;
                         }
-                        totalCount += documentFiles.size();
-                        totalDetectedCount.setValue(totalCount);
                         originalDetectedList.addAll(0, documentFiles);
                         List<FilesSearch.DocumentFile> videoList = getList(detectedVideoList);
                         for (FilesSearch.DocumentFile documentFile : documentFiles) {
@@ -225,7 +215,7 @@ public class AudioRecoverViewModel extends BaseViewModel {
         if (isTrial) {
             showTrialView.setValue(true);
             List<FilesSearch.DocumentFile> list = getList(detectedVideoList);
-            if (list.size() > 0) {
+            if (!list.isEmpty()) {
                 list.get(0).setTrial(true);
             }
         }
@@ -263,7 +253,7 @@ public class AudioRecoverViewModel extends BaseViewModel {
 
     public void onExportClick() {
         List<FilesSearch.DocumentFile> list = selectedList.getValue();
-        if (list == null || list.size() == 0) {
+        if (list == null || list.isEmpty()) {
             return;
         }
         if (isTrial) {
@@ -361,9 +351,9 @@ public class AudioRecoverViewModel extends BaseViewModel {
         list.addAll(originalDetectedList);
     }
 
-    private List<FilesSearch.DocumentFile> getAwayWeekList() {
+    private void getAwayWeekList() {
         if (originalDetectedList.isEmpty()) {
-            return originalDetectedList;
+            return;
         }
         List<FilesSearch.DocumentFile> list = getList(detectedVideoList);
         list.clear();
@@ -372,12 +362,11 @@ public class AudioRecoverViewModel extends BaseViewModel {
                 list.add(file);
             }
         }
-        return list;
     }
 
-    private List<FilesSearch.DocumentFile> getYearAgoList() {
+    private void getYearAgoList() {
         if (originalDetectedList.isEmpty()) {
-            return originalDetectedList;
+            return;
         }
         List<FilesSearch.DocumentFile> list = getList(detectedVideoList);
         list.clear();
@@ -386,12 +375,11 @@ public class AudioRecoverViewModel extends BaseViewModel {
                 list.add(file);
             }
         }
-        return list;
     }
 
-    private List<FilesSearch.DocumentFile> getMonthAgoList() {
+    private void getMonthAgoList() {
         if (originalDetectedList.isEmpty()) {
-            return originalDetectedList;
+            return;
         }
         List<FilesSearch.DocumentFile> list = getList(detectedVideoList);
         list.clear();
@@ -400,13 +388,12 @@ public class AudioRecoverViewModel extends BaseViewModel {
                 list.add(file);
             }
         }
-        return list;
     }
 
 
-    private List<FilesSearch.DocumentFile> getWithinWeekList() {
+    private void getWithinWeekList() {
         if (originalDetectedList.isEmpty()) {
-            return originalDetectedList;
+            return;
         }
         List<FilesSearch.DocumentFile> list = getList(detectedVideoList);
         list.clear();
@@ -415,7 +402,6 @@ public class AudioRecoverViewModel extends BaseViewModel {
                 list.add(file);
             }
         }
-        return list;
     }
 
     @Override

+ 8 - 20
app/src/main/java/com/datarecovery/master/module/filerecover/FileRecoverViewModel.java

@@ -6,7 +6,6 @@ import androidx.lifecycle.Transformations;
 
 import com.atmob.app.lib.base.BaseViewModel;
 import com.atmob.app.lib.livedata.SingleLiveEvent;
-import com.atmob.common.logging.AtmobLog;
 import com.atmob.common.runtime.ActivityUtil;
 import com.atmob.common.runtime.ContextUtil;
 import com.datarecovery.master.R;
@@ -19,7 +18,6 @@ import com.datarecovery.master.sdk.bugly.BuglyHelper;
 import com.datarecovery.master.utils.BoxingUtil;
 import com.datarecovery.master.utils.FileUtil;
 import com.datarecovery.master.utils.FilesSearch;
-import com.datarecovery.master.utils.ImageDeepDetector;
 import com.datarecovery.master.utils.Maps;
 import com.datarecovery.master.utils.MediaStoreHelper;
 import com.datarecovery.master.utils.ReportUtil;
@@ -30,7 +28,6 @@ import org.reactivestreams.Subscription;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
@@ -53,10 +50,11 @@ public class FileRecoverViewModel extends BaseViewModel {
     private final List<MutableLiveData<Boolean>> checkList = new ArrayList<>();
     private final MutableLiveData<List<FilesSearch.DocumentFile>> detectedWordList = new MutableLiveData<>(new ArrayList<>());
     private final MutableLiveData<List<FilesSearch.DocumentFile>> detectedExcelList = new MutableLiveData<>(new ArrayList<>());
-    private final SingleLiveEvent<?> scrollTop = new SingleLiveEvent<>();
     private final MutableLiveData<List<FilesSearch.DocumentFile>> detectedPPTList = new MutableLiveData<>(new ArrayList<>());
     private final MutableLiveData<List<FilesSearch.DocumentFile>> detectedPDFList = new MutableLiveData<>(new ArrayList<>());
     private final MutableLiveData<List<FilesSearch.DocumentFile>> selectedList = new MutableLiveData<>(new ArrayList<>());
+
+    private final SingleLiveEvent<?> scrollTop = new SingleLiveEvent<>();
     private final MutableLiveData<Boolean> showTrialView = new MutableLiveData<>();
     private final MutableLiveData<String> detectedLastFileName = new MutableLiveData<>();
     private final MutableLiveData<Integer> checkPosition = new MutableLiveData<>();
@@ -65,8 +63,6 @@ public class FileRecoverViewModel extends BaseViewModel {
     private final SingleLiveEvent<Boolean> showLoadingEvent = new SingleLiveEvent<>();
     private final SingleLiveEvent<Boolean> showScanDialogEvent = new SingleLiveEvent<>();
     private final DeviceFuncRepository deviceFuncRepository;
-    private int totalCount = 0;
-    private final MutableLiveData<Integer> totalDetectedCount = new MutableLiveData<>();
     private final LiveData<String> selectedCountTxt;
     private Disposable scanDisposable;
     private boolean isTrial;
@@ -139,10 +135,6 @@ public class FileRecoverViewModel extends BaseViewModel {
         return showLoadingEvent;
     }
 
-    public LiveData<Integer> getTotalDetectedCount() {
-        return totalDetectedCount;
-    }
-
     public LiveData<List<FilesSearch.DocumentFile>> getSelectedList() {
         return selectedList;
     }
@@ -175,8 +167,6 @@ public class FileRecoverViewModel extends BaseViewModel {
                         scanDisposable = Disposable.fromSubscription(s);
                         addDisposable(scanDisposable);
                         showScanDialogEvent.setValue(true);
-                        totalCount = 0;
-                        totalDetectedCount.setValue(0);
                     }
 
                     @Override
@@ -184,10 +174,8 @@ public class FileRecoverViewModel extends BaseViewModel {
                         if (documentFiles == null || documentFiles.isEmpty()) {
                             return;
                         }
-                        totalCount += documentFiles.size();
-                        totalDetectedCount.setValue(totalCount);
+                        MutableLiveData<List<FilesSearch.DocumentFile>> liveData = null;
                         for (FilesSearch.DocumentFile item : documentFiles) {
-                            MutableLiveData<List<FilesSearch.DocumentFile>> liveData = null;
                             if (item.getCategory() == FilesSearch.DocumentFile.WORD) {
                                 liveData = detectedWordList;
                             } else if (item.getCategory() == FilesSearch.DocumentFile.EXCEL) {
@@ -232,19 +220,19 @@ public class FileRecoverViewModel extends BaseViewModel {
         if (isTrial) {
             showTrialView.setValue(true);
             List<FilesSearch.DocumentFile> list = getList(detectedWordList);
-            if (list.size() > 0) {
+            if (!list.isEmpty()) {
                 list.get(0).setTrial(true);
             }
             list = getList(detectedExcelList);
-            if (list.size() > 0) {
+            if (!list.isEmpty()) {
                 list.get(0).setTrial(true);
             }
             list = getList(detectedPPTList);
-            if (list.size() > 0) {
+            if (!list.isEmpty()) {
                 list.get(0).setTrial(true);
             }
             list = getList(detectedPDFList);
-            if (list.size() > 0) {
+            if (!list.isEmpty()) {
                 list.get(0).setTrial(true);
             }
         }
@@ -301,7 +289,7 @@ public class FileRecoverViewModel extends BaseViewModel {
 
     public void onExportClick() {
         List<FilesSearch.DocumentFile> list = selectedList.getValue();
-        if (list == null || list.size() == 0) {
+        if (list == null || list.isEmpty()) {
             return;
         }
         if (isTrial) {

+ 1 - 12
app/src/main/java/com/datarecovery/master/module/imgrecover/ImageRecoverViewModel.java

@@ -92,9 +92,6 @@ public class ImageRecoverViewModel extends BaseViewModel {
     private final SingleLiveEvent<?> notifyList = new SingleLiveEvent<>();
     private final MutableLiveData<String> barTitle = new MutableLiveData<>();
     private final MutableLiveData<Boolean> checkAll = new MutableLiveData<>(false);
-    //总探测到的图片数量
-    private int totalCount = 0;
-    private final MutableLiveData<Integer> totalDetectedCount = new MutableLiveData<>();
     private final MutableLiveData<String> detectedLastFileName = new MutableLiveData<>();
     private LiveData<String> selectedCountTxt;
     private Disposable scanDisposable;
@@ -163,10 +160,6 @@ public class ImageRecoverViewModel extends BaseViewModel {
         return previewEvent;
     }
 
-    public LiveData<Integer> getTotalDetectedCount() {
-        return totalDetectedCount;
-    }
-
     public LiveData<String> getSelectedCountTxt() {
         return selectedCountTxt;
     }
@@ -278,8 +271,6 @@ public class ImageRecoverViewModel extends BaseViewModel {
                         addDisposable(scanDisposable);
                         showScanDialogEvent.setValue(true);
                         checkAll.setValue(false);
-                        totalCount = 0;
-                        totalDetectedCount.setValue(0);
                         detectTime = System.currentTimeMillis();
                         detectedPhotoList.clear();
                         detectedWxList.clear();
@@ -293,8 +284,6 @@ public class ImageRecoverViewModel extends BaseViewModel {
                         if (imageFiles == null) {
                             return;
                         }
-                        totalCount += imageFiles.size();
-                        totalDetectedCount.setValue(totalCount);
                         int photoCount = 0;
                         int wxCount = 0;
                         int qqCount = 0;
@@ -338,7 +327,7 @@ public class ImageRecoverViewModel extends BaseViewModel {
                     @Override
                     public void onComplete() {
                         setFreeExport();
-                        AtmobLog.d("ImageRecoverViewModel", System.currentTimeMillis() - detectTime + "ms - " + totalCount);
+                        AtmobLog.d("ImageRecoverViewModel", System.currentTimeMillis() - detectTime + "ms");
                         if (isTrial) {
                             showTrialFinishDialog.call();
                         }

+ 2 - 12
app/src/main/java/com/datarecovery/master/module/videorecover/VideoRecoverViewModel.java

@@ -59,8 +59,6 @@ public class VideoRecoverViewModel extends BaseViewModel {
     private final SingleLiveEvent<Boolean> showScanDialogEvent = new SingleLiveEvent<>();
     private final SingleLiveEvent<Boolean> showLoadingEvent = new SingleLiveEvent<>();
     private final DeviceFuncRepository deviceFuncRepository;
-    private int totalCount = 0;
-    private final MutableLiveData<Integer> totalDetectedCount = new MutableLiveData<>();
     private final MutableLiveData<Boolean> isShowHint = new MutableLiveData<>();
     private Disposable scanDisposable;
     private boolean isTrial;
@@ -119,10 +117,6 @@ public class VideoRecoverViewModel extends BaseViewModel {
         return showScanDialogEvent;
     }
 
-    public LiveData<Integer> getTotalDetectedCount() {
-        return totalDetectedCount;
-    }
-
     public LiveData<List<FilesSearch.DocumentFile>> getSelectedList() {
         return selectedList;
     }
@@ -154,8 +148,6 @@ public class VideoRecoverViewModel extends BaseViewModel {
                         scanDisposable = Disposable.fromSubscription(s);
                         addDisposable(scanDisposable);
                         showScanDialogEvent.setValue(true);
-                        totalCount = 0;
-                        totalDetectedCount.setValue(0);
                     }
 
                     @Override
@@ -163,8 +155,6 @@ public class VideoRecoverViewModel extends BaseViewModel {
                         if (documentFiles == null) {
                             return;
                         }
-                        totalCount += documentFiles.size();
-                        totalDetectedCount.setValue(totalCount);
                         List<FilesSearch.DocumentFile> videoList = getList(detectedVideoList);
                         for (FilesSearch.DocumentFile documentFile : documentFiles) {
                             detectedLastFileName.setValue(documentFile.getName());
@@ -195,7 +185,7 @@ public class VideoRecoverViewModel extends BaseViewModel {
         if (isTrial) {
             showTrialView.setValue(true);
             List<FilesSearch.DocumentFile> list = getList(detectedVideoList);
-            if (list.size() > 0) {
+            if (!list.isEmpty()) {
                 list.get(0).setTrial(true);
             }
         }
@@ -233,7 +223,7 @@ public class VideoRecoverViewModel extends BaseViewModel {
 
     public void onExportClick() {
         List<FilesSearch.DocumentFile> list = selectedList.getValue();
-        if (list == null || list.size() == 0) {
+        if (list == null || list.isEmpty()) {
             return;
         }
         if (isTrial) {