正倒计时布局统一消除晃动;原因弹层适配输入法;已完成按钮位置固定;原因文案与暂停原因;科技蓝主色
This commit is contained in:
@@ -6,8 +6,10 @@ import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.data.Store
|
||||
import com.focusbox.app.model.FocusFinish
|
||||
import com.focusbox.app.util.Dates
|
||||
import com.focusbox.app.util.Prefs
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import kotlin.math.abs
|
||||
@@ -74,6 +76,11 @@ object TimerCore {
|
||||
private var endElapsed = 0L
|
||||
private var clockOffset = 0L
|
||||
|
||||
/** 暂停原因在恢复时才补写备注,这里暂存起点与任务 */
|
||||
private var pendingPauseReason = ""
|
||||
private var pendingPauseStartAt = 0L
|
||||
private var pendingPauseTaskId = 0L
|
||||
|
||||
private val listeners = CopyOnWriteArrayList<() -> Unit>()
|
||||
|
||||
fun addListener(l: () -> Unit) {
|
||||
@@ -105,6 +112,9 @@ object TimerCore {
|
||||
startedAt = Prefs.timerStartedAt
|
||||
endElapsed = Prefs.timerEndElapsed
|
||||
clockOffset = Prefs.timerClockOffset
|
||||
pendingPauseReason = Prefs.timerPauseReason
|
||||
pendingPauseStartAt = Prefs.timerPauseStartAt
|
||||
pendingPauseTaskId = Prefs.timerPauseTaskId
|
||||
|
||||
if (running) {
|
||||
if (countUp) {
|
||||
@@ -203,6 +213,7 @@ object TimerCore {
|
||||
startedAt = 0
|
||||
endAt = 0
|
||||
endElapsed = 0
|
||||
clearPause()
|
||||
save()
|
||||
notifyChanged()
|
||||
}
|
||||
@@ -244,6 +255,7 @@ object TimerCore {
|
||||
endAt = 0
|
||||
endElapsed = 0
|
||||
accReset()
|
||||
clearPause()
|
||||
save()
|
||||
notifyChanged()
|
||||
}
|
||||
@@ -290,8 +302,13 @@ object TimerCore {
|
||||
notifyChanged()
|
||||
}
|
||||
|
||||
fun pause() {
|
||||
fun pause(reason: String = "") {
|
||||
if (!running) return
|
||||
if (reason.isNotBlank()) {
|
||||
pendingPauseReason = reason.trim()
|
||||
pendingPauseStartAt = System.currentTimeMillis()
|
||||
pendingPauseTaskId = taskId
|
||||
}
|
||||
if (countUp) {
|
||||
accumMs += (System.currentTimeMillis() - startedAt).coerceAtLeast(0)
|
||||
startedAt = 0
|
||||
@@ -306,11 +323,31 @@ object TimerCore {
|
||||
notifyChanged()
|
||||
}
|
||||
|
||||
fun resume() = start()
|
||||
fun resume() {
|
||||
val reason = pendingPauseReason
|
||||
val startAt = pendingPauseStartAt
|
||||
val pausedTaskId = pendingPauseTaskId
|
||||
start()
|
||||
if (reason.isNotBlank() && startAt > 0L && pausedTaskId > 0L) {
|
||||
val endAtPause = System.currentTimeMillis()
|
||||
val seconds = ((endAtPause - startAt) / 1000).toInt().coerceAtLeast(0)
|
||||
val line = ctx.getString(
|
||||
R.string.task_note_pause,
|
||||
reason,
|
||||
Dates.hms(startAt),
|
||||
Dates.hms(endAtPause),
|
||||
Dates.duration(seconds),
|
||||
)
|
||||
appendTaskNote(pausedTaskId, line)
|
||||
}
|
||||
clearPause()
|
||||
save()
|
||||
}
|
||||
|
||||
/** 回到本轮起点,不记记录。倒计时保留当前设定的时长,正计时归零。 */
|
||||
fun reset() {
|
||||
running = false
|
||||
clearPause()
|
||||
endAt = 0
|
||||
startedAt = 0
|
||||
if (countUp) {
|
||||
@@ -349,6 +386,7 @@ object TimerCore {
|
||||
totalMs = if (totalMs > 0) totalMs else durationFor(mode)
|
||||
remainingMs = totalMs
|
||||
}
|
||||
clearPause()
|
||||
save()
|
||||
notifyChanged()
|
||||
TimerService.stop(ctx)
|
||||
@@ -372,6 +410,7 @@ object TimerCore {
|
||||
endElapsed = 0
|
||||
startedAt = 0
|
||||
if (countUp) accReset() else remainingMs = totalMs
|
||||
clearPause()
|
||||
save()
|
||||
notifyChanged()
|
||||
TimerService.stop(ctx)
|
||||
@@ -399,6 +438,7 @@ object TimerCore {
|
||||
totalMs = durationFor(MODE_FOCUS)
|
||||
remainingMs = totalMs
|
||||
}
|
||||
clearPause()
|
||||
save()
|
||||
notifyChanged()
|
||||
TimerService.stop(ctx)
|
||||
@@ -485,6 +525,21 @@ object TimerCore {
|
||||
Prefs.timerAccumMs = 0
|
||||
}
|
||||
|
||||
private fun clearPause() {
|
||||
pendingPauseReason = ""
|
||||
pendingPauseStartAt = 0L
|
||||
pendingPauseTaskId = 0L
|
||||
}
|
||||
|
||||
private fun appendTaskNote(id: Long, line: String) {
|
||||
runCatching {
|
||||
Store.task(id)?.let { t ->
|
||||
val note = if (t.note.isBlank()) line else "${t.note}\n$line"
|
||||
Store.updateTask(t.copy(note = note))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun save() {
|
||||
Prefs.timerMode = mode
|
||||
Prefs.timerRunning = running
|
||||
@@ -494,6 +549,9 @@ object TimerCore {
|
||||
Prefs.timerEndAt = endAt
|
||||
Prefs.timerEndElapsed = if (endAt > 0) endElapsed else 0L
|
||||
Prefs.timerClockOffset = clockOffset
|
||||
Prefs.timerPauseReason = pendingPauseReason
|
||||
Prefs.timerPauseStartAt = pendingPauseStartAt
|
||||
Prefs.timerPauseTaskId = pendingPauseTaskId
|
||||
Prefs.timerStartedAt = startedAt
|
||||
Prefs.timerTaskId = taskId
|
||||
Prefs.timerProjectId = projectId
|
||||
|
||||
Reference in New Issue
Block a user