From 0faae97cd2523f840c426da68464e577e01dfa80 Mon Sep 17 00:00:00 2001
From: zuojincheng <lf_zuo@163.com>
Date: 星期一, 23 六月 2025 20:35:08 +0800
Subject: [PATCH] refactor(CardReplaceActivity): 重构补卡流程并优化界面显示- 重新设计卡片信息展示布局,增加新卡卡地址、客户编号等字段 - 优化补卡逻辑,支持通过卡号或客户编号获取卡片信息 -调整工本费和返回金额输入框位置 - 更新API调用路径,使用新的卡片查询接口
---
generallibrary/src/main/java/com/dayu/general/activity/MainActivity.kt | 73 +++++++++++++++++++++++++++++++++---
1 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/generallibrary/src/main/java/com/dayu/general/activity/MainActivity.kt b/generallibrary/src/main/java/com/dayu/general/activity/MainActivity.kt
index 4e425e0..81b20a0 100644
--- a/generallibrary/src/main/java/com/dayu/general/activity/MainActivity.kt
+++ b/generallibrary/src/main/java/com/dayu/general/activity/MainActivity.kt
@@ -1,6 +1,9 @@
package com.dayu.general.activity
+import android.content.Intent
import android.os.Bundle
+import android.os.Handler
+import android.os.Looper
import android.view.KeyEvent
import android.view.LayoutInflater
import android.widget.Toast
@@ -12,26 +15,88 @@
import com.dayu.general.R
import com.dayu.general.adapter.TabAdapter
import com.dayu.general.bean.net.UserInfoResult
+import com.dayu.general.bean.net.WaterPriceResult
import com.dayu.general.databinding.ActivityMainBinding
import com.dayu.general.net.ApiManager
import com.dayu.general.net.BaseResponse
-class MainActivity : BaseActivity() {
+class MainActivity : BaseNfcActivity() {
var binding: ActivityMainBinding? = null
private val fragments: ArrayList<Fragment> = ArrayList()
var mExitTime: Long = 0
+ private val handler = Handler(Looper.getMainLooper())
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(LayoutInflater.from(this))
setContentView(binding?.root)
+
+ // 娉ㄥ唽MainActivity瀹炰緥鍒癇aseApplication
+ BaseApplication.setMainActivity(this)
+
setupFragments()
initView()
initTab()
getUserInfo()
+
+ // 寤舵椂20绉掑悗鑾峰彇姘翠环
+ handler.postDelayed({
+ getWaterPriceFromActivity()
+ }, 20000) // 20绉掑欢鏃�
}
+ override fun onDestroy() {
+ super.onDestroy()
+ // 娓呯悊Handler鍥炶皟锛岄槻姝㈠唴瀛樻硠婕�
+ handler.removeCallbacksAndMessages(null)
+ // 娓呯悊BaseApplication涓殑MainActivity寮曠敤
+ BaseApplication.setMainActivity(null)
+ }
+
+ override fun onNfcBack(intent: Intent) {
+ intent.let { nfcIntent ->
+ // 鑾峰彇褰撳墠鏄剧ず鐨凢ragment
+ val currentFragment = fragments[binding?.viewPager?.currentItem ?: 0]
+
+ // 濡傛灉褰撳墠鏄剧ず鐨勬槸鍏呭�糉ragment锛屽垯灏哊FC淇℃伅浼犻�掔粰瀹冨鐞�
+ if (currentFragment is RechargeFragment) {
+ currentFragment.handleNfcIntent(nfcIntent)
+ }
+ }
+ }
+
+ /**
+ * 鑾峰彇姘翠环淇℃伅 - 鍏紑鏂规硶渚涘叾浠栧湴鏂硅皟鐢�
+ */
+ fun getWaterPriceFromActivity() {
+ // 濡傛灉姘翠环宸插瓨鍦ㄤ笖澶т簬0锛屽垯涓嶉噸澶嶈幏鍙�
+ if (BaseApplication.waterPrice > 0.0) {
+ return
+ }
+
+ ApiManager.getInstance().requestGetHideLoading(
+ this,
+ "terminal/client/getWaterPrice",
+ WaterPriceResult::class.java,
+ null,
+ object : SubscriberListener<BaseResponse<WaterPriceResult>>() {
+ override fun onNext(response: BaseResponse<WaterPriceResult>) {
+ if (response.success && response.code == "0001") {
+ // 鑾峰彇姘翠环鎴愬姛锛屼繚瀛樺埌BaseApplication
+ response.content?.let { waterPriceResult ->
+ BaseApplication.waterPrice = waterPriceResult.price
+ }
+ }
+ }
+
+ override fun onError(e: Throwable?) {
+ super.onError(e)
+ // 缃戠粶寮傚父鏃朵笉鏄剧ず閿欒淇℃伅锛岄伩鍏嶅奖鍝嶇敤鎴蜂綋楠�
+ }
+ }
+ )
+ }
private fun getUserInfo() {
// 浣跨敤姝g‘鐨勭被鍨嬪弬鏁�
@@ -63,8 +128,8 @@
private fun initView() {
binding!!.BSCardLL.setOnClickListener { changeBottomState(Tab.BSC) }
- binding!!.rechargeLL.setOnClickListener { changeBottomState(Tab.RECHARGE) }
binding!!.myLL.setOnClickListener { changeBottomState(Tab.MY) }
+ binding!!.rechargeLL.setOnClickListener { changeBottomState(Tab.RECHARGE) }
}
@@ -153,8 +218,6 @@
}
}
-
-
//鐐瑰嚮涓ゆ閫�鍑虹▼搴� 鏈夋椂闂撮棿闅� 闂撮殧鍐呯偣鍑诲垯閫�鍑虹▼搴� 鍚﹀垯 鍒欐彁绀�
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK) {
@@ -169,6 +232,4 @@
}
return super.onKeyDown(keyCode, event)
}
-
-
}
\ No newline at end of file
--
Gitblit v1.8.0