|
@@ -39,6 +39,7 @@ import org.reactivestreams.Subscription;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -69,15 +70,16 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
private final List<ImageDeepDetector.ImageFile> detectedOtherList = new ReverseArrayList<>();
|
|
private final List<ImageDeepDetector.ImageFile> detectedOtherList = new ReverseArrayList<>();
|
|
|
private final List<ImageDeepDetector.ImageFile> selectList = new ReverseArrayList<>();
|
|
private final List<ImageDeepDetector.ImageFile> selectList = new ReverseArrayList<>();
|
|
|
|
|
|
|
|
- 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>> detectedPhotoImg = new MutableLiveData<>(detectedPhotoList);
|
|
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedWxImg = new MutableLiveData<>(detectedWxList);
|
|
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedQQImg = new MutableLiveData<>(detectedQQList);
|
|
|
|
|
+ private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedOtherImg = new MutableLiveData<>(detectedOtherList);
|
|
|
private final MutableLiveData<List<ImageDeepDetector.ImageFile>> selectedList = new MutableLiveData<>();
|
|
private final MutableLiveData<List<ImageDeepDetector.ImageFile>> selectedList = new MutableLiveData<>();
|
|
|
|
|
|
|
|
private final SingleLiveEvent<List<Uri>> deleteUriListSdk11 = new SingleLiveEvent<>();
|
|
private final SingleLiveEvent<List<Uri>> deleteUriListSdk11 = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<?> showTrialFinishDialog = new SingleLiveEvent<>();
|
|
private final SingleLiveEvent<?> showTrialFinishDialog = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<?> showTrialExportFailDialog = new SingleLiveEvent<>();
|
|
private final SingleLiveEvent<?> showTrialExportFailDialog = new SingleLiveEvent<>();
|
|
|
|
|
+ private final SingleLiveEvent<ImageDeepDetector.ImageFile> failScrollPosition = new SingleLiveEvent<>();
|
|
|
private final MutableLiveData<Boolean> showTrialView = new MutableLiveData<>();
|
|
private final MutableLiveData<Boolean> showTrialView = new MutableLiveData<>();
|
|
|
private final DeviceFuncRepository deviceFuncRepository;
|
|
private final DeviceFuncRepository deviceFuncRepository;
|
|
|
private LiveData<String> detectedPhotoTitle;
|
|
private LiveData<String> detectedPhotoTitle;
|
|
@@ -113,6 +115,11 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
initLiveData();
|
|
initLiveData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public LiveData<ImageDeepDetector.ImageFile> getFailScrollPosition() {
|
|
|
|
|
+ return failScrollPosition;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public LiveData<?> getScrollTop() {
|
|
public LiveData<?> getScrollTop() {
|
|
|
return scrollTop;
|
|
return scrollTop;
|
|
|
}
|
|
}
|
|
@@ -557,29 +564,62 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- showLoadingEvent.setValue(true);
|
|
|
|
|
- RxJavaUtil.doInBackground(() -> {
|
|
|
|
|
- for (ImageDeepDetector.ImageFile item : selectList) {
|
|
|
|
|
- MediaStoreHelper.saveToSharedStorage(MediaStoreHelper.TYPE_IMAGE, item.newInputStream(), FileUtil.getExportImageFileName(item.getName()));
|
|
|
|
|
- item.setCheck(false);
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
- }, o -> {
|
|
|
|
|
- checkAll.setValue(false);
|
|
|
|
|
- showLoadingEvent.setValue(false);
|
|
|
|
|
- ToastUtil.show(R.string.export_success, ToastUtil.LENGTH_SHORT);
|
|
|
|
|
- selectList.clear();
|
|
|
|
|
- selectedList.setValue(selectList);
|
|
|
|
|
- }, throwable -> {
|
|
|
|
|
- showLoadingEvent.setValue(false);
|
|
|
|
|
- ToastUtil.show(throwable.getMessage(), ToastUtil.LENGTH_SHORT);
|
|
|
|
|
- BuglyHelper.postCatchedException(new Exception("图片导出:", throwable));
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ Single.just(selectList.size())
|
|
|
|
|
+ .map(oldSize -> {
|
|
|
|
|
+ Iterator<ImageDeepDetector.ImageFile> iterator = selectList.iterator();
|
|
|
|
|
+ int errorCount = 0;
|
|
|
|
|
+ int test = 0;
|
|
|
|
|
+ Exception exception = null;
|
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
|
+ ImageDeepDetector.ImageFile item = iterator.next();
|
|
|
|
|
+ try {
|
|
|
|
|
+ MediaStoreHelper.saveToSharedStorage(MediaStoreHelper.TYPE_IMAGE, item.newInputStream(), FileUtil.getCreateFileName(MediaStoreHelper.TYPE_IMAGE, item.getName()));
|
|
|
|
|
+ item.setCheck(false);
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ } catch (Exception throwable) {
|
|
|
|
|
+ errorCount++;
|
|
|
|
|
+ exception = throwable;
|
|
|
|
|
+ BuglyHelper.postCatchedException(new Exception("图片导出:", throwable));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (errorCount == oldSize) {
|
|
|
|
|
+ throw new Exception("导出失败" + (exception == null ? "" : ":" + exception.getMessage()));
|
|
|
|
|
+ } else if (errorCount > 0) {
|
|
|
|
|
+ throw new Exception("部分导出失败" + ":" + exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return errorCount;
|
|
|
|
|
+ })
|
|
|
|
|
+ .compose(RxJavaUtil.SingleSchedule.io2Main())
|
|
|
|
|
+ .subscribe(new SingleObserver<Integer>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onSubscribe(@NonNull Disposable d) {
|
|
|
|
|
+ addDisposable(d);
|
|
|
|
|
+ showLoadingEvent.setValue(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onSuccess(@NonNull Integer integer) {
|
|
|
|
|
+ showLoadingEvent.setValue(false);
|
|
|
|
|
+ selectedList.setValue(selectList);
|
|
|
|
|
+ checkAll.setValue(false);
|
|
|
|
|
+ ToastUtil.show(R.string.export_success, ToastUtil.LENGTH_SHORT);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(@NonNull Throwable e) {
|
|
|
|
|
+ showLoadingEvent.setValue(false);
|
|
|
|
|
+ selectedList.setValue(selectList);
|
|
|
|
|
+ ToastUtil.show(e.getMessage(), ToastUtil.LENGTH_SHORT);
|
|
|
|
|
+ if (!selectList.isEmpty()) {
|
|
|
|
|
+ failScrollPosition.setValue(selectList.get(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<ImageDeepDetector.ImageFile> getAllDetectedList() {
|
|
public List<ImageDeepDetector.ImageFile> getAllDetectedList() {
|
|
|
- ArrayList<ImageDeepDetector.ImageFile> allList = new ArrayList<>();
|
|
|
|
|
|
|
+ List<ImageDeepDetector.ImageFile> allList = new ReverseArrayList<>();
|
|
|
allList.addAll(detectedPhotoList);
|
|
allList.addAll(detectedPhotoList);
|
|
|
allList.addAll(detectedWxList);
|
|
allList.addAll(detectedWxList);
|
|
|
allList.addAll(detectedQQList);
|
|
allList.addAll(detectedQQList);
|