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/App.kt |   28 +++++++++-------------------
 1 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/app/src/main/java/com/example/firstapp/App.kt b/app/src/main/java/com/example/firstapp/App.kt
index 83a1eae..4fba306 100644
--- a/app/src/main/java/com/example/firstapp/App.kt
+++ b/app/src/main/java/com/example/firstapp/App.kt
@@ -16,6 +16,7 @@
 import com.example.firstapp.database.repository.CodeRepository
 import com.example.firstapp.database.repository.KeywordRepository
 import com.example.firstapp.database.repository.MsgRepository
+import com.example.firstapp.database.repository.ReminderRepository
 import com.example.firstapp.database.service.RetrofitClient
 import com.example.firstapp.receiver.CactusReceiver
 import com.example.firstapp.service.ReminderWorker
@@ -37,6 +38,7 @@
 import java.io.IOException
 import java.text.SimpleDateFormat
 import java.util.*
+import java.util.concurrent.TimeUnit
 
 @Suppress("DEPRECATION")
 class App : Application(), CactusCallback, Configuration.Provider {
@@ -46,6 +48,7 @@
     val msgRepository by lazy { MsgRepository(database.msgDao()) }
     val codeRepository by lazy { CodeRepository(database.codeDao()) }
     val keywordRepository by lazy { KeywordRepository(RetrofitClient.apiService,database.keywordDao()) }
+    val reminderRepository by lazy { ReminderRepository(this) }
 
     companion object {
         const val TAG: String = "SmsForwarder"
@@ -452,28 +455,15 @@
      * 设置定时提醒Worker
      * 配置为每天运行一次检查是否有新的提醒内容
      */
-    private fun setupReminderWorker() {
+    fun setupReminderWorker() {
         Log.d(TAG, "设置定时提醒Worker")
         
-        val constraints = Constraints.Builder()
-            .setRequiredNetworkType(NetworkType.CONNECTED)
-            .build()
+        // 仅在特定时间执行(每天指定时间)
+        // 可根据需要设置多个不同时间点的提醒
+        ReminderWorker.setupScheduledWorker(this, 9, 0)  // 上午9:00
+        ReminderWorker.setupScheduledWorker(this, 13, 50) // 下午13:50
         
-        // 创建周期性工作请求
-        val reminderWorkRequest = PeriodicWorkRequestBuilder<ReminderWorker>(
-            ReminderWorker.REPEAT_INTERVAL,
-            ReminderWorker.REPEAT_INTERVAL_TIME_UNIT
-        )
-            .setConstraints(constraints)
-            .addTag("reminder_worker")
-            .build()
-
-        // 使用 REPLACE 策略确保新配置生效
-        WorkManager.getInstance(this).enqueueUniquePeriodicWork(
-            "reminder_work",
-            ExistingPeriodicWorkPolicy.REPLACE,
-            reminderWorkRequest
-        )
+        // 不再使用周期性轮询和立即执行的方式
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.3