|
|
@@ -30,6 +30,7 @@ import io.reactivex.Observable;
|
|
|
import io.reactivex.ObservableEmitter;
|
|
|
import io.reactivex.ObservableOnSubscribe;
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.annotations.NonNull;
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
import top.zibin.luban.Luban;
|
|
|
|
|
|
@@ -275,21 +276,25 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
.ignoreBy(400)
|
|
|
.setTargetDir(file.getParentFile().getAbsolutePath())
|
|
|
.get();
|
|
|
- File compressedFile = fileList.get(0);
|
|
|
+ if (fileList != null && fileList.size() == 1) {
|
|
|
+ File compressedFile = fileList.get(0);
|
|
|
|
|
|
- if (!TextUtils.equals(compressedFile.getAbsolutePath(), file.getAbsolutePath())) {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
+ if (!TextUtils.equals(compressedFile.getAbsolutePath(), file.getAbsolutePath())) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
|
|
|
- // 通知相册去获取
|
|
|
- MediaScannerConnection.scanFile(context, new String[] { compressedFile.getAbsolutePath() }, new String[] { "image/jpeg" }, null);
|
|
|
- // 保存最终截图成功
|
|
|
- // 根据URI获取图片的base64字符串
|
|
|
- String photoBase64 = Base64Tool.getBase64FromFilePath(compressedFile.getAbsolutePath());
|
|
|
- if (TextUtils.isEmpty(photoBase64)) {
|
|
|
- emitter.onError(new Exception("Empty image"));
|
|
|
+ // 通知相册去获取
|
|
|
+ MediaScannerConnection.scanFile(context, new String[] { compressedFile.getAbsolutePath() }, new String[] { "image/jpeg" }, null);
|
|
|
+ // 保存最终截图成功
|
|
|
+ // 根据URI获取图片的base64字符串
|
|
|
+ String photoBase64 = Base64Tool.getBase64FromFilePath(compressedFile.getAbsolutePath());
|
|
|
+ if (TextUtils.isEmpty(photoBase64)) {
|
|
|
+ emitter.onError(new Exception("Empty image"));
|
|
|
+ } else {
|
|
|
+ emitter.onNext(photoBase64);
|
|
|
+ }
|
|
|
} else {
|
|
|
- emitter.onNext(photoBase64);
|
|
|
+ emitter.onNext("Empty image");
|
|
|
}
|
|
|
} else {
|
|
|
emitter.onError(new Exception("Empty image"));
|
|
|
@@ -399,7 +404,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
.load(file)
|
|
|
.ignoreBy(400)
|
|
|
.setTargetDir(file.getParentFile().getAbsolutePath()).get();
|
|
|
- if (fileList.size() == 1) {
|
|
|
+ if (fileList != null && fileList.size() == 1) {
|
|
|
File compressedFile = fileList.get(0);
|
|
|
// 通知相册去获取
|
|
|
MediaScannerConnection.scanFile(context, new String[] { compressedFile.getAbsolutePath() }, new String[] { "image/jpeg" }, null);
|
|
|
@@ -455,6 +460,11 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
|
|
|
getView().onOcrResult(null);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(@NonNull Throwable e) {
|
|
|
+ super.onError(e);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|