From b8aa11a7b447fb8048115bdd156c2aa9e3b16a07 Mon Sep 17 00:00:00 2001
From: tj <1378534974@qq.com>
Date: 星期二, 15 四月 2025 16:40:08 +0800
Subject: [PATCH] 1.3

---
 app/src/main/java/com/example/firstapp/MainActivity.kt |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/com/example/firstapp/MainActivity.kt b/app/src/main/java/com/example/firstapp/MainActivity.kt
index 13ae51e..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
@@ -323,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