列表星标紧贴标题、开始按钮圆底自动开跑;主题弹窗圆角化与版权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

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

View File

@@ -6,7 +6,6 @@ import android.view.Gravity
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat
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.col
import com.focusbox.app.util.dpi
import com.focusbox.app.util.roundBg
import com.focusbox.app.util.tint
/**
@@ -266,40 +266,113 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
// ------------------------------------------------------------ 交互
private fun pickTheme() {
val labels = arrayOf(
getString(R.string.theme_follow),
getString(R.string.theme_light),
getString(R.string.theme_dark),
val ctx = requireContext()
val labels = intArrayOf(
R.string.theme_follow,
R.string.theme_light,
R.string.theme_dark,
)
AlertDialog.Builder(requireContext())
.setTitle(R.string.theme)
.setSingleChoiceItems(labels, Prefs.themeMode) { dialog, which ->
Prefs.themeMode = which
(requireActivity().application as App).applyTheme()
dialog.dismiss()
requireActivity().recreate()
val dialog = android.app.Dialog(ctx)
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
val panel = LinearLayout(ctx).apply {
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()
if (Prefs.themeMode != index) {
Prefs.themeMode = index
(requireActivity().application as App).applyTheme()
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() {
AlertDialog.Builder(requireContext())
.setTitle(R.string.clear_data)
.setMessage(R.string.clear_confirm)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete) { _, _ ->
TimerCore.reset()
Store.clearAll()
Prefs.clearTimer()
Prefs.timerRound = 0
TimerCore.resetRound()
(activity as? MainActivity)?.refreshAll()
build()
}
.show()
val ctx = requireContext()
val dialog = android.app.Dialog(ctx)
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
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()
Store.clearAll()
Prefs.clearTimer()
Prefs.timerRound = 0
TimerCore.resetRound()
(activity as? MainActivity)?.refreshAll()
build()
}, LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT).apply {
marginStart = dpi(10f)
})
panel.addView(btnRow)
dialog.setContentView(panel)
dialog.show()
}
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.Typeface
import android.text.SpannableStringBuilder
import android.text.style.RelativeSizeSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -67,7 +69,6 @@ class TaskAdapter(
private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) {
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 tvNote: TextView = v.findViewById(R.id.tvNote)
private val checkCircle: View = v.findViewById(R.id.checkCircle)
@@ -79,7 +80,23 @@ class TaskAdapter(
val task = row.task
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 or Paint.STRIKE_THRU_TEXT_FLAG
} else {
@@ -88,20 +105,6 @@ class TaskAdapter(
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
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰;完成任务不再显示
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) {
checkCircle.background = ctx.circleBg(ctx.col(R.color.brand))
checkMark.visible(true)
@@ -128,7 +131,7 @@ class TaskAdapter(
tvNote.visible(task.note.isNotBlank())
btnPlay.visible(!task.done)
btnPlay.tint(ctx.col(R.color.text_tertiary))
btnPlay.tint(ctx.col(R.color.brand))
checkWrap.setOnClickListener { onToggle(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:maxLines="2"
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>
<TextView
@@ -85,10 +75,12 @@
<ImageView
android:id="@+id/btnPlay"
android:layout_width="34dp"
android:layout_height="34dp"
android:padding="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="6dp"
android:padding="11dp"
android:background="@drawable/bg_play_circle"
android:scaleType="fitCenter"
android:src="@drawable/ic_play"
android:contentDescription="@string/start" />
</LinearLayout>

View File

@@ -172,14 +172,14 @@
<string name="vibrate">振动</string>
<string name="keep_screen_on">计时时保持屏幕常亮</string>
<string name="daily_goal">每日目标</string>
<string name="theme">深色模式</string>
<string name="theme">深浅色</string>
<string name="theme_follow">跟随系统</string>
<string name="theme_light">浅色</string>
<string name="theme_dark">深色</string>
<string name="clear_data">清空所有数据</string>
<string name="clear_data_hint">项目、任务、专注记录全部删除,不可恢复</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_rounds">%1$d 轮</string>