cloudroam
5 天以前 6403ddc78af1190995fa4f6335b57b3820fa2fc6
add: 消息提醒图片,code工具类
已修改1个文件
已添加2个文件
204 ■■■■■ 文件已修改
app/src/main/java/com/example/firstapp/utils/CodeUtils.kt 202 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/drawable/reminder_png.png 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_reminder_settings.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/utils/CodeUtils.kt
对比新文件
@@ -0,0 +1,202 @@
package com.example.firstapp.utils
import com.example.firstapp.core.Core
import com.example.firstapp.database.entity.Code
import android.util.Log
object CodeUtils {
    private const val TAG = "CodeUtils"
    /**
     * 保存code到数据库,如果已存在则跳过
     * @param code 要保存的code对象
     * @return Boolean 是否成功保存
     */
    fun saveCode(code: Code): Boolean {
        // 检查必要字段是否为空
        if (code.oneLevel.isEmpty() || code.code.isEmpty()) {
            Log.d(TAG, "保存失败:必要字段为空")
            return false
        }
        // 检查是否已存在相同记录
        val existingCode = Core.code.queryByTypeAndCodeAndDate(
            code.category,
            code.code,
            code.createTime
        )
        return if (existingCode == null) {
            try {
                Core.code.insert(code)
                Log.d(TAG, "成功保存${code.category}记录: ${code.code}")
                true
            } catch (e: Exception) {
                Log.e(TAG, "保存${code.category}记录失败: ${e.message}")
                false
            }
        } else {
            Log.d(TAG, "发现重复${code.category}记录,跳过保存: ${code.code}")
            false
        }
    }
    /**
     * 创建快递类型的Code对象
     */
    fun createExpressCode(
        msgId: Long,
        createTime: String,
        post: String?,
        company: String?,
        pickupCode: String?,
        address: String?,
        time: String?
    ): Code {
//        val secondLevel = if (company.isNullOrEmpty()) "未知" else company
        return Code(
            id = 0,
            category = "快递",
            categoryId = 1,
            typeId = 1,
            ruleId = 1,
            msgId = msgId,
            createTime = createTime,
            oneLevel = post ?: "",
            secondLevel = if (company.isNullOrEmpty()) "未知" else company,
            code = pickupCode ?: "",
            pickup = 0,
            pickupTime = "",
            overTime = "",
            address = address ?: "",
            remarks = time ?: ""
        )
    }
    /**
     * 创建还款类型的Code对象
     */
    fun createRepaymentCode(
        msgId: Long,
        createTime: String,
        type: String?,
        bank: String?,
        amount: String?,
        date: String?,
        address: String?,
        minAmount: String?,
        number: String?
    ): Code {
        return Code(
            id = 0,
            category = "还款",
            categoryId = 2,
            typeId = 1,
            ruleId = 2,
            msgId = msgId,
            createTime = createTime,
            oneLevel = type ?: "还款",
            secondLevel = if (bank.isNullOrEmpty()) "未知" else bank ,
            code = amount ?: "",
            pickup = 0,
            pickupTime = "",
            overTime = date ?: "",
            address = address ?: "",
            remarks = "最小还款金额${minAmount ?: ""}还款卡号${number ?: ""}"
        )
    }
    /**
     * 创建收入类型的Code对象
     */
    fun createIncomeCode(
        msgId: Long,
        createTime: String,
        bank: String?,
        amount: String?,
        datetime: String?,
        address: String?,
        balance: String?
    ): Code {
        return Code(
            id = 0,
            category = "收入",
            categoryId = 3,
            typeId = 1,
            ruleId = 2,
            msgId = msgId,
            createTime = createTime,
            oneLevel = bank ?: "",
            secondLevel = if (bank.isNullOrEmpty()) "未知" else bank,
            code = amount ?: "",
            pickup = 0,
            pickupTime = "",
            overTime = datetime ?: "",
            address = address ?: "",
            remarks = "余额${balance ?: ""}"
        )
    }
    /**
     * 创建航班类型的Code对象
     */
    fun createFlightCode(
        msgId: Long,
        createTime: String,
        company: String?,
        start: String?,
        end: String?,
        seat: String?,
        time: String?,
        address: String?
    ): Code {
        return Code(
            id = 0,
            category = "航班",
            categoryId = 4,
            typeId = 1,
            ruleId = 2,
            msgId = msgId,
            createTime = createTime,
            oneLevel = company ?: "",
            secondLevel = "${start ?: ""}${end ?: ""}",
            code = seat ?: "",
            pickup = 0,
            pickupTime = "",
            overTime = time ?: "",
            address = address ?: "",
            remarks = seat ?: ""
        )
    }
    /**
     * 创建火车票类型的Code对象
     */
    fun createTrainTicketCode(
        msgId: Long,
        createTime: String,
        company: String?,
        seat: String?,
        time: String?,
        address: String?,
        trips: String?
    ): Code {
        return Code(
            id = 0,
            category = "火车票",
            categoryId = 5,
            typeId = 1,
            ruleId = 2,
            msgId = msgId,
            createTime = createTime,
            oneLevel = company ?: "",
            secondLevel = company ?: "未知",
            code = seat ?: "",
            pickup = 0,
            pickupTime = "",
            overTime = time ?: "",
            address = address ?: "",
            remarks = trips ?: ""
        )
    }
}
app/src/main/res/drawable/reminder_png.png
app/src/main/res/layout/activity_reminder_settings.xml
@@ -228,7 +228,7 @@
                    android:background="#F8F8F8"
                    android:contentDescription="通知示例"
                    android:padding="8dp"
                    android:src="@drawable/up" />
                    android:src="@drawable/reminder_png" />
            </LinearLayout>
        </androidx.cardview.widget.CardView>