休息纯计时解耦滑动;重复任务按周期自动生成;统计数字去空格
This commit is contained in:
@@ -3,6 +3,8 @@ package com.focusbox.app.ui
|
||||
import android.content.Intent
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.Gravity
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
@@ -11,6 +13,7 @@ import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.data.Store
|
||||
import com.focusbox.app.model.Task
|
||||
import com.focusbox.app.service.TimerCore
|
||||
import com.focusbox.app.service.TimerService
|
||||
@@ -93,11 +96,30 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
/** 前台每 60 秒检查一次跨零点,重复任务在 0 点后自动生成当日实例 */
|
||||
private val rollHandler = Handler(Looper.getMainLooper())
|
||||
private val rollRunner = object : Runnable {
|
||||
override fun run() {
|
||||
if (runCatching { Store.rollRepeatingTasks() }.getOrDefault(0) > 0) {
|
||||
(fragments[TAB_TASKS] as? TasksFragment)?.reload()
|
||||
(fragments[TAB_PROJECTS] as? ProjectsFragment)?.reload()
|
||||
}
|
||||
rollHandler.postDelayed(this, 60_000L)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
// 进程常驻时跨天不会重走 App.onCreate,回到前台再滚一次重复任务。
|
||||
// 放在 super 之前:片段 onResume 里的 reload 读到的就是推进后的日期。
|
||||
runCatching { com.focusbox.app.data.Store.rollRepeatingTasks() }
|
||||
runCatching { Store.rollRepeatingTasks() }
|
||||
super.onResume()
|
||||
rollHandler.removeCallbacks(rollRunner)
|
||||
rollHandler.postDelayed(rollRunner, 60_000L)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
rollHandler.removeCallbacks(rollRunner)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
|
||||
Reference in New Issue
Block a user