From e98e5ebf6a786a778249e09028782f90fd601f92 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期五, 14 三月 2025 16:07:33 +0800
Subject: [PATCH] fix: 1

---
 app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt |   46 +++++++++
 app/src/main/res/layout/fragment_home.xml                      |  196 +++++++++++++++++++++++++++------------
 app/src/main/res/values/colors.xml                             |    3 
 3 files changed, 184 insertions(+), 61 deletions(-)

diff --git a/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt b/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
index be80342..b272afa 100644
--- a/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
+++ b/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
@@ -52,6 +52,7 @@
 
         //调用这个方法来设置 RecyclerView用于设置 RecyclerView 的布局和适配器。
         setupRecyclerViews()
+        setupTabSwitching()
         //调用这个方法来观察 ViewModel 中的数据变化
         observeViewModelData()
     }
@@ -102,6 +103,51 @@
 //        }
     }
 
+    private fun setupTabSwitching() {
+        binding.apply {
+            // 设置初始状态
+            tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected))
+            tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+            others.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+            
+            // 快递标签点击事件
+            tabExpress.setOnClickListener {
+                expressContent.visibility = View.VISIBLE
+                financeContent.visibility = View.GONE
+                tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected))
+                tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+                others.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+                tabExpress.textSize = 16f
+                tabFinance.textSize = 14f
+                others.textSize = 14f
+            }
+            
+            // 财务标签点击事件
+            tabFinance.setOnClickListener {
+                expressContent.visibility = View.GONE
+                financeContent.visibility = View.VISIBLE
+                tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+                tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected))
+                others.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+                tabExpress.textSize = 14f
+                tabFinance.textSize = 16f
+                others.textSize = 14f
+            }
+
+            // 其他标签点击事件
+            others.setOnClickListener {
+                expressContent.visibility = View.GONE
+                financeContent.visibility = View.GONE
+                tabExpress.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+                tabFinance.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
+                others.setTextColor(ContextCompat.getColor(requireContext(), R.color.tab_selected))
+                tabExpress.textSize = 14f
+                tabFinance.textSize = 14f
+                others.textSize = 16f
+            }
+        }
+    }
+
     //这个方法用于观察 homeViewModel 中的 expressItems 数据。
     private fun observeViewModelData() {
         //当 expressItems 数据发生变化时,更新 RecyclerView 的数据。
diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
index 87907ab..5df2603 100644
--- a/app/src/main/res/layout/fragment_home.xml
+++ b/app/src/main/res/layout/fragment_home.xml
@@ -13,99 +13,173 @@
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="vertical"
-        android:padding="16dp">
+        android:orientation="vertical">
 
-        <!-- 我的快递板块 -->
+        <!-- 顶部广告位 -->
         <androidx.cardview.widget.CardView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginBottom="16dp"
             app:cardCornerRadius="8dp"
             app:cardElevation="2dp">
+            
+            <ImageView
+                android:id="@+id/adBanner"
+                android:layout_width="match_parent"
+                android:layout_height="80dp"
+                android:scaleType="centerCrop"/>
+        </androidx.cardview.widget.CardView>
 
-            <LinearLayout
+        <!-- 快递/财务切换区域 -->
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            android:layout_marginBottom="8dp">
+
+            <TextView
+                android:id="@+id/tabExpress"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:text="快递"
+                android:gravity="center"
+                android:padding="8dp"
+                android:textSize="16sp"
+                android:textStyle="bold"/>
+
+            <TextView
+                android:id="@+id/tabFinance"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:text="财务"
+                android:gravity="center"
+                android:padding="8dp"
+                android:textSize="16sp"/>
+
+            <TextView
+                android:id="@+id/others"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:text="其他"
+                android:gravity="center"
+                android:padding="8dp"
+                android:textSize="16sp"/>
+        </LinearLayout>
+
+        <!-- 内容区域 -->
+        <FrameLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="16dp">
+
+            <!-- 快递内容 -->
+            <androidx.cardview.widget.CardView
+                android:id="@+id/expressContent"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:orientation="vertical">
-                <TextView
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:text="我的快递"
-                    android:textColor="#333333"
-                    android:textSize="16sp"
-                    android:textStyle="bold"/>
+                app:cardBackgroundColor="@color/light_blue_50"
+                app:cardCornerRadius="8dp"
+                app:cardElevation="0dp">
 
                 <androidx.recyclerview.widget.RecyclerView
                     android:id="@+id/express_recycler"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:layout_marginTop="8dp" />
+                    android:padding="8dp"/>
 
+            </androidx.cardview.widget.CardView>
 
-            </LinearLayout>
-        </androidx.cardview.widget.CardView>
-
-        <!-- 我的财务板块 -->
-        <androidx.cardview.widget.CardView
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginBottom="16dp"
-            app:cardCornerRadius="8dp"
-            app:cardElevation="2dp">
-
-            <LinearLayout
+            <!-- 财务内容 -->
+            <androidx.cardview.widget.CardView
+                android:id="@+id/financeContent"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:orientation="vertical"
-                android:padding="16dp"
-                android:background="#E8F5E9">
+                app:cardBackgroundColor="@color/light_blue_50"
+                app:cardCornerRadius="8dp"
+                app:cardElevation="0dp">
 
                 <androidx.recyclerview.widget.RecyclerView
                     android:id="@+id/finance_recycler"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:layout_marginTop="8dp"/>
+                    android:padding="8dp"/>
 
-                <TextView
-                    android:layout_width="wrap_content"
+                <LinearLayout
+                    android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:text="我的财务"
-                    android:textColor="#333333"
-                    android:textSize="16sp"
-                    android:textStyle="bold"/>
-            </LinearLayout>
-        </androidx.cardview.widget.CardView>
+                    android:orientation="vertical"
+                    android:padding="16dp">
 
-        <!-- 纪念日板块 -->
+                    <!-- 花呗还款 -->
+                    <TextView
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:text="花呗"
+                        android:textSize="16sp"
+                        android:textStyle="bold"
+                        android:layout_marginBottom="8dp"/>
+
+                    <TextView
+                        android:id="@+id/huabeiAmount"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:text="230,721 元"
+                        android:textSize="24sp"
+                        android:textColor="#FF5722"
+                        android:layout_marginBottom="4dp"/>
+
+                    <TextView
+                        android:id="@+id/huabeiDueDate"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:text="提醒您2025.01.14 还款"
+                        android:textSize="14sp"
+                        android:layout_marginBottom="16dp"/>
+
+                    <!-- 信用卡还款 -->
+                    <TextView
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:text="中国银行信用卡"
+                        android:textSize="16sp"
+                        android:textStyle="bold"
+                        android:layout_marginBottom="8dp"/>
+
+                    <TextView
+                        android:id="@+id/creditCardAmount"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:text="310,621 元"
+                        android:textSize="24sp"
+                        android:textColor="#FF5722"
+                        android:layout_marginBottom="4dp"/>
+
+                    <TextView
+                        android:id="@+id/creditCardDueDate"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:text="提醒您2025.02.10 还款"
+                        android:textSize="14sp"/>
+
+                </LinearLayout>
+            </androidx.cardview.widget.CardView>
+
+        </FrameLayout>
+
+        <!-- 底部广告位 -->
         <androidx.cardview.widget.CardView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginBottom="16dp"
             app:cardCornerRadius="8dp"
             app:cardElevation="2dp">
-
-            <LinearLayout
+            
+            <ImageView
+                android:id="@+id/bottomAdBanner"
                 android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="vertical"
-                android:padding="16dp"
-                android:background="#FFF3E0">
-
-                <androidx.recyclerview.widget.RecyclerView
-                    android:id="@+id/memorial_recycler"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:layout_marginTop="8dp"/>
-
-                <TextView
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:text="纪念日"
-                    android:textColor="#333333"
-                    android:textSize="16sp"
-                    android:textStyle="bold"/>
-            </LinearLayout>
+                android:layout_height="80dp"
+                android:scaleType="centerCrop"/>
         </androidx.cardview.widget.CardView>
 
     </LinearLayout>
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 426ac4e..8581b0b 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -12,4 +12,7 @@
     <color name="light_blue_A200">#FF40C4FF</color>
     <color name="light_blue_A400">#FF00B0FF</color>
     <color name="black_overlay">#66000000</color>
+    <color name="gray">#757575</color>
+    <color name="light_blue_50">#E1F5FE</color>
+    <color name="tab_selected">#FF039BE5</color>
 </resources>
\ No newline at end of file

--
Gitblit v1.9.3