cloudroam
2025-03-24 380d70f2f1cd03b314fa6de64df30eab914956ba
fix 324 免登陆,删除ActionBar
已修改7个文件
已添加2个文件
100 ■■■■■ 文件已修改
app/build.gradle 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/MainActivity.kt 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/ui/login/LoginViewModel.kt 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/drawable/down.png 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/drawable/up.jpg 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/fragment_home.xml 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values-night/themes.xml 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values/themes.xml 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/build.gradle
@@ -273,4 +273,8 @@
    //图形化
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    //添加了 Glide 依赖
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
app/src/main/java/com/example/firstapp/MainActivity.kt
@@ -91,14 +91,7 @@
        val navView = binding.navView
        val navController = findNavController(R.id.nav_host_fragment_activity_main)
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        val appBarConfiguration = AppBarConfiguration(
            setOf(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
            )
        )
        setupActionBarWithNavController(navController, appBarConfiguration)
        // 只保留底部导航的设置
        navView.setupWithNavController(navController)
        // 检查权限
@@ -144,10 +137,7 @@
//        }, filter)
    }
    override fun onSupportNavigateUp(): Boolean {
        val navController = findNavController(R.id.nav_host_fragment_activity_main)
        return navController.navigateUp() || super.onSupportNavigateUp()
    }
    private fun registerSmsReceiver() {
//        应用启动时执行 registerSmsReceiver()
//        创建 SmsReceiver 实例
app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
@@ -14,6 +14,7 @@
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.firstapp.R
import com.example.firstapp.activity.PickupActivity
import com.example.firstapp.adapter.ExpressAdapter
@@ -50,7 +51,8 @@
        //通过 ViewModelProvider 获取 HomeViewModel 的实例,以便在视图中使用。
        homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)
        // 加载广告图片
        //loadAdvertisements()
        //调用这个方法来设置 RecyclerView用于设置 RecyclerView 的布局和适配器。
        setupRecyclerViews()
        setupTabSwitching()
@@ -210,4 +212,15 @@
        super.onDestroyView()
        _binding = null
    }
    private fun loadAdvertisements() {
        // 使用 Glide 加载网络图片
        Glide.with(this)
            .load("http://192.168.1.235:9999/advertisement/up.png")
            .into(binding.adBanner)
        Glide.with(this)
            .load("http://192.168.1.235:9999/advertisement/down.png")
            .into(binding.bottomAdBanner)
    }
}
app/src/main/java/com/example/firstapp/ui/login/LoginViewModel.kt
@@ -23,12 +23,12 @@
        viewModelScope.launch {
            _isLoading.value = true
            try {
                val response = RetrofitClient.apiService.sendVerificationCode(phone)
                if (response.code == 200) {
//                val response = RetrofitClient.apiService.sendVerificationCode(phone)
//                if (response.code == 200) {
                    _loginMessage.value = "验证码已发送"
                } else {
                    _loginMessage.value = response.msg.ifEmpty { "发送验证码失败" }
                }
//                } else {
//                    _loginMessage.value = response.msg.ifEmpty { "发送验证码失败" }
//                }
            } catch (e: Exception) {
                Log.e("LoginError", "Login failed: ${e.message}", e)
                _loginMessage.value = "网络错误,请稍后重试"
@@ -42,12 +42,12 @@
        viewModelScope.launch {
            _isLoading.value = true
            try {
                val response = RetrofitClient.apiService.verifyCode(phone, code)
                if (response.code == 200 && response.data) {
//                val response = RetrofitClient.apiService.verifyCode(phone, code)
//                if (response.code == 200 && response.data) {
                    _loginState.value = true
                } else {
                    _loginMessage.value = response.msg.ifEmpty { "登录失败" }
                }
//                } else {
//                    _loginMessage.value = response.msg.ifEmpty { "登录失败" }
//                }
            } catch (e: Exception) {
                Log.e("LoginError", "Login failed: ${e.message}", e)
                _loginMessage.value = "网络错误,请稍后重试"
app/src/main/res/drawable/down.png
app/src/main/res/drawable/up.jpg
app/src/main/res/layout/fragment_home.xml
@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="80dp"> <!-- 留出顶部广告位的高度 -->
    >
<!--    LinearLayout的作用是按照垂直或者水平方向排列其子视图-->
<!--    CardView组件是用于实现卡片式布局-->
@@ -15,19 +22,7 @@
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <!-- 顶部广告位 -->
        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            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
@@ -126,3 +121,19 @@
    </LinearLayout>
</ScrollView>
    <!-- 顶部广告位 -->
    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       >
        <ImageView
            android:id="@+id/adBanner"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:scaleType="centerCrop"
            android:src="@drawable/up"/>
    </androidx.cardview.widget.CardView>
</FrameLayout>
app/src/main/res/values-night/themes.xml
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.FirstApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <style name="Theme.FirstApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_200</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
@@ -11,6 +11,9 @@
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
        <!-- 确保没有ActionBar -->
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <!-- Customize your theme here. -->
    </style>
app/src/main/res/values/themes.xml
@@ -1,7 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <!--    <style name="Theme.FirstApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">-->
    <style name="Theme.FirstApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <style name="Theme.FirstApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/light_blue_new</item>
        <item name="colorPrimaryVariant">@color/light_blue_new</item>
@@ -12,6 +12,9 @@
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
        <!-- 确保没有ActionBar -->
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <!-- Customize your theme here. -->
    </style>