diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index f19ae75..9a2f1d1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -20,9 +22,13 @@ listModel.value = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ listModel.value = RetrofitServiceManager.obtainAllWell() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index f19ae75..9a2f1d1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -20,9 +22,13 @@ listModel.value = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ listModel.value = RetrofitServiceManager.obtainAllWell() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt index 0200c19..7a8e3a5 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellMonitorModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellMonitorViewModel : BaseViewModel() { + private val gson = Gson() val monitorModel = MutableLiveData() fun obtainMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading - monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainMonitorResult(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + monitorModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index f19ae75..9a2f1d1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -20,9 +22,13 @@ listModel.value = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ listModel.value = RetrofitServiceManager.obtainAllWell() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt index 0200c19..7a8e3a5 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellMonitorModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellMonitorViewModel : BaseViewModel() { + private val gson = Gson() val monitorModel = MutableLiveData() fun obtainMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading - monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainMonitorResult(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + monitorModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt index 62d5675..1a76400 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt @@ -1,21 +1,39 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellOperationViewModel : BaseViewModel() { - val operationResultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun obtainOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading - operationResultModel.value = RetrofitServiceManager.obtainOperationResult(id, state) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainOperationResult(id, state) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "操作成功".show(BaseApplication.obtainInstance()) + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index f19ae75..9a2f1d1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -20,9 +22,13 @@ listModel.value = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ listModel.value = RetrofitServiceManager.obtainAllWell() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt index 0200c19..7a8e3a5 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellMonitorModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellMonitorViewModel : BaseViewModel() { + private val gson = Gson() val monitorModel = MutableLiveData() fun obtainMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading - monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainMonitorResult(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + monitorModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt index 62d5675..1a76400 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt @@ -1,21 +1,39 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellOperationViewModel : BaseViewModel() { - val operationResultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun obtainOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading - operationResultModel.value = RetrofitServiceManager.obtainOperationResult(id, state) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainOperationResult(id, state) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "操作成功".show(BaseApplication.obtainInstance()) + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt index 494e5b5..e9da747 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainWellType() = launch({ wellTypeModel.value = RetrofitServiceManager.obtainWellType() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index f19ae75..9a2f1d1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -20,9 +22,13 @@ listModel.value = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ listModel.value = RetrofitServiceManager.obtainAllWell() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt index 0200c19..7a8e3a5 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellMonitorModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellMonitorViewModel : BaseViewModel() { + private val gson = Gson() val monitorModel = MutableLiveData() fun obtainMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading - monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainMonitorResult(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + monitorModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt index 62d5675..1a76400 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt @@ -1,21 +1,39 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellOperationViewModel : BaseViewModel() { - val operationResultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun obtainOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading - operationResultModel.value = RetrofitServiceManager.obtainOperationResult(id, state) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainOperationResult(id, state) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "操作成功".show(BaseApplication.obtainInstance()) + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt index 494e5b5..e9da747 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainWellType() = launch({ wellTypeModel.value = RetrofitServiceManager.obtainWellType() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt index 4363ef9..b17ecad 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WorkOrderDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WorkOrderDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWorkOrderDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWorkOrderDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index f19ae75..9a2f1d1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -20,9 +22,13 @@ listModel.value = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ listModel.value = RetrofitServiceManager.obtainAllWell() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt index 0200c19..7a8e3a5 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellMonitorModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellMonitorViewModel : BaseViewModel() { + private val gson = Gson() val monitorModel = MutableLiveData() fun obtainMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading - monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainMonitorResult(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + monitorModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt index 62d5675..1a76400 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt @@ -1,21 +1,39 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellOperationViewModel : BaseViewModel() { - val operationResultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun obtainOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading - operationResultModel.value = RetrofitServiceManager.obtainOperationResult(id, state) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainOperationResult(id, state) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "操作成功".show(BaseApplication.obtainInstance()) + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt index 494e5b5..e9da747 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainWellType() = launch({ wellTypeModel.value = RetrofitServiceManager.obtainWellType() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt index 4363ef9..b17ecad 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WorkOrderDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WorkOrderDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWorkOrderDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWorkOrderDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt index 2d8cbb6..cb56baa 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WorkOrderListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainWorkOrderListByState(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainWorkOrderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 2cdd63d..4d4178a 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,9 +6,13 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.qmuiteam.qmui.util.QMUIDisplayHelper +import org.json.JSONObject /** * String扩展方法 @@ -68,4 +72,18 @@ "未知" } } +} + +fun String.separateResponseCode(): Int { + if (this.isBlank()) { + return 404 + } + return JSONObject(this).getInt("code") +} + +fun String.toErrorMessage(): String { + val errorModel = Gson().fromJson( + this, object : TypeToken() {}.type + ) + return errorModel.message.toString() } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt new file mode 100644 index 0000000..0b56128 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.kt @@ -0,0 +1,9 @@ +package com.casic.app.smartwell.model + +class ErrorMessageModel { + var code = 0 + var data: String? = null + var exceptionClazz: String? = null + var message: String? = null + var isSuccess = false +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt b/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt deleted file mode 100644 index 6be8813..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/NoPermissionModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.casic.app.smartwell.model - -class NoPermissionModel { - var code = 0 - var message: String? = null - var isSuccess = false -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt index 405486c..ac0f9d4 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/model/VersionResultModel.kt @@ -1,12 +1,23 @@ package com.casic.app.smartwell.model -/** - * TODO 有效返回值格式不确定,数据模型暂时按如下定义 - * */ class VersionResultModel { + /** + * code : 200 + * data : {"downloadUrl":"app/v1.1.0.0.apk","version":"v1.1.0.0"} + * message : 请求成功 + * success : true + */ var code = 0 - var data: String? = null - var exceptionClazz: String? = null + var data: DataBean? = null var message: String? = null var isSuccess = false + + class DataBean { + /** + * downloadUrl : app/v1.1.0.0.apk + * version : v1.1.0.0 + */ + var downloadUrl: String? = null + var version: String? = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 92bbcb6..66135e5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -83,7 +83,7 @@ suspend fun obtainWellDetail( @Header("token") token: String, @Query("id") id: String - ): WellDetailModel + ): String /** * 获取井下监控设备列表 @@ -94,7 +94,7 @@ suspend fun obtainMonitorResult( @Header("token") token: String, @Query("id") id: String - ): WellMonitorModel + ): String /** * 闸井布防撤防 @@ -108,7 +108,7 @@ @Header("token") token: String, @Field("wellId") wellId: String, @Field("bfzt") bfzt: String - ): CommonResultModel + ): String /** * 根据工单状态获取工单列表 @@ -134,7 +134,7 @@ suspend fun obtainWorkOrderDetail( @Header("token") token: String, @Query("id") id: String - ): WorkOrderDetailModel + ): String /** * 接单 @@ -146,7 +146,7 @@ suspend fun acceptWorkOrder( @Header("token") token: String, @Field("id") id: String - ): CommonResultModel + ): String /** * 上传图片 @@ -158,7 +158,7 @@ suspend fun uploadImage( @Header("token") token: String, @Part file: MultipartBody.Part - ): CommonResultModel + ): String /** * 查找同一单位下的用户 @@ -186,7 +186,7 @@ @Header("token") token: String, @Field("id") id: String, @Field("transferPerson") transferPerson: String - ): CommonResultModel + ): String /** * 确认工单 @@ -203,7 +203,7 @@ @Field("firstState") firstState: String, @Field("firstStatePhotos") firstStatePhotos: String, @Field("needHandle") needHandle: String - ): CommonResultModel + ): String /** * 完成工单 @@ -219,7 +219,7 @@ @Field("id") id: String, @Field("handleMessage") handleMessage: String, @Field("handlePhotos") handlePhotos: String - ): CommonResultModel + ): String /** * 告警内容列表 @@ -253,7 +253,7 @@ @Query("endTime") endTime: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): SearchResultModel + ): String /** * 获取超时工单列表 @@ -284,17 +284,17 @@ @Header("token") token: String, @Field("oldPwd") oldPwd: String, @Field("newPwd") newPwd: String - ): CommonResultModel + ): String /** * 退出登录 */ @GET("/user/logout") - suspend fun loginOut(@Header("token") token: String): CommonResultModel + suspend fun loginOut(@Header("token") token: String): String /** * 更新APK版本 */ @POST("/app/checkVersion") - suspend fun obtainVersionResult(@Header("token") token: String): VersionResultModel + suspend fun obtainVersionResult(@Header("token") token: String): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index c9368ef..f7317ff 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -76,21 +76,21 @@ /** * 获取闸井详情 */ - suspend fun obtainWellDetail(id: String): WellDetailModel { + suspend fun obtainWellDetail(id: String): String { return api.obtainWellDetail(AuthenticationHelper.token!!, id) } /** * 获取井下监控设备列表 */ - suspend fun obtainMonitorResult(id: String): WellMonitorModel { + suspend fun obtainMonitorResult(id: String): String { return api.obtainMonitorResult(AuthenticationHelper.token!!, id) } /** * 闸井布防撤防 */ - suspend fun obtainOperationResult(wellId: String, bfzt: String): CommonResultModel { + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) } @@ -109,21 +109,21 @@ /** * 获取工单详情 */ - suspend fun obtainWorkOrderDetail(id: String): WorkOrderDetailModel { + suspend fun obtainWorkOrderDetail(id: String): String { return api.obtainWorkOrderDetail(AuthenticationHelper.token!!, id) } /** * 接单 */ - suspend fun acceptWorkOrder(id: String): CommonResultModel { + suspend fun acceptWorkOrder(id: String): String { return api.acceptWorkOrder(AuthenticationHelper.token!!, id) } /** * 上传图片 */ - suspend fun uploadImage(image: File): CommonResultModel { + suspend fun uploadImage(image: File): String { val requestBody = RequestBody.create("image/png".toMediaTypeOrNull(), image) val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) @@ -139,7 +139,7 @@ /** * 转单 */ - suspend fun transferWorkOrder(id: String, userId: String): CommonResultModel { + suspend fun transferWorkOrder(id: String, userId: String): String { return api.transferWorkOrder(AuthenticationHelper.token!!, id, userId) } @@ -149,7 +149,7 @@ suspend fun confirmWorkOrder( id: String, firstState: String, firstStatePhotos: String, needHandle: String - ): CommonResultModel { + ): String { return api.confirmWorkOrder( AuthenticationHelper.token!!, id, firstState, firstStatePhotos, needHandle @@ -161,7 +161,7 @@ */ suspend fun completeWorkOrder( id: String, handleMessage: String, handlePhotos: String - ): CommonResultModel { + ): String { return api.completeWorkOrder( AuthenticationHelper.token!!, id, handleMessage, handlePhotos ) @@ -192,7 +192,7 @@ beginTime: String?, endTime: String?, page: Int - ): SearchResultModel { + ): String { return api.obtainSearchResult( AuthenticationHelper.token!!, keywords, @@ -228,21 +228,21 @@ /** * 修改密码 */ - suspend fun changePassword(oldPwd: String, newPwd: String): CommonResultModel { + suspend fun changePassword(oldPwd: String, newPwd: String): String { return api.changePassword(AuthenticationHelper.token!!, oldPwd, newPwd) } /** * 退出登录 */ - suspend fun loginOut(): CommonResultModel { + suspend fun loginOut(): String { return api.loginOut(AuthenticationHelper.token!!) } /** * 更新APK版本 */ - suspend fun updateVersion(): VersionResultModel { + suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt index efb590d..67102dd 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/ChangePasswordActivity.kt @@ -82,14 +82,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "修改成功,请重新登录".show(this) AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() } else -> { DialogHelper.dismissLoadingDialog() - "修改失败,请检查原密码".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt index 1235bc6..69931d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/DetermineDetailActivity.kt @@ -304,14 +304,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -324,7 +322,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单确认成功".show(this) //通知列表刷新数据 UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) if (needHandle == "0") { @@ -336,7 +333,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单确认失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt index 69529f3..0420f37 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/InHandleDetailActivity.kt @@ -341,14 +341,12 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "转单成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) this.finish() } else -> { DialogHelper.dismissLoadingDialog() - "转单失败".show(this) } } }) @@ -361,7 +359,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "工单处理成功".show(this) //通知列表刷新数据 InHandleOrderFragment.sendEmptyMessage(Constant.ORDER_IN_HANDLE) CompletedOrderFragment.sendEmptyMessage(Constant.ORDER_COMPLETED) @@ -369,7 +366,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "工单处理失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt index fda9277..8d0b912 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/SearchResultActivity.kt @@ -112,13 +112,11 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷行数据 weakReferenceHandler.sendEmptyMessage(2022040102) } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt index 828ae17..6fddcd8 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/TodoDetailActivity.kt @@ -158,7 +158,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(this) //通知列表刷新数据 TodoOrderFragment.sendEmptyMessage(Constant.ORDER_TODO_OK) UndeterminedOrderFragment.sendEmptyMessage(Constant.ORDER_DETERMINED_OK) @@ -166,7 +165,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt index 8a19ea8..8c8a72a 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/UserDetailActivity.kt @@ -5,7 +5,6 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.base.BaseActivity import com.casic.app.smartwell.extensions.navigatePageTo -import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant @@ -14,6 +13,7 @@ import com.casic.app.smartwell.vm.LoginOutViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.activity_user_detail.* import kotlinx.android.synthetic.main.fragment_mine.userNameView import kotlinx.android.synthetic.main.include_base_title.* @@ -54,15 +54,26 @@ loginOutButton.setChangeAlphaWhenPress(true) loginOutButton.setOnClickListener { - loginOutViewModel.loginOut() + AlertControlDialog.Builder() + .setContext(this) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + loginOutViewModel.loginOut() + } + + override fun onCancelClick() {} + }).build().show() } loginOutViewModel.resultModel.observe(this, { if (it.code == 200) { AuthenticationHelper.removeToken() this.navigatePageTo(LoginActivity::class.java) PageNavigationManager.finishAllActivity() - } else { - it.message!!.show(this) } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt index 0a4b8ad..9876f1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellOperationActivity.kt @@ -115,7 +115,7 @@ }) //撤防布防状态监听 - operationViewModel.operationResultModel.observe(this, { + operationViewModel.resultModel.observe(this, { if (it.code == 200) { val rowsBean = dataBeans[clickedPosition] if (rowsBean.bfztName == "布防") { @@ -134,12 +134,10 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "操作成功".show(this) wellOperationAdapter.notifyItemChanged(clickedPosition) } else -> { DialogHelper.dismissLoadingDialog() - "操作失败".show(this) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt index 1df65f2..f048749 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/MinePageFragment.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.view.fragment -import android.util.Log import androidx.lifecycle.ViewModelProvider +import com.casic.app.smartwell.BuildConfig import com.casic.app.smartwell.R import com.casic.app.smartwell.extensions.navigatePageTo import com.casic.app.smartwell.extensions.show @@ -56,7 +56,9 @@ updateVersionViewModel.updateVersion() } updateVersionViewModel.resultModel.observe(this, { - if (it.code == 200) { + if (BuildConfig.VERSION_NAME == it.version) { + "已是最新版本,无需更新".show(requireContext()) + } else { AlertControlDialog.Builder() .setContext(requireContext()) .setTitle("提示") @@ -66,15 +68,13 @@ .setOnDialogButtonClickListener(object : AlertControlDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - Log.d(kTag, "新版本APK下载地址: ${it.data}") + downloadApk(it.downloadUrl) } override fun onCancelClick() { } }).build().show() - } else { - it.message!!.show(requireContext()) } }) updateVersionViewModel.loadState.observe(this, { @@ -92,4 +92,11 @@ requireContext().navigatePageTo(AboutUsActivity::class.java) } } + + private fun downloadApk(url: String?) { + if (url.toString().isBlank()) { + "抱歉,版本下载失败".show(requireContext()) + return + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt index 3166bd0..3ef3869 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/TodoOrderFragment.kt @@ -89,7 +89,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -99,7 +98,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt index b7929b5..3cb4c52 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/fragment/UnacceptedOrderFragment.kt @@ -80,7 +80,6 @@ } is LoadState.Success -> { DialogHelper.dismissLoadingDialog() - "接单成功".show(requireContext()) //接单成功之后刷新数据 isRefresh = true pageIndex = 1 @@ -90,7 +89,6 @@ } else -> { DialogHelper.dismissLoadingDialog() - "接单失败".show(requireContext()) } } }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt index 8da8883..b958522 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AcceptOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.acceptWorkOrder(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.acceptWorkOrder(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "接单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index 3810257..b64edb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainAlarmContentType(alarmType: String) = launch({ listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index b7c87a1..8c42541 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -14,5 +16,7 @@ fun obtainPublicKey() = launch({ loadState.value = LoadState.Loading keyModel.value = RetrofitServiceManager.authenticate() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt index 87ca52b..486d958 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ChangePasswordViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.changePassword(oldPwd, newPwd) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "修改成功,请重新登录".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt index 6de21ce..ba30614 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/CompleteOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单处理成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt index 2530455..8858d26 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/ConfirmOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,9 +16,18 @@ firstStatePhotos: String, needHandle: String ) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - loadState.value = LoadState.Success + val response = + RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "工单确认成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt index cc0b898..144447f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginInViewModel.kt @@ -1,8 +1,12 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,18 +19,19 @@ val resultModel = MutableLiveData() fun login(account: String, secretKey: String) = launch({ - val resultJson = RetrofitServiceManager.login(account, secretKey) - val loginResultModel = gson.fromJson( - resultJson, - object : TypeToken() {}.type - ) - if (loginResultModel == null) { - loadState.value = LoadState.Fail - } else { - resultModel.value = loginResultModel + val response = RetrofitServiceManager.login(account, secretKey) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt index 312d224..6e43adc 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginOutViewModel.kt @@ -1,16 +1,33 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class LoginOutViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun loginOut() = launch({ - resultModel.value = RetrofitServiceManager.loginOut() + val response = RetrofitServiceManager.loginOut() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index 03fff89..b9c5eb1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOrderStatus() = launch({ listModel.value = RetrofitServiceManager.obtainOrderStatus() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index a78cf59..5a24195 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt index ee0149f..5043c3b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SearchOrderViewModel.kt @@ -1,14 +1,21 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SearchResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SearchOrderViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSearchResult( @@ -21,11 +28,21 @@ page: Int ) = launch({ loadState.value = LoadState.Loading - listModel.value = RetrofitServiceManager.obtainSearchResult( + val response = RetrofitServiceManager.obtainSearchResult( keywords, alarmContent, alarmLevel, jobStatus, beginTime, endTime, page ) - loadState.value = LoadState.Success + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index 18aff97..bcec54b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -15,5 +17,7 @@ fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt index 052c560..35146bf 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/TransferOrderViewModel.kt @@ -1,7 +1,11 @@ package com.casic.app.smartwell.vm +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -9,9 +13,17 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading - RetrofitServiceManager.transferWorkOrder(id, userId) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.transferWorkOrder(id, userId) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "转单成功".show(BaseApplication.obtainInstance()) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt index ea4077d..8c6414d 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UpdateVersionViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.VersionResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class UpdateVersionViewModel : BaseViewModel() { - val resultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun updateVersion() = launch({ loadState.value = LoadState.Loading - resultModel.value = RetrofitServiceManager.updateVersion() - loadState.value = LoadState.Success + val response = RetrofitServiceManager.updateVersion() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ).data + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index acf7576..7f245b9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,20 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import java.io.File class UploadImageViewModel : BaseViewModel() { + + private val gson = Gson() val resultModel = MutableLiveData() fun uploadImage(image: File) = launch({ - resultModel.value = RetrofitServiceManager.uploadImage(image) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.uploadImage(image) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt index 49a8fde..80e8535 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserDetailViewModel.kt @@ -1,8 +1,11 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.utils.Constant import com.casic.app.smartwell.utils.SaveKeyValues @@ -18,18 +21,20 @@ val flag = MutableLiveData() fun obtainUserDetail() = launch({ - val detailJson = RetrofitServiceManager.obtainUserDetail() - val data = gson.fromJson( - detailJson, - object : TypeToken() {}.type - ).data - if (data == null) { + val response = RetrofitServiceManager.obtainUserDetail() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val userData = gson.fromJson( + response, object : TypeToken() {}.type + ).data + SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(userData)) + flag.value = true + } else { //如果此次获取不到用户信息,那么就清空之前的用户缓存,然后让用户重新登录 SaveKeyValues.removeKey(Constant.USER_DETAIL_MODEL) flag.value = false - } else { - SaveKeyValues.putValue(Constant.USER_DETAIL_MODEL, gson.toJson(data)) - flag.value = true } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index c3b6b03..498db8b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,18 +16,21 @@ val resultModel = MutableLiveData>() fun countWellByState() = launch({ - val resultJson = RetrofitServiceManager.countWellByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(3) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["bfWell"] = data.getString("bfWell") map["cfWell"] = data.getString("cfWell") map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "obtainWellCountByState: 错误码===>${code}") + Log.d(kTag, "countWellByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt index 4ba71c9..283ad24 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWellDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWellDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index f19ae75..9a2f1d1 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -20,9 +22,13 @@ listModel.value = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ listModel.value = RetrofitServiceManager.obtainAllWell() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt index 0200c19..7a8e3a5 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellMonitorModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellMonitorViewModel : BaseViewModel() { + private val gson = Gson() val monitorModel = MutableLiveData() fun obtainMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading - monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainMonitorResult(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + monitorModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt index 62d5675..1a76400 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellOperationViewModel.kt @@ -1,21 +1,39 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellOperationViewModel : BaseViewModel() { - val operationResultModel = MutableLiveData() + private val gson = Gson() + val resultModel = MutableLiveData() fun obtainOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading - operationResultModel.value = RetrofitServiceManager.obtainOperationResult(id, state) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainOperationResult(id, state) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "操作成功".show(BaseApplication.obtainInstance()) + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt index 494e5b5..e9da747 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WellTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainWellType() = launch({ wellTypeModel.value = RetrofitServiceManager.obtainWellType() + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt index 4363ef9..b17ecad 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderDetailViewModel.kt @@ -1,21 +1,38 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WorkOrderDetailModel import com.casic.app.smartwell.utils.LoadState import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WorkOrderDetailViewModel : BaseViewModel() { + private val gson = Gson() val detailModel = MutableLiveData() fun obtainWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading - detailModel.value = RetrofitServiceManager.obtainWorkOrderDetail(id) - loadState.value = LoadState.Success + val response = RetrofitServiceManager.obtainWorkOrderDetail(id) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { loadState.value = LoadState.Fail + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt index 2d8cbb6..cb56baa 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt @@ -1,8 +1,10 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.model.WorkOrderListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -12,5 +14,7 @@ fun obtainWorkOrderListByState(jobStatus: String, page: Int) = launch({ resultModel.value = RetrofitServiceManager.obtainWorkOrderList(jobStatus, page) + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt index 7f0f016..36a154c 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt @@ -2,8 +2,11 @@ import android.util.Log import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.show import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject @@ -13,11 +16,12 @@ val resultModel = MutableLiveData>() fun countWorkOrderByState() = launch({ - val resultJson = RetrofitServiceManager.countWorkOrderByState() - val jsonObject = JSONObject(resultJson) - val code = jsonObject.getInt("code") - if (code == 200) { + val response = RetrofitServiceManager.countWorkOrderByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { val map = HashMap(4) + + val jsonObject = JSONObject(response) val data = jsonObject.getJSONObject("data") map["beforeGet"] = data.getString("beforeGet") map["beforeConfirm"] = data.getString("beforeConfirm") @@ -25,7 +29,9 @@ map["over"] = data.getString("over") resultModel.value = map } else { - Log.d(kTag, "obtainWorkOrderCountByState: 错误码===>${code}") + Log.d(kTag, "countWorkOrderByState: 错误码===>${responseCode}") } + }, { + "服务器异常".show(BaseApplication.obtainInstance()) }) } \ No newline at end of file