已修改10个文件
已添加3个文件
681 ■■■■ 文件已修改
app/src/main/java/com/example/firstapp/MainActivity.kt 266 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/activity/LoginActivity.kt 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/activity/SettingActivity.kt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/adapter/InvitationRecord2Adapter.kt 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/entity/InvitationRecord.kt 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/receiver/SmsReceiver.kt 131 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/ui/home/HomeViewModel.kt 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/ui/invitation/InvitationActivity.kt 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/drawable/bg_invitation_record.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_invitation_main.xml 70 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/item_invitation_record.xml 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values/styles.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/MainActivity.kt
@@ -33,6 +33,7 @@
import java.util.Date
import java.util.Locale
import android.app.AlertDialog
import com.example.firstapp.utils.CodeUtils
class MainActivity : AppCompatActivity() {
    // 安全防护关键词数组
@@ -286,12 +287,6 @@
                    val msg = Msg(0, "1111", "111111", messageBody, 1, "111", 1, 1)
                    val msgId = Core.msg.insert(msg)
                    // 禁用关键词拦截
//                    if (securityKeywordsList.any { it in messageBody }) {
//                        android.util.Log.d("MainActivity", "历史短信含有禁用关键词,跳过处理")
//                        continue
//                    }
                    // 使用协程处理API调用和数据库操作
                    CoroutineScope(Dispatchers.IO).launch {
                        try {
@@ -302,224 +297,71 @@
                                if (response.status == "success") {
                                    when (response.data.category) {
                                        "快递" -> {
                                            val pickupCode = response.data.details.pickupCode ?: ""
                                            if (pickupCode.isNotEmpty()) {
                                                val existingCode =
                                                    Core.code.queryByTypeAndCodeAndDate(
                                                        response.data.category,
                                                        pickupCode,
                                                        dateString
                                                    )
                                                if (existingCode == null) {
                                                    val code = Code(
                                                        id = 0,
                                                        category = response.data.category,
                                                        categoryId = 1,
                                                        typeId = 1,
                                                        ruleId = 1,
                                                        msgId = msgId,
                                                        createTime = dateString,
                                                        oneLevel = response.data.details.post ?: "",
                                                        secondLevel = response.data.details.company
                                                            ?: "未知",
                                                        code = pickupCode,
                                                        pickup = 0,
                                                        pickupTime = "",
                                                        overTime = "",
                                                        address = response.data.details.address
                                                            ?: "",
                                                        remarks = response.data.details.time ?: "",
                                                    )
//                                                    if(code.oneLevel.isNotEmpty() && code.secondLevel.isNotEmpty() && code.code.isNotEmpty()) {
                                                    if (code.oneLevel.isNotEmpty() && code.code.isNotEmpty()) {
                                                        Core.code.insert(code)
                                                        android.util.Log.d(
                                                            "MainActivity",
                                                            "历史快递短信已保存: $pickupCode"
                                                        )
                                                    }
                                                } else {
                                                    android.util.Log.d(
                                                        "MainActivity",
                                                        "发现重复快递短信,跳过保存: $pickupCode"
                                                    )
                                                }
                                            }
                                            val code = CodeUtils.createExpressCode(
                                                msgId = msgId,
                                                createTime = dateString,
                                                post = response.data.details.post,
                                                company = response.data.details.company,
                                                pickupCode = response.data.details.pickupCode,
                                                address = response.data.details.address,
                                                time = response.data.details.time
                                            )
                                            CodeUtils.saveCode(code)
                                        }
                                        "还款" -> {
                                            val amount = response.data.details.amount ?: ""
                                            if (amount.isNotEmpty()) {
                                                val existingCode =
                                                    Core.code.queryByTypeAndCodeAndDate(
                                                        response.data.category, amount, dateString
                                                    )
                                                if (existingCode == null) {
                                                    val code = Code(
                                                        id = 0,
                                                        category = response.data.category,
                                                        categoryId = 2,
                                                        typeId = 1,
                                                        ruleId = 2,
                                                        msgId = msgId,
                                                        createTime = dateString,
                                                        oneLevel = response.data.details.type ?: "",
                                                        secondLevel = response.data.details.bank
                                                            ?: "未知",
                                                        code = amount,
                                                        pickup = 0,
                                                        pickupTime = "",
                                                        overTime = response.data.details.date ?: "",
                                                        address = response.data.details.address
                                                            ?: "",
                                                        remarks = "最小还款金额${response.data.details.min_amount}还款卡号${response.data.details.number}"
                                                    )
                                                    if (code.oneLevel.isNotEmpty() && code.secondLevel.isNotEmpty() && code.code.isNotEmpty()) {
                                                        Core.code.insert(code)
                                                        android.util.Log.d(
                                                            "MainActivity",
                                                            "历史还款短信已保存: $amount"
                                                        )
                                                    }
                                                } else {
                                                    android.util.Log.d(
                                                        "MainActivity",
                                                        "发现重复还款短信,跳过保存: $amount"
                                                    )
                                                }
                                            }
                                            val code = CodeUtils.createRepaymentCode(
                                                msgId = msgId,
                                                createTime = dateString,
                                                type = response.data.details.type,
                                                bank = response.data.details.bank,
                                                amount = response.data.details.amount,
                                                date = response.data.details.date,
                                                address = response.data.details.address,
                                                minAmount = response.data.details.min_amount,
                                                number = response.data.details.number
                                            )
                                            CodeUtils.saveCode(code)
                                        }
                                        "收入" -> {
                                            val amount = response.data.details.amount ?: ""
                                            if (amount.isNotEmpty()) {
                                                val existingCode =
                                                    Core.code.queryByTypeAndCodeAndDate(
                                                        response.data.category, amount, dateString
                                                    )
                                                if (existingCode == null) {
                                                    val code = Code(
                                                        id = 0,
                                                        category = response.data.category,
                                                        categoryId = 3, // 3-收入类型
                                                        typeId = 1,     //暂时没有根据type分类
                                                        ruleId = 2,     //1-还款类型
                                                        msgId = msgId,
                                                        createTime = dateString,
                                                        oneLevel = response.data.details.bank ?: "",
                                                        secondLevel = response.data.details.bank
                                                            ?: "未知",
                                                        code = amount,
                                                        pickup = 0, // 0-未取件,1-已取件
                                                        pickupTime = "", // 取件时间为空
                                                        overTime = response.data.details.datetime
                                                            ?: "",  // 超时时间为空,暂时没有这块处理逻辑
                                                        address = response.data.details.address
                                                            ?: "",
                                                        remarks = "余额" + response.data.details.balance
                                                            ?: "",
                                                    )
                                                    if (code.oneLevel.isNotEmpty() && code.secondLevel.isNotEmpty() && code.code.isNotEmpty()) {
                                                        Core.code.insert(code)
                                                        android.util.Log.d(
                                                            "MainActivity",
                                                            "历史还款短信已保存: $amount"
                                                        )
                                                    }
                                                } else {
                                                    android.util.Log.d(
                                                        "MainActivity",
                                                        "发现重复还款短信,跳过保存: $amount"
                                                    )
                                                }
                                            }
                                            val code = CodeUtils.createIncomeCode(
                                                msgId = msgId,
                                                createTime = dateString,
                                                bank = response.data.details.bank,
                                                amount = response.data.details.amount,
                                                datetime = response.data.details.datetime,
                                                address = response.data.details.address,
                                                balance = response.data.details.balance
                                            )
                                            CodeUtils.saveCode(code)
                                        }
                                        "航班" -> {
                                            val flight = response.data.details.flight ?: ""
                                            if (flight.isNotEmpty()) {
                                                val existingCode =
                                                    Core.code.queryByTypeAndCodeAndDate(
                                                        response.data.category, flight, dateString
                                                    )
                                                if (existingCode == null) {
                                                    val code = Code(
                                                        id = 0,
                                                        category = response.data.category,
                                                        categoryId = 4, // 4-航班类型
                                                        typeId = 1,     //暂时没有根据type分类
                                                        ruleId = 2,     //1-还款类型
                                                        msgId = msgId,
                                                        createTime = dateString,
                                                        oneLevel = response.data.details.company
                                                            ?: "未知",
                                                        secondLevel = response.data.details.start + response.data.details.end
                                                            ?: "",
                                                        code = flight,
                                                        pickup = 0, // 0-未取件,1-已取件
                                                        pickupTime = "", // 取件时间为空
                                                        overTime = response.data.details.time
                                                            ?: "",  // 超时时间为空,暂时没有这块处理逻辑
                                                        address = response.data.details.address
                                                            ?: "",
                                                        remarks = response.data.details.seat ?: "",
                                                    )
                                                    if (code.oneLevel != "" && code.secondLevel != "" && code.code != "") {
                                                        Core.code.insert(code)
                                                    }
                                                } else {
                                                    android.util.Log.d(
                                                        "MainActivity",
                                                        "发现重复还款短信,跳过保存: $flight"
                                                    )
                                                }
                                            }
                                            val code = CodeUtils.createFlightCode(
                                                msgId = msgId,
                                                createTime = dateString,
                                                company = response.data.details.company,
                                                start = response.data.details.start,
                                                end = response.data.details.end,
                                                seat = response.data.details.seat,
                                                time = response.data.details.time,
                                                address = response.data.details.address
                                            )
                                            CodeUtils.saveCode(code)
                                        }
                                        "火车票" -> {
                                            val seat = response.data.details.seat ?: ""
                                            if (seat.isNotEmpty()) {
                                                val existingCode =
                                                    Core.code.queryByTypeAndCodeAndDate(
                                                        response.data.category, seat, dateString
                                                    )
                                                if (existingCode == null) {
                                                    val code = Code(
                                                        id = 0,
                                                        category = response.data.category,
                                                        categoryId = 5, // 5-火车票类型
                                                        typeId = 1,     //暂时没有根据type分类
                                                        ruleId = 2,     //1-还款类型
                                                        msgId = msgId,
                                                        createTime = dateString,
                                                        oneLevel = response.data.details.company
                                                            ?: "",
                                                        secondLevel = response.data.details.company
                                                            ?: "未知",
                                                        code = seat,
                                                        pickup = 0, // 0-未取件,1-已取件
                                                        pickupTime = "", // 取件时间为空
                                                        overTime = response.data.details.time
                                                            ?: "",  // 超时时间为空,暂时没有这块处理逻辑
                                                        address = response.data.details.address
                                                            ?: "",
                                                        remarks = response.data.details.trips ?: "",
                                                    )
                                                    if (code.oneLevel != "" && code.secondLevel != "" && code.code != "") {
                                                        Core.code.insert(code)
                                                    }
                                                } else {
                                                    android.util.Log.d(
                                                        "MainActivity",
                                                        "发现重复还款短信,跳过保存: $seat"
                                                    )
                                                }
                                            }
                                            val code = CodeUtils.createTrainTicketCode(
                                                msgId = msgId,
                                                createTime = dateString,
                                                company = response.data.details.company,
                                                seat = response.data.details.seat,
                                                time = response.data.details.time,
                                                address = response.data.details.address,
                                                trips = response.data.details.trips
                                            )
                                            CodeUtils.saveCode(code)
                                        }
                                    }
app/src/main/java/com/example/firstapp/activity/LoginActivity.kt
@@ -15,25 +15,42 @@
import android.widget.Button
import android.widget.CheckBox
import android.widget.TextView
import androidx.activity.viewModels
import com.example.firstapp.MainActivity
import com.example.firstapp.R
import com.example.firstapp.databinding.ActivityLoginBinding
import com.example.firstapp.ui.login.LoginViewModel
import com.example.firstapp.utils.PreferencesManager
import kotlin.system.exitProcess
class LoginActivity : AppCompatActivity() {
    private lateinit var binding: ActivityLoginBinding
    private val viewModel: LoginViewModel by viewModels()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityLoginBinding.inflate(layoutInflater)
        setContentView(binding.root)
        setupViews()
        val phone=PreferencesManager.getLastLoginPhone()
        // 如果phone不存在则展示弹框
        if (phone.isNullOrEmpty()) {
            showConfirmDialog()
        // 这里查看是否已经登录过,如果已经登录过则直接跳转到主页
        // 获取token
        val token = PreferencesManager.getToken()
        if (!token.isNullOrEmpty()) {
            startActivity(Intent(this, MainActivity::class.java))
            finishAffinity() // 结束所有之前的Activity
        }else{
            setContentView(binding.root)
            setupViews()
            val phone=PreferencesManager.getLastLoginPhone()
            // 如果phone不存在则展示弹框
            if (phone.isNullOrEmpty()) {
                showConfirmDialog()
            }
        }
    }
    private fun setupViews() {
app/src/main/java/com/example/firstapp/activity/SettingActivity.kt
@@ -168,6 +168,7 @@
                lifecycleScope.launch {
                    try {
                        // 清除本地的数据库
                        RetrofitClient.apiService.closeAccount()
                        Core.code.deleteAll()
@@ -175,6 +176,9 @@
                        Core.keyword.deleteAll()
//                        Core.reminder.deleteAll()
                        // 清楚登录相关信息
                        homeViewModel.logout()
                        dialog.dismiss()
                        // 跳转到 LoginActivity 并清除之前的任务栈
                        var intent = Intent(this@SettingActivity, LoginActivity::class.java)
app/src/main/java/com/example/firstapp/adapter/InvitationRecord2Adapter.kt
对比新文件
@@ -0,0 +1,49 @@
package com.example.firstapp.adapter
import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.firstapp.R
import com.example.firstapp.entity.InvitationRecord
import com.google.android.material.imageview.ShapeableImageView
class InvitationRecord2Adapter(
    private val records: List<InvitationRecord>
) : RecyclerView.Adapter<InvitationRecord2Adapter.RecordViewHolder>() {
    class RecordViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val avatarImageView: ShapeableImageView = itemView.findViewById(R.id.avatarImageView)
        val nameTextView: TextView = itemView.findViewById(R.id.nameTextView)
        val statusTextView: TextView = itemView.findViewById(R.id.statusTextView)
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecordViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_invitation_record, parent, false)
        return RecordViewHolder(view)
    }
    override fun onBindViewHolder(holder: RecordViewHolder, position: Int) {
        val record = records[position]
        // 加载网络图片
        Glide.with(holder.itemView.context)
            .load(record.cover) // 网络图片 URL
            .placeholder(R.drawable.default_avatar) // 加载中占位图
            .error(R.drawable.default_avatar) // 加载失败时显示的图片
            .into(holder.avatarImageView)
        holder.nameTextView.text = record.userName
        holder.statusTextView.text = record.status
    }
    override fun getItemCount(): Int = records.size
}
app/src/main/java/com/example/firstapp/entity/InvitationRecord.kt
@@ -4,7 +4,9 @@
    val userId: String,
    val userName: String,
    val reward: String,
    val status: String
    val status: String,
    val cover:String,
)
data class InvitationRecords(
app/src/main/java/com/example/firstapp/receiver/SmsReceiver.kt
@@ -22,6 +22,7 @@
import java.time.ZoneId
import java.util.Date
import java.util.Locale
import com.example.firstapp.utils.CodeUtils
class SmsReceiver : BroadcastReceiver() {
@@ -72,121 +73,71 @@
                            // 根据不同类型处理数据
                            when (response.data.category) {
                                "快递" -> {
                                    val code = Code(
                                        id = 0,
                                        category = response.data.category,
                                        categoryId = 1, // 1-快递类型
                                        typeId = 1,     //暂时没有根据type分类
                                        ruleId = 1,     //1-快递类型
                                    val code = CodeUtils.createExpressCode(
                                        msgId = msgId,
                                        createTime = createtime,
                                        oneLevel = response.data.details.post ?: "",
                                        secondLevel = response.data.details.company ?: "未知",
                                        code = response.data.details.pickupCode ?: "",
                                        pickup = 0, // 0-未取件,1-已取件
                                        pickupTime = "", // 取件时间为空
                                        overTime = "",  // 超时时间为空,暂时没有这块处理逻辑
                                        address = response.data.details.address ?: "",
                                        remarks = response.data.details.time ?: "",
                                        post = response.data.details.post,
                                        company = response.data.details.company,
                                        pickupCode = response.data.details.pickupCode,
                                        address = response.data.details.address,
                                        time = response.data.details.time
                                    )
                                    if(code.oneLevel!=""  && code.secondLevel!="" && code.code!="") {
                                        Core.code.insert(code)
                                    }
                                    CodeUtils.saveCode(code)
                                }
                                "还款" -> {
                                    val code = Code(
                                        id = 0,
                                        category = response.data.category,
                                        categoryId = 2, // 2-还款类型
                                        typeId = 1,     //暂时没有根据type分类
                                        ruleId = 2,     //1-还款类型
                                    val code = CodeUtils.createRepaymentCode(
                                        msgId = msgId,
                                        createTime = createtime,
                                        oneLevel = response.data.details.type ?: "",
                                        secondLevel = response.data.details.bank ?: "未知",
                                        code = response.data.details.amount ?: "",
                                        pickup = 0, // 0-未取件,1-已取件
                                        pickupTime = "", // 取件时间为空
                                        overTime = response.data.details.date
                                            ?: "",  // 超时时间为空,暂时没有这块处理逻辑
                                        address = response.data.details.address ?: "",
                                        remarks = "最小还款金额" + response.data.details.min_amount + "还款卡号" + response.data.details.number
                                            ?: "",
                                        type = response.data.details.type,
                                        bank = response.data.details.bank,
                                        amount = response.data.details.amount,
                                        date = response.data.details.date,
                                        address = response.data.details.address,
                                        minAmount = response.data.details.min_amount,
                                        number = response.data.details.number
                                    )
                                    if(code.oneLevel!=""  && code.secondLevel!="" && code.code!="") {
                                        Core.code.insert(code)
                                    }
                                    CodeUtils.saveCode(code)
                                }
                                "收入" -> {
                                    val code = Code(
                                        id = 0,
                                        category = response.data.category,
                                        categoryId = 3, // 3-收入类型
                                        typeId = 1,     //暂时没有根据type分类
                                        ruleId = 2,     //1-还款类型
                                    val code = CodeUtils.createIncomeCode(
                                        msgId = msgId,
                                        createTime = createtime,
                                        oneLevel = response.data.details.bank ?: "",
                                        secondLevel = response.data.details.bank ?: "未知",
                                        code = response.data.details.amount ?: "",
                                        pickup = 0, // 0-未取件,1-已取件
                                        pickupTime = "", // 取件时间为空
                                        overTime = response.data.details.datetime
                                            ?: "",  // 超时时间为空,暂时没有这块处理逻辑
                                        address = response.data.details.address ?: "",
                                        remarks = "余额" + response.data.details.balance ?: "",
                                        bank = response.data.details.bank,
                                        amount = response.data.details.amount,
                                        datetime = response.data.details.datetime,
                                        address = response.data.details.address,
                                        balance = response.data.details.balance
                                    )
                                    if(code.oneLevel!=""  && code.secondLevel!="" && code.code!="") {
                                        Core.code.insert(code)
                                    }
                                    CodeUtils.saveCode(code)
                                }
                                "航班" -> {
                                    val code = Code(
                                        id = 0,
                                        category = response.data.category,
                                        categoryId = 4, // 4-航班类型
                                        typeId = 1,     //暂时没有根据type分类
                                        ruleId = 2,     //1-还款类型
                                    val code = CodeUtils.createFlightCode(
                                        msgId = msgId,
                                        createTime = createtime,
                                        oneLevel = response.data.details.company ?: "",
                                        secondLevel = response.data.details.start +response.data.details.end?: "未知",
                                        code = response.data.details.seat ?: "",
                                        pickup = 0, // 0-未取件,1-已取件
                                        pickupTime = "", // 取件时间为空
                                        overTime = response.data.details.time
                                            ?: "",  // 超时时间为空,暂时没有这块处理逻辑
                                        address = response.data.details.address ?: "",
                                        remarks = response.data.details.seat ?: "",
                                        company = response.data.details.company,
                                        start = response.data.details.start,
                                        end = response.data.details.end,
                                        seat = response.data.details.seat,
                                        time = response.data.details.time,
                                        address = response.data.details.address
                                    )
                                    if(code.oneLevel!=""  && code.secondLevel!="" && code.code!="") {
                                        Core.code.insert(code)
                                    }
                                    CodeUtils.saveCode(code)
                                }
                                "火车票" -> {
                                    val code = Code(
                                        id = 0,
                                        category = response.data.category,
                                        categoryId = 5, // 5-火车票类型
                                        typeId = 1,     //暂时没有根据type分类
                                        ruleId = 2,     //1-还款类型
                                    val code = CodeUtils.createTrainTicketCode(
                                        msgId = msgId,
                                        createTime = createtime,
                                        oneLevel = response.data.details.company ?: "",
                                        secondLevel = response.data.details.company ?: "未知",
                                        code = response.data.details.seat ?: "",
                                        pickup = 0, // 0-未取件,1-已取件
                                        pickupTime = "", // 取件时间为空
                                        overTime = response.data.details.time
                                            ?: "",  // 超时时间为空,暂时没有这块处理逻辑
                                        address = response.data.details.address ?: "",
                                        remarks = response.data.details.trips ?: "",
                                        company = response.data.details.company,
                                        seat = response.data.details.seat,
                                        time = response.data.details.time,
                                        address = response.data.details.address,
                                        trips = response.data.details.trips
                                    )
                                    if(code.oneLevel!=""  && code.secondLevel!="" && code.code!="") {
                                        Core.code.insert(code)
                                    }
                                    CodeUtils.saveCode(code)
                                }
                            }
app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
@@ -596,7 +596,37 @@
                    if (isMember) {
                        // 会员可以看到所有分类
                        adapter.setCategories(categories)
                        val serverCategories = RetrofitClient.apiService.getUserCategories(response.data?.id.toString())
                        if(serverCategories.size==2 && serverCategories[0].name=="快递"&&serverCategories[1].name=="还款"){
                            // 将 serverCategories 转换为可变列表
                            val mutableServerCategories = serverCategories.toMutableList()
                            // 添加多个新分类
                            mutableServerCategories.add(CategoryConfig(
                                id = 5,
                                name = "火车票",
                                order = 4,
                                isEnabled = false
                            ))
                            mutableServerCategories.add(CategoryConfig(
                                id = 4,
                                name = "航班",
                                order = 3,
                                isEnabled = false
                            ))
                            mutableServerCategories.add(CategoryConfig(
                                id = 3,
                                name = "收入",
                                order = 2,
                                isEnabled = false
                            ))
                            // 设置适配器的分类列表
                            adapter.setCategories(mutableServerCategories)
                        }else {
                            adapter.setCategories(serverCategories)
                        }
                    } else {
                        // 非会员只能看到快递和还款
                        val limitedCategories = categories.filter {
app/src/main/java/com/example/firstapp/ui/home/HomeViewModel.kt
@@ -379,6 +379,8 @@
        // 只清除内存中的数据
        _categories.value = emptyList()
        categoriesLoaded = false
        // 删除token
        PreferencesManager.clearUserData()
    }
}
app/src/main/java/com/example/firstapp/ui/invitation/InvitationActivity.kt
@@ -19,6 +19,7 @@
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
@@ -31,6 +32,7 @@
import com.example.firstapp.App.Companion.context
import com.example.firstapp.R
import com.example.firstapp.adapter.InvitationAdapter
import com.example.firstapp.adapter.InvitationRecord2Adapter
import com.example.firstapp.adapter.InvitationRecordAdapter
import com.example.firstapp.database.request.SmsLoginRequest
import com.example.firstapp.database.service.RetrofitClient
@@ -49,7 +51,7 @@
    private lateinit var recyclerSuccessView: RecyclerView
    private lateinit var recyclerRecordView: RecyclerView
    private lateinit var adapter: InvitationAdapter
    private lateinit var recordadapter: InvitationRecordAdapter
//    private lateinit var recordadapter: InvitationRecordAdapter
    private var data = mutableListOf<InvitationRecord>()
    private var recorddata = mutableListOf<InvitationRecord>()
    private val handler = Handler(Looper.getMainLooper())
@@ -57,6 +59,11 @@
    private var currentScrollPosition = 0
    private var currentRecordScrollPosition = 0
    private var itemHeight = 0 // 动态存储item高度
    private lateinit var invitedRecordRecyclerView2: RecyclerView
    private lateinit var invitationAdapter: InvitationRecord2Adapter
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
@@ -68,7 +75,7 @@
        //初始化Adapter
        initSuccessAdapter()
        initRecorddapter()
//        initRecorddapter()
        //加载数据
        getInvitereward()
@@ -94,6 +101,8 @@
            clipboard.setPrimaryClip(clip)
            Toast.makeText(this, "已复制邀请码", Toast.LENGTH_SHORT).show()
        }
    }
@@ -142,8 +151,8 @@
            }
        }
        // 记录列表
        recyclerRecordView = findViewById(R.id.invitationrecordRecyclerView)
        recyclerRecordView.layoutManager = LinearLayoutManager(this)
//        recyclerRecordView = findViewById(R.id.invitationrecordRecyclerView)
//        recyclerRecordView.layoutManager = LinearLayoutManager(this)
    }
    private fun initSuccessAdapter() {
@@ -162,10 +171,25 @@
        recyclerSuccessView.adapter = adapter
    }
    private fun initRecorddapter() {
        recordadapter = InvitationRecordAdapter(this, recorddata)
        recyclerRecordView.adapter = recordadapter
    }
//    private fun initRecorddapter() {
//        recordadapter = InvitationRecordAdapter(this, recorddata)
//        recyclerRecordView.adapter = recordadapter
//    }
//    private fun initRecorddapter() {
//        recordadapter = InvitationRecordAdapter(this, recorddata).apply {
//            registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
//                override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
//                    // 数据插入时检查高度
//                    recyclerRecordView.post {
//                        if (recyclerRecordView.childCount > 0) {
//                            itemHeight = recyclerRecordView.getChildAt(0).height
//                        }
//                    }
//                }
//            })
//        }
//        recyclerRecordView.adapter = recordadapter
//    }
    private fun getInvitereward() {
        lifecycleScope.launch {
@@ -184,10 +208,17 @@
                            addAll(records.myInvite ?: emptyList())  // 注意这里使用myInvite
                        }
                        // 加载适配器
                        invitedRecordRecyclerView2 = findViewById(R.id.invited_record_recycler_view_2)
                        invitedRecordRecyclerView2.layoutManager = LinearLayoutManager(this@InvitationActivity)
                        invitationAdapter = InvitationRecord2Adapter(records.myInvite)
                        invitedRecordRecyclerView2.adapter = invitationAdapter
                        // 在UI线程更新适配器
                        withContext(Dispatchers.Main) {
                            adapter.notifyDataSetChanged()
                            recordadapter.notifyDataSetChanged()
//                            recordadapter.notifyDataSetChanged()
                        }
                    } ?: run {
                        Log.w("API", "Response data is null")
app/src/main/res/drawable/bg_invitation_record.xml
对比新文件
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF" /> <!-- 背景白色 -->
    <corners android:radius="12dp" /> <!-- 圆角半径 -->
</shape>
app/src/main/res/layout/activity_invitation_main.xml
@@ -39,15 +39,15 @@
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="16dp"
                    android:padding="10dp"
                    android:textColor="#FFFFFF"
                    android:textSize="15sp" />
                <!-- 横幅广告区域 -->
                <androidx.cardview.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="160dp"
                    android:layout_marginBottom="16dp"
                    android:layout_height="140dp"
                    android:layout_marginBottom="10dp"
                    app:cardCornerRadius="13dp"
                    app:cardPreventCornerOverlap="true">
@@ -62,13 +62,13 @@
                <androidx.cardview.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="20dp"
                    android:layout_marginBottom="10dp"
                    app:cardCornerRadius="38dp">
                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/invitationsuccessRecyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="60dp"
                        android:layout_height="40dp"
                        android:nestedScrollingEnabled="false"
                        android:overScrollMode="never" />
                </androidx.cardview.widget.CardView>
@@ -82,7 +82,7 @@
                    android:backgroundTint="#FF0000"
                    android:insetTop="0dp"
                    android:insetBottom="0dp"
                    android:padding="12dp"
                    android:padding="10dp"
                    android:text="立即邀请好友"
                    android:textColor="#FFFFFF"
                    android:textSize="16sp"
@@ -288,13 +288,14 @@
                    </LinearLayout>
                </androidx.cardview.widget.CardView>
                <!-- 邀请记录区域 -->
                <androidx.cardview.widget.CardView
                <LinearLayout
                    android:id="@+id/invitationrecordLinearLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="20dp"
                    app:cardCornerRadius="6dp"
                    app:cardPreventCornerOverlap="true">
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:background="@drawable/bg_invitation_record"
                    android:padding="10dp">
                    <LinearLayout
                        android:layout_width="match_parent"
@@ -305,13 +306,45 @@
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:paddingLeft="16dp"
                            android:paddingBottom="5dp"
                            android:text="我的邀请记录"
                            android:textColor="#333333"
                            android:textSize="16sp"
                            android:textStyle="bold" />
                    </LinearLayout>
                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/invited_record_recycler_view_2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />
                </LinearLayout>
                <!-- 邀请记录区域 -->
               <!-- <androidx.cardview.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:cardCornerRadius="6dp"
                >
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">
                        &lt;!&ndash; 添加"我的邀请记录"标题 &ndash;&gt;
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:paddingLeft="16dp"
                            android:paddingBottom="8dp"
                            android:text="我的邀请记录"
                            android:textColor="#333333"
                            android:textSize="16sp"
                            android:textStyle="bold"
                            android:gravity="center" />
                            android:textStyle="bold" />
                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/invitationrecordRecyclerView"
@@ -319,8 +352,13 @@
                            android:layout_height="wrap_content"
                            android:nestedScrollingEnabled="false"
                            android:overScrollMode="never" />
                    </LinearLayout>
                </androidx.cardview.widget.CardView>
                        </LinearLayout>
                </androidx.cardview.widget.CardView>-->
                <!-- 添加一个权重为1的View,用于填充剩余空间 -->
                <View
app/src/main/res/layout/item_invitation_record.xml
对比新文件
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:padding="8dp">
    <com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/avatarImageView"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="10dp"
        android:scaleType="centerCrop"
        app:shapeAppearance="@style/CircleImage"
        />
    <TextView
        android:id="@+id/nameTextView"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_marginLeft="10dp"
        android:gravity="center_vertical"
        android:minWidth="100dp"
        android:text="Name" />
    <TextView
        android:id="@+id/statusTextView"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_marginLeft="50dp"
        android:gravity="center_vertical"
        android:text="Status" />
</LinearLayout>
app/src/main/res/values/styles.xml
@@ -63,4 +63,9 @@
        <item name="android:textColor">#000000</item> <!-- 设置标题颜色 -->
    </style>
    <style name="CircleImage">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">50%</item>
    </style>
</resources>