|
|
@@ -1,23 +1,17 @@
|
|
|
package com.datarecovery.master.module.imgrecover;
|
|
|
|
|
|
-import android.app.PendingIntent;
|
|
|
import android.content.ContentResolver;
|
|
|
import android.content.ContentUris;
|
|
|
import android.content.Context;
|
|
|
-import android.content.IntentSender;
|
|
|
import android.database.Cursor;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
-import android.os.Handler;
|
|
|
-import android.os.Looper;
|
|
|
import android.provider.MediaStore;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.util.Log;
|
|
|
import android.util.Pair;
|
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
-import androidx.lifecycle.Observer;
|
|
|
import androidx.lifecycle.Transformations;
|
|
|
|
|
|
import com.atmob.app.lib.base.BaseViewModel;
|
|
|
@@ -28,6 +22,7 @@ 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.member.MemberActivity;
|
|
|
import com.datarecovery.master.module.member.MemberType;
|
|
|
import com.datarecovery.master.sdk.bugly.BuglyHelper;
|
|
|
import com.datarecovery.master.utils.BoxingUtil;
|
|
|
@@ -35,12 +30,10 @@ import com.datarecovery.master.utils.FileUtil;
|
|
|
import com.datarecovery.master.utils.ImageDeepDetector;
|
|
|
import com.datarecovery.master.utils.MediaStoreHelper;
|
|
|
import com.datarecovery.master.utils.ToastUtil;
|
|
|
-import com.datarecovery.master.utils.xfile.XSAFFile;
|
|
|
|
|
|
import org.reactivestreams.Subscription;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
@@ -50,12 +43,12 @@ import javax.inject.Inject;
|
|
|
|
|
|
import atmob.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
|
import atmob.reactivex.rxjava3.annotations.NonNull;
|
|
|
+import atmob.reactivex.rxjava3.core.Flowable;
|
|
|
import atmob.reactivex.rxjava3.core.FlowableSubscriber;
|
|
|
import atmob.reactivex.rxjava3.core.Single;
|
|
|
import atmob.reactivex.rxjava3.core.SingleObserver;
|
|
|
import atmob.reactivex.rxjava3.core.SingleSource;
|
|
|
import atmob.reactivex.rxjava3.disposables.Disposable;
|
|
|
-import atmob.reactivex.rxjava3.functions.Function;
|
|
|
import atmob.rxjava.utils.RxJavaUtil;
|
|
|
import dagger.hilt.android.lifecycle.HiltViewModel;
|
|
|
|
|
|
@@ -65,6 +58,7 @@ 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<>());
|
|
|
@@ -72,13 +66,15 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
private final MutableLiveData<List<ImageDeepDetector.ImageFile>> detectedOtherImg = new MutableLiveData<>(new ArrayList<>());
|
|
|
|
|
|
private final SingleLiveEvent<List<Uri>> deleteUriListSdk11 = new SingleLiveEvent<>();
|
|
|
+ private final SingleLiveEvent<?> showTrialExportFailDialog = new SingleLiveEvent<>();
|
|
|
+ private final MutableLiveData<Boolean> showTrialView = new MutableLiveData<>();
|
|
|
private final DeviceFuncRepository deviceFuncRepository;
|
|
|
private LiveData<String> detectedPhotoTitle;
|
|
|
private LiveData<String> detectedWxTitle;
|
|
|
private LiveData<String> detectedQQTitle;
|
|
|
private LiveData<String> detectedOtherTitle;
|
|
|
|
|
|
- private final SingleLiveEvent<ImageDeepDetector.ImageFile> previewEvent = new SingleLiveEvent<>();
|
|
|
+ private final SingleLiveEvent<Pair<List<ImageDeepDetector.ImageFile>, Integer>> previewEvent = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<?> detectedFinish = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<?> showClearDialog = new SingleLiveEvent<>();
|
|
|
private final SingleLiveEvent<Boolean> showScanDialogEvent = new SingleLiveEvent<>();
|
|
|
@@ -89,6 +85,7 @@ 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;
|
|
|
@@ -97,6 +94,8 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
private String type;
|
|
|
|
|
|
private SingleObserver<? super Boolean> dealMediaObserver;
|
|
|
+ //是否会员试用
|
|
|
+ private boolean isTrial;
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
@@ -106,6 +105,22 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
initLiveData();
|
|
|
}
|
|
|
|
|
|
+ public LiveData<?> getShowTrialExportFailDialog() {
|
|
|
+ return showTrialExportFailDialog;
|
|
|
+ }
|
|
|
+
|
|
|
+ public LiveData<String> getDetectedLastFileName() {
|
|
|
+ return detectedLastFileName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public LiveData<Boolean> getShowTrialView() {
|
|
|
+ return showTrialView;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isTrial() {
|
|
|
+ return isTrial;
|
|
|
+ }
|
|
|
+
|
|
|
public LiveData<List<Uri>> getDeleteUriListSdk11() {
|
|
|
return deleteUriListSdk11;
|
|
|
}
|
|
|
@@ -122,7 +137,7 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
return showLoadingEvent;
|
|
|
}
|
|
|
|
|
|
- public LiveData<ImageDeepDetector.ImageFile> getPreviewEvent() {
|
|
|
+ public LiveData<Pair<List<ImageDeepDetector.ImageFile>, Integer>> getPreviewEvent() {
|
|
|
return previewEvent;
|
|
|
}
|
|
|
|
|
|
@@ -244,7 +259,7 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
return;
|
|
|
}
|
|
|
ImageDeepDetector.detect(ContextUtil.getContext())
|
|
|
- .take(SCANNING_COUNTDOWN, TimeUnit.MILLISECONDS)
|
|
|
+ .take(isTrial ? SCANNING_IS_TRIAL_COUNTDOWN : SCANNING_COUNTDOWN, TimeUnit.MILLISECONDS)
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(new FlowableSubscriber<List<ImageDeepDetector.ImageFile>>() {
|
|
|
@Override
|
|
|
@@ -276,6 +291,7 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
} else {
|
|
|
liveData = detectedOtherImg;
|
|
|
}
|
|
|
+ detectedLastFileName.setValue(imageFile.getName());
|
|
|
List<ImageDeepDetector.ImageFile> list = getList(liveData);
|
|
|
list.add(0, imageFile);
|
|
|
liveData.setValue(list);
|
|
|
@@ -289,18 +305,46 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
|
|
|
@Override
|
|
|
public void onComplete() {
|
|
|
+ setFreeExport();
|
|
|
detectedFinish.call();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void setFreeExport() {
|
|
|
+ if (isTrial) {
|
|
|
+ showTrialView.setValue(true);
|
|
|
+ List<ImageDeepDetector.ImageFile> photoList = getList(detectedPhotoImg);
|
|
|
+ if (photoList.size() != 0) {
|
|
|
+ photoList.get(0).setTrial(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ImageDeepDetector.ImageFile> wxList = getList(detectedWxImg);
|
|
|
+ if (wxList.size() != 0) {
|
|
|
+ wxList.get(0).setTrial(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ImageDeepDetector.ImageFile> qqList = getList(detectedQQImg);
|
|
|
+ if (qqList.size() != 0) {
|
|
|
+ qqList.get(0).setTrial(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ImageDeepDetector.ImageFile> otherList = getList(detectedOtherImg);
|
|
|
+ if (otherList.size() != 0) {
|
|
|
+ otherList.get(0).setTrial(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void cancelScan() {
|
|
|
if (scanDisposable != null) scanDisposable.dispose();
|
|
|
+ setFreeExport();
|
|
|
}
|
|
|
|
|
|
public void setItemCheck(@NonNull ImageDeepDetector.ImageFile imageFile) {
|
|
|
- imageFile.setCheck(!imageFile.isCheck());
|
|
|
List<ImageDeepDetector.ImageFile> list = getList(this.selectedList);
|
|
|
+ imageFile.setCheck(!imageFile.isCheck());
|
|
|
if (imageFile.isCheck()) {
|
|
|
list.add(imageFile);
|
|
|
} else {
|
|
|
@@ -310,6 +354,10 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
}
|
|
|
|
|
|
public void checkPreview(@NonNull ImageDeepDetector.ImageFile imageFile) {
|
|
|
+ if (isTrial) {
|
|
|
+ sendPreviewEvent(imageFile);
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (Objects.equals(type, MemberType.APP_IMAGE_CLEAN)) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -318,7 +366,13 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
} else if (Objects.equals(type, MemberType.APP_IMAGE_CLEAN) && !deviceFuncRepository.isHaveAuth(type)) {
|
|
|
return;
|
|
|
}
|
|
|
- previewEvent.setValue(imageFile);
|
|
|
+ sendPreviewEvent(imageFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendPreviewEvent(@NonNull ImageDeepDetector.ImageFile imageFile) {
|
|
|
+ List<ImageDeepDetector.ImageFile> allDetectedList = getAllDetectedList();
|
|
|
+ int position = getPosition(allDetectedList, imageFile);
|
|
|
+ previewEvent.setValue(new Pair<>(allDetectedList, position));
|
|
|
}
|
|
|
|
|
|
public void onOperationClick() {
|
|
|
@@ -469,10 +523,19 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
if (list.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
- if (Objects.equals(type, MemberType.APP_IMAGE_RECOVER) && !deviceFuncRepository.isHaveAuth(type)) {
|
|
|
- return;
|
|
|
- } else if (Objects.equals(type, MemberType.APP_IMAGE_CLEAN) && !deviceFuncRepository.isHaveAuth(type)) {
|
|
|
- return;
|
|
|
+ if (isTrial) {
|
|
|
+ for (ImageDeepDetector.ImageFile imageFile : list) {
|
|
|
+ if (!imageFile.isTrial()) {
|
|
|
+ showTrialExportFailDialog.call();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (Objects.equals(type, MemberType.APP_IMAGE_RECOVER) && !deviceFuncRepository.isHaveAuth(type)) {
|
|
|
+ return;
|
|
|
+ } else if (Objects.equals(type, MemberType.APP_IMAGE_CLEAN) && !deviceFuncRepository.isHaveAuth(type)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
showLoadingEvent.setValue(true);
|
|
|
RxJavaUtil.doInBackground(() -> {
|
|
|
@@ -556,4 +619,12 @@ public class ImageRecoverViewModel extends BaseViewModel {
|
|
|
dealMediaObserver.onSuccess(isDelete);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void setIsTrial(boolean isTrial) {
|
|
|
+ this.isTrial = isTrial;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onTrialRecoverClick() {
|
|
|
+ MemberActivity.start(ActivityUtil.getTopActivity(), type);
|
|
|
+ }
|
|
|
}
|