| | |
| | | import java.util.Date |
| | | import java.util.Locale |
| | | import android.app.AlertDialog |
| | | import com.example.firstapp.utils.CodeUtils |
| | | |
| | | class MainActivity : AppCompatActivity() { |
| | | // 安全防护关键词数组 |
| | |
| | | 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 { |
| | |
| | | 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) |
| | | } |
| | | } |
| | | |
| | |
| | | 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() { |
| | |
| | | lifecycleScope.launch { |
| | | try { |
| | | // 清除本地的数据库 |
| | | |
| | | RetrofitClient.apiService.closeAccount() |
| | | |
| | | Core.code.deleteAll() |
| | |
| | | Core.keyword.deleteAll() |
| | | // Core.reminder.deleteAll() |
| | | |
| | | // 清楚登录相关信息 |
| | | homeViewModel.logout() |
| | | |
| | | dialog.dismiss() |
| | | // 跳转到 LoginActivity 并清除之前的任务栈 |
| | | var intent = Intent(this@SettingActivity, LoginActivity::class.java) |
对比新文件 |
| | |
| | | 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 |
| | | } |
| | |
| | | val userId: String, |
| | | val userName: String, |
| | | val reward: String, |
| | | val status: String |
| | | val status: String, |
| | | val cover:String, |
| | | |
| | | ) |
| | | |
| | | data class InvitationRecords( |
| | |
| | | import java.time.ZoneId |
| | | import java.util.Date |
| | | import java.util.Locale |
| | | import com.example.firstapp.utils.CodeUtils |
| | | |
| | | |
| | | class SmsReceiver : BroadcastReceiver() { |
| | |
| | | // 根据不同类型处理数据 |
| | | 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) |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | 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 { |
| | |
| | | // 只清除内存中的数据 |
| | | _categories.value = emptyList() |
| | | categoriesLoaded = false |
| | | // 删除token |
| | | PreferencesManager.clearUserData() |
| | | } |
| | | |
| | | } |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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()) |
| | |
| | | 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) |
| | |
| | | //初始化Adapter |
| | | initSuccessAdapter() |
| | | |
| | | initRecorddapter() |
| | | // initRecorddapter() |
| | | |
| | | //加载数据 |
| | | getInvitereward() |
| | |
| | | clipboard.setPrimaryClip(clip) |
| | | Toast.makeText(this, "已复制邀请码", Toast.LENGTH_SHORT).show() |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | // 记录列表 |
| | | recyclerRecordView = findViewById(R.id.invitationrecordRecyclerView) |
| | | recyclerRecordView.layoutManager = LinearLayoutManager(this) |
| | | // recyclerRecordView = findViewById(R.id.invitationrecordRecyclerView) |
| | | // recyclerRecordView.layoutManager = LinearLayoutManager(this) |
| | | } |
| | | |
| | | private fun initSuccessAdapter() { |
| | |
| | | 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 { |
| | |
| | | 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") |
对比新文件 |
| | |
| | | <?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> |
| | |
| | | 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"> |
| | | |
| | |
| | | <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> |
| | |
| | | android:backgroundTint="#FF0000" |
| | | android:insetTop="0dp" |
| | | android:insetBottom="0dp" |
| | | android:padding="12dp" |
| | | android:padding="10dp" |
| | | android:text="立即邀请好友" |
| | | android:textColor="#FFFFFF" |
| | | android:textSize="16sp" |
| | |
| | | </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" |
| | |
| | | <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"> |
| | | |
| | | <!– 添加"我的邀请记录"标题 –> |
| | | <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" |
| | |
| | | android:layout_height="wrap_content" |
| | | android:nestedScrollingEnabled="false" |
| | | android:overScrollMode="never" /> |
| | | </LinearLayout> |
| | | </androidx.cardview.widget.CardView> |
| | | |
| | | </LinearLayout> |
| | | |
| | | |
| | | </androidx.cardview.widget.CardView>--> |
| | | |
| | | |
| | | |
| | | <!-- 添加一个权重为1的View,用于填充剩余空间 --> |
| | | <View |
对比新文件 |
| | |
| | | <?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> |
| | |
| | | <item name="android:textColor">#000000</item> <!-- 设置标题颜色 --> |
| | | </style> |
| | | |
| | | <style name="CircleImage"> |
| | | <item name="cornerFamily">rounded</item> |
| | | <item name="cornerSize">50%</item> |
| | | </style> |
| | | |
| | | </resources> |