From 61c1c53696492479a17a90616af440d7edbcf2b8 Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Tue, 28 Mar 2023 10:57:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E7=85=A7=E7=89=87=E6=8D=9F=E5=9D=8F?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=94=B9=E7=BA=BF?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=85=A7=E7=89=87=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=97=B6=E9=98=BB=E6=AD=A2=E7=94=A8=E6=88=B7=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/AutoTakePictureActivity.java | 167 ++++++++++-------- .../navinfo/outdoor/http/HttpInterface.java | 4 +- .../navinfo/outdoor/util/PoiSaveUtils.java | 8 +- 3 files changed, 95 insertions(+), 84 deletions(-) diff --git a/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java index 1ba09f6..5cd2b34 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java @@ -174,6 +174,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import io.reactivex.BackpressureStrategy; +import io.reactivex.Emitter; import io.reactivex.Flowable; import io.reactivex.FlowableEmitter; import io.reactivex.FlowableOnSubscribe; @@ -241,6 +242,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic private Logger logger; private ImageView imgLocationType; private PicturesSpeedCheck speedCheck; + // 任务结束对应的控制对象 + private Disposable finishDisposable; + private Emitter finishEmitter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -638,6 +642,82 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic // 清空缓存数据 spf.edit().remove("match-data"); spf.edit().commit(); + + // 启动数据完成的Rx流,当有数据需要完成时,会在捕捉流程中由上游发送数据 + finishDisposable = Observable.create(new ObservableOnSubscribe() { + @Override + public void subscribe(ObservableEmitter emitter) throws Exception { + finishEmitter =emitter; + } + }) + .subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()) + .filter(roadMatchEntity -> roadMatchEntity!=null) + .map(roadMatchEntity -> { + // 判断是否已领取,未领取则调用领取数据接口 + PoiEntity poiEntity = poiDao.getTaskIdPoiEntity(roadMatchEntity.getId()); + if (poiEntity == null) { + // 数据库中不存在,尝试再次领取 + InsertAndUpdateUtils.getInstance().insertOrUpdate(AutoTakePictureActivity.this, translateRoadMatchEntity(roadMatchEntity)); + // 调用网络领取任务 + receiverRoadTask(roadMatchEntity).subscribe(receiveObserver); + } + + List recorderList = recorderDao.getLocationRecorderByTime(roadMatchEntity.getStartMatchTime(), roadMatchEntity.getEndMathchTime()); + File recorderFolder = new File(Constant.PICTURE_FOLDER+"/"+poiEntity.getId()); + if (!recorderFolder.exists()) { + recorderFolder.mkdirs(); + } + // 编辑paper.txt + // 复制图片文件 + File paperFile = new File(recorderFolder.getAbsolutePath(), "paper.txt"); + for (int i = 0; i < recorderList.size(); i++) { + File originImg = new File(recorderList.get(i).getImgFileName()); + File destFile = new File(recorderFolder.getAbsolutePath()+"/"+i+".jpg"); + if (!destFile.exists()) { + FileUtils.copyFile(originImg.getAbsolutePath(), destFile.getAbsolutePath()); + } + FileUtils.writeFile(paperFile.getAbsolutePath(), recorderList.get(i).toString(picFormatter ,i), true); + } + + return poiEntity; + }) + .doOnNext(poiEntity -> { + // 网络提交数据 + if (poiEntity!=null) { + // 提交数据,更新状态 + roadSaveWork(poiEntity); + } + }) + .observeOn(AndroidSchedulers.mainThread()) + .onErrorResumeNext(Observable.empty()) + .subscribe(new Consumer() { + @Override + public void accept(PoiEntity poiEntity) { + // 重新绘制网络任务和本地任务 + initRoadLine2Map(); + finishTaskCount--; + if (finishTaskCount == 0&&wantBack) { + showExitDialog(false); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) { + // 此处异常可能是服务返回的数据无法解析,但http正常返回了,因此可能为程序问题,不再重复尝试上报 + systemTTS.playText("注意,领取任务失败!"); + XLog.e("完成失败:"+throwable.getMessage()); + ToastUtils.Message(AutoTakePictureActivity.this, throwable.getMessage()); + finishTaskCount--; + if (finishTaskCount == 0&&wantBack) { + showExitDialog(true); + } + } + }, new Action() { + @Override + public void run() throws Exception { + + } + }); } /** @@ -1333,84 +1413,12 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic private boolean wantBack = false; // 用户是否想要退出当前界面,如果当前有正在处理的图片转移任务,会阻挡用户退出,此时该值状态置为true,当照片处理完后,可以对话框提示用户退出 private void finishRoadTask(Map finishEntityMap) { if (finishEntityMap!=null&&!finishEntityMap.isEmpty()) { - finishTaskCount++; - - Observable.fromIterable(finishEntityMap.values()) - .subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()) - .filter(roadMatchEntity -> roadMatchEntity!=null) - .map(roadMatchEntity -> { - // 判断是否已领取,未领取则调用领取数据接口 - PoiEntity poiEntity = poiDao.getTaskIdPoiEntity(roadMatchEntity.getId()); - if (poiEntity == null) { - // 数据库中不存在,尝试再次领取 - InsertAndUpdateUtils.getInstance().insertOrUpdate(AutoTakePictureActivity.this, translateRoadMatchEntity(roadMatchEntity)); - // 调用网络领取任务 - receiverRoadTask(roadMatchEntity).subscribe(receiveObserver); - } - - List recorderList = recorderDao.getLocationRecorderByTime(roadMatchEntity.getStartMatchTime(), roadMatchEntity.getEndMathchTime()); - File recorderFolder = new File(Constant.PICTURE_FOLDER+"/"+poiEntity.getId()); - if (!recorderFolder.exists()) { - recorderFolder.mkdirs(); - } - // 编辑paper.txt - // 复制图片文件 - File paperFile = new File(recorderFolder.getAbsolutePath(), "paper.txt"); - for (int i = 0; i < recorderList.size(); i++) { - File originImg = new File(recorderList.get(i).getImgFileName()); - File destFile = new File(recorderFolder.getAbsolutePath()+"/"+i+".jpg"); - if (!destFile.exists()) { - FileUtils.copyFile(originImg.getAbsolutePath(), destFile.getAbsolutePath()); - } - FileUtils.writeFile(paperFile.getAbsolutePath(), recorderList.get(i).toString(picFormatter ,i), true); - } - - return poiEntity; - }) - .doOnNext(poiEntity -> { - // 网络提交数据 - if (poiEntity!=null) { - // 提交数据,更新状态 - roadSaveWork(poiEntity); - /*poiEntity.setTaskStatus(3); - InsertAndUpdateUtils.getInstance().insertOrUpdate(AutoTakePictureActivity.this, poiEntity);*/ - finishEntityMap.remove(poiEntity.getTaskId()); - } - }) - .observeOn(AndroidSchedulers.mainThread()) - .onErrorResumeNext(Observable.empty()) - .subscribe(new Consumer() { - @Override - public void accept(PoiEntity poiEntity) { -// // 已经处理过该任务,将其从finish列表中移除 -// if (poiEntity!=null) { -// finishEntityMap.remove(poiEntity.getTaskId()); -// } - - } - }, new Consumer() { - @Override - public void accept(Throwable throwable) { - // 此处异常可能是服务返回的数据无法解析,但http正常返回了,因此可能为程序问题,不再重复尝试上报 - systemTTS.playText("注意,领取任务失败!"); - XLog.e("完成失败:"+throwable.getMessage()); - ToastUtils.Message(AutoTakePictureActivity.this, throwable.getMessage()); - finishTaskCount--; - if (finishTaskCount == 0) { - showExitDialog(true); - } - } - }, new Action() { - @Override - public void run() throws Exception { - // 重新绘制网络任务和本地任务 - initRoadLine2Map(); - finishTaskCount--; - if (finishTaskCount == 0) { - showExitDialog(false); - } - } - }); + for (Map.Entry entry: finishEntityMap.entrySet()) { + if (finishEmitter!=null) { + finishTaskCount++; + finishEmitter.onNext(entry.getValue()); + } + } } } @@ -1741,6 +1749,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic // 退出后切换主定位模式为腾讯定位 LocationLifeCycle.getInstance().setMainLocationFrom(LocationLifeCycle.LOCATION_FROM.TENCENT); LocationLifeCycle.getInstance().stopGPSLocation(); + if (finishDisposable!=null&&!finishDisposable.isDisposed()) { + finishDisposable.dispose(); + } } @Override diff --git a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java index e9a998b..3862823 100644 --- a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java +++ b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java @@ -2,9 +2,9 @@ package com.navinfo.outdoor.http; public class HttpInterface { // public static final String IP = "http://172.23.138.133:9999/m4";//测试接口-IP - public static final String IP0 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网 + public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网 public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网 - public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口 + public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口 public static final String USER_PATH = "/user/";//我的 public static final String MSG_LIST_PATH = "/msgList/";//发现 public static final String USER_LOGIN_PATH = "/userlogin/";//登录 diff --git a/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java b/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java index 42bc32e..9fd3555 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java +++ b/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java @@ -174,7 +174,7 @@ public class PoiSaveUtils { @Override public ObservableSource apply(PoiEntity poiEntity) throws Exception { List photoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); - if (photoFileList == null||photoFileList.isEmpty()) { + if (photoFileList == null||photoFileList.size()<2/*如果文件压缩包内小于2个文件,说明拍摄的照片丢失了*/) { bInt++; return Observable.empty(); } @@ -431,7 +431,7 @@ public class PoiSaveUtils { initList(HttpInterface.C_TASK_UP_LOAD_PIC, photoFile, poiEntity); } else if (poiEntity.getType() == 3) { List videoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); - if (videoFileList != null && !videoFileList.isEmpty()) { + if (videoFileList != null && videoFileList.size()<2) { boolean existsPic = PoiSaveUtils.getInstance(mContext).checkPicExists(videoFileList); if (!existsPic) { bInt++; @@ -475,7 +475,7 @@ public class PoiSaveUtils { // } } else if (poiEntity.getType() == 4) { List videoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); - if (videoFileList != null && !videoFileList.isEmpty()) { + if (videoFileList != null && videoFileList.size()<2) { boolean existsPic = PoiSaveUtils.getInstance(mContext).checkPicExists(videoFileList); if (!existsPic) { bInt++; @@ -762,7 +762,7 @@ public class PoiSaveUtils { public boolean checkPicExists(List fileList) { boolean isExistsPic = false; // 是否记录的照片全部不存在 for (File picFile: fileList) { - if (picFile!=null&&picFile.exists()) { + if (picFile!=null&&picFile.exists()&&!picFile.getName().endsWith(".txt")/*至少包含1张照片*/) { isExistsPic = true; break; }