|
|
@@ -62,10 +62,17 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
private final long SCANNING_COUNTDOWN = 1000 * 60 * 6;
|
|
|
private final long SCANNING_IS_TRIAL_COUNTDOWN = 1000 * 5;
|
|
|
|
|
|
- private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedPhotoImg = new MutableLiveData<>(new ArrayList<>());
|
|
|
- private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedWxImg = new MutableLiveData<>(new ArrayList<>());
|
|
|
- private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedQQImg = new MutableLiveData<>(new ArrayList<>());
|
|
|
- private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedOtherImg = new MutableLiveData<>(new ArrayList<>());
|
|
|
+ private final List<ImageDeepDetector.ImageFile> detectedPhotoList = new ArrayList<>();
|
|
|
+ private final List<ImageDeepDetector.ImageFile> detectedWxList = new ArrayList<>();
|
|
|
+ private final List<ImageDeepDetector.ImageFile> detectedQQList = new ArrayList<>();
|
|
|
+ private final List<ImageDeepDetector.ImageFile> detectedOtherList = new ArrayList<>();
|
|
|
+ private final List<ImageDeepDetector.ImageFile> selectList = new ArrayList<>();
|
|
|
+
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedPhotoImg = new MutableLiveData<>();
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedWxImg = new MutableLiveData<>();
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedQQImg = new MutableLiveData<>();
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedOtherImg = new MutableLiveData<>();
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> selectedList = new MutableLiveData<>();
|
|
|
|
|
|
private final SingleLiveEvent<List<Uri>> deleteUriListSdk11 = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<?> showTrialFinishDialog = new SingleLiveEvent<>();
|
|
|
@@ -89,7 +96,6 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
private int totalCount = 0;
|
|
|
private final MutableLiveData<Integer> totalDetectedCount = new MutableLiveData<>();
|
|
|
private final MutableLiveData<String> detectedLastFileName = new MutableLiveData<>();
|
|
|
- private final MutableLiveData<List<ImageDeepDetector.ImageFile>> selectedList = new MutableLiveData<>(new ArrayList<>());
|
|
|
private LiveData<String> selectedCountTxt;
|
|
|
private Disposable scanDisposable;
|
|
|
|
|
|
@@ -231,17 +237,16 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
|
|
|
public void onCheckAllClick(boolean isCheck) {
|
|
|
checkAll.setValue(isCheck);
|
|
|
- List<ImageDeepDetector.ImageFile> selectList = getList(selectedList);
|
|
|
- setListCheck(detectedPhotoImg.getValue(), isCheck);
|
|
|
- setListCheck(detectedWxImg.getValue(), isCheck);
|
|
|
- setListCheck(detectedQQImg.getValue(), isCheck);
|
|
|
- setListCheck(detectedOtherImg.getValue(), isCheck);
|
|
|
+ setListCheck(detectedPhotoList, isCheck);
|
|
|
+ setListCheck(detectedWxList, isCheck);
|
|
|
+ setListCheck(detectedQQList, isCheck);
|
|
|
+ setListCheck(detectedOtherList, isCheck);
|
|
|
if (isCheck) {
|
|
|
selectList.clear();
|
|
|
- selectList.addAll(getList(detectedPhotoImg));
|
|
|
- selectList.addAll(getList(detectedWxImg));
|
|
|
- selectList.addAll(getList(detectedQQImg));
|
|
|
- selectList.addAll(getList(detectedOtherImg));
|
|
|
+ selectList.addAll(detectedPhotoList);
|
|
|
+ selectList.addAll(detectedWxList);
|
|
|
+ selectList.addAll(detectedQQList);
|
|
|
+ selectList.addAll(detectedOtherList);
|
|
|
} else {
|
|
|
selectList.clear();
|
|
|
}
|
|
|
@@ -258,14 +263,6 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private List<ImageDeepDetector.ImageFile> getList(LiveData<List<ImageDeepDetector.ImageFile>> liveData) {
|
|
|
- List<ImageDeepDetector.ImageFile> selectList = liveData.getValue();
|
|
|
- if (selectList == null) {
|
|
|
- selectList = new ArrayList<>();
|
|
|
- }
|
|
|
- return selectList;
|
|
|
- }
|
|
|
-
|
|
|
public void startImageScanning() {
|
|
|
if (scanDisposable != null && !scanDisposable.isDisposed()) {
|
|
|
return;
|
|
|
@@ -284,6 +281,11 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
totalCount = 0;
|
|
|
totalDetectedCount.setValue(0);
|
|
|
detectTime = System.currentTimeMillis();
|
|
|
+ detectedPhotoList.clear();
|
|
|
+ detectedWxList.clear();
|
|
|
+ detectedQQList.clear();
|
|
|
+ detectedOtherList.clear();
|
|
|
+ selectList.clear();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -293,21 +295,37 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
totalCount += imageFiles.size();
|
|
|
totalDetectedCount.setValue(totalCount);
|
|
|
+ int photoCount = 0;
|
|
|
+ int wxCount = 0;
|
|
|
+ int qqCount = 0;
|
|
|
+ int otherCount = 0;
|
|
|
for (ImageDeepDetector.ImageFile imageFile : imageFiles) {
|
|
|
- MutableLiveData<List<ImageDeepDetector.ImageFile>> liveData;
|
|
|
if (imageFile.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_GALLERY) {
|
|
|
- liveData = detectedPhotoImg;
|
|
|
+ detectedPhotoList.add(imageFile);
|
|
|
+ photoCount++;
|
|
|
} else if (imageFile.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_WECHAT) {
|
|
|
- liveData = detectedWxImg;
|
|
|
+ detectedWxList.add(imageFile);
|
|
|
+ wxCount++;
|
|
|
} else if (imageFile.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_QQ) {
|
|
|
- liveData = detectedQQImg;
|
|
|
+ detectedQQList.add(imageFile);
|
|
|
+ qqCount++;
|
|
|
} else {
|
|
|
- liveData = detectedOtherImg;
|
|
|
+ detectedOtherList.add(imageFile);
|
|
|
+ otherCount++;
|
|
|
}
|
|
|
detectedLastFileName.setValue(imageFile.getName());
|
|
|
- List<ImageDeepDetector.ImageFile> list = getList(liveData);
|
|
|
- list.add(0, imageFile);
|
|
|
- liveData.setValue(list);
|
|
|
+ }
|
|
|
+ if (photoCount > 0) {
|
|
|
+ detectedPhotoImg.setValue(detectedPhotoList);
|
|
|
+ }
|
|
|
+ if (wxCount > 0) {
|
|
|
+ detectedWxImg.setValue(detectedWxList);
|
|
|
+ }
|
|
|
+ if (qqCount > 0) {
|
|
|
+ detectedQQImg.setValue(detectedQQList);
|
|
|
+ }
|
|
|
+ if (otherCount > 0) {
|
|
|
+ detectedOtherImg.setValue(detectedOtherList);
|
|
|
}
|
|
|
scrollTop.call();
|
|
|
}
|
|
|
@@ -332,24 +350,20 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
private void setFreeExport() {
|
|
|
if (isTrial) {
|
|
|
showTrialView.setValue(true);
|
|
|
- List<ImageDeepDetector.ImageFile> photoList = getList(detectedPhotoImg);
|
|
|
- if (photoList.size() != 0) {
|
|
|
- photoList.get(0).setTrial(true);
|
|
|
+ if (!detectedPhotoList.isEmpty()) {
|
|
|
+ detectedPhotoList.get(0).setTrial(true);
|
|
|
return;
|
|
|
}
|
|
|
- List<ImageDeepDetector.ImageFile> wxList = getList(detectedWxImg);
|
|
|
- if (wxList.size() != 0) {
|
|
|
- wxList.get(0).setTrial(true);
|
|
|
+ if (!detectedWxList.isEmpty()) {
|
|
|
+ detectedWxList.get(0).setTrial(true);
|
|
|
return;
|
|
|
}
|
|
|
- List<ImageDeepDetector.ImageFile> qqList = getList(detectedQQImg);
|
|
|
- if (qqList.size() != 0) {
|
|
|
- qqList.get(0).setTrial(true);
|
|
|
+ if (!detectedQQList.isEmpty()) {
|
|
|
+ detectedQQList.get(0).setTrial(true);
|
|
|
return;
|
|
|
}
|
|
|
- List<ImageDeepDetector.ImageFile> otherList = getList(detectedOtherImg);
|
|
|
- if (otherList.size() != 0) {
|
|
|
- otherList.get(0).setTrial(true);
|
|
|
+ if (!detectedOtherList.isEmpty()) {
|
|
|
+ detectedOtherList.get(0).setTrial(true);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
@@ -362,14 +376,13 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
|
|
|
public void setItemCheck(@NonNull ImageDeepDetector.ImageFile imageFile) {
|
|
|
- List<ImageDeepDetector.ImageFile> list = getList(this.selectedList);
|
|
|
imageFile.setCheck(!imageFile.isCheck());
|
|
|
if (imageFile.isCheck()) {
|
|
|
- list.add(imageFile);
|
|
|
+ selectList.add(imageFile);
|
|
|
} else {
|
|
|
- list.remove(imageFile);
|
|
|
+ selectList.remove(imageFile);
|
|
|
}
|
|
|
- selectedList.setValue(list);
|
|
|
+ selectedList.setValue(selectList);
|
|
|
}
|
|
|
|
|
|
public void checkPreview(@NonNull ImageDeepDetector.ImageFile imageFile) {
|
|
|
@@ -407,8 +420,7 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
|
|
|
public void executeImageDelete() {
|
|
|
- List<ImageDeepDetector.ImageFile> list = getList(selectedList);
|
|
|
- if (list.size() == 0) {
|
|
|
+ if (selectList.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
Single.just(Build.VERSION.SDK_INT)
|
|
|
@@ -417,7 +429,7 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
List<ImageDeepDetector.ImageFile> safList = new ArrayList<>();
|
|
|
List<Uri> uriList = new ArrayList<>();
|
|
|
if (isSdk11) {
|
|
|
- for (ImageDeepDetector.ImageFile item : list) {
|
|
|
+ for (ImageDeepDetector.ImageFile item : selectList) {
|
|
|
File tempFile = new File(item.getPath());
|
|
|
long mediaID = getFilePathToMediaID(tempFile.getAbsolutePath(), ContextUtil.getContext());
|
|
|
if (mediaID > 0) {
|
|
|
@@ -428,29 +440,29 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- safList.addAll(list);
|
|
|
+ safList.addAll(selectList);
|
|
|
}
|
|
|
return new Pair<>(safList, uriList);
|
|
|
})
|
|
|
.map(pair -> {
|
|
|
if (pair.first != null && !pair.first.isEmpty()) {
|
|
|
for (ImageDeepDetector.ImageFile item : pair.first) {
|
|
|
- item.delete();
|
|
|
- MutableLiveData<List<ImageDeepDetector.ImageFile>> liveData;
|
|
|
- if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_GALLERY) {
|
|
|
- liveData = detectedPhotoImg;
|
|
|
- } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_WECHAT) {
|
|
|
- liveData = detectedWxImg;
|
|
|
- } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_QQ) {
|
|
|
- liveData = detectedQQImg;
|
|
|
- } else {
|
|
|
- liveData = detectedOtherImg;
|
|
|
+ try {
|
|
|
+ item.delete();
|
|
|
+ if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_GALLERY) {
|
|
|
+ detectedPhotoList.remove(item);
|
|
|
+ } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_WECHAT) {
|
|
|
+ detectedWxList.remove(item);
|
|
|
+ } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_QQ) {
|
|
|
+ detectedQQList.remove(item);
|
|
|
+ } else {
|
|
|
+ detectedOtherList.remove(item);
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
}
|
|
|
- List<ImageDeepDetector.ImageFile> itemList = getList(liveData);
|
|
|
- itemList.remove(item);
|
|
|
}
|
|
|
- list.removeAll(pair.first);
|
|
|
- selectedList.postValue(list);
|
|
|
+ selectList.removeAll(pair.first);
|
|
|
+ selectedList.postValue(selectList);
|
|
|
notifyList.postValue(null);
|
|
|
}
|
|
|
return pair.second;
|
|
|
@@ -482,28 +494,24 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
public void onSuccess(@NonNull Boolean result) {
|
|
|
showLoadingEvent.setValue(false);
|
|
|
if (result) {
|
|
|
- for (ImageDeepDetector.ImageFile item : list) {
|
|
|
+ for (ImageDeepDetector.ImageFile item : selectList) {
|
|
|
try {
|
|
|
item.delete();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- MutableLiveData<List<ImageDeepDetector.ImageFile>> liveData;
|
|
|
- if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_GALLERY) {
|
|
|
- liveData = detectedPhotoImg;
|
|
|
- } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_WECHAT) {
|
|
|
- liveData = detectedWxImg;
|
|
|
- } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_QQ) {
|
|
|
- liveData = detectedQQImg;
|
|
|
- } else {
|
|
|
- liveData = detectedOtherImg;
|
|
|
+ if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_GALLERY) {
|
|
|
+ detectedPhotoList.remove(item);
|
|
|
+ } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_WECHAT) {
|
|
|
+ detectedWxList.remove(item);
|
|
|
+ } else if (item.getCategory() == ImageDeepDetector.ImageFile.CATEGORY_QQ) {
|
|
|
+ detectedQQList.remove(item);
|
|
|
+ } else {
|
|
|
+ detectedOtherList.remove(item);
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
}
|
|
|
- List<ImageDeepDetector.ImageFile> itemList = getList(liveData);
|
|
|
- itemList.remove(item);
|
|
|
}
|
|
|
ToastUtil.show(R.string.delete_success, ToastUtil.LENGTH_SHORT);
|
|
|
- list.clear();
|
|
|
- selectedList.setValue(list);
|
|
|
+ selectList.clear();
|
|
|
+ selectedList.setValue(selectList);
|
|
|
notifyList.call();
|
|
|
}
|
|
|
checkAll.setValue(false);
|
|
|
@@ -542,12 +550,11 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
|
|
|
public void onExportClick() {
|
|
|
- List<ImageDeepDetector.ImageFile> list = getList(selectedList);
|
|
|
- if (list.size() == 0) {
|
|
|
+ if (selectList.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
if (isTrial) {
|
|
|
- for (ImageDeepDetector.ImageFile imageFile : list) {
|
|
|
+ for (ImageDeepDetector.ImageFile imageFile : selectList) {
|
|
|
if (!imageFile.isTrial()) {
|
|
|
showTrialExportFailDialog.call();
|
|
|
return;
|
|
|
@@ -562,7 +569,7 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
showLoadingEvent.setValue(true);
|
|
|
RxJavaUtil.doInBackground(() -> {
|
|
|
- for (ImageDeepDetector.ImageFile item : list) {
|
|
|
+ for (ImageDeepDetector.ImageFile item : selectList) {
|
|
|
MediaStoreHelper.saveToSharedStorage(MediaStoreHelper.TYPE_IMAGE, item.newInputStream(), FileUtil.getExportImageFileName(item.getName()));
|
|
|
item.setCheck(false);
|
|
|
}
|
|
|
@@ -571,8 +578,8 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
checkAll.setValue(false);
|
|
|
showLoadingEvent.setValue(false);
|
|
|
ToastUtil.show(R.string.export_success, ToastUtil.LENGTH_SHORT);
|
|
|
- list.clear();
|
|
|
- selectedList.setValue(list);
|
|
|
+ selectList.clear();
|
|
|
+ selectedList.setValue(selectList);
|
|
|
}, throwable -> {
|
|
|
showLoadingEvent.setValue(false);
|
|
|
ToastUtil.show(throwable.getMessage(), ToastUtil.LENGTH_SHORT);
|
|
|
@@ -583,10 +590,10 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
|
|
|
public List<ImageDeepDetector.ImageFile> getAllDetectedList() {
|
|
|
ArrayList<ImageDeepDetector.ImageFile> allList = new ArrayList<>();
|
|
|
- allList.addAll(getList(detectedPhotoImg));
|
|
|
- allList.addAll(getList(detectedWxImg));
|
|
|
- allList.addAll(getList(detectedQQImg));
|
|
|
- allList.addAll(getList(detectedOtherImg));
|
|
|
+ allList.addAll(detectedPhotoList);
|
|
|
+ allList.addAll(detectedWxList);
|
|
|
+ allList.addAll(detectedQQList);
|
|
|
+ allList.addAll(detectedOtherList);
|
|
|
return allList;
|
|
|
}
|
|
|
|