From 71ac5ea208fb15da401b980fe788d03ed0f086b1 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 04 十二月 2024 09:56:14 +0800
Subject: [PATCH] 1.添加退出登录时判断是否开启巡检,开启巡检不可退出登录。 2.添加异常退出后恢复巡检记录的功能。 3.添加统一的提示Dialog
---
app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java | 78 +++++++++++++++++++++++++++++++++++---
1 files changed, 71 insertions(+), 7 deletions(-)
diff --git a/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java b/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java
index eb3a256..b14376b 100644
--- a/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java
+++ b/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java
@@ -4,10 +4,14 @@
import android.location.Location;
import android.util.Log;
+import androidx.room.Transaction;
+
+import com.dayu.pipirrapp.MyApplication;
import com.dayu.pipirrapp.bean.db.InspectionBean;
import com.dayu.pipirrapp.bean.db.InspectionLocationBean;
import com.dayu.pipirrapp.bean.db.LatLonBean;
import com.dayu.pipirrapp.dao.DaoSingleton;
+import com.dayu.pipirrapp.fragment.MapFragment;
import com.dayu.pipirrapp.utils.DateUtils;
import java.util.UUID;
@@ -26,17 +30,42 @@
private static final String TAG = "InspectionUtils";
//鎵撶偣鐨勬渶灏忎袱鐐规渶灏忚窛绂�
private static final int MinMeters = 10;
+ //0娌℃湁寮�濮嬶紝1寮�濮嬶紝2鏆傚仠,3鍏抽棴,4鏄偣鍑荤殑寮�濮嬫寜閽�
+ public static final int NO_INSPECTION = 0;
+ public static final int STAT_INSPECTION = 1;
+ public static final int STAT_INSPECTION_ONCLICK = 4;
+ public static final int PAUSE_INSPECTION = 2;
+ public static final int STOP_INSPECTION = 3;
+
/**
* 鑾峰彇褰撳墠宸℃璁板綍ID
*
- * @param context
+ * @param fragment
* @return
*/
- public static String getInspectionId(Context context) {
+ public static String getInspectionId(MapFragment fragment) {
+ DaoSingleton.getAsynchInstance(fragment.getContext()).inspectionDao().getMostRecentInspectionWithNoStopTime()
+ .subscribeOn(Schedulers.io())
+ .observeOn(Schedulers.io()).subscribe(inspectionBean -> {
-
+ });
return "";
+ }
+
+
+ public static void aginShowLocation(MapFragment fragment) {
+ //鏌ヨ褰撳墠鏈叧闂殑宸℃璁板綍
+ DaoSingleton.getAsynchInstance(fragment.getContext()).inspectionDao().getMostRecentInspectionWithNoStopTime()
+ .subscribeOn(Schedulers.io())
+ .observeOn(Schedulers.io()).subscribe(inspectionBean -> {
+ fragment.mInspectionBean = inspectionBean;
+ // 鏌ヨ褰撳墠鏈叧闂殑宸℃璁板綍涓嬫墍鏈夌殑鍧愭爣
+ DaoSingleton.getAsynchInstance(fragment.getContext()).inspectionLocationDao().findByInspectId(inspectionBean.getmInspectId()).subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread()).subscribe(inspectionLocationBeans -> {
+ fragment.aginShowLocation(inspectionLocationBeans);
+ });
+ });
}
@@ -49,8 +78,9 @@
public static InspectionBean startInspection(Context context) {
// 鍒涘缓宸℃璁板綍
InspectionBean inspectionBean = new InspectionBean();
- inspectionBean.setInspectId(UUID.randomUUID().toString());
+ inspectionBean.setmInspectId(UUID.randomUUID().toString());
inspectionBean.setStartTime(DateUtils.getNowDateStr());
+// inspectionBean.
// 寮傛鎻掑叆鍒版暟鎹簱
DaoSingleton.getAsynchInstance(context)
.inspectionDao()
@@ -60,7 +90,7 @@
.subscribe(() -> {
Log.i(TAG, "Inspection started and inserted successfully.");
}, throwable -> {
- Log.e(TAG, "Error inserting inspection data: ", throwable);
+ Log.e(TAG, "Error inserting inspection data: "+throwable);
});
// 鑾峰彇Dao骞舵墽琛屾彃鍏ユ搷浣�
return inspectionBean; // 鎻掑叆瀹屾垚鍚庡垏鎹㈠埌涓荤嚎绋�
@@ -74,7 +104,15 @@
* @param locationBean
*/
public static void addInspectionLocationData(Context context, InspectionLocationBean locationBean) {
- DaoSingleton.getAsynchInstance(context).inspectionLocationDao().insert(locationBean).subscribeOn(Schedulers.io());
+ DaoSingleton.getAsynchInstance(context).inspectionLocationDao().insert(locationBean).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
+ .subscribe(() -> {
+ // 鎻掑叆鎴愬姛鐨勫洖璋�
+ Log.d(TAG, "addInspectionLocationData鏁版嵁鎻掑叆鎴愬姛");
+ }, throwable -> {
+ // 澶勭悊閿欒
+ Log.e(TAG, "addInspectionLocationData鏁版嵁鎻掑叆澶辫触", throwable);
+ });
+ ;
}
/**
@@ -83,8 +121,17 @@
* @param context
* @param locationBean
*/
+ @Transaction
public static void updateInspectionLocationData(Context context, InspectionLocationBean locationBean) {
- DaoSingleton.getAsynchInstance(context).inspectionLocationDao().update(locationBean).subscribeOn(Schedulers.io());
+ DaoSingleton.getAsynchInstance(context).inspectionLocationDao().update(locationBean).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
+ .subscribe(() -> {
+ // 鎻掑叆鎴愬姛鐨勫洖璋�
+ Log.d(TAG, "updateInspectionLocationData鏁版嵁鎻掑叆鎴愬姛");
+ }, throwable -> {
+ // 澶勭悊閿欒
+ Log.e(TAG, "updateInspectionLocationData鏁版嵁鎻掑叆澶辫触", throwable);
+ });
+ ;
}
/**
@@ -109,4 +156,21 @@
}
}
+
+ /**
+ * 鍒涘缓InspectionLocationBean
+ */
+ public static InspectionLocationBean createInspectionLocation(LatLonBean latLonBean, InspectionBean mInspectionBean) {
+ InspectionLocationBean inspectionLocationBean = new InspectionLocationBean();
+ inspectionLocationBean.setId(UUID.randomUUID().toString());
+ inspectionLocationBean.setInspectId(mInspectionBean.getInspectId());
+ inspectionLocationBean.setmInspectId(mInspectionBean.getmInspectId());
+ inspectionLocationBean.setLocateTime(DateUtils.getNowDateStr());
+ inspectionLocationBean.setPost(false);
+ inspectionLocationBean.setInspectorId(MyApplication.myApplication.userId);
+ inspectionLocationBean.setLng(String.valueOf(latLonBean.getLongitude()));
+ inspectionLocationBean.setLat(String.valueOf(latLonBean.getLatitude()));
+ return inspectionLocationBean;
+ }
+
}
--
Gitblit v1.8.0