refactor(generallibrary):优化 NFC 写卡流程
- 在 NewCard2Activity 中添加 startActivityForResult 启动 NFC 写卡界面
- 在 onActivityResult 中处理写卡成功后的逻辑
- 优化 NfcWreatActivity 中的写卡成功处理流程
- 移除冗余的写卡成功提示和状态更新逻辑
| | |
| | | |
| | | companion object { |
| | | private const val TAG = "NewCard2Activity" |
| | | private const val REQUEST_CODE_NFC_WRITE = 1001 |
| | | } |
| | | |
| | | |
| | |
| | | putExtra("operationTypeCode", CardOperationType.OpenCard.code) |
| | | putExtra("orderNumber", response.content?.orderNo) |
| | | putExtra("cardFee", cardFee) |
| | | startActivity(this) |
| | | startActivityForResult(this, REQUEST_CODE_NFC_WRITE) |
| | | } |
| | | } catch (e: Exception) { |
| | | CrashReport.postCatchedException(e) |
| | |
| | | } |
| | | } |
| | | |
| | | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
| | | super.onActivityResult(requestCode, resultCode, data) |
| | | if (requestCode == REQUEST_CODE_NFC_WRITE && resultCode == RESULT_OK) { |
| | | // 写卡成功,关闭当前Activity |
| | | finish() |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | runOnUiThread { |
| | | if (success) { |
| | | postCardData(cardType, cardAddr) |
| | | // 写卡成功后更新数据库中的isCardWritten状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | ToastUtil.show("写卡成功!") |
| | | // 处理写卡成功的情况 |
| | | } else { |
| | | // 处理写卡失败的情况 |
| | | ToastUtil.show(message) |
| | |
| | | // 确保Toast在主线程中调用 |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 写卡成功后更新数据库中的isCardWritten状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | ToastUtil.show("写卡成功!") |
| | | postCardData(cardType, cardAddr) |
| | | |
| | | } else { |
| | | ToastUtil.show("写卡失败: ${msg ?: "未知错误"}") |
| | | } |
| | |
| | | val updatedCardRegistration = cardRegistration.copy(isCardWritten = true) |
| | | // 更新数据库记录 |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | | |
| | | // 在主线程中关闭Activity |
| | | runOnUiThread { |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | ToastUtil.show("写卡成功") |
| | | } |
| | | } |
| | | } catch (e: Exception) { |
| | | CrashReport.postCatchedException(e) |
| | | e.printStackTrace() |
| | | runOnUiThread { |
| | | ToastUtil.show("更新写卡状态失败: ${e.message}") |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | object : SubscriberListener<BaseResponse<String>>() { |
| | | override fun onNext(t: BaseResponse<String>) { |
| | | if (t.success) { |
| | | ToastUtil.show("写卡成功") |
| | | this@NfcWreatActivity.finish() |
| | | |
| | | updateCardWrittenStatus(cardAddr) |
| | | |
| | | |
| | | } else { |
| | | // 处理搜索失败的情况 |