修复倒计时读数冻结、原因输入键盘遮挡、备注括号与任务备注截断
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# 变更记录
|
# 变更记录
|
||||||
|
|
||||||
|
## 2026-11-28 · 修复倒计时读数冻结、原因输入键盘遮挡、备注括号与任务备注截断
|
||||||
|
|
||||||
|
- 同步源码更新 4 个文件(新增/修改 4,删除 0)。
|
||||||
|
|
||||||
## 2026-11-28 · v0.5.1:正倒计时布局统一、输入法适配、暂停原因与科技蓝
|
## 2026-11-28 · v0.5.1:正倒计时布局统一、输入法适配、暂停原因与科技蓝
|
||||||
|
|
||||||
- **首页切换**:左右滑动在倒计时 / 正计时之间切换时去掉位移动画,页面不再晃动;顶部专注 / 休息分段两页都显示且样式一致,环内轮次圆点也不再随页面隐藏。
|
- **首页切换**:左右滑动在倒计时 / 正计时之间切换时去掉位移动画,页面不再晃动;顶部专注 / 休息分段两页都显示且样式一致,环内轮次圆点也不再随页面隐藏。
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ object Store {
|
|||||||
const val INBOX_ID = 1L
|
const val INBOX_ID = 1L
|
||||||
|
|
||||||
private const val DB_NAME = "focusbox.db"
|
private const val DB_NAME = "focusbox.db"
|
||||||
private const val DB_VERSION = 3
|
private const val DB_VERSION = 4
|
||||||
|
|
||||||
private lateinit var helper: Helper
|
private lateinit var helper: Helper
|
||||||
|
|
||||||
@@ -109,6 +109,13 @@ object Store {
|
|||||||
if (oldVersion < 3) {
|
if (oldVersion < 3) {
|
||||||
db.execSQL("ALTER TABLE tasks ADD COLUMN origin_id INTEGER NOT NULL DEFAULT 0")
|
db.execSQL("ALTER TABLE tasks ADD COLUMN origin_id INTEGER NOT NULL DEFAULT 0")
|
||||||
}
|
}
|
||||||
|
// v3 → v4:早期版本的原因备注带【】方括号,一次性清掉历史数据
|
||||||
|
if (oldVersion < 4) {
|
||||||
|
db.execSQL(
|
||||||
|
"UPDATE tasks SET note = REPLACE(REPLACE(note, '【', ''), '】', '') " +
|
||||||
|
"WHERE note LIKE '%【%' OR note LIKE '%】%'"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewTreeObserver
|
import android.view.ViewTreeObserver
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import android.widget.FrameLayout
|
||||||
import com.focusbox.app.R
|
import com.focusbox.app.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,8 +21,9 @@ import com.focusbox.app.R
|
|||||||
*/
|
*/
|
||||||
open class SheetDialog(context: Context) : Dialog(context, R.style.SheetDialog) {
|
open class SheetDialog(context: Context) : Dialog(context, R.style.SheetDialog) {
|
||||||
|
|
||||||
private var imeRoot: View? = null
|
private var imeContainer: FrameLayout? = null
|
||||||
private var imeListener: ViewTreeObserver.OnGlobalLayoutListener? = null
|
private var imeListener: ViewTreeObserver.OnGlobalLayoutListener? = null
|
||||||
|
private var fullHeight = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
window?.apply {
|
window?.apply {
|
||||||
@@ -41,36 +43,61 @@ open class SheetDialog(context: Context) : Dialog(context, R.style.SheetDialog)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 让带输入框的弹层跟随软键盘:弹出时整体上移,收起后回到页面底部。
|
* 让带输入框的弹层跟随软键盘。
|
||||||
* ADJUST_RESIZE 在部分 EMUI 上不会推动 Dialog 内容,只能自己按可见区域平移。
|
*
|
||||||
|
* 关键点:窗口必须是"满屏 + 内容贴底",ADJUST_RESIZE 才有高度可缩。
|
||||||
|
* 之前用 WRAP_CONTENT 窗口 + ADJUST_NOTHING + 自己平移,在 EMUI/HarmonyOS 上
|
||||||
|
* 既拿不到正确的键盘高度,Dialog 本身也不被推动,输入框会被键盘盖住。
|
||||||
|
*
|
||||||
|
* 现在双保险:
|
||||||
|
* 1. 标准路径靠 ADJUST_RESIZE 收缩满屏容器,贴底内容自动抬到键盘之上;
|
||||||
|
* 2. 某些 ROM 忽略 resize 时,按可见显示区域与容器高度的差值兜底平移。
|
||||||
*/
|
*/
|
||||||
fun fitOnIme(content: View) {
|
fun fitOnIme(content: View) {
|
||||||
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
|
val container = FrameLayout(context).apply {
|
||||||
val root = content.rootView
|
layoutParams = ViewGroup.LayoutParams(
|
||||||
imeRoot = root
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
val threshold = (context.resources.displayMetrics.density * 100).toInt()
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
val screenHeight = context.resources.displayMetrics.heightPixels
|
)
|
||||||
|
}
|
||||||
|
val lp = FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
Gravity.BOTTOM,
|
||||||
|
)
|
||||||
|
content.layoutParams = lp
|
||||||
|
container.addView(content)
|
||||||
|
setContentView(container)
|
||||||
|
fullHeight = true
|
||||||
|
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
|
||||||
|
|
||||||
|
val threshold = (context.resources.displayMetrics.density * 80).toInt()
|
||||||
val listener = object : ViewTreeObserver.OnGlobalLayoutListener {
|
val listener = object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
val frame = Rect()
|
val frame = Rect()
|
||||||
root.getWindowVisibleDisplayFrame(frame)
|
container.getWindowVisibleDisplayFrame(frame)
|
||||||
val keyboard = screenHeight - frame.bottom
|
// resize 生效时容器已经收缩,差值为 0;未生效时差值就是键盘(含导航栏)高度
|
||||||
|
val keyboard = container.height - frame.bottom
|
||||||
content.translationY = if (keyboard > threshold) -keyboard.toFloat() else 0f
|
content.translationY = if (keyboard > threshold) -keyboard.toFloat() else 0f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root.viewTreeObserver.addOnGlobalLayoutListener(listener)
|
container.viewTreeObserver.addOnGlobalLayoutListener(listener)
|
||||||
|
imeContainer = container
|
||||||
imeListener = listener
|
imeListener = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dismiss() {
|
override fun dismiss() {
|
||||||
imeListener?.let { imeRoot?.viewTreeObserver?.removeOnGlobalLayoutListener(it) }
|
imeListener?.let { imeContainer?.viewTreeObserver?.removeOnGlobalLayoutListener(it) }
|
||||||
imeListener = null
|
imeListener = null
|
||||||
imeRoot = null
|
imeContainer = null
|
||||||
super.dismiss()
|
super.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
super.show()
|
super.show()
|
||||||
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
window?.setLayout(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
if (fullHeight) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.focusbox.app.ui.focus
|
package com.focusbox.app.ui.focus
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -8,6 +9,7 @@ import android.os.Handler
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.view.ViewConfiguration
|
import android.view.ViewConfiguration
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
@@ -81,11 +83,10 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
private val ticker = object : Runnable {
|
private val ticker = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
// 兜底推进:万一前台服务被系统限流没起来,只要页面还在前台,
|
// 兜底推进:万一前台服务被系统限流没起来,只要页面还在前台,
|
||||||
// 计时与到时结算仍然准确。
|
// 计时与到时结算仍然准确。续命统一交给 render() 末尾的 syncTicker(),
|
||||||
|
// 避免"点开始时轮询已经停了却没人重新拉起"导致圆环数字冻住。
|
||||||
if (TimerCore.running) TimerCore.tick()
|
if (TimerCore.running) TimerCore.tick()
|
||||||
render()
|
render()
|
||||||
// 空闲且没拖动时 render 已经移除轮询,这里不再续命
|
|
||||||
if (TimerCore.running || dragging) handler.postDelayed(this, 250L)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,10 +155,9 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
cachedTaskId = Long.MIN_VALUE // 任务可能被改名/改时长,回到页面强制重读
|
cachedTaskId = Long.MIN_VALUE // 任务可能被改名/改时长,回到页面强制重读
|
||||||
TimerCore.addListener(onTimerChanged)
|
TimerCore.addListener(onTimerChanged)
|
||||||
|
// show/hide 模式下所有片段都处于 resumed,隐藏的页面不该继续跑 250ms 刷新;
|
||||||
|
// render() 末尾会按当前 running 与 isHidden 自行决定是否挂上轮询。
|
||||||
render()
|
render()
|
||||||
handler.removeCallbacks(ticker)
|
|
||||||
// show/hide 模式下所有片段都处于 resumed,隐藏的页面不该继续跑 250ms 刷新
|
|
||||||
if (!isHidden) handler.post(ticker)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@@ -176,8 +176,6 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
// 任务可能在别的页面被改名/改时长,重新显示时强制重读
|
// 任务可能在别的页面被改名/改时长,重新显示时强制重读
|
||||||
cachedTaskId = Long.MIN_VALUE
|
cachedTaskId = Long.MIN_VALUE
|
||||||
render()
|
render()
|
||||||
handler.removeCallbacks(ticker)
|
|
||||||
handler.post(ticker)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,8 +236,19 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
renderDots(accent)
|
renderDots(accent)
|
||||||
renderTask()
|
renderTask()
|
||||||
applyKeepScreen(TimerCore.running && Prefs.keepScreenOn)
|
applyKeepScreen(TimerCore.running && Prefs.keepScreenOn)
|
||||||
// 空闲且没在拖动时不必每 250ms 重绘一次,省电也避免无谓 GC
|
syncTicker()
|
||||||
if (!TimerCore.running && !dragging) handler.removeCallbacks(ticker)
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 轮询必须与 TimerCore.running 同步:点"开始"时先前空闲状态已经移除了回调,
|
||||||
|
* 若只靠 onResume 挂一次,圆环数字就会一直停在点击那一刻。
|
||||||
|
* 每次 render 都先撤后挂,保证任何时刻至多只有一个待执行的 ticker。
|
||||||
|
*/
|
||||||
|
private fun syncTicker() {
|
||||||
|
handler.removeCallbacks(ticker)
|
||||||
|
if (TimerCore.running && !isHidden && view != null) {
|
||||||
|
handler.postDelayed(ticker, 250L)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 通用的原因输入弹层:输入法弹出时整体上移,收起后归位 */
|
/** 通用的原因输入弹层:输入法弹出时整体上移,收起后归位 */
|
||||||
@@ -260,15 +269,25 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
val btnConfirm = root.findViewById<TextView>(R.id.btnFinishNow)
|
val btnConfirm = root.findViewById<TextView>(R.id.btnFinishNow)
|
||||||
btnConfirm.setText(buttonRes)
|
btnConfirm.setText(buttonRes)
|
||||||
btnConfirm.setOnClickListener {
|
btnConfirm.setOnClickListener {
|
||||||
|
// 备注里不保留任何方括号;历史数据由数据库升级一并清掉
|
||||||
val raw = etReason.text?.toString()?.trim().orEmpty()
|
val raw = etReason.text?.toString()?.trim().orEmpty()
|
||||||
|
.replace("【", "").replace("】", "")
|
||||||
onConfirm(raw)
|
onConfirm(raw)
|
||||||
sheet.dismiss()
|
sheet.dismiss()
|
||||||
render()
|
render()
|
||||||
}
|
}
|
||||||
sheet.setContentView(root)
|
|
||||||
sheet.fitOnIme(root)
|
sheet.fitOnIme(root)
|
||||||
etReason.requestFocus()
|
etReason.requestFocus()
|
||||||
sheet.show()
|
sheet.show()
|
||||||
|
// show 之后窗口才有 InputMethodManager 的绑定关系;post 一次确保键盘真的弹出
|
||||||
|
etReason.post {
|
||||||
|
if (!isAdded) return@post
|
||||||
|
etReason.requestFocus()
|
||||||
|
runCatching {
|
||||||
|
(ctx.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager)
|
||||||
|
?.showSoftInput(etReason, InputMethodManager.SHOW_IMPLICIT)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 提前完成:按真实起止结束,并把"原计划 / 原因 / 提前多久"写进任务备注 */
|
/** 提前完成:按真实起止结束,并把"原计划 / 原因 / 提前多久"写进任务备注 */
|
||||||
|
|||||||
@@ -60,8 +60,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="3dp"
|
android:layout_marginTop="3dp"
|
||||||
android:maxLines="2"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:textColor="@color/text_secondary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|||||||
Reference in New Issue
Block a user