项目排序模式序号与置顶;横屏锁屏遮状态栏、排版对称化;版本 1.2

This commit is contained in:
XIGE
2026-11-29 14:20:09 +08:00
parent bc01e0ac67
commit fd674322a1
11 changed files with 140 additions and 42 deletions

View File

@@ -1,5 +1,18 @@
# 变更记录 # 变更记录
## 2026-11-29 · 项目排序模式序号与置顶;横屏锁屏遮状态栏、排版对称化;版本 1.2
- 同步源码更新 10 个文件(新增/修改 10,删除 0)。
## 2026-11-29 · 项目排序模式(序号+置顶);横屏锁屏遮状态栏、排版对称化(v1.2)
- 项目排序模式:数据库 v6 → v7,projects 新增 sort_index(序号)与 pinned_at(置顶时间)两列,旧数据自动迁移(默认 0 = 不置顶/未设置)
- 列表排序规则:归档仍排最后 → 置顶项目排最前(多个置顶按置顶时间倒序,越近越靠前)→ 非置顶按序号升序(同序号按创建先后)
- 新增/编辑项目弹窗:序号输入框(数字,留空按 0)+ 置顶开关;已置顶再保存不刷新置顶时间,新勾置顶以保存时刻为准;归档/取消归档切换原样保留序号与置顶状态
- 横屏锁屏:主题加 windowFullscreen 强制全屏,横竖屏都彻底遮掉状态栏时间/信号/电池
- 横屏排版重排:左侧倒计时(96sp)+ 任务名,右侧时钟(96sp)+ 日期星期移到时钟下面,两侧主字号统一、左右对称;删除横屏「工作中/休息中」提示(竖屏保留)
- 版本 1.1 → 1.2(versionCode 36)
## 2026-11-29 · 锁屏倒计时改灭屏投递拉起不再出横幅;沉浸式遮状态栏;横屏专属排版;版本 1.1 ## 2026-11-29 · 锁屏倒计时改灭屏投递拉起不再出横幅;沉浸式遮状态栏;横屏专属排版;版本 1.1
- 同步源码更新 5 个文件(新增/修改 5,删除 0)。 - 同步源码更新 5 个文件(新增/修改 5,删除 0)。

View File

@@ -26,7 +26,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 = 6 private const val DB_VERSION = 7
private lateinit var helper: Helper private lateinit var helper: Helper
@@ -46,6 +46,8 @@ object Store {
color INTEGER NOT NULL, color INTEGER NOT NULL,
archived INTEGER NOT NULL DEFAULT 0, archived INTEGER NOT NULL DEFAULT 0,
sort INTEGER NOT NULL DEFAULT 0, sort INTEGER NOT NULL DEFAULT 0,
sort_index INTEGER NOT NULL DEFAULT 0,
pinned_at INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL created_at INTEGER NOT NULL
) )
""".trimIndent() """.trimIndent()
@@ -125,6 +127,11 @@ object Store {
if (oldVersion < 6) { if (oldVersion < 6) {
db.execSQL("ALTER TABLE tasks ADD COLUMN urgency INTEGER NOT NULL DEFAULT 1") db.execSQL("ALTER TABLE tasks ADD COLUMN urgency INTEGER NOT NULL DEFAULT 1")
} }
// v6 → v7:项目排序模式——序号(非置顶按序号升序)+ 置顶时间(置顶排最前,越近越靠前)
if (oldVersion < 7) {
db.execSQL("ALTER TABLE projects ADD COLUMN sort_index INTEGER NOT NULL DEFAULT 0")
db.execSQL("ALTER TABLE projects ADD COLUMN pinned_at INTEGER NOT NULL DEFAULT 0")
}
} }
} }
@@ -132,14 +139,17 @@ object Store {
fun projects(includeArchived: Boolean = false): List<Project> { fun projects(includeArchived: Boolean = false): List<Project> {
val sql = """ val sql = """
SELECT p._id, p.name, p.color, p.archived, p.sort, SELECT p._id, p.name, p.color, p.archived, p.sort, p.sort_index, p.pinned_at,
(SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 0) AS open_tasks, (SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 0) AS open_tasks,
(SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 1) AS done_tasks, (SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 1) AS done_tasks,
(SELECT IFNULL(SUM(s.seconds), 0) FROM sessions s WHERE s.project_id = p._id) AS focus_sec, (SELECT IFNULL(SUM(s.seconds), 0) FROM sessions s WHERE s.project_id = p._id) AS focus_sec,
(SELECT COUNT(*) FROM sessions s WHERE s.project_id = p._id AND s.completed = 1) AS pomos (SELECT COUNT(*) FROM sessions s WHERE s.project_id = p._id AND s.completed = 1) AS pomos
FROM projects p FROM projects p
WHERE p.archived = 0 OR ${if (includeArchived) 1 else 0} = 1 WHERE p.archived = 0 OR ${if (includeArchived) 1 else 0} = 1
ORDER BY p.archived ASC, p.sort ASC, p._id ASC ORDER BY p.archived ASC,
CASE WHEN p.pinned_at > 0 THEN 1 ELSE 0 END DESC,
CASE WHEN p.pinned_at > 0 THEN p.pinned_at ELSE 0 END DESC,
p.sort_index ASC, p.sort ASC, p._id ASC
""".trimIndent() """.trimIndent()
val list = ArrayList<Project>() val list = ArrayList<Project>()
db.rawQuery(sql, null).use { c -> db.rawQuery(sql, null).use { c ->
@@ -151,10 +161,12 @@ object Store {
color = c.getInt(2), color = c.getInt(2),
archived = c.getInt(3) == 1, archived = c.getInt(3) == 1,
sort = c.getInt(4), sort = c.getInt(4),
openTasks = c.getInt(5), sortIndex = c.getInt(5),
doneTasks = c.getInt(6), pinnedAt = c.getLong(6),
focusSeconds = c.getInt(7), openTasks = c.getInt(7),
pomodoros = c.getInt(8), doneTasks = c.getInt(8),
focusSeconds = c.getInt(9),
pomodoros = c.getInt(10),
) )
) )
} }
@@ -164,22 +176,34 @@ object Store {
fun project(id: Long): Project? = projects(true).firstOrNull { it.id == id } fun project(id: Long): Project? = projects(true).firstOrNull { it.id == id }
fun addProject(name: String, color: Int): Long { fun addProject(name: String, color: Int, sortIndex: Int = 0, pinned: Boolean = false): Long {
val now = System.currentTimeMillis()
val cv = ContentValues().apply { val cv = ContentValues().apply {
put("name", name) put("name", name)
put("color", color) put("color", color)
put("archived", 0) put("archived", 0)
put("sort", System.currentTimeMillis() / 1000) put("sort", now / 1000)
put("created_at", System.currentTimeMillis()) put("sort_index", sortIndex)
put("pinned_at", if (pinned) now else 0L)
put("created_at", now)
} }
return db.insert("projects", null, cv) return db.insert("projects", null, cv)
} }
fun updateProject(id: Long, name: String, color: Int, archived: Boolean) { /**
* pinnedAt 语义:pinned=true 且原值 0 → 取传入值(新建置顶时由调用方给 now);
* 已置顶保持置顶 → 保留原置顶时间(重复保存不刷新排序);取消置顶 → 归 0。
*/
fun updateProject(
id: Long, name: String, color: Int, archived: Boolean,
sortIndex: Int = 0, pinned: Boolean = false, pinnedAt: Long = 0,
) {
val cv = ContentValues().apply { val cv = ContentValues().apply {
put("name", name) put("name", name)
put("color", color) put("color", color)
put("archived", if (archived) 1 else 0) put("archived", if (archived) 1 else 0)
put("sort_index", sortIndex)
put("pinned_at", if (pinned) pinnedAt else 0L)
} }
db.update("projects", cv, "_id = ?", arrayOf(id.toString())) db.update("projects", cv, "_id = ?", arrayOf(id.toString()))
} }

View File

@@ -11,6 +11,10 @@ data class Project(
val doneTasks: Int, val doneTasks: Int,
val focusSeconds: Int, val focusSeconds: Int,
val pomodoros: Int, val pomodoros: Int,
/** 排序序号:非置顶项目按它升序排,数字越小越靠前 */
val sortIndex: Int = 0,
/** 置顶时间戳:0 未置顶;置顶项目排最前,多个置顶按它倒序(越近越靠前) */
val pinnedAt: Long = 0,
) { ) {
val totalTasks: Int get() = openTasks + doneTasks val totalTasks: Int get() = openTasks + doneTasks
val progress: Float get() = if (totalTasks == 0) 0f else doneTasks.toFloat() / totalTasks val progress: Float get() = if (totalTasks == 0) 0f else doneTasks.toFloat() / totalTasks

View File

@@ -51,7 +51,6 @@ class LockScreenActivity : AppCompatActivity() {
private lateinit var tvDate: TextView private lateinit var tvDate: TextView
private lateinit var tvClock: TextView private lateinit var tvClock: TextView
private lateinit var tvCountdown: TextView private lateinit var tvCountdown: TextView
private lateinit var tvMode: TextView
private lateinit var tvTask: TextView private lateinit var tvTask: TextView
private val clockFmt = SimpleDateFormat("HH:mm", Locale.getDefault()) private val clockFmt = SimpleDateFormat("HH:mm", Locale.getDefault())
@@ -86,11 +85,12 @@ class LockScreenActivity : AppCompatActivity() {
tvDate = findViewById(R.id.tvLockDate) tvDate = findViewById(R.id.tvLockDate)
tvClock = findViewById(R.id.tvLockClock) tvClock = findViewById(R.id.tvLockClock)
tvCountdown = findViewById(R.id.tvLockCountdown) tvCountdown = findViewById(R.id.tvLockCountdown)
tvMode = findViewById(R.id.tvLockMode)
tvTask = findViewById(R.id.tvLockTask) tvTask = findViewById(R.id.tvLockTask)
findViewById<View>(R.id.lockRoot).setOnClickListener { finish() } findViewById<View>(R.id.lockRoot).setOnClickListener { finish() }
applyImmersive()
ContextCompat.registerReceiver( ContextCompat.registerReceiver(
this, this,
unlockReceiver, unlockReceiver,
@@ -156,7 +156,8 @@ class LockScreenActivity : AppCompatActivity() {
tvClock.text = clockFmt.format(cal.time) tvClock.text = clockFmt.format(cal.time)
tvCountdown.text = Dates.clock(now) tvCountdown.text = Dates.clock(now)
tvMode.text = getString( // 工作中/休息中提示只有竖屏布局有(横屏排版里删掉了),横屏下 findViewById 返回 null
findViewById<TextView>(R.id.tvLockMode)?.text = getString(
if (TimerCore.mode == TimerCore.MODE_FOCUS) R.string.lock_mode_focus else R.string.lock_mode_break if (TimerCore.mode == TimerCore.MODE_FOCUS) R.string.lock_mode_focus else R.string.lock_mode_break
) )

View File

@@ -28,6 +28,8 @@ class ProjectSheet(
private val root = LayoutInflater.from(context).inflate(R.layout.sheet_project, null) private val root = LayoutInflater.from(context).inflate(R.layout.sheet_project, null)
private val etName: EditText = root.findViewById(R.id.etName) private val etName: EditText = root.findViewById(R.id.etName)
private val etSortIndex: EditText = root.findViewById(R.id.etSortIndex)
private val swPinned: androidx.appcompat.widget.SwitchCompat = root.findViewById(R.id.swPinned)
private val colorRow: LinearLayout = root.findViewById(R.id.colorRow) private val colorRow: LinearLayout = root.findViewById(R.id.colorRow)
private var color: Int = existing?.color ?: Palette.colorAt(0) private var color: Int = existing?.color ?: Palette.colorAt(0)
@@ -38,6 +40,11 @@ class ProjectSheet(
if (existing == null) R.string.add_project else R.string.edit if (existing == null) R.string.add_project else R.string.edit
) )
etName.setText(existing?.name ?: "") etName.setText(existing?.name ?: "")
// 编辑已有序号才回填;未设置过序号显示空,保存时按 0 处理(同级按创建先后排)
if (existing != null && existing.sortIndex > 0) {
etSortIndex.setText(existing.sortIndex.toString())
}
swPinned.isChecked = (existing?.pinnedAt ?: 0L) > 0L
renderColors() renderColors()
val btnDelete = root.findViewById<TextView>(R.id.btnDelete) val btnDelete = root.findViewById<TextView>(R.id.btnDelete)
@@ -62,10 +69,20 @@ class ProjectSheet(
etName.error = context.getString(R.string.project_name_hint) etName.error = context.getString(R.string.project_name_hint)
return@setOnClickListener return@setOnClickListener
} }
val sortIndex = etSortIndex.text.toString().trim().toIntOrNull() ?: 0
val pinned = swPinned.isChecked
if (existing == null) { if (existing == null) {
Store.addProject(name, color) // 新建置顶:置顶时间取当下,排进置顶组
Store.addProject(name, color, sortIndex, pinned)
} else { } else {
Store.updateProject(existing.id, name, color, existing.archived) // 已置顶且保持置顶 → 保留原置顶时间(重复保存不刷新排序);
// 新勾置顶 → 以保存这一刻为置顶时间;取消置顶 → Store 里归 0
val pinnedAt = when {
!pinned -> 0L
existing.pinnedAt > 0L -> existing.pinnedAt
else -> System.currentTimeMillis()
}
Store.updateProject(existing.id, name, color, existing.archived, sortIndex, pinned, pinnedAt)
} }
onSaved() onSaved()
dismiss() dismiss()

View File

@@ -128,7 +128,11 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
when { when {
which == 0 -> ProjectSheet(requireContext(), p) { reload() }.show() which == 0 -> ProjectSheet(requireContext(), p) { reload() }.show()
which == 1 && !isInbox -> { which == 1 && !isInbox -> {
Store.updateProject(p.id, p.name, p.color, !p.archived) // 归档/取消归档只切 archived,序号与置顶状态原样保留
Store.updateProject(
p.id, p.name, p.color, !p.archived,
p.sortIndex, p.pinnedAt > 0, p.pinnedAt,
)
reload() reload()
} }
which == 2 && !isInbox -> confirmDelete(p) which == 2 && !isInbox -> confirmDelete(p)

View File

@@ -431,6 +431,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
} }
companion object { companion object {
const val VERSION = "1.1" const val VERSION = "1.2"
} }
} }

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
锁屏全屏倒计时·横屏专属排版(区别于竖屏的纯纵向堆叠): 锁屏全屏倒计时·横屏专属排版(区别于竖屏的纯纵向堆叠):
左右分栏 —— 左侧主角是大号倒计时 + 任务名,细竖线分隔, 左右对称分栏 —— 左侧倒计时(大)+ 任务名,右侧时钟(大)+ 日期星期,
右侧信息栏纵向排日期/时钟/状态,重心靠左、信息靠右。 两侧主字号统一 96sp,视觉左右对应;无「工作中/休息中」提示。
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lockRoot" android:id="@+id/lockRoot"
@@ -14,11 +14,11 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<!-- 左:倒计时 + 任务名(主角区) --> <!-- 左:倒计时 + 任务名 -->
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1.2" android:layout_weight="1"
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
@@ -28,16 +28,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:includeFontPadding="false" android:includeFontPadding="false"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="120sp" android:textSize="96sp"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/tvLockTask" android:id="@+id/tvLockTask"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="18dp" android:layout_marginTop="20dp"
android:ellipsize="end" android:ellipsize="end"
android:maxWidth="360dp" android:maxWidth="320dp"
android:maxLines="1" android:maxLines="1"
android:textColor="#CCFFFFFF" android:textColor="#CCFFFFFF"
android:textSize="17sp" /> android:textSize="17sp" />
@@ -49,7 +49,7 @@
android:layout_height="180dp" android:layout_height="180dp"
android:background="#26FFFFFF" /> android:background="#26FFFFFF" />
<!-- 右:信息栏(日期 / 时钟 / 状态) --> <!-- 右:时钟(大)+ 日期星期在时钟下面 -->
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -57,32 +57,23 @@
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/tvLockDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.08"
android:textColor="#99FFFFFF"
android:textSize="15sp" />
<TextView <TextView
android:id="@+id/tvLockClock" android:id="@+id/tvLockClock"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:includeFontPadding="false" android:includeFontPadding="false"
android:textColor="#CCFFFFFF" android:textColor="#FFFFFF"
android:textSize="64sp" android:textSize="96sp"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/tvLockMode" android:id="@+id/tvLockDate"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="18dp" android:layout_marginTop="20dp"
android:letterSpacing="0.2" android:letterSpacing="0.08"
android:textColor="#66FFFFFF" android:textColor="#99FFFFFF"
android:textSize="13sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -45,6 +45,45 @@
android:inputType="text" android:inputType="text"
android:maxLines="1" /> android:maxLines="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:orientation="horizontal"
android:gravity="center_vertical">
<EditText
android:id="@+id/etSortIndex"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_field"
android:paddingStart="14dp"
android:paddingEnd="14dp"
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:hint="@string/sort_index_hint"
android:textColor="@color/text"
android:textColorHint="@color/text_tertiary"
android:textSize="15sp"
android:inputType="number"
android:maxLines="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="@string/project_pinned"
android:textSize="15sp"
android:textColor="@color/text" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPinned"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp" />
</LinearLayout>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -191,6 +191,9 @@
<string name="lock_perm_title">锁屏显示权限</string> <string name="lock_perm_title">锁屏显示权限</string>
<string name="lock_perm_value">去开启</string> <string name="lock_perm_value">去开启</string>
<string name="go_set">去设置</string> <string name="go_set">去设置</string>
<string name="project_sort_index">排序序号</string>
<string name="sort_index_hint">序号,越小越靠前</string>
<string name="project_pinned">置顶</string>
<string name="lock_perm_hint">华为/鸿蒙默认拦截后台拉起页面,锁屏倒计时需要手动开启。路径:设置 → 应用 → 应用启动管理 → 时间简史 → 关闭「自动管理」,并允许「后台弹出界面」和「锁屏显示」。点「去设置」可直接打开对应页面。</string> <string name="lock_perm_hint">华为/鸿蒙默认拦截后台拉起页面,锁屏倒计时需要手动开启。路径:设置 → 应用 → 应用启动管理 → 时间简史 → 关闭「自动管理」,并允许「后台弹出界面」和「锁屏显示」。点「去设置」可直接打开对应页面。</string>
<string name="lock_mode_focus">工作中</string> <string name="lock_mode_focus">工作中</string>
<string name="lock_mode_break">休息中</string> <string name="lock_mode_break">休息中</string>

View File

@@ -20,6 +20,8 @@
<!-- 锁屏全屏倒计时页:纯黑底、白色字,不随深浅色主题切换 --> <!-- 锁屏全屏倒计时页:纯黑底、白色字,不随深浅色主题切换 -->
<style name="LockScreenTheme" parent="Theme.AppCompat.NoActionBar"> <style name="LockScreenTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@android:color/black</item> <item name="android:windowBackground">@android:color/black</item>
<!-- 主题级全屏:横竖屏都把状态栏(时间/信号/电池)彻底拿掉,横屏同样生效 -->
<item name="android:windowFullscreen">true</item>
<item name="android:statusBarColor">@android:color/black</item> <item name="android:statusBarColor">@android:color/black</item>
<item name="android:navigationBarColor">@android:color/black</item> <item name="android:navigationBarColor">@android:color/black</item>
<item name="android:windowLightStatusBar">false</item> <item name="android:windowLightStatusBar">false</item>