feat(spraying): 添加OCR结果保存功能并优化任务流程
- 新增OcrNavigationData数据类用于传递OCR导航参数 - 在Service中添加saveOcrResult接口用于保存OCR识别结果 - 在SprayingActivity中添加productionInfoId参数传递逻辑 - 在SprayingOCRActivity中接收并传递OCR相关参数到结果页面 - 在SprayingResultActivity中实现OCR结果保存和任务状态管理 - 新增SaveOcrState枚举管理OCR保存状态 - 实现saveOcrAndContinue和saveOcrAndFinish方法处理不同保存场景 - 优化SprayingOCRVM中的OCR结果数据转换逻辑 - 更新语音命令处理逻辑,统一调用新的触发方法 - 添加OCR结果JSON序列化和反序列化功能
这个提交包含在:
父节点
931dd43fe5
当前提交
056302cc10
@ -32,3 +32,11 @@ data class RecognizeByPathResponse(
|
|||||||
val data: OcrResultData? = null
|
val data: OcrResultData? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class OcrNavigationData(
|
||||||
|
val filePath: String,
|
||||||
|
val ocrResultJson: String,
|
||||||
|
val judgment: String,
|
||||||
|
val one: String,
|
||||||
|
val two: String
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
@ -79,6 +79,16 @@ interface Service {
|
|||||||
@POST("/skyscopicsecond-api/api/aiGlasses/recognizeByPath")
|
@POST("/skyscopicsecond-api/api/aiGlasses/recognizeByPath")
|
||||||
fun recognizeByPath(@Body body: RecognizeByPathRequest): Observable<RecognizeByPathResponse>
|
fun recognizeByPath(@Body body: RecognizeByPathRequest): Observable<RecognizeByPathResponse>
|
||||||
|
|
||||||
|
@Multipart
|
||||||
|
@POST("/skyscopicsecond-api/api/aiGlasses/saveOcrResult")
|
||||||
|
fun saveOcrResult(
|
||||||
|
@Part("taskId") taskId: RequestBody,
|
||||||
|
@Part("productionInfoId") productionInfoId: RequestBody,
|
||||||
|
@Part("ocrResult") ocrResult: RequestBody,
|
||||||
|
@Part("result") result: RequestBody,
|
||||||
|
@Part("filePath") filePath: RequestBody
|
||||||
|
): Observable<SubmitTaskResponse>
|
||||||
|
|
||||||
@POST("/skyscopicsecond-api/api/aiGlasses/submitTask")
|
@POST("/skyscopicsecond-api/api/aiGlasses/submitTask")
|
||||||
fun submitTask(@Body body: SubmitTaskRequest): Observable<SubmitTaskResponse>
|
fun submitTask(@Body body: SubmitTaskRequest): Observable<SubmitTaskResponse>
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,7 @@ class SprayingActivity :
|
|||||||
.orEmpty()
|
.orEmpty()
|
||||||
.ifBlank { "1495087454883938304" }
|
.ifBlank { "1495087454883938304" }
|
||||||
}
|
}
|
||||||
|
private var productionInfoId: String = ""
|
||||||
|
|
||||||
private val listener = object : OfflineCmdListener {
|
private val listener = object : OfflineCmdListener {
|
||||||
override fun onOfflineCmd(cmd: String) {
|
override fun onOfflineCmd(cmd: String) {
|
||||||
@ -92,6 +93,7 @@ class SprayingActivity :
|
|||||||
startActivity(Intent(this@SprayingActivity, SprayingOCRActivity::class.java).apply {
|
startActivity(Intent(this@SprayingActivity, SprayingOCRActivity::class.java).apply {
|
||||||
putExtra("path", path)
|
putExtra("path", path)
|
||||||
putExtra("taskId", taskId)
|
putExtra("taskId", taskId)
|
||||||
|
putExtra("productionInfoId", productionInfoId)
|
||||||
})
|
})
|
||||||
finish()
|
finish()
|
||||||
// runOnUiThread {
|
// runOnUiThread {
|
||||||
@ -108,6 +110,7 @@ class SprayingActivity :
|
|||||||
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
binding.tvTaskHeader.text = "您还有10项任务未完成"
|
binding.tvTaskHeader.text = "您还有10项任务未完成"
|
||||||
viewModel.taskInfo.observe(this) { info ->
|
viewModel.taskInfo.observe(this) { info ->
|
||||||
|
productionInfoId = info.productionInfoId
|
||||||
binding.tvTaskHeader.text = "您还有${info.taskCount}项任务未完成"
|
binding.tvTaskHeader.text = "您还有${info.taskCount}项任务未完成"
|
||||||
binding.title.text = "任务1:${info.itemName}"
|
binding.title.text = "任务1:${info.itemName}"
|
||||||
binding.content1.text = "AO/AAO:${info.aoNumber}"
|
binding.content1.text = "AO/AAO:${info.aoNumber}"
|
||||||
|
|||||||
@ -34,6 +34,7 @@ class SprayingOCRActivity :
|
|||||||
|
|
||||||
override fun getRecyclerOrientation(): Int = RecyclerView.VERTICAL
|
override fun getRecyclerOrientation(): Int = RecyclerView.VERTICAL
|
||||||
private val taskId: String by lazy { intent.getStringExtra("taskId").orEmpty() }
|
private val taskId: String by lazy { intent.getStringExtra("taskId").orEmpty() }
|
||||||
|
private val productionInfoId: String by lazy { intent.getStringExtra("productionInfoId").orEmpty() }
|
||||||
|
|
||||||
private val listener = object : OfflineCmdListener {
|
private val listener = object : OfflineCmdListener {
|
||||||
override fun onOfflineCmd(cmd: String) {
|
override fun onOfflineCmd(cmd: String) {
|
||||||
@ -120,6 +121,9 @@ class SprayingOCRActivity :
|
|||||||
viewModel.clearOcrResult()
|
viewModel.clearOcrResult()
|
||||||
startActivity(Intent(this@SprayingOCRActivity, SprayingResultActivity::class.java).apply {
|
startActivity(Intent(this@SprayingOCRActivity, SprayingResultActivity::class.java).apply {
|
||||||
putExtra("taskId", taskId)
|
putExtra("taskId", taskId)
|
||||||
|
putExtra("productionInfoId", productionInfoId)
|
||||||
|
putExtra("filePath", result.filePath)
|
||||||
|
putExtra("ocrResultJson", result.ocrResultJson)
|
||||||
putExtra("judgment", result.judgment)
|
putExtra("judgment", result.judgment)
|
||||||
putExtra("one", result.one)
|
putExtra("one", result.one)
|
||||||
putExtra("two", result.two)
|
putExtra("two", result.two)
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import com.nova.brain.glass.helper.OfflineCmdListener
|
|||||||
import com.nova.brain.glass.helper.OfflineCmdServiceHelper
|
import com.nova.brain.glass.helper.OfflineCmdServiceHelper
|
||||||
import com.nova.brain.glass.helper.SprayingPhotoManager
|
import com.nova.brain.glass.helper.SprayingPhotoManager
|
||||||
import com.nova.brain.glass.model.ItemItem
|
import com.nova.brain.glass.model.ItemItem
|
||||||
|
import com.nova.brain.glass.viewmodel.SaveOcrState
|
||||||
import com.nova.brain.glass.viewmodel.SubmitTaskState
|
import com.nova.brain.glass.viewmodel.SubmitTaskState
|
||||||
import com.nova.brain.glass.viewmodel.SprayingResultVM
|
import com.nova.brain.glass.viewmodel.SprayingResultVM
|
||||||
import com.rokid.security.glass3.sdk.base.data.media.PhotoResolution
|
import com.rokid.security.glass3.sdk.base.data.media.PhotoResolution
|
||||||
@ -37,47 +38,59 @@ class SprayingResultActivity :
|
|||||||
override fun fullscreen(): Boolean = true
|
override fun fullscreen(): Boolean = true
|
||||||
|
|
||||||
override fun getRecyclerOrientation(): Int = RecyclerView.HORIZONTAL
|
override fun getRecyclerOrientation(): Int = RecyclerView.HORIZONTAL
|
||||||
|
|
||||||
private val taskId: String by lazy {
|
private val taskId: String by lazy {
|
||||||
intent.getStringExtra("taskId")
|
intent.getStringExtra("taskId").orEmpty().ifBlank { "1493291302287048704" }
|
||||||
.orEmpty()
|
|
||||||
.ifBlank { "1493291302287048704" }
|
|
||||||
}
|
}
|
||||||
|
private val productionInfoId: String by lazy {
|
||||||
|
intent.getStringExtra("productionInfoId").orEmpty()
|
||||||
|
}
|
||||||
|
private val filePath: String by lazy {
|
||||||
|
intent.getStringExtra("filePath").orEmpty()
|
||||||
|
}
|
||||||
|
private val ocrResultJson: String by lazy {
|
||||||
|
intent.getStringExtra("ocrResultJson").orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
private var ocrOne: String = ""
|
private var ocrOne: String = ""
|
||||||
private var ocrTwo: String = ""
|
private var ocrTwo: String = ""
|
||||||
private var status = true
|
private var status = true
|
||||||
private var successDialog: AlertDialog? = null
|
private var successDialog: AlertDialog? = null
|
||||||
private val uiHandler = Handler(Looper.getMainLooper())
|
private val uiHandler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
private fun currentResultJson(): String {
|
||||||
|
val judgment = if (status) "合格" else "不合格"
|
||||||
|
return "{\"judgment\":\"$judgment\",\"one\":\"$ocrOne\",\"two\":\"$ocrTwo\"}"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun triggerContinue() {
|
||||||
|
binding.hint.text = "保存中,请稍后..."
|
||||||
|
viewModel.saveOcrAndContinue(taskId, productionInfoId, ocrResultJson, currentResultJson(), filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun triggerFinish() {
|
||||||
|
binding.hint.text = "保存中,请稍后..."
|
||||||
|
viewModel.saveOcrAndFinish(taskId, productionInfoId, ocrResultJson, currentResultJson(), filePath)
|
||||||
|
}
|
||||||
|
|
||||||
private val manualResultLauncher =
|
private val manualResultLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
if (result.resultCode != Activity.RESULT_OK) {
|
if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult
|
||||||
return@registerForActivityResult
|
|
||||||
}
|
|
||||||
when (result.data?.getStringExtra(SprayingManualResultActivity.EXTRA_MANUAL_RESULT)) {
|
when (result.data?.getStringExtra(SprayingManualResultActivity.EXTRA_MANUAL_RESULT)) {
|
||||||
SprayingManualResultActivity.RESULT_PASS -> {
|
SprayingManualResultActivity.RESULT_PASS -> { status = true; setStatusImage() }
|
||||||
status = true
|
SprayingManualResultActivity.RESULT_FAIL -> { status = false; setStatusImage() }
|
||||||
setStatusImage()
|
|
||||||
}
|
|
||||||
|
|
||||||
SprayingManualResultActivity.RESULT_FAIL -> {
|
|
||||||
status = false
|
|
||||||
setStatusImage()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val finishLauncher =
|
private val finishLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
if (result.resultCode != Activity.RESULT_OK) {
|
if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult
|
||||||
return@registerForActivityResult
|
|
||||||
}
|
|
||||||
when (result.data?.getStringExtra(SprayingFinishActivity.EXTRA_FINISH_ACTION)) {
|
when (result.data?.getStringExtra(SprayingFinishActivity.EXTRA_FINISH_ACTION)) {
|
||||||
SprayingFinishActivity.ACTION_SUPPLEMENT -> {
|
SprayingFinishActivity.ACTION_SUPPLEMENT -> {
|
||||||
runOnUiThread {
|
runOnUiThread { binding.hint.text = "拍照中,请稍后..." }
|
||||||
binding.hint.text = "拍照中,请稍后..."
|
|
||||||
}
|
|
||||||
isPhoto = true
|
isPhoto = true
|
||||||
takePhoto()
|
takePhoto()
|
||||||
}
|
}
|
||||||
|
|
||||||
SprayingFinishActivity.ACTION_SUBMIT -> {
|
SprayingFinishActivity.ACTION_SUBMIT -> {
|
||||||
viewModel.submitTask(taskId)
|
viewModel.submitTask(taskId)
|
||||||
}
|
}
|
||||||
@ -88,34 +101,18 @@ class SprayingResultActivity :
|
|||||||
override fun onOfflineCmd(cmd: String) {
|
override fun onOfflineCmd(cmd: String) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
when (cmd) {
|
when (cmd) {
|
||||||
"退出", "返回", "退回" -> {
|
"退出", "返回", "退回" -> finish()
|
||||||
finish()
|
"重拍", "重新拍", "继续拍照", "再拍一次", "继续拍摄" -> triggerContinue()
|
||||||
}
|
"人工更正结果", "更正结果", "人工更正", "更正" -> rest()
|
||||||
|
"结束任务", "完成任务", "完成", "结束" -> triggerFinish()
|
||||||
"重拍", "重新拍", "继续拍照", "再拍一次", "继续拍摄" -> {
|
|
||||||
runOnUiThread {
|
|
||||||
binding.hint.text = "拍照中,请稍后..."
|
|
||||||
}
|
|
||||||
isPhoto = true
|
|
||||||
takePhoto()
|
|
||||||
}
|
|
||||||
|
|
||||||
"人工更正结果", "更正结果", "人工更正", "更正" -> {
|
|
||||||
rest()
|
|
||||||
}
|
|
||||||
"结束任务", "完成任务", "完成", "结束" -> {
|
|
||||||
taskFinish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun takePhoto() {
|
fun takePhoto() {
|
||||||
val fileName = "test_${System.currentTimeMillis()}.png"
|
val fileName = "test_${System.currentTimeMillis()}.png"
|
||||||
val publicPicturesDir =
|
val publicPicturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
|
||||||
val file = File(publicPicturesDir, fileName)
|
val file = File(publicPicturesDir, fileName)
|
||||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
||||||
}
|
}
|
||||||
@ -123,9 +120,6 @@ class SprayingResultActivity :
|
|||||||
fun rest() {
|
fun rest() {
|
||||||
manualResultLauncher.launch(Intent(this, SprayingManualResultActivity::class.java))
|
manualResultLauncher.launch(Intent(this, SprayingManualResultActivity::class.java))
|
||||||
}
|
}
|
||||||
fun taskFinish() {
|
|
||||||
finishLauncher.launch(Intent(this, SprayingFinishActivity::class.java))
|
|
||||||
}
|
|
||||||
|
|
||||||
private val photoCallbackId = UUID.randomUUID().toString()
|
private val photoCallbackId = UUID.randomUUID().toString()
|
||||||
|
|
||||||
@ -134,9 +128,7 @@ class SprayingResultActivity :
|
|||||||
LogHelper.d("onTakePhoto-->path = $path")
|
LogHelper.d("onTakePhoto-->path = $path")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCallbackId(): String {
|
override fun getCallbackId(): String = photoCallbackId
|
||||||
return photoCallbackId
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTakePhotoV2(path: String?, width: Int, height: Int) {
|
override fun onTakePhotoV2(path: String?, width: Int, height: Int) {
|
||||||
LogHelper.d("width:$width--height:$height")
|
LogHelper.d("width:$width--height:$height")
|
||||||
@ -145,50 +137,66 @@ class SprayingResultActivity :
|
|||||||
isPhoto = false
|
isPhoto = false
|
||||||
takePhoto()
|
takePhoto()
|
||||||
} else {
|
} else {
|
||||||
runOnUiThread {
|
runOnUiThread { binding.hint.text = "单击或语音输入「开始」,进入下一步" }
|
||||||
binding.hint.text = "单击或语音输入“开始”,进入下一步"
|
|
||||||
}
|
|
||||||
"相机异常".showMessage()
|
"相机异常".showMessage()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SprayingPhotoManager.addPhoto(path)
|
SprayingPhotoManager.addPhoto(path)
|
||||||
startActivity(
|
startActivity(Intent(this@SprayingResultActivity, SprayingOCRActivity::class.java).apply {
|
||||||
Intent(
|
putExtra("path", path)
|
||||||
this@SprayingResultActivity, SprayingOCRActivity::class.java
|
putExtra("taskId", taskId)
|
||||||
).apply {
|
putExtra("productionInfoId", productionInfoId)
|
||||||
putExtra("path", path)
|
})
|
||||||
putExtra("taskId", taskId)
|
|
||||||
})
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun initData() {
|
override fun initData() {
|
||||||
super.initData()
|
super.initData()
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
|
viewModel.saveOcrState.observe(this) { state ->
|
||||||
|
when (state) {
|
||||||
|
SaveOcrState.LOADING -> binding.hint.text = "保存中,请稍后..."
|
||||||
|
SaveOcrState.SUCCESS_CONTINUE -> {
|
||||||
|
viewModel.resetSaveOcrState()
|
||||||
|
runOnUiThread { binding.hint.text = "拍照中,请稍后..." }
|
||||||
|
isPhoto = true
|
||||||
|
takePhoto()
|
||||||
|
}
|
||||||
|
SaveOcrState.SUCCESS_FINISH -> {
|
||||||
|
viewModel.resetSaveOcrState()
|
||||||
|
finishLauncher.launch(Intent(this, SprayingFinishActivity::class.java))
|
||||||
|
}
|
||||||
|
SaveOcrState.FAILED -> {
|
||||||
|
viewModel.resetSaveOcrState()
|
||||||
|
binding.hint.text = "单击或语音输入「结束任务」,进入任务确认"
|
||||||
|
}
|
||||||
|
SaveOcrState.IDLE -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
viewModel.saveOcrError.observe(this) { message ->
|
||||||
|
if (message.isNotBlank()) message.showMessage()
|
||||||
|
}
|
||||||
viewModel.submitTaskState.observe(this) { state ->
|
viewModel.submitTaskState.observe(this) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
SubmitTaskState.LOADING -> {
|
SubmitTaskState.LOADING -> binding.hint.text = "提交中,请稍后..."
|
||||||
binding.hint.text = "提交中,请稍后..."
|
|
||||||
}
|
|
||||||
SubmitTaskState.SUCCESS -> {
|
SubmitTaskState.SUCCESS -> {
|
||||||
viewModel.resetSubmitTaskState()
|
viewModel.resetSubmitTaskState()
|
||||||
showSuccessDialogThenBackToTaskList()
|
showSuccessDialogThenBackToTaskList()
|
||||||
}
|
}
|
||||||
SubmitTaskState.FAILED -> {
|
SubmitTaskState.FAILED -> {
|
||||||
binding.hint.text = "单击或语音输入“结束任务”,进入任务确认"
|
binding.hint.text = "单击或语音输入「结束任务」,进入任务确认"
|
||||||
viewModel.resetSubmitTaskState()
|
viewModel.resetSubmitTaskState()
|
||||||
}
|
}
|
||||||
SubmitTaskState.IDLE -> Unit
|
SubmitTaskState.IDLE -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.submitTaskError.observe(this) { message ->
|
viewModel.submitTaskError.observe(this) { message ->
|
||||||
if (message.isNotBlank()) {
|
if (message.isNotBlank()) message.showMessage()
|
||||||
message.showMessage()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val judgment = intent.getStringExtra("judgment").orEmpty()
|
val judgment = intent.getStringExtra("judgment").orEmpty()
|
||||||
ocrOne = intent.getStringExtra("one").orEmpty()
|
ocrOne = intent.getStringExtra("one").orEmpty()
|
||||||
ocrTwo = intent.getStringExtra("two").orEmpty()
|
ocrTwo = intent.getStringExtra("two").orEmpty()
|
||||||
@ -202,17 +210,15 @@ class SprayingResultActivity :
|
|||||||
binding.value1.text = "识码一:$ocrOne"
|
binding.value1.text = "识码一:$ocrOne"
|
||||||
binding.value2.text = "识码二:$ocrTwo"
|
binding.value2.text = "识码二:$ocrTwo"
|
||||||
binding.value3.text = if (status) "两码一致,符合要求!" else "两码不一致,不符合要求!"
|
binding.value3.text = if (status) "两码一致,符合要求!" else "两码不一致,不符合要求!"
|
||||||
|
val strikeFlag = Paint.STRIKE_THRU_TEXT_FLAG
|
||||||
if (status) {
|
if (status) {
|
||||||
binding.value1.paintFlags =
|
binding.value1.paintFlags = binding.value1.paintFlags and strikeFlag.inv()
|
||||||
binding.value1.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
binding.value2.paintFlags = binding.value2.paintFlags and strikeFlag.inv()
|
||||||
binding.value2.paintFlags =
|
binding.value3.paintFlags = binding.value3.paintFlags and strikeFlag.inv()
|
||||||
binding.value2.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
|
||||||
binding.value3.paintFlags =
|
|
||||||
binding.value3.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
|
||||||
} else {
|
} else {
|
||||||
binding.value1.paintFlags = binding.value1.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
binding.value1.paintFlags = binding.value1.paintFlags or strikeFlag
|
||||||
binding.value2.paintFlags = binding.value2.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
binding.value2.paintFlags = binding.value2.paintFlags or strikeFlag
|
||||||
binding.value3.paintFlags = binding.value3.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
binding.value3.paintFlags = binding.value3.paintFlags or strikeFlag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,12 +228,14 @@ class SprayingResultActivity :
|
|||||||
OfflineCmdServiceHelper.addOnLineListener(listener)
|
OfflineCmdServiceHelper.addOnLineListener(listener)
|
||||||
GlassMediaServiceHelper.addPhotoCallback(mPhotoFileCallback)
|
GlassMediaServiceHelper.addPhotoCallback(mPhotoFileCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
OfflineCmdServiceHelper.removeListenerSprayingResult()
|
OfflineCmdServiceHelper.removeListenerSprayingResult()
|
||||||
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
||||||
GlassMediaServiceHelper.removePhotoCallback(mPhotoFileCallback)
|
GlassMediaServiceHelper.removePhotoCallback(mPhotoFileCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
uiHandler.removeCallbacksAndMessages(null)
|
uiHandler.removeCallbacksAndMessages(null)
|
||||||
successDialog?.dismiss()
|
successDialog?.dismiss()
|
||||||
@ -252,21 +260,9 @@ class SprayingResultActivity :
|
|||||||
)
|
)
|
||||||
.setClickListener(R.id.photo) {
|
.setClickListener(R.id.photo) {
|
||||||
when (item.text) {
|
when (item.text) {
|
||||||
"继续拍摄" -> {
|
"继续拍摄" -> triggerContinue()
|
||||||
runOnUiThread {
|
"结束任务" -> triggerFinish()
|
||||||
binding.hint.text = "拍照中,请稍后..."
|
"人工更正结果" -> rest()
|
||||||
}
|
|
||||||
isPhoto = true
|
|
||||||
takePhoto()
|
|
||||||
}
|
|
||||||
|
|
||||||
"结束任务" -> {
|
|
||||||
taskFinish()
|
|
||||||
}
|
|
||||||
|
|
||||||
"人工更正结果" -> {
|
|
||||||
rest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,8 +270,6 @@ class SprayingResultActivity :
|
|||||||
|
|
||||||
override fun adapter(): BasePagedAdapter<ItemItem> = adapter
|
override fun adapter(): BasePagedAdapter<ItemItem> = adapter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun showSuccessDialogThenBackToTaskList() {
|
private fun showSuccessDialogThenBackToTaskList() {
|
||||||
successDialog?.dismiss()
|
successDialog?.dismiss()
|
||||||
val contentView = LayoutInflater.from(this).inflate(R.layout.dialog_review, null)
|
val contentView = LayoutInflater.from(this).inflate(R.layout.dialog_review, null)
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
package com.nova.brain.glass.viewmodel
|
package com.nova.brain.glass.viewmodel
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import com.google.gson.Gson
|
||||||
import com.nova.brain.glass.MyApplication
|
import com.nova.brain.glass.MyApplication
|
||||||
import com.nova.brain.glass.model.ItemItem
|
import com.nova.brain.glass.model.ItemItem
|
||||||
|
import com.nova.brain.glass.model.data.OcrNavigationData
|
||||||
import com.nova.brain.glass.model.data.OcrResultData
|
import com.nova.brain.glass.model.data.OcrResultData
|
||||||
import com.nova.brain.glass.model.data.RecognizeByPathRequest
|
import com.nova.brain.glass.model.data.RecognizeByPathRequest
|
||||||
import com.nova.brain.glass.repository.Service
|
import com.nova.brain.glass.repository.Service
|
||||||
@ -27,9 +29,10 @@ enum class UploadState {
|
|||||||
class SprayingOCRVM : BaseListViewModel<ItemItem>() {
|
class SprayingOCRVM : BaseListViewModel<ItemItem>() {
|
||||||
val uploadState = MutableLiveData(UploadState.IDLE)
|
val uploadState = MutableLiveData(UploadState.IDLE)
|
||||||
val uploadError = MutableLiveData<String>()
|
val uploadError = MutableLiveData<String>()
|
||||||
val ocrResult = MutableLiveData<OcrResultData?>()
|
val ocrResult = MutableLiveData<OcrNavigationData?>()
|
||||||
private var uploadingPath: String? = null
|
private var uploadingPath: String? = null
|
||||||
private var uploadDisposable: Disposable? = null
|
private var uploadDisposable: Disposable? = null
|
||||||
|
private val gson = Gson()
|
||||||
|
|
||||||
override fun loadData(
|
override fun loadData(
|
||||||
page: Int,
|
page: Int,
|
||||||
@ -84,7 +87,14 @@ class SprayingOCRVM : BaseListViewModel<ItemItem>() {
|
|||||||
if (uploadingPath != localPath) return@subscribe
|
if (uploadingPath != localPath) return@subscribe
|
||||||
if (response.code == 200) {
|
if (response.code == 200) {
|
||||||
uploadState.value = UploadState.SUCCESS
|
uploadState.value = UploadState.SUCCESS
|
||||||
ocrResult.value = response.data ?: OcrResultData()
|
val data = response.data ?: OcrResultData()
|
||||||
|
ocrResult.value = OcrNavigationData(
|
||||||
|
filePath = serverPath,
|
||||||
|
ocrResultJson = gson.toJson(data),
|
||||||
|
judgment = data.judgment,
|
||||||
|
one = data.one,
|
||||||
|
two = data.two
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
uploadState.value = UploadState.FAILED
|
uploadState.value = UploadState.FAILED
|
||||||
uploadError.value = if (response.message.isBlank()) "OCR识别失败" else response.message
|
uploadError.value = if (response.message.isBlank()) "OCR识别失败" else response.message
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import com.xuqm.base.viewmodel.BaseListViewModel
|
|||||||
import com.xuqm.base.viewmodel.callback.Response
|
import com.xuqm.base.viewmodel.callback.Response
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
|
||||||
enum class SubmitTaskState {
|
enum class SubmitTaskState {
|
||||||
IDLE,
|
IDLE,
|
||||||
@ -18,9 +20,19 @@ enum class SubmitTaskState {
|
|||||||
FAILED
|
FAILED
|
||||||
}
|
}
|
||||||
|
|
||||||
class SprayingResultVM: BaseListViewModel<ItemItem>() {
|
enum class SaveOcrState {
|
||||||
|
IDLE,
|
||||||
|
LOADING,
|
||||||
|
SUCCESS_CONTINUE,
|
||||||
|
SUCCESS_FINISH,
|
||||||
|
FAILED
|
||||||
|
}
|
||||||
|
|
||||||
|
class SprayingResultVM : BaseListViewModel<ItemItem>() {
|
||||||
val submitTaskState = MutableLiveData(SubmitTaskState.IDLE)
|
val submitTaskState = MutableLiveData(SubmitTaskState.IDLE)
|
||||||
val submitTaskError = MutableLiveData<String>()
|
val submitTaskError = MutableLiveData<String>()
|
||||||
|
val saveOcrState = MutableLiveData(SaveOcrState.IDLE)
|
||||||
|
val saveOcrError = MutableLiveData<String>()
|
||||||
|
|
||||||
override fun loadData(
|
override fun loadData(
|
||||||
page: Int,
|
page: Int,
|
||||||
@ -33,6 +45,66 @@ class SprayingResultVM: BaseListViewModel<ItemItem>() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveOcrAndContinue(
|
||||||
|
taskId: String,
|
||||||
|
productionInfoId: String,
|
||||||
|
ocrResultJson: String,
|
||||||
|
resultJson: String,
|
||||||
|
filePath: String
|
||||||
|
) {
|
||||||
|
doSaveOcr(taskId, productionInfoId, ocrResultJson, resultJson, filePath, finish = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveOcrAndFinish(
|
||||||
|
taskId: String,
|
||||||
|
productionInfoId: String,
|
||||||
|
ocrResultJson: String,
|
||||||
|
resultJson: String,
|
||||||
|
filePath: String
|
||||||
|
) {
|
||||||
|
doSaveOcr(taskId, productionInfoId, ocrResultJson, resultJson, filePath, finish = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doSaveOcr(
|
||||||
|
taskId: String,
|
||||||
|
productionInfoId: String,
|
||||||
|
ocrResultJson: String,
|
||||||
|
resultJson: String,
|
||||||
|
filePath: String,
|
||||||
|
finish: Boolean
|
||||||
|
) {
|
||||||
|
if (saveOcrState.value == SaveOcrState.LOADING) return
|
||||||
|
saveOcrState.value = SaveOcrState.LOADING
|
||||||
|
val plain = "text/plain".toMediaTypeOrNull()
|
||||||
|
add(
|
||||||
|
HttpManager.getApi(MyApplication.appComponent2, Service::class.java)
|
||||||
|
.saveOcrResult(
|
||||||
|
taskId = taskId.toRequestBody(plain),
|
||||||
|
productionInfoId = productionInfoId.toRequestBody(plain),
|
||||||
|
ocrResult = ocrResultJson.toRequestBody(plain),
|
||||||
|
result = resultJson.toRequestBody(plain),
|
||||||
|
filePath = filePath.toRequestBody(plain)
|
||||||
|
)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ response ->
|
||||||
|
if (response.code == 200) {
|
||||||
|
saveOcrState.value = if (finish) SaveOcrState.SUCCESS_FINISH else SaveOcrState.SUCCESS_CONTINUE
|
||||||
|
} else {
|
||||||
|
saveOcrState.value = SaveOcrState.FAILED
|
||||||
|
saveOcrError.value = if (response.message.isBlank()) "保存失败" else response.message
|
||||||
|
}
|
||||||
|
}, { e ->
|
||||||
|
saveOcrState.value = SaveOcrState.FAILED
|
||||||
|
saveOcrError.value = e.message ?: "保存失败"
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetSaveOcrState() {
|
||||||
|
saveOcrState.value = SaveOcrState.IDLE
|
||||||
|
}
|
||||||
|
|
||||||
fun submitTask(taskId: String) {
|
fun submitTask(taskId: String) {
|
||||||
if (taskId.isBlank()) {
|
if (taskId.isBlank()) {
|
||||||
submitTaskState.value = SubmitTaskState.FAILED
|
submitTaskState.value = SubmitTaskState.FAILED
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户