增加异常日志记录,接口报错提示,app启动时有网络不再进行倒计时处理
This commit is contained in:
@@ -37,6 +37,8 @@ import com.sw.inbound.utils.BitmapSaver
|
|||||||
import com.sw.inbound.utils.CameraUtils
|
import com.sw.inbound.utils.CameraUtils
|
||||||
import com.sw.inbound.utils.ImageUploader
|
import com.sw.inbound.utils.ImageUploader
|
||||||
import com.sw.inbound.utils.ImageUtil
|
import com.sw.inbound.utils.ImageUtil
|
||||||
|
import com.sw.inbound.utils.LogSaveUtil
|
||||||
|
import com.sw.inbound.utils.NetworkUtils
|
||||||
import com.sw.inbound.utils.ext.addOnActionSearchListener
|
import com.sw.inbound.utils.ext.addOnActionSearchListener
|
||||||
import com.sw.inbound.utils.ext.clickWithDebounce
|
import com.sw.inbound.utils.ext.clickWithDebounce
|
||||||
import com.sw.inbound.utils.ext.dp
|
import com.sw.inbound.utils.ext.dp
|
||||||
@@ -213,6 +215,10 @@ class FoodCollectionActivity : BaseActivity() {
|
|||||||
|
|
||||||
},
|
},
|
||||||
confirmBlock = {
|
confirmBlock = {
|
||||||
|
if (NetworkUtils.isNetworkConnected(this).not()) {
|
||||||
|
toast("网络异常,请稍后重试")
|
||||||
|
return@WarnDialog
|
||||||
|
}
|
||||||
upload()
|
upload()
|
||||||
}
|
}
|
||||||
).show()
|
).show()
|
||||||
@@ -318,6 +324,7 @@ class FoodCollectionActivity : BaseActivity() {
|
|||||||
// uriToBitmap 返回 null 时关闭 loading,否则转圈永不消失
|
// uriToBitmap 返回 null 时关闭 loading,否则转圈永不消失
|
||||||
hideWaitingDialog()
|
hideWaitingDialog()
|
||||||
toast("图片读取失败,请重试")
|
toast("图片读取失败,请重试")
|
||||||
|
LogSaveUtil.saveLogFile("图片读取失败,请重试")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cropBitmap = withContext(Dispatchers.IO) {
|
cropBitmap = withContext(Dispatchers.IO) {
|
||||||
@@ -336,6 +343,7 @@ class FoodCollectionActivity : BaseActivity() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
hideWaitingDialog()
|
hideWaitingDialog()
|
||||||
toast("操作失败")
|
toast("操作失败")
|
||||||
|
LogSaveUtil.saveLogFile("操作失败:${e.message}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Timber.tag(TAG).d("向量:${imageVector.toJsonString()}")
|
Timber.tag(TAG).d("向量:${imageVector.toJsonString()}")
|
||||||
@@ -355,6 +363,7 @@ class FoodCollectionActivity : BaseActivity() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
toast("数据库异常,请稍后重试")
|
toast("数据库异常,请稍后重试")
|
||||||
|
LogSaveUtil.saveLogFile("数据库异常,请稍后重试:${e.message}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val filterList =
|
val filterList =
|
||||||
@@ -362,6 +371,7 @@ class FoodCollectionActivity : BaseActivity() {
|
|||||||
if (filterList.isNotEmpty()) {
|
if (filterList.isNotEmpty()) {
|
||||||
hideWaitingDialog()
|
hideWaitingDialog()
|
||||||
toast("当前物品可能被袋子遮挡,请检查后重试")
|
toast("当前物品可能被袋子遮挡,请检查后重试")
|
||||||
|
LogSaveUtil.saveLogFile("当前物品可能被袋子遮挡,请检查后重试")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 图片保存为磁盘 I/O,切换到 IO 线程
|
// 图片保存为磁盘 I/O,切换到 IO 线程
|
||||||
@@ -398,8 +408,10 @@ class FoodCollectionActivity : BaseActivity() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
toast("请重试")
|
toast("请重试")
|
||||||
|
LogSaveUtil.saveLogFile("请重试:${e.message}")
|
||||||
} else {
|
} else {
|
||||||
toast("程序异常$errMsg")
|
toast("程序异常$errMsg")
|
||||||
|
LogSaveUtil.saveLogFile("程序异常$errMsg:${e.message}")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// 无论成功、失败还是提前返回,均在此回收 bitmap,彻底消除内存泄漏
|
// 无论成功、失败还是提前返回,均在此回收 bitmap,彻底消除内存泄漏
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ class InitActivity : BaseActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
if (NetworkUtils.isNetworkConnected(this)) {
|
||||||
|
navigateToHome()
|
||||||
|
return
|
||||||
|
}
|
||||||
startCountdown()
|
startCountdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.sw.inbound.repository
|
|||||||
|
|
||||||
import com.google.gson.JsonParseException
|
import com.google.gson.JsonParseException
|
||||||
import com.sw.inbound.model.response.ApiResponse
|
import com.sw.inbound.model.response.ApiResponse
|
||||||
|
import com.sw.inbound.utils.LogSaveUtil
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -15,7 +16,7 @@ abstract class BaseRepository {
|
|||||||
apiCall()
|
apiCall()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e("safeApiCall Exception: ${e.stackTraceToString()}")
|
Timber.e("safeApiCall Exception: ${e.stackTraceToString()}")
|
||||||
|
LogSaveUtil.saveLogFile("safeApiCall Exception: ${e.stackTraceToString()}")
|
||||||
when (e) {
|
when (e) {
|
||||||
is HttpException -> {
|
is HttpException -> {
|
||||||
// 对于HTTP异常,尝试从响应体中获取错误信息
|
// 对于HTTP异常,尝试从响应体中获取错误信息
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.sw.inbound.GlobalData
|
import com.sw.inbound.GlobalData
|
||||||
|
import com.sw.inbound.MyApp
|
||||||
import com.sw.inbound.model.response.ApiResponse
|
import com.sw.inbound.model.response.ApiResponse
|
||||||
import com.sw.inbound.model.response.DictType
|
import com.sw.inbound.model.response.DictType
|
||||||
import com.sw.inbound.model.response.EquipmentInfo
|
import com.sw.inbound.model.response.EquipmentInfo
|
||||||
@@ -16,6 +17,7 @@ import com.sw.inbound.repository.RemoteRepository
|
|||||||
import com.sw.inbound.utils.SPUtil
|
import com.sw.inbound.utils.SPUtil
|
||||||
//import com.sw.inbound.utils.ToastUtils
|
//import com.sw.inbound.utils.ToastUtils
|
||||||
import com.sw.inbound.utils.ext.toType
|
import com.sw.inbound.utils.ext.toType
|
||||||
|
import com.sw.inbound.utils.ext.toast
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -102,7 +104,8 @@ abstract class BaseViewModel(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
Timber.d("msg = ${response.msg}, code = ${response.code}")
|
Timber.d("msg = ${response.msg}, code = ${response.code}")
|
||||||
//ToastUtils.showToast("${response.msg}(${response.code})")
|
// ToastUtils.showToast("${response.msg}(${response.code})")
|
||||||
|
MyApp.instance?.toast("${response.msg}(${response.code})")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -409,11 +409,7 @@ class ReceiptViewModel @Inject constructor(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
val resp = repository.uploadMultipleImages(fileList = fileList, params = params)
|
val resp = repository.uploadMultipleImages(fileList = fileList, params = params)
|
||||||
// if (!parseResponse(resp)) {
|
return parseResponse(resp)
|
||||||
// callback(false)
|
|
||||||
// return@launchWithLoading
|
|
||||||
// }
|
|
||||||
return resp.code == "00000"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user