修复通知时间读数基准错误;今日筛选只保留今日到期与今日完成
This commit is contained in:
@@ -7,6 +7,7 @@ import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
@@ -147,27 +148,25 @@ object Notif {
|
||||
/**
|
||||
* 把计时读数交给系统 Chronometer。
|
||||
*
|
||||
* 倒计时:base = 结束时刻,配合 countDown 显示"还剩多少";
|
||||
* 正计时:base 往前推已用时长,显示"已经过了多久";
|
||||
* 暂停时 started=false,Chronometer 停在按下暂停那一刻的值。
|
||||
* 关键:Chronometer 的时间轴是 SystemClock.elapsedRealtime()(开机后的毫秒数),
|
||||
* 不是 System.currentTimeMillis()(1970 年起的绝对时间)。
|
||||
* 用后者当 base,两者相差十几亿毫秒,屏幕上就会滚出一长串天文数字。
|
||||
*
|
||||
* 倒计时:base = 现在(单调钟) + 剩余,配合 countDown 显示"还剩多少";
|
||||
* 正计时:base = 现在 - 已用,显示"已经过了多久";
|
||||
* 暂停时 started=false,数字停在刷新那一刻的读数上。
|
||||
*/
|
||||
private fun bindChronometer(rv: RemoteViews, running: Boolean, countUp: Boolean) {
|
||||
val now = System.currentTimeMillis()
|
||||
val now = SystemClock.elapsedRealtime()
|
||||
val base: Long
|
||||
val countDown: Boolean
|
||||
when {
|
||||
countUp -> {
|
||||
base = now - TimerCore.displayNow()
|
||||
countDown = false
|
||||
}
|
||||
running -> {
|
||||
base = TimerCore.endAtMs()
|
||||
countDown = true
|
||||
}
|
||||
else -> {
|
||||
base = now + TimerCore.remainingNow()
|
||||
countDown = true
|
||||
}
|
||||
if (countUp) {
|
||||
base = now - TimerCore.displayNow()
|
||||
countDown = false
|
||||
} else {
|
||||
// remainingNow() 在运行中是现算、暂停时是快照,两种情况都对得上
|
||||
base = now + TimerCore.remainingNow()
|
||||
countDown = true
|
||||
}
|
||||
rv.setChronometer(R.id.notifChrono, base, null, running)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
|
||||
Reference in New Issue
Block a user