From 0a730b84c41f44129bf5ecc112450d2edf4312c9 Mon Sep 17 00:00:00 2001
From: tj <1378534974@qq.com>
Date: 星期二, 15 四月 2025 17:44:56 +0800
Subject: [PATCH] 1.4 返回按钮
---
app/src/main/java/com/example/firstapp/MainActivity.kt | 27 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/MainActivity.kt b/app/src/main/java/com/example/firstapp/MainActivity.kt
index c59ca87..9c533a8 100644
--- a/app/src/main/java/com/example/firstapp/MainActivity.kt
+++ b/app/src/main/java/com/example/firstapp/MainActivity.kt
@@ -75,6 +75,9 @@
// 只保留底部导航的设置
navView.setupWithNavController(navController)
+ // 重置提醒计划并检查是否有错过的提醒
+ resetReminders()
+
// 检查权限
if (ContextCompat.checkSelfPermission(
this, Manifest.permission.RECEIVE_SMS
@@ -222,7 +225,8 @@
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.secondLevel.isNotEmpty() && code.code.isNotEmpty()) {
+ if(code.oneLevel.isNotEmpty() && code.code.isNotEmpty()) {
Core.code.insert(code)
android.util.Log.d("MainActivity", "历史快递短信已保存: $pickupCode")
}
@@ -322,4 +326,25 @@
Toast.makeText(this, "同步短信失败:${e.message}", Toast.LENGTH_SHORT).show()
}
}
+
+ // 重置提醒计划
+ private fun resetReminders() {
+ try {
+ // 取消所有现有的提醒任务
+ androidx.work.WorkManager.getInstance(this).cancelAllWorkByTag("reminder_worker")
+
+ // 清除旧的提醒偏好设置
+ getSharedPreferences("reminder_prefs", Context.MODE_PRIVATE).edit().clear().apply()
+
+ // 重新设置提醒任务
+ (application as App).setupReminderWorker()
+
+ // 检查是否有错过的提醒
+ com.example.firstapp.service.ReminderWorker.checkMissedReminders(this)
+
+ android.util.Log.d("MainActivity", "已重置提醒计划")
+ } catch (e: Exception) {
+ android.util.Log.e("MainActivity", "重置提醒计划失败: ${e.message}")
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3