列表星标紧贴标题、开始按钮圆底自动开跑;主题弹窗圆角化与版权V化

This commit is contained in:
XIGE
2026-11-28 17:40:00 +08:00
parent edde6e84fc
commit d319eb1d10
7 changed files with 148 additions and 62 deletions

View File

@@ -1,5 +1,9 @@
# 变更记录 # 变更记录
## 2026-11-28 · 列表星标紧贴标题、开始按钮圆底自动开跑;主题弹窗圆角化与版权V化
- 同步源码更新 6 个文件(新增/修改 6,删除 0)。
## 2026-11-28 · v0.5.7:任务完成后消失、紧急度五角星与通知间距 ## 2026-11-28 · v0.5.7:任务完成后消失、紧急度五角星与通知间距
- **通知按钮间距**:锁屏/通知右侧「结束」按钮与「暂停/继续」之间加 8dp 间距,不再贴在一起。 - **通知按钮间距**:锁屏/通知右侧「结束」按钮与「暂停/继续」之间加 8dp 间距,不再贴在一起。

View File

@@ -225,13 +225,18 @@ class MainActivity : AppCompatActivity() {
(fragments[TAB_TASKS] as? TasksFragment)?.applyProjectFilter(projectId) (fragments[TAB_TASKS] as? TasksFragment)?.applyProjectFilter(projectId)
} }
/** 任务行的播放键:把该任务设为当前任务并回到首页,圆环套用任务时长 */ /** 任务行的播放键:把该任务设为当前任务并回到首页,圆环套用任务时长并直接开始 */
fun startFocusOn(task: Task) { fun startFocusOn(task: Task) {
TimerCore.setCountUp(false) TimerCore.setCountUp(false)
TimerCore.setTask(task.id, task.projectId, task.focusMinutes) TimerCore.setTask(task.id, task.projectId, task.focusMinutes)
if (!TimerCore.running && TimerCore.mode != TimerCore.MODE_FOCUS) { if (!TimerCore.running && TimerCore.mode != TimerCore.MODE_FOCUS) {
TimerCore.setMode(TimerCore.MODE_FOCUS) TimerCore.setMode(TimerCore.MODE_FOCUS)
} }
// 空闲时自动开跑,不用回到专注页再点一次「开始专注」;
// 已在计时(本轮进行中)则只换任务与时长,不打断当前进度
if (!TimerCore.running && TimerCore.elapsedNow() <= 0) {
TimerCore.start()
}
showTab(TAB_FOCUS) showTab(TAB_FOCUS)
} }

View File

@@ -6,7 +6,6 @@ import android.view.Gravity
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@@ -19,6 +18,7 @@ import com.focusbox.app.util.Dates
import com.focusbox.app.util.Prefs import com.focusbox.app.util.Prefs
import com.focusbox.app.util.col import com.focusbox.app.util.col
import com.focusbox.app.util.dpi import com.focusbox.app.util.dpi
import com.focusbox.app.util.roundBg
import com.focusbox.app.util.tint import com.focusbox.app.util.tint
/** /**
@@ -266,28 +266,96 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
// ------------------------------------------------------------ 交互 // ------------------------------------------------------------ 交互
private fun pickTheme() { private fun pickTheme() {
val labels = arrayOf( val ctx = requireContext()
getString(R.string.theme_follow), val labels = intArrayOf(
getString(R.string.theme_light), R.string.theme_follow,
getString(R.string.theme_dark), R.string.theme_light,
R.string.theme_dark,
) )
AlertDialog.Builder(requireContext()) val dialog = android.app.Dialog(ctx)
.setTitle(R.string.theme) dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
.setSingleChoiceItems(labels, Prefs.themeMode) { dialog, which ->
Prefs.themeMode = which val panel = LinearLayout(ctx).apply {
(requireActivity().application as App).applyTheme() orientation = LinearLayout.VERTICAL
// 与全局卡片一致:圆角 16dp、surface 底色随深浅色自动切换
background = ctx.roundBg(ctx.col(R.color.surface), 16f, ctx.col(R.color.card_stroke), 1f)
setPadding(dpi(16f), dpi(14f), dpi(16f), dpi(14f))
}
labels.forEachIndexed { index, res ->
val selected = Prefs.themeMode == index
val row = TextView(ctx).apply {
text = getString(res)
textSize = 15f
gravity = Gravity.CENTER
setTextColor(col(if (selected) R.color.brand else R.color.text))
typeface = if (selected) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
background = if (selected) {
ctx.roundBg(ctx.col(R.color.brand_soft), 12f)
} else {
ctx.roundBg(ctx.col(R.color.surface), 12f)
}
setPadding(0, dpi(14f), 0, dpi(14f))
setOnClickListener {
dialog.dismiss() dialog.dismiss()
if (Prefs.themeMode != index) {
Prefs.themeMode = index
(requireActivity().application as App).applyTheme()
requireActivity().recreate() requireActivity().recreate()
} }
.show() }
}
panel.addView(row, LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
).apply { topMargin = dpi(6f) })
}
dialog.setContentView(panel)
dialog.show()
} }
private fun confirmClear() { private fun confirmClear() {
AlertDialog.Builder(requireContext()) val ctx = requireContext()
.setTitle(R.string.clear_data) val dialog = android.app.Dialog(ctx)
.setMessage(R.string.clear_confirm) dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete) { _, _ -> val panel = LinearLayout(ctx).apply {
orientation = LinearLayout.VERTICAL
background = ctx.roundBg(ctx.col(R.color.surface), 16f, ctx.col(R.color.card_stroke), 1f)
setPadding(dpi(20f), dpi(20f), dpi(20f), dpi(14f))
}
panel.addView(TextView(ctx).apply {
text = getString(R.string.clear_data)
textSize = 16f
typeface = Typeface.DEFAULT_BOLD
setTextColor(col(R.color.text))
})
panel.addView(TextView(ctx).apply {
text = getString(R.string.clear_confirm)
textSize = 14f
setTextColor(col(R.color.text_secondary))
setPadding(0, dpi(10f), 0, dpi(6f))
})
val btnRow = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.END
setPadding(0, dpi(12f), 0, 0)
}
fun btn(labelRes: Int, danger: Boolean, onClick: () -> Unit) = TextView(ctx).apply {
text = getString(labelRes)
textSize = 14f
typeface = Typeface.DEFAULT_BOLD
gravity = Gravity.CENTER
setTextColor(col(if (danger) R.color.danger else R.color.brand))
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
setPadding(dpi(22f), dpi(10f), dpi(22f), dpi(10f))
setOnClickListener { onClick() }
}
btnRow.addView(btn(R.string.cancel, false) { dialog.dismiss() })
btnRow.addView(btn(R.string.delete, true) {
dialog.dismiss()
TimerCore.reset() TimerCore.reset()
Store.clearAll() Store.clearAll()
Prefs.clearTimer() Prefs.clearTimer()
@@ -295,11 +363,16 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
TimerCore.resetRound() TimerCore.resetRound()
(activity as? MainActivity)?.refreshAll() (activity as? MainActivity)?.refreshAll()
build() build()
} }, LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT).apply {
.show() marginStart = dpi(10f)
})
panel.addView(btnRow)
dialog.setContentView(panel)
dialog.show()
} }
companion object { companion object {
const val VERSION = "0.2.0" const val VERSION = "0.5.8"
} }
} }

View File

@@ -2,6 +2,8 @@ package com.focusbox.app.ui.tasks
import android.graphics.Paint import android.graphics.Paint
import android.graphics.Typeface import android.graphics.Typeface
import android.text.SpannableStringBuilder
import android.text.style.RelativeSizeSpan
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@@ -67,7 +69,6 @@ class TaskAdapter(
private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) { private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) {
private val tvTitle: TextView = v.findViewById(R.id.tvTitle) private val tvTitle: TextView = v.findViewById(R.id.tvTitle)
private val tvStars: TextView = v.findViewById(R.id.tvStars)
private val tvMeta: TextView = v.findViewById(R.id.tvMeta) private val tvMeta: TextView = v.findViewById(R.id.tvMeta)
private val tvNote: TextView = v.findViewById(R.id.tvNote) private val tvNote: TextView = v.findViewById(R.id.tvNote)
private val checkCircle: View = v.findViewById(R.id.checkCircle) private val checkCircle: View = v.findViewById(R.id.checkCircle)
@@ -79,7 +80,23 @@ class TaskAdapter(
val task = row.task val task = row.task
val ctx = itemView.context val ctx = itemView.context
tvTitle.text = task.title // 紧急度五角星直接拼在标题后:紧急三颗红 / 中两颗绿 / 不急一颗灰;
// 完成任务不再显示。用 spannable 保证星星紧贴标题而不是被推到行尾。
val title = SpannableStringBuilder(task.title)
if (!task.done) {
val (stars, color) = when (task.urgency) {
2 -> " ★★★" to R.color.urgent_high
1 -> " ★★" to R.color.urgent_mid
else -> " ★" to R.color.urgent_low
}
val start = title.length
title.append(stars)
title.setSpan(
android.text.style.ForegroundColorSpan(ctx.col(color)), start, title.length, 0
)
title.setSpan(RelativeSizeSpan(0.95f), start, title.length, 0)
}
tvTitle.text = title
tvTitle.paintFlags = if (task.done) { tvTitle.paintFlags = if (task.done) {
tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
} else { } else {
@@ -88,20 +105,6 @@ class TaskAdapter(
tvTitle.setTextColor(ctx.col(if (task.done) R.color.text_tertiary else R.color.text)) tvTitle.setTextColor(ctx.col(if (task.done) R.color.text_tertiary else R.color.text))
tvTitle.typeface = if (task.priority >= 2 && !task.done) Typeface.DEFAULT_BOLD else Typeface.DEFAULT tvTitle.typeface = if (task.priority >= 2 && !task.done) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰;完成任务不再显示
if (!task.done) {
val (stars, color) = when (task.urgency) {
2 -> "★★★" to R.color.urgent_high
1 -> "★★" to R.color.urgent_mid
else -> "★" to R.color.urgent_low
}
tvStars.text = stars
tvStars.setTextColor(ctx.col(color))
tvStars.visible(true)
} else {
tvStars.visible(false)
}
if (task.done) { if (task.done) {
checkCircle.background = ctx.circleBg(ctx.col(R.color.brand)) checkCircle.background = ctx.circleBg(ctx.col(R.color.brand))
checkMark.visible(true) checkMark.visible(true)
@@ -128,7 +131,7 @@ class TaskAdapter(
tvNote.visible(task.note.isNotBlank()) tvNote.visible(task.note.isNotBlank())
btnPlay.visible(!task.done) btnPlay.visible(!task.done)
btnPlay.tint(ctx.col(R.color.text_tertiary)) btnPlay.tint(ctx.col(R.color.brand))
checkWrap.setOnClickListener { onToggle(task) } checkWrap.setOnClickListener { onToggle(task) }
itemView.setOnClickListener { onEdit(task) } itemView.setOnClickListener { onEdit(task) }

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 任务列表的开始按钮:圆形底色随深浅色自动切换 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/surface_alt" />
<stroke
android:width="1dp"
android:color="@color/card_stroke" />
</shape>

View File

@@ -52,16 +52,6 @@
android:textColor="@color/text" android:textColor="@color/text"
android:maxLines="2" android:maxLines="2"
android:ellipsize="end" /> android:ellipsize="end" />
<TextView
android:id="@+id/tvStars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:textSize="11sp"
android:includeFontPadding="false"
android:letterSpacing="0.08"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
<TextView <TextView
@@ -85,10 +75,12 @@
<ImageView <ImageView
android:id="@+id/btnPlay" android:id="@+id/btnPlay"
android:layout_width="34dp" android:layout_width="38dp"
android:layout_height="34dp" android:layout_height="38dp"
android:padding="8dp" android:layout_marginStart="6dp"
android:background="?attr/selectableItemBackgroundBorderless" android:padding="11dp"
android:background="@drawable/bg_play_circle"
android:scaleType="fitCenter"
android:src="@drawable/ic_play" android:src="@drawable/ic_play"
android:contentDescription="@string/start" /> android:contentDescription="@string/start" />
</LinearLayout> </LinearLayout>

View File

@@ -172,14 +172,14 @@
<string name="vibrate">振动</string> <string name="vibrate">振动</string>
<string name="keep_screen_on">计时时保持屏幕常亮</string> <string name="keep_screen_on">计时时保持屏幕常亮</string>
<string name="daily_goal">每日目标</string> <string name="daily_goal">每日目标</string>
<string name="theme">深色模式</string> <string name="theme">深浅色</string>
<string name="theme_follow">跟随系统</string> <string name="theme_follow">跟随系统</string>
<string name="theme_light">浅色</string> <string name="theme_light">浅色</string>
<string name="theme_dark">深色</string> <string name="theme_dark">深色</string>
<string name="clear_data">清空所有数据</string> <string name="clear_data">清空所有数据</string>
<string name="clear_data_hint">项目、任务、专注记录全部删除,不可恢复</string> <string name="clear_data_hint">项目、任务、专注记录全部删除,不可恢复</string>
<string name="clear_confirm">确定清空全部数据?此操作不可恢复。</string> <string name="clear_confirm">确定清空全部数据?此操作不可恢复。</string>
<string name="about_version">版本 %1$s · 自用版</string> <string name="about_version">V%1$s</string>
<string name="value_minutes">%1$d 分钟</string> <string name="value_minutes">%1$d 分钟</string>
<string name="value_rounds">%1$d 轮</string> <string name="value_rounds">%1$d 轮</string>