From 55b196ea2e28a8d859c85326f2147a4f7b7196de Mon Sep 17 00:00:00 2001
From: zuojincheng <lf_zuo@163.com>
Date: 星期四, 10 四月 2025 10:58:32 +0800
Subject: [PATCH] feat(general): 新增开卡信息保存功能并优化界面布局- 新增 CardRegistrationBean 数据模型用于保存开卡信息 - 在数据库中添加 card_registration 表用于存储开卡记录 - 优化 NewCard2Activity 界面布局,调整样式和间距 - 添加协程支持,实现异步保存开卡信息到数据库 - 更新颜色配置,统一使用新加的 base_blue_bg 和 base_green_bg颜色
---
generallibrary/src/main/java/com/dayu/general/activity/NewCard2Activity.kt | 41 ++++++++-
baselibrary/src/main/res/values/colors.xml | 5 +
generallibrary/src/main/res/layout/activity_new_card_1_ge.xml | 73 +++++++++---------
generallibrary/src/main/java/com/dayu/general/dao/AppDataBase.kt | 4
generallibrary/src/main/java/com/dayu/general/dao/BaseDaoSingleton.kt | 27 +++---
generallibrary/src/main/res/values/colors.xml | 2
generallibrary/src/main/java/com/dayu/general/dao/CardRegistrationDao.kt | 31 +++++++
generallibrary/src/main/java/com/dayu/general/bean/db/CardRegistrationBean.kt | 21 +++++
8 files changed, 145 insertions(+), 59 deletions(-)
diff --git a/baselibrary/src/main/res/values/colors.xml b/baselibrary/src/main/res/values/colors.xml
index af528ef..5e9e7d3 100644
--- a/baselibrary/src/main/res/values/colors.xml
+++ b/baselibrary/src/main/res/values/colors.xml
@@ -14,7 +14,10 @@
<color name="colorBackground">#FFFFFF</color>
<!--鍏叡鏍囬-->
- <color name="title_bg">#009ad6</color>
+ <color name="base_blue_bg">#009ad6</color>
+ <color name="base_green_bg">#e6e6e6</color>
+
+ <color name="title_bg">@color/base_blue_bg</color>
<color name="main_bg">#F0F0F0</color>
<color name="select_title_text">#B0B0B0</color>
diff --git a/generallibrary/src/main/java/com/dayu/general/activity/NewCard2Activity.kt b/generallibrary/src/main/java/com/dayu/general/activity/NewCard2Activity.kt
index 9ab0d3d..55330fd 100644
--- a/generallibrary/src/main/java/com/dayu/general/activity/NewCard2Activity.kt
+++ b/generallibrary/src/main/java/com/dayu/general/activity/NewCard2Activity.kt
@@ -6,14 +6,18 @@
import android.text.TextWatcher
import android.view.View
import android.widget.Toast
+import androidx.lifecycle.lifecycleScope
import com.dayu.baselibrary.net.subscribers.SubscriberListener
import com.dayu.baselibrary.view.TitleBar.ClickType_LEFT_IMAGE
import com.dayu.general.BaseApplication
import com.dayu.general.R
+import com.dayu.general.bean.db.CardRegistrationBean
+import com.dayu.general.dao.BaseDaoSingleton
import com.dayu.general.databinding.ActivityNewCard1GeBinding
import com.dayu.general.net.ApiManager
import com.dayu.general.net.BaseResponse
import com.dayu.general.tool.NfcReadHelper
+import kotlinx.coroutines.launch
/**
* Description: 鐢ㄦ埛寮�鍗$晫闈�
@@ -167,10 +171,30 @@
object : SubscriberListener<BaseResponse<String>>() {
override fun onNext(response: BaseResponse<String>) {
if (response.success) {
- // 婵�娲绘垚鍔�
- Toast.makeText(this@NewCard2Activity, "寮�鍗℃垚鍔�", Toast.LENGTH_SHORT).show()
- setResult(RESULT_OK)
- finish()
+ // 淇濆瓨寮�鍗′俊鎭埌鏁版嵁搴�
+ val cardRegistration = CardRegistrationBean(
+ cardNumber = cardPhysicalId,
+ userName = binding.newCardUserName.text.toString(),
+ idCard = binding.newCardIdCard.text.toString(),
+ farmerCode = binding.newCardFarmerCode.text.toString(),
+ cardFee = cardFee,
+ remark = binding.newCardRemark.text.toString(),
+ paymentMethod = paymentId,
+ isReported = true,
+ isCardWritten = true
+ )
+
+ // 浣跨敤鍗忕▼鍦ㄥ悗鍙扮嚎绋嬩腑淇濆瓨鏁版嵁
+ lifecycleScope.launch {
+ try {
+ BaseDaoSingleton.getInstance(this@NewCard2Activity).cardRegistrationDao().insert(cardRegistration)
+ Toast.makeText(this@NewCard2Activity, "寮�鍗℃垚鍔�", Toast.LENGTH_SHORT).show()
+ setResult(RESULT_OK)
+ finish()
+ } catch (e: Exception) {
+ Toast.makeText(this@NewCard2Activity, "淇濆瓨寮�鍗′俊鎭け璐�: ${e.message}", Toast.LENGTH_SHORT).show()
+ }
+ }
} else {
// 婵�娲诲け璐�
Toast.makeText(
@@ -215,10 +239,15 @@
binding.newCardArerNumber.text = cardNumber
// 闅愯棌NFC璇诲崱鐣岄潰
binding.nfcContainer.visibility = View.GONE
-
- Toast.makeText(this, "璇诲崱鎴愬姛", Toast.LENGTH_SHORT).show()
+ binding.centerScroll.visibility = View.VISIBLE
+ binding.newCardRegistBtn.visibility = View.VISIBLE
}
}
+
+
+
+
+
}
\ No newline at end of file
diff --git a/generallibrary/src/main/java/com/dayu/general/bean/db/CardRegistrationBean.kt b/generallibrary/src/main/java/com/dayu/general/bean/db/CardRegistrationBean.kt
new file mode 100644
index 0000000..e758469
--- /dev/null
+++ b/generallibrary/src/main/java/com/dayu/general/bean/db/CardRegistrationBean.kt
@@ -0,0 +1,21 @@
+package com.dayu.general.bean.db
+
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName = "card_registration")
+data class CardRegistrationBean(
+ @PrimaryKey(autoGenerate = true)
+ val id: Long = 0,
+ val cardNumber: String, // IC鍗″崱鍙�
+ val userName: String, // 濮撳悕
+ val idCard: String, // 韬唤璇佸彿
+ val farmerCode: String, // 鍐滄埛缂栧彿
+ val cardFee: Double, // 宸ユ湰璐�
+ val remark: String, // 澶囨敞
+ val paymentMethod: Int, // 鏀粯鏂瑰紡
+ val orderId: String? = null, // 璁㈠崟id锛屽垵濮嬩负null锛屽悗缁洿鏂�
+ val isReported: Boolean = false, // 鏄惁涓婃姤鎴愬姛
+ val isCardWritten: Boolean = false, // 鏄惁鍐欏崱鎴愬姛
+ val createTime: Long = System.currentTimeMillis() // 鍒涘缓鏃堕棿
+)
\ No newline at end of file
diff --git a/generallibrary/src/main/java/com/dayu/general/dao/AppDataBase.kt b/generallibrary/src/main/java/com/dayu/general/dao/AppDataBase.kt
index b76c767..a8de4ec 100644
--- a/generallibrary/src/main/java/com/dayu/general/dao/AppDataBase.kt
+++ b/generallibrary/src/main/java/com/dayu/general/dao/AppDataBase.kt
@@ -3,11 +3,13 @@
import androidx.room.Database
import androidx.room.RoomDatabase
import com.dayu.general.bean.db.CardData
+import com.dayu.general.bean.db.CardRegistrationBean
import com.dayu.general.bean.db.PassWordCardBean
import com.dayu.general.bean.db.ProjectDataBean
-@Database(entities = [PassWordCardBean::class, CardData::class, ProjectDataBean::class], version = 1, exportSchema = false)
+@Database(entities = [PassWordCardBean::class, CardData::class, ProjectDataBean::class, CardRegistrationBean::class], version = 2, exportSchema = false)
abstract class AppDataBase : RoomDatabase() {
abstract fun cardDataDao(): CardDataDao
abstract fun projectDataDao(): ProjectDataDao
+ abstract fun cardRegistrationDao(): CardRegistrationDao
}
\ No newline at end of file
diff --git a/generallibrary/src/main/java/com/dayu/general/dao/BaseDaoSingleton.kt b/generallibrary/src/main/java/com/dayu/general/dao/BaseDaoSingleton.kt
index 1bcc754..9ed72b7 100644
--- a/generallibrary/src/main/java/com/dayu/general/dao/BaseDaoSingleton.kt
+++ b/generallibrary/src/main/java/com/dayu/general/dao/BaseDaoSingleton.kt
@@ -10,6 +10,7 @@
companion object {
var baseDao: AppDataBase? = null
+ var AsynchBaseDao: AppDataBase? = null
@JvmField
val SqlitePath: String =
Environment.getExternalStorageDirectory().absolutePath + File.separator + ".dayu" + File.separator + "data" + File.separator
@@ -23,22 +24,22 @@
}
return baseDao as AppDataBase
}
-
- }
-
- var AsynchBaseDao: AppDataBase? = null
-
- fun getAsynchInstance(context: Context?): AppDataBase? {
- if (AsynchBaseDao == null) {
- AsynchBaseDao = Room.databaseBuilder<AppDataBase>(
- context!!,
- AppDataBase::class.java,
- SqlitePath + "ConfigurationData_generalV1"
- ).build()
+ fun getAsynchInstance(context: Context?): AppDataBase? {
+ if (AsynchBaseDao == null) {
+ AsynchBaseDao = Room.databaseBuilder<AppDataBase>(
+ context!!,
+ AppDataBase::class.java,
+ SqlitePath + "ConfigurationData_generalV1"
+ ).build()
+ }
+ return AsynchBaseDao
}
- return AsynchBaseDao
}
+
+
+
+
// companion object {
// fun getAsynchInstance(baseActivity: BaseActivity): AppDataBase? {
// return getAsynchInstance(baseActivity)
diff --git a/generallibrary/src/main/java/com/dayu/general/dao/CardRegistrationDao.kt b/generallibrary/src/main/java/com/dayu/general/dao/CardRegistrationDao.kt
new file mode 100644
index 0000000..959e232
--- /dev/null
+++ b/generallibrary/src/main/java/com/dayu/general/dao/CardRegistrationDao.kt
@@ -0,0 +1,31 @@
+package com.dayu.general.dao
+
+import androidx.room.*
+import com.dayu.general.bean.db.CardRegistrationBean
+
+@Dao
+interface CardRegistrationDao {
+ @Insert
+ suspend fun insert(cardRegistration: CardRegistrationBean): Long
+
+ @Update
+ suspend fun update(cardRegistration: CardRegistrationBean)
+
+ @Delete
+ suspend fun delete(cardRegistration: CardRegistrationBean)
+
+ @Query("SELECT * FROM card_registration WHERE cardNumber = :cardNumber")
+ suspend fun getByCardNumber(cardNumber: String): CardRegistrationBean?
+
+ @Query("SELECT * FROM card_registration WHERE orderId = :orderId")
+ suspend fun getByOrderId(orderId: String): CardRegistrationBean?
+
+ @Query("SELECT * FROM card_registration WHERE isReported = 0")
+ suspend fun getUnreportedCards(): List<CardRegistrationBean>
+
+ @Query("SELECT * FROM card_registration WHERE isCardWritten = 0")
+ suspend fun getUnwrittenCards(): List<CardRegistrationBean>
+
+ @Query("SELECT * FROM card_registration ORDER BY createTime DESC")
+ suspend fun getAllCards(): List<CardRegistrationBean>
+}
\ No newline at end of file
diff --git a/generallibrary/src/main/res/layout/activity_new_card_1_ge.xml b/generallibrary/src/main/res/layout/activity_new_card_1_ge.xml
index 0fdbd92..adba47f 100644
--- a/generallibrary/src/main/res/layout/activity_new_card_1_ge.xml
+++ b/generallibrary/src/main/res/layout/activity_new_card_1_ge.xml
@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="#F5F7FA">
+ android:background="@color/base_list_bg">
<com.dayu.baselibrary.view.TitleBar
android:id="@+id/titleBar"
@@ -79,24 +79,28 @@
</androidx.cardview.widget.CardView>
<ScrollView
+ android:id="@+id/center_scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:scrollbars="none"
- android:visibility="gone"
- app:layout_constraintBottom_toTopOf="@+id/newCard_registBtn"
+ android:visibility="visible"
+ app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/titleBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:padding="16dp">
+ android:paddingBottom="16dp"
+ android:paddingLeft="16dp"
+ android:paddingRight="16dp"
+ android:paddingTop="10dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
+ android:layout_marginBottom="10dp"
app:cardCornerRadius="8dp"
app:cardElevation="2dp">
@@ -110,7 +114,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
+ android:layout_marginBottom="10dp"
android:text="鍩烘湰淇℃伅"
android:textColor="#333333"
android:textSize="18sp"
@@ -119,12 +123,12 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="12dp"
+ android:layout_marginBottom="6dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
- android:layout_width="120dp"
+ android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="鍗″彿锛�"
android:textColor="#666666"
@@ -142,12 +146,12 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="12dp"
+ android:layout_marginBottom="6dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
- android:layout_width="120dp"
+ android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="濮撳悕锛�"
android:textColor="#666666"
@@ -165,12 +169,12 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="12dp"
+ android:layout_marginBottom="6dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
- android:layout_width="120dp"
+ android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="韬唤璇佸彿锛�"
android:textColor="#666666"
@@ -188,12 +192,12 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="12dp"
+ android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
- android:layout_width="120dp"
+ android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="鍐滄埛缂栧彿锛�"
android:textColor="#666666"
@@ -213,7 +217,7 @@
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
+ android:layout_marginBottom="10dp"
app:cardCornerRadius="8dp"
app:cardElevation="2dp">
@@ -226,7 +230,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
+ android:layout_marginBottom="10dp"
android:text="璐圭敤淇℃伅"
android:textColor="#333333"
android:textSize="18sp"
@@ -240,7 +244,7 @@
android:orientation="horizontal">
<TextView
- android:layout_width="120dp"
+ android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="宸ユ湰璐癸細"
android:textColor="#666666"
@@ -259,7 +263,6 @@
android:background="@null"
android:hint="璇疯緭鍏ュ伐鏈垂(閫夊~)"
android:inputType="numberDecimal"
- android:padding="12dp"
android:textColor="#333333"
android:textSize="@dimen/new_card_size" />
</LinearLayout>
@@ -273,7 +276,7 @@
android:orientation="horizontal">
<TextView
- android:layout_width="120dp"
+ android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="鍏呭�奸噾棰濓細"
android:textColor="#666666"
@@ -292,7 +295,6 @@
android:background="@null"
android:hint="璇疯緭鍏ュ厖鍊奸噾棰�(閫夊~)"
android:inputType="numberDecimal"
- android:padding="12dp"
android:textColor="#333333"
android:textSize="@dimen/new_card_size" />
</LinearLayout>
@@ -302,12 +304,12 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="12dp"
+ android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
- android:layout_width="120dp"
+ android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="澶囨敞锛�"
android:textColor="#666666"
@@ -325,7 +327,6 @@
android:layout_height="wrap_content"
android:background="@null"
android:hint="璇疯緭鍏ュ娉�(閫夊~)"
- android:padding="12dp"
android:textColor="#333333"
android:textSize="@dimen/new_card_size" />
</LinearLayout>
@@ -348,7 +349,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
+ android:layout_marginBottom="10dp"
android:text="鏀粯鏂瑰紡"
android:textColor="#333333"
android:textSize="18sp"
@@ -404,20 +405,18 @@
</RadioGroup>
</LinearLayout>
</androidx.cardview.widget.CardView>
+ <TextView
+ android:id="@+id/newCard_registBtn"
+ android:layout_width="match_parent"
+ android:layout_height="56dp"
+ android:layout_marginTop="15dp"
+ android:background="@color/bottom_color"
+ android:visibility="visible"
+ android:gravity="center"
+ android:text="纭寮�鍗�"
+ android:textColor="#FFFFFF"
+ android:textSize="16sp" />
</LinearLayout>
</ScrollView>
-
- <TextView
- android:id="@+id/newCard_registBtn"
- android:layout_width="match_parent"
- android:layout_height="56dp"
- android:layout_margin="16dp"
- android:background="#4285F4"
- android:visibility="gone"
- android:gravity="center"
- android:text="纭寮�鍗�"
- android:textColor="#FFFFFF"
- android:textSize="16sp"
- app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/generallibrary/src/main/res/values/colors.xml b/generallibrary/src/main/res/values/colors.xml
index b34be43..4b52ad5 100644
--- a/generallibrary/src/main/res/values/colors.xml
+++ b/generallibrary/src/main/res/values/colors.xml
@@ -4,7 +4,7 @@
<color name="black">#333</color>
<color name="white">#fff</color>
<color name="nav_item_color">#555555</color>
- <color name="base_list_bg">#e6e6e6</color>
+ <color name="base_list_bg">@color/base_green_bg</color>
<color name="green">#32CD32</color>
<color name="blue">#007BFF</color>
<color name="grey">#808080</color>
--
Gitblit v1.8.0