Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae75410e9b | ||
|
|
234df41f64 | ||
|
|
aad58da3b9 | ||
|
|
0a7d5fda8c | ||
|
|
ec286bcc6b | ||
|
|
853186015d | ||
|
|
1df122af48 | ||
|
|
177c965894 | ||
|
|
c9c7a79349 | ||
|
|
320554381e | ||
|
|
a1e200a1d6 | ||
|
|
256ccfe1ae | ||
|
|
0058efe5df | ||
|
|
6989dc0c68 | ||
|
|
43b12b1bf4 | ||
|
|
fcfd167623 | ||
|
|
44b0baacca | ||
|
|
ce48d805fc | ||
|
|
65f56490e9 | ||
|
|
35a7c4a785 | ||
|
|
ab8840d421 | ||
|
|
ce4ec2cd51 | ||
|
|
467d34afe8 | ||
|
|
256c0d4540 | ||
|
|
30b385a4d9 | ||
|
|
8a7147b299 | ||
|
|
47294f4fcf | ||
|
|
8ad5441ba4 | ||
|
|
9c8e2eb534 | ||
|
|
eb3d961b0a | ||
|
|
9fdecfb1b9 | ||
|
|
a8446bcf51 | ||
|
|
54df5b398c | ||
|
|
8a1f41ca9d | ||
|
|
4a648669ea | ||
|
|
60fd3d1044 | ||
|
|
ed7927af1d | ||
|
|
2d999edc0c | ||
|
|
4e062923ef | ||
|
|
7d8995ead0 | ||
|
|
4444b18b29 | ||
|
|
11dc2825cc | ||
|
|
2dd7f8b506 | ||
|
|
3277fa5826 | ||
|
|
00a01b3f22 | ||
|
|
01ca852b2a | ||
|
|
8e7de267a4 | ||
|
|
9305bd588b | ||
|
|
77319b30da | ||
|
|
8694908305 | ||
|
|
5b58596727 | ||
|
|
7762e463d6 | ||
|
|
3cad26fbdb | ||
|
|
035da90a76 | ||
|
|
68b9961784 | ||
|
|
d03fb45adf | ||
|
|
e7089ae76b | ||
|
|
1d355693be | ||
|
|
93faf6d21e | ||
|
|
a5cd605a5c | ||
|
|
05a3462c6e | ||
|
|
c8cc773fef | ||
|
|
c0182de5e5 | ||
|
|
65dd5bfe91 | ||
|
|
fd674322a1 | ||
|
|
bc01e0ac67 |
322
CHANGELOG.md
322
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,8 @@
|
|||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<!-- 锁屏全屏倒计时:计时中锁屏亮屏时把全屏页盖在锁屏上 -->
|
<!-- 锁屏全屏倒计时:计时中锁屏亮屏时把全屏页盖在锁屏上 -->
|
||||||
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
||||||
|
<!-- 锁屏悬浮窗:鸿蒙拦 Activity 后台启动,改用 WindowManager 直接把倒计时画在锁屏上(addView 不受"后台弹出界面"限制) -->
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
@@ -44,13 +46,12 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.lockscreen.LockScreenActivity"
|
android:name=".ui.lockscreen.LockScreenActivity"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
android:launchMode="singleTask"
|
||||||
android:showWhenLocked="true"
|
android:showWhenLocked="true"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
android:theme="@style/LockScreenTheme"
|
android:theme="@style/LockScreenTheme" />
|
||||||
android:turnScreenOn="true" />
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.TimerService"
|
android:name=".service.TimerService"
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
package com.focusbox.app.model
|
package com.focusbox.app.model
|
||||||
|
|
||||||
/** 项目(清单)。收件箱固定 id=1,不可删除。 */
|
/** 项目(清单)。id=0 表示未分类,不对应项目行;项目行均可编辑/归档/删除。 */
|
||||||
data class Project(
|
data class Project(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val name: String,
|
val name: String,
|
||||||
@@ -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
|
||||||
@@ -58,6 +62,30 @@ data class Task(
|
|||||||
/** 一条专注记录的起止时刻与实际秒数,用于在已完成任务上显示真实工作时段。 */
|
/** 一条专注记录的起止时刻与实际秒数,用于在已完成任务上显示真实工作时段。 */
|
||||||
data class SessionSpan(val startAt: Long, val endAt: Long, val seconds: Int = 0)
|
data class SessionSpan(val startAt: Long, val endAt: Long, val seconds: Int = 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目卡展开后的一条任务行:任务本体 + 三项统计。
|
||||||
|
* 仅用于项目页展开列表,任务页的 Task 口径不变。
|
||||||
|
*/
|
||||||
|
data class ProjectTaskStat(
|
||||||
|
val task: Task,
|
||||||
|
/** 最近一次完成时刻(源任务 done_at 与该任务 sessions 最近 end_at 取大),0 表示未完成过 */
|
||||||
|
val lastDoneAt: Long,
|
||||||
|
/** 累计完成次数(done_pomodoros;勾选完成且无 session 时至少 1) */
|
||||||
|
val doneCount: Int,
|
||||||
|
/** 累计专注秒数(sessions 里该任务的 seconds 之和) */
|
||||||
|
val focusSeconds: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 项目页一条完成记录:对应一条已完成的任务行(与任务页完成记录同源)。 */
|
||||||
|
data class ProjectCompletion(
|
||||||
|
val taskId: Long,
|
||||||
|
val taskTitle: String,
|
||||||
|
val note: String,
|
||||||
|
val startAt: Long,
|
||||||
|
val endAt: Long,
|
||||||
|
val seconds: Int,
|
||||||
|
)
|
||||||
|
|
||||||
/** 提前完成时交给 UI 落备注的实际专注信息 */
|
/** 提前完成时交给 UI 落备注的实际专注信息 */
|
||||||
data class FocusFinish(
|
data class FocusFinish(
|
||||||
val taskId: Long,
|
val taskId: Long,
|
||||||
|
|||||||
147
src/main/java/com/focusbox/app/service/LockOverlay.kt
Normal file
147
src/main/java/com/focusbox/app/service/LockOverlay.kt
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
package com.focusbox.app.service
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.PixelFormat
|
||||||
|
import android.os.Build
|
||||||
|
import android.provider.Settings
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
|
import android.widget.TextView
|
||||||
|
import com.focusbox.app.R
|
||||||
|
import com.focusbox.app.data.Store
|
||||||
|
import com.focusbox.app.util.Dates
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Calendar
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 锁屏悬浮窗:计时中锁屏/灭屏时,把黑底倒计时窗口直接画在锁屏之上。
|
||||||
|
*
|
||||||
|
* 为什么用悬浮窗:鸿蒙 4.0 对「后台弹出界面」的限制只拦 startActivity
|
||||||
|
* (实测开了权限也拦,全屏意图灭屏投递也不可靠),而 WindowManager.addView
|
||||||
|
* 悬浮窗不属于 Activity 启动,只要用户授了「悬浮窗」权限就能稳定盖在锁屏上
|
||||||
|
* ——这正是专注清单等 App 锁屏显示的做法。
|
||||||
|
*
|
||||||
|
* 窗口内容直接复用锁屏页布局(activity_lock_screen),inflate 时系统按当前
|
||||||
|
* 横竖屏自动选 layout 或 layout-land,旋转后重建窗口即可切换排版。
|
||||||
|
* FLAG_NOT_FOCUSABLE 不抢按键(不影响锁屏密码输入),点击任意处关闭。
|
||||||
|
*/
|
||||||
|
object LockOverlay {
|
||||||
|
|
||||||
|
private var root: View? = null
|
||||||
|
private var wm: WindowManager? = null
|
||||||
|
private var orientation = Configuration.ORIENTATION_PORTRAIT
|
||||||
|
|
||||||
|
private val clockFmt = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||||
|
|
||||||
|
/** 悬浮窗窗口是否正显示在锁屏上 */
|
||||||
|
fun isShowing(): Boolean = root != null
|
||||||
|
|
||||||
|
/** 用户是否已授予「悬浮窗」权限 */
|
||||||
|
fun canShow(context: Context): Boolean = Settings.canDrawOverlays(context)
|
||||||
|
|
||||||
|
/** 显示(幂等):已在显示或无权限时不重复添加 */
|
||||||
|
fun show(context: Context) {
|
||||||
|
if (root != null || !canShow(context)) return
|
||||||
|
try {
|
||||||
|
val ctx = context.applicationContext
|
||||||
|
val manager = ctx.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||||
|
val view = LayoutInflater.from(ctx).inflate(R.layout.activity_lock_screen, null)
|
||||||
|
view.setOnClickListener { hide() }
|
||||||
|
|
||||||
|
// API 26+ 用应用悬浮窗类型;更旧版本退回 TYPE_PHONE(本应用 minSdk 24)
|
||||||
|
val type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
WindowManager.LayoutParams.TYPE_PHONE
|
||||||
|
}
|
||||||
|
// 关键:EMUI 把悬浮窗限制在状态栏以下的内容区里(顶部时间/信号/电池露出来)。
|
||||||
|
// 对策是把窗口做得比屏幕更大并向上顶出——高度补上状态栏和导航栏,
|
||||||
|
// y 偏移取负的状态栏高度,配 FLAG_LAYOUT_NO_LIMITS 允许越界绘制,
|
||||||
|
// 黑底就完整盖住状态栏区域(护眼滤镜类 App 同款做法)
|
||||||
|
val res = ctx.resources
|
||||||
|
val sbId = res.getIdentifier("status_bar_height", "dimen", "android")
|
||||||
|
val navId = res.getIdentifier("navigation_bar_height", "dimen", "android")
|
||||||
|
val statusBar = if (sbId > 0) res.getDimensionPixelSize(sbId) else 0
|
||||||
|
val navBar = if (navId > 0) res.getDimensionPixelSize(navId) else 0
|
||||||
|
val lp = WindowManager.LayoutParams(
|
||||||
|
res.displayMetrics.widthPixels,
|
||||||
|
res.displayMetrics.heightPixels + statusBar + navBar,
|
||||||
|
type,
|
||||||
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||||
|
or WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||||
|
or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
|
||||||
|
or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||||
|
PixelFormat.TRANSLUCENT,
|
||||||
|
)
|
||||||
|
lp.gravity = Gravity.TOP
|
||||||
|
lp.x = 0
|
||||||
|
lp.y = -statusBar
|
||||||
|
manager.addView(view, lp)
|
||||||
|
|
||||||
|
root = view
|
||||||
|
wm = manager
|
||||||
|
orientation = ctx.resources.configuration.orientation
|
||||||
|
render(view)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
root = null
|
||||||
|
wm = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 关闭(幂等):窗口不存在时无事发生 */
|
||||||
|
fun hide() {
|
||||||
|
val view = root ?: return
|
||||||
|
root = null
|
||||||
|
wm?.let { runCatching { it.removeView(view) } }
|
||||||
|
wm = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每秒刷新读数;顺带做两件保活级检查:
|
||||||
|
* 1. 用户已解锁(keyguard 解除)→ 自动关窗——不依赖 USER_PRESENT 广播,
|
||||||
|
* 广播在个别 ROM 上时序不稳,靠这秒级兜底保证解锁后不留全屏黑窗挡桌面;
|
||||||
|
* 2. 横竖屏变化 → 重建窗口换对应排版(悬浮窗不经过 Activity 重建)。
|
||||||
|
*/
|
||||||
|
fun update(context: Context) {
|
||||||
|
val view = root ?: return
|
||||||
|
val km = context.getSystemService(Context.KEYGUARD_SERVICE) as android.app.KeyguardManager
|
||||||
|
if (!km.isKeyguardLocked()) {
|
||||||
|
hide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val current = context.resources.configuration.orientation
|
||||||
|
if (current != orientation) {
|
||||||
|
hide()
|
||||||
|
show(context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
render(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun render(view: View) {
|
||||||
|
val now = TimerCore.displayNow()
|
||||||
|
// 计时结束:窗口使命完成,自动关闭
|
||||||
|
if (!TimerCore.running && now <= 0) {
|
||||||
|
hide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val cal = Calendar.getInstance()
|
||||||
|
view.findViewById<TextView>(R.id.tvLockDate)?.text =
|
||||||
|
"${Dates.mdLong(cal.timeInMillis)} 星期${Dates.weekdayShort(weekdayIndex(cal))}"
|
||||||
|
view.findViewById<TextView>(R.id.tvLockClock)?.text = clockFmt.format(cal.time)
|
||||||
|
view.findViewById<TextView>(R.id.tvLockCountdown)?.text = Dates.clock(now)
|
||||||
|
|
||||||
|
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
|
||||||
|
view.findViewById<TextView>(R.id.tvLockTask)?.text =
|
||||||
|
task?.takeIf { it.isNotBlank() } ?: view.context.getString(R.string.notif_no_task)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */
|
||||||
|
private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import android.os.IBinder
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.focusbox.app.ui.lockscreen.LockScreenActivity
|
||||||
import com.focusbox.app.util.Prefs
|
import com.focusbox.app.util.Prefs
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,6 +53,8 @@ class TimerService : Service() {
|
|||||||
// 只推进状态,不再每秒重发通知:通知里的时间是系统的 Chronometer 在走,
|
// 只推进状态,不再每秒重发通知:通知里的时间是系统的 Chronometer 在走,
|
||||||
// 每秒 notify 反而会让锁屏上的计时被系统限流后"冻住"。
|
// 每秒 notify 反而会让锁屏上的计时被系统限流后"冻住"。
|
||||||
TimerCore.tick()
|
TimerCore.tick()
|
||||||
|
// 锁屏悬浮窗的读数刷新(窗口存在时每秒重画日期/时钟/倒计时)
|
||||||
|
LockOverlay.update(this@TimerService)
|
||||||
handler.postDelayed(this, 1000L)
|
handler.postDelayed(this, 1000L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,8 +62,8 @@ class TimerService : Service() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
TimerCore.addListener(onStateChanged)
|
TimerCore.addListener(onStateChanged)
|
||||||
// 锁屏全屏倒计时:计时中亮屏(用户按电源键偷看)→ 发全屏意图把
|
// 锁屏倒计时主链路:悬浮窗(WindowManager 直接画在锁屏上,
|
||||||
// LockScreenActivity 盖在锁屏上;灭屏时撤回触发通知,不在抽屉里堆垃圾
|
// 不受"后台弹出界面"限制);灭屏/亮屏/解锁三个时机同步显隐
|
||||||
ContextCompat.registerReceiver(
|
ContextCompat.registerReceiver(
|
||||||
this,
|
this,
|
||||||
screenReceiver,
|
screenReceiver,
|
||||||
@@ -70,42 +73,95 @@ class TimerService : Service() {
|
|||||||
},
|
},
|
||||||
ContextCompat.RECEIVER_NOT_EXPORTED,
|
ContextCompat.RECEIVER_NOT_EXPORTED,
|
||||||
)
|
)
|
||||||
|
// 用户解锁(输密码/指纹进入系统)后悬浮窗没有存在意义,立即关闭
|
||||||
|
ContextCompat.registerReceiver(
|
||||||
|
this,
|
||||||
|
unlockReceiver,
|
||||||
|
IntentFilter(Intent.ACTION_USER_PRESENT),
|
||||||
|
ContextCompat.RECEIVER_NOT_EXPORTED,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val screenReceiver = object : BroadcastReceiver() {
|
private val screenReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
Intent.ACTION_SCREEN_ON -> showLockPeek()
|
Intent.ACTION_SCREEN_ON -> onScreenOn()
|
||||||
Intent.ACTION_SCREEN_OFF -> Notif.cancelFullscreen(context)
|
Intent.ACTION_SCREEN_OFF -> onScreenOff()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showLockPeek() {
|
private val unlockReceiver = object : BroadcastReceiver() {
|
||||||
// 先补结算:EMUI 冻结进程后到点闹钟可能被推迟,用户按电源键亮屏
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
// 这一瞬进程已解冻,正好把过期的倒计时立刻结算掉,
|
if (intent.action == Intent.ACTION_USER_PRESENT) {
|
||||||
// 通知/锁屏卡片就不会再滚负数
|
LockOverlay.hide()
|
||||||
TimerCore.tick()
|
Notif.cancelFullscreen(this@TimerService)
|
||||||
if (!Prefs.lockFullscreen) return
|
}
|
||||||
if (!TimerCore.running) return
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 悬浮窗显隐的总开关:锁屏中 + 计时未清零 + 开关打开 + 有悬浮窗权限。
|
||||||
|
* 显示成功时顺手清掉抽屉里的全屏意图触发通知(不再需要)。
|
||||||
|
*/
|
||||||
|
private fun syncLockOverlay() {
|
||||||
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
// 只有真在锁屏界面才拉全屏页;用户正在用手机时不打扰
|
val want = Prefs.lockFullscreen
|
||||||
if (!km.inKeyguardRestrictedInputMode()) return
|
&& LockOverlay.canShow(this)
|
||||||
// 鸿蒙上全屏意图只在"锁屏且灭屏时投递"才会直接拉起 Activity,
|
&& km.isKeyguardLocked()
|
||||||
// 亮屏后投递只会出横幅通知——所以直接从服务启动页面(鸿蒙允许
|
&& (TimerCore.running || TimerCore.displayNow() > 0)
|
||||||
// 前台服务拉起自己的 Activity),全屏意图通知保留作兜底
|
if (want) LockOverlay.show(this) else LockOverlay.hide()
|
||||||
|
if (LockOverlay.isShowing()) Notif.cancelFullscreen(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 灭屏:先补结算,悬浮窗可用就直接盖到锁屏上(保持熄屏,按电源键即见);不可用走全屏意图兜底 */
|
||||||
|
private fun onScreenOff() {
|
||||||
|
TimerCore.tick() // 灭屏一瞬先补结算,避免到点边界上拉出 00:00 的空页面
|
||||||
|
if (!Prefs.lockFullscreen || !TimerCore.running) return
|
||||||
|
syncLockOverlay()
|
||||||
|
if (LockOverlay.isShowing()) return
|
||||||
|
// 无悬浮窗权限的兜底:灭屏投递全屏意图(个别 ROM 直启,其余进抽屉可点)
|
||||||
|
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
if (km.isKeyguardLocked()) Notif.updateFullscreen(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 亮屏:先补结算(冻结进程的到点闹钟被推迟时,靠这一下止损,不再滚负数) */
|
||||||
|
private fun onScreenOn() {
|
||||||
|
TimerCore.tick()
|
||||||
|
syncLockOverlay()
|
||||||
|
// 悬浮窗已盖住锁屏时,仍尝试用沉浸式锁屏页接管——
|
||||||
|
// Activity 有主题级全屏(状态栏彻底遮掉)+ 横竖屏专属排版,
|
||||||
|
// 直启成功则显示效果更完整;被鸿蒙拦截也无损失,悬浮窗继续顶着
|
||||||
|
if (Prefs.lockFullscreen && TimerCore.running) {
|
||||||
|
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
if (km.isKeyguardLocked()) {
|
||||||
runCatching {
|
runCatching {
|
||||||
startActivity(
|
startActivity(
|
||||||
Intent(this, com.focusbox.app.ui.lockscreen.LockScreenActivity::class.java)
|
Intent(this, LockScreenActivity::class.java)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (!LockOverlay.isShowing() && !LockScreenActivity.showing) {
|
||||||
|
// 悬浮窗和直启都失败:留全屏意图通知兜底(点进同一页面)
|
||||||
Notif.updateFullscreen(this)
|
Notif.updateFullscreen(this)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else if (LockScreenActivity.showing) {
|
||||||
|
Notif.cancelFullscreen(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 系统配置变化(旋转):悬浮窗立刻换横/竖屏排版重建 */
|
||||||
|
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
LockOverlay.update(this)
|
||||||
|
}
|
||||||
|
|
||||||
private val onStateChanged: () -> Unit = {
|
private val onStateChanged: () -> Unit = {
|
||||||
Notif.updateOngoing(this)
|
Notif.updateOngoing(this)
|
||||||
// 暂停/结束时同步停掉 1 秒轮询,别让 Handler 空转
|
// 计时结束/暂停时清掉锁屏触发通知,抽屉里不留垃圾
|
||||||
|
if (!TimerCore.running) Notif.cancelFullscreen(this)
|
||||||
|
syncLockOverlay()
|
||||||
syncTicker()
|
syncTicker()
|
||||||
syncWakeLock()
|
syncWakeLock()
|
||||||
}
|
}
|
||||||
@@ -217,7 +273,9 @@ class TimerService : Service() {
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
stopTicker()
|
stopTicker()
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
|
LockOverlay.hide()
|
||||||
runCatching { unregisterReceiver(screenReceiver) }
|
runCatching { unregisterReceiver(screenReceiver) }
|
||||||
|
runCatching { unregisterReceiver(unlockReceiver) }
|
||||||
Notif.cancelFullscreen(this)
|
Notif.cancelFullscreen(this)
|
||||||
TimerCore.removeListener(onStateChanged)
|
TimerCore.removeListener(onStateChanged)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|||||||
@@ -254,6 +254,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
showTab(TAB_FOCUS)
|
showTab(TAB_FOCUS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按任务 id 开始计时,供项目页的完成记录行使用:
|
||||||
|
* 记录行本身是已完成的行,先经 [Store.startTargetFor] 换成系列里可计时的任务。
|
||||||
|
*/
|
||||||
|
fun startFocusFrom(taskId: Long) {
|
||||||
|
val target = Store.startTargetFor(taskId) ?: return
|
||||||
|
startFocusOn(target)
|
||||||
|
}
|
||||||
|
|
||||||
/** 设置改动后(清空数据、改主题)统一刷新其余页面 */
|
/** 设置改动后(清空数据、改主题)统一刷新其余页面 */
|
||||||
fun refreshAll() {
|
fun refreshAll() {
|
||||||
for (f in fragments) {
|
for (f in fragments) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.focusbox.app.model.Project
|
|||||||
import com.focusbox.app.model.Task
|
import com.focusbox.app.model.Task
|
||||||
import com.focusbox.app.service.TimerCore
|
import com.focusbox.app.service.TimerCore
|
||||||
import com.focusbox.app.ui.SheetDialog
|
import com.focusbox.app.ui.SheetDialog
|
||||||
|
import com.focusbox.app.ui.tasks.TaskSheet
|
||||||
import com.focusbox.app.util.Dates
|
import com.focusbox.app.util.Dates
|
||||||
import com.focusbox.app.util.Prefs
|
import com.focusbox.app.util.Prefs
|
||||||
import com.focusbox.app.util.circleBg
|
import com.focusbox.app.util.circleBg
|
||||||
@@ -404,6 +405,10 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
cachedProject = cachedTask?.let { Store.project(it.projectId) }
|
cachedProject = cachedTask?.let { Store.project(it.projectId) }
|
||||||
}
|
}
|
||||||
val task = cachedTask
|
val task = cachedTask
|
||||||
|
// 专注进行中,任务已经绑进这一轮:右侧文案改成「正在专注」,整卡不可点。
|
||||||
|
// 否则中途换任务会把 elapsed 清零重建(setTask 会重设 totalMs),这一轮就白跑了。
|
||||||
|
val locked = TimerCore.running && TimerCore.mode == TimerCore.MODE_FOCUS && task != null
|
||||||
|
taskCard.isClickable = !locked
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
taskDot.visible(false)
|
taskDot.visible(false)
|
||||||
tvTask.text = getString(R.string.no_task)
|
tvTask.text = getString(R.string.no_task)
|
||||||
@@ -417,7 +422,7 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
tvTask.text = task.title
|
tvTask.text = task.title
|
||||||
val projectName = project?.name ?: getString(R.string.inbox)
|
val projectName = project?.name ?: getString(R.string.inbox)
|
||||||
tvTaskMeta.text = getString(R.string.task_card_meta, projectName, task.focusMinutes, task.donePomodoros)
|
tvTaskMeta.text = getString(R.string.task_card_meta, projectName, task.focusMinutes, task.donePomodoros)
|
||||||
tvTaskAction.text = getString(R.string.task_selected)
|
tvTaskAction.text = getString(if (locked) R.string.task_focusing else R.string.task_selected)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------ 手势
|
// ------------------------------------------------------------------ 手势
|
||||||
@@ -487,6 +492,33 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
|
|
||||||
// ------------------------------------------------------------------ 任务
|
// ------------------------------------------------------------------ 任务
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选任务弹层第二步底部的「立即创建」:拉起新建任务弹层。
|
||||||
|
*
|
||||||
|
* 保存成功后把新任务设为当前任务(圆环套用它设定的专注时长)并直接开始计时,
|
||||||
|
* 与「选中已有任务」走同一条路径;取消新建则什么都不变。
|
||||||
|
*/
|
||||||
|
private fun createTaskAndSelect() {
|
||||||
|
val ctx = context ?: return
|
||||||
|
val act = activity
|
||||||
|
val sheet = TaskSheet(ctx, null, 0L) { newId ->
|
||||||
|
if (newId > 0) {
|
||||||
|
Store.task(newId)?.let { t ->
|
||||||
|
TimerCore.setCountUp(false)
|
||||||
|
TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
|
||||||
|
// 走的是同一条「选任务」路径,建完也直接开跑,保持口径一致
|
||||||
|
requestNotifPermissionIfNeeded()
|
||||||
|
if (TimerCore.elapsedNow() > 0) TimerCore.resume() else TimerCore.start()
|
||||||
|
Toast.makeText(ctx, R.string.task_created, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
cachedTaskId = Long.MIN_VALUE
|
||||||
|
(act as? com.focusbox.app.ui.MainActivity)?.refreshAll()
|
||||||
|
}
|
||||||
|
if (view != null) render()
|
||||||
|
}
|
||||||
|
sheet.show()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选择任务:第一步选项目,第二步只列出该项目的待办。
|
* 选择任务:第一步选项目,第二步只列出该项目的待办。
|
||||||
* 用自绘底部弹层而不是系统 AlertDialog,便于圆角、分步标题与选中态。
|
* 用自绘底部弹层而不是系统 AlertDialog,便于圆角、分步标题与选中态。
|
||||||
@@ -543,7 +575,8 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
btnBack.visibility = View.VISIBLE
|
btnBack.visibility = View.VISIBLE
|
||||||
btnClear.visibility = View.VISIBLE
|
btnClear.visibility = View.VISIBLE
|
||||||
list.removeAllViews()
|
list.removeAllViews()
|
||||||
val tasks = Store.tasks(projectId, includeDone = false)
|
// 选任务只按项目列任务:不按完成、逾期过滤,也不显示完成记录
|
||||||
|
val tasks = Store.projectTasks(projectId)
|
||||||
if (tasks.isEmpty()) {
|
if (tasks.isEmpty()) {
|
||||||
list.addView(TextView(ctx).apply {
|
list.addView(TextView(ctx).apply {
|
||||||
text = getString(R.string.pick_task_empty)
|
text = getString(R.string.pick_task_empty)
|
||||||
@@ -554,10 +587,8 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
tasks.forEach { t ->
|
tasks.forEach { t ->
|
||||||
val meta = buildString {
|
// 行内只写任务时间(专注时长),不挂截止/随时、也不标完成或逾期
|
||||||
append(getString(R.string.minutes_value, t.focusMinutes))
|
val meta = "${t.focusMinutes}分钟"
|
||||||
if (t.due > 0) append(" · ${Dates.dueLabel(t.due)}截止")
|
|
||||||
}
|
|
||||||
addRow(
|
addRow(
|
||||||
title = t.title,
|
title = t.title,
|
||||||
meta = meta,
|
meta = meta,
|
||||||
@@ -568,6 +599,10 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
TimerCore.setCountUp(false)
|
TimerCore.setCountUp(false)
|
||||||
TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
|
TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
|
||||||
sheet.dismiss()
|
sheet.dismiss()
|
||||||
|
// 选完即开跑,不用再点一次「开始专注」;
|
||||||
|
// 没跑过就 start,暂停过的(elapsed > 0)走 resume,才会补写暂停原因
|
||||||
|
requestNotifPermissionIfNeeded()
|
||||||
|
if (TimerCore.elapsedNow() > 0) TimerCore.resume() else TimerCore.start()
|
||||||
render()
|
render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -586,7 +621,7 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
Store.projects().forEach { p ->
|
Store.projects().forEach { p ->
|
||||||
addRow(
|
addRow(
|
||||||
title = p.name,
|
title = p.name,
|
||||||
meta = getString(R.string.pick_project_meta, p.openTasks),
|
meta = getString(R.string.pick_project_meta, p.totalTasks),
|
||||||
color = p.color,
|
color = p.color,
|
||||||
selected = p.id == currentPid,
|
selected = p.id == currentPid,
|
||||||
alignLeft = true, // 项目列表不要左侧色点缩进,名称贴左对齐
|
alignLeft = true, // 项目列表不要左侧色点缩进,名称贴左对齐
|
||||||
@@ -597,10 +632,12 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
|||||||
|
|
||||||
btnBack.setOnClickListener { showProjects() }
|
btnBack.setOnClickListener { showProjects() }
|
||||||
btnClose.setOnClickListener { sheet.dismiss() }
|
btnClose.setOnClickListener { sheet.dismiss() }
|
||||||
|
// 第二步底部:没有合适的任务就当场建一个,建完自动选中并回到专注页
|
||||||
|
btnClear.text = getString(R.string.create_now)
|
||||||
|
btnClear.setTextColor(col(R.color.brand))
|
||||||
btnClear.setOnClickListener {
|
btnClear.setOnClickListener {
|
||||||
TimerCore.setTask(0, 0)
|
|
||||||
sheet.dismiss()
|
sheet.dismiss()
|
||||||
render()
|
createTaskAndSelect()
|
||||||
}
|
}
|
||||||
sheet.setContentView(root)
|
sheet.setContentView(root)
|
||||||
showProjects()
|
showProjects()
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
package com.focusbox.app.ui.lockscreen
|
package com.focusbox.app.ui.lockscreen
|
||||||
|
|
||||||
import android.app.KeyguardManager
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.text.format.DateFormat
|
import android.text.format.DateFormat
|
||||||
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import com.focusbox.app.R
|
import com.focusbox.app.R
|
||||||
import com.focusbox.app.data.Store
|
import com.focusbox.app.data.Store
|
||||||
|
import com.focusbox.app.service.Notif
|
||||||
import com.focusbox.app.service.TimerCore
|
import com.focusbox.app.service.TimerCore
|
||||||
import com.focusbox.app.util.Dates
|
import com.focusbox.app.util.Dates
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -20,21 +26,31 @@ import java.util.Locale
|
|||||||
/**
|
/**
|
||||||
* 锁屏全屏倒计时页。
|
* 锁屏全屏倒计时页。
|
||||||
*
|
*
|
||||||
* 触发链路:计时中按电源键亮屏 → TimerService 收到 SCREEN_ON →
|
* 触发链路:计时中用户锁屏(灭屏)→ TimerService 灭屏瞬间发全屏意图通知 →
|
||||||
* 检查处于锁屏后发一条全屏意图通知 → 系统把本页直接盖在锁屏上展示。
|
* 鸿蒙直接把本页盖在锁屏上(屏幕保持熄灭,本页不设 turnScreenOn)→
|
||||||
|
* 用户按电源键亮屏即见倒计时,全程不出通知横幅。
|
||||||
*
|
*
|
||||||
* 交互极简:黑底上只有日期、时钟、大号倒计时和任务名,
|
* 交互极简:黑底上只有日期、时钟、大号倒计时和任务名,
|
||||||
* 点按任意处退出;倒计时本身在前台服务里走,退出/熄屏都不受影响,
|
* 点按任意处退出、解锁时自动退出;倒计时本身在前台服务里走,
|
||||||
* 计时结束后本页在下一次刷新时自动关闭。
|
* 退出/熄屏都不受影响,计时结束后本页在下一次刷新时自动关闭。
|
||||||
|
*
|
||||||
|
* 沉浸式:STATUS_BAR_HIDDEN + LAYOUT_NO_LIMITS 把顶部的时间/信号/电池
|
||||||
|
* 一起遮掉,整块屏幕只有页面内容。
|
||||||
*/
|
*/
|
||||||
class LockScreenActivity : AppCompatActivity() {
|
class LockScreenActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/** 服务用来判断页面是否已盖在锁屏上(避免重复拉起/多报通知) */
|
||||||
|
@Volatile
|
||||||
|
var showing: Boolean = false
|
||||||
|
private set
|
||||||
|
}
|
||||||
|
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
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())
|
||||||
@@ -46,40 +62,87 @@ class LockScreenActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 用户解锁(输密码/指纹进系统)后页面没有存在意义,立即退出 */
|
||||||
|
private val unlockReceiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
if (intent.action == Intent.ACTION_USER_PRESENT) finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
// 盖在锁屏上显示(API 27+ 用官方方法,清单里的 showWhenLocked/turnScreenOn 双保险)
|
// 盖在锁屏上显示(API 27+ 用官方方法,清单里的 showWhenLocked 双保险)。
|
||||||
|
// 注意不能开 turnScreenOn:灭屏投递拉起本页时屏幕要保持熄灭,
|
||||||
|
// 等用户按电源键才亮,否则每次锁屏都会自动亮屏耗电
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
setShowWhenLocked(true)
|
setShowWhenLocked(true)
|
||||||
setTurnScreenOn(true)
|
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
window.addFlags(
|
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
|
||||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
|
||||||
or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_lock_screen)
|
setContentView(R.layout.activity_lock_screen)
|
||||||
|
|
||||||
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<android.view.View>(R.id.lockRoot).setOnClickListener { finish() }
|
findViewById<View>(R.id.lockRoot).setOnClickListener { finish() }
|
||||||
|
|
||||||
|
applyImmersive()
|
||||||
|
|
||||||
|
ContextCompat.registerReceiver(
|
||||||
|
this,
|
||||||
|
unlockReceiver,
|
||||||
|
IntentFilter(Intent.ACTION_USER_PRESENT),
|
||||||
|
ContextCompat.RECEIVER_NOT_EXPORTED,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
showing = true
|
||||||
|
// 页面已经实际盖到锁屏上了,抽屉里那条触发通知清掉
|
||||||
|
Notif.cancelFullscreen(this)
|
||||||
|
applyImmersive()
|
||||||
handler.post(tick)
|
handler.post(tick)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
|
showing = false
|
||||||
handler.removeCallbacks(tick)
|
handler.removeCallbacks(tick)
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
runCatching { unregisterReceiver(unlockReceiver) }
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 沉浸式全屏:状态栏/导航栏全隐藏,且布局延伸到状态栏底下(时间信号电池彻底不见) */
|
||||||
|
private fun applyImmersive() {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.setFlags(
|
||||||
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||||
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||||
|
)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.decorView.systemUiVisibility = (
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
|
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从别的窗口/通知横幅抢回焦点后,沉浸式标记会被系统清掉,重新套一遍 */
|
||||||
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
|
super.onWindowFocusChanged(hasFocus)
|
||||||
|
if (hasFocus) applyImmersive()
|
||||||
|
}
|
||||||
|
|
||||||
private fun render() {
|
private fun render() {
|
||||||
val now = TimerCore.displayNow()
|
val now = TimerCore.displayNow()
|
||||||
// 计时已结束且没有剩余读数:页面使命完成,自动关闭
|
// 计时已结束且没有剩余读数:页面使命完成,自动关闭
|
||||||
@@ -93,10 +156,6 @@ 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(
|
|
||||||
if (TimerCore.mode == TimerCore.MODE_FOCUS) R.string.lock_mode_focus else R.string.lock_mode_break
|
|
||||||
)
|
|
||||||
|
|
||||||
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
|
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
|
||||||
tvTask.text = task?.takeIf { it.isNotBlank() } ?: getString(R.string.notif_no_task)
|
tvTask.text = task?.takeIf { it.isNotBlank() } ?: getString(R.string.notif_no_task)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,61 @@
|
|||||||
package com.focusbox.app.ui.projects
|
package com.focusbox.app.ui.projects
|
||||||
|
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.text.Spannable
|
||||||
|
import android.text.SpannableString
|
||||||
|
import android.text.style.StrikethroughSpan
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import android.widget.LinearLayout
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.focusbox.app.R
|
import com.focusbox.app.R
|
||||||
import com.focusbox.app.model.Project
|
import com.focusbox.app.model.Project
|
||||||
|
import com.focusbox.app.model.ProjectCompletion
|
||||||
|
import com.focusbox.app.model.ProjectTaskStat
|
||||||
|
import com.focusbox.app.model.Task
|
||||||
import com.focusbox.app.util.Dates
|
import com.focusbox.app.util.Dates
|
||||||
import com.focusbox.app.util.col
|
import com.focusbox.app.util.col
|
||||||
import com.focusbox.app.util.roundBg
|
import com.focusbox.app.util.roundBg
|
||||||
import com.focusbox.app.util.tint
|
import com.focusbox.app.util.tint
|
||||||
|
import com.focusbox.app.util.visible
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目列表:点击项目头就地展开该项目下创建的任务,不再跳转任务页。
|
||||||
|
* 任务不按完成/逾期过滤,全部列出;任务下方用「展开/收起完成记录」开关
|
||||||
|
* 控制该项目的历史完成记录,避免记录越积越长。
|
||||||
|
*/
|
||||||
class ProjectAdapter(
|
class ProjectAdapter(
|
||||||
private val onClick: (Project) -> Unit,
|
private val onToggleExpand: (Project) -> Unit,
|
||||||
private val onLongClick: (Project) -> Unit,
|
private val onLongClick: (Project) -> Unit,
|
||||||
private val onMore: (Project) -> Unit,
|
private val onMore: (Project) -> Unit,
|
||||||
|
private val onStart: (Task) -> Unit,
|
||||||
|
private val onEdit: (Task) -> Unit,
|
||||||
|
private val onToggleDone: () -> Unit,
|
||||||
) : RecyclerView.Adapter<ProjectAdapter.VH>() {
|
) : RecyclerView.Adapter<ProjectAdapter.VH>() {
|
||||||
|
|
||||||
private var items: List<Project> = emptyList()
|
private var items: List<Project> = emptyList()
|
||||||
|
private var expandedId: Long = -1L
|
||||||
|
private var stats: Map<Long, List<ProjectTaskStat>> = emptyMap()
|
||||||
|
private var completions: Map<Long, List<ProjectCompletion>> = emptyMap()
|
||||||
|
private var showDone: Boolean = false
|
||||||
|
|
||||||
fun submit(list: List<Project>) {
|
fun submit(
|
||||||
|
list: List<Project>,
|
||||||
|
expanded: Long,
|
||||||
|
taskStats: Map<Long, List<ProjectTaskStat>>,
|
||||||
|
completionRows: Map<Long, List<ProjectCompletion>>,
|
||||||
|
showDoneRows: Boolean,
|
||||||
|
) {
|
||||||
items = list
|
items = list
|
||||||
|
expandedId = expanded
|
||||||
|
stats = taskStats
|
||||||
|
completions = completionRows
|
||||||
|
showDone = showDoneRows
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,16 +72,19 @@ class ProjectAdapter(
|
|||||||
private val progress: ProgressBar = v.findViewById(R.id.progress)
|
private val progress: ProgressBar = v.findViewById(R.id.progress)
|
||||||
private val colorBar: View = v.findViewById(R.id.colorBar)
|
private val colorBar: View = v.findViewById(R.id.colorBar)
|
||||||
private val more: ImageView = v.findViewById(R.id.btnMore)
|
private val more: ImageView = v.findViewById(R.id.btnMore)
|
||||||
|
private val header: View = v.findViewById(R.id.projectHeader)
|
||||||
|
private val taskList: LinearLayout = v.findViewById(R.id.taskList)
|
||||||
|
private val tvTaskEmpty: TextView = v.findViewById(R.id.tvTaskEmpty)
|
||||||
|
|
||||||
fun bind(p: Project) {
|
fun bind(p: Project) {
|
||||||
val ctx = itemView.context
|
val ctx = itemView.context
|
||||||
name.text = p.name
|
name.text = p.name
|
||||||
colorBar.background = ctx.roundBg(p.color, 2f)
|
colorBar.background = ctx.roundBg(p.color, 2f)
|
||||||
|
|
||||||
// 只看任务与时长,不再显示番茄数
|
// 项目页只统计项目下创建的任务:总数、已完成数、累计专注时长
|
||||||
val parts = ArrayList<String>(3)
|
val parts = ArrayList<String>(3)
|
||||||
parts.add("${p.openTasks} 待办")
|
parts.add(ctx.getString(R.string.project_tasks_total, p.totalTasks))
|
||||||
if (p.doneTasks > 0) parts.add("${p.doneTasks} 已完成")
|
if (p.doneTasks > 0) parts.add(ctx.getString(R.string.project_tasks_done, p.doneTasks))
|
||||||
if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds))
|
if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds))
|
||||||
meta.text = parts.joinToString(" · ")
|
meta.text = parts.joinToString(" · ")
|
||||||
|
|
||||||
@@ -61,11 +95,127 @@ class ProjectAdapter(
|
|||||||
more.tint(ctx.col(R.color.text_tertiary))
|
more.tint(ctx.col(R.color.text_tertiary))
|
||||||
more.setOnClickListener { onMore(p) }
|
more.setOnClickListener { onMore(p) }
|
||||||
|
|
||||||
itemView.setOnClickListener { onClick(p) }
|
header.setOnClickListener { onToggleExpand(p) }
|
||||||
itemView.setOnLongClickListener {
|
header.setOnLongClickListener {
|
||||||
onLongClick(p)
|
onLongClick(p)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val expanded = expandedId == p.id
|
||||||
|
val rows = if (expanded) stats[p.id].orEmpty() else emptyList()
|
||||||
|
val records = if (expanded) completions[p.id].orEmpty() else emptyList()
|
||||||
|
taskList.visible(expanded && (rows.isNotEmpty() || records.isNotEmpty()))
|
||||||
|
tvTaskEmpty.visible(expanded && rows.isEmpty() && records.isEmpty())
|
||||||
|
if (!expanded) return
|
||||||
|
|
||||||
|
fun addTaskRow(row: ProjectTaskStat) {
|
||||||
|
val item = LayoutInflater.from(ctx)
|
||||||
|
.inflate(R.layout.item_project_task, taskList, false)
|
||||||
|
bindTaskRow(item, row, p)
|
||||||
|
taskList.addView(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
taskList.removeAllViews()
|
||||||
|
// 项目下创建的任务全部列出:不按完成/逾期过滤,也不重复生成
|
||||||
|
rows.forEach { addTaskRow(it) }
|
||||||
|
|
||||||
|
// 任务下面单独一条开关:展开/隐藏该项目下的完成记录
|
||||||
|
if (records.isNotEmpty()) {
|
||||||
|
val toggle = LayoutInflater.from(ctx)
|
||||||
|
.inflate(R.layout.item_footer, taskList, false)
|
||||||
|
val tv = toggle.findViewById<TextView>(R.id.tvFooter)
|
||||||
|
tv.text = ctx.getString(
|
||||||
|
if (showDone) R.string.project_collapse_done else R.string.project_expand_done,
|
||||||
|
records.size,
|
||||||
|
)
|
||||||
|
tv.setTextColor(ctx.col(R.color.brand))
|
||||||
|
toggle.setOnClickListener { onToggleDone() }
|
||||||
|
taskList.addView(toggle)
|
||||||
|
if (showDone) records.forEach { addCompletionRow(it, p) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindTaskRow(item: View, row: ProjectTaskStat, p: Project) {
|
||||||
|
val ctx = item.context
|
||||||
|
val task = row.task
|
||||||
|
val tvTitle: TextView = item.findViewById(R.id.tvTaskTitle)
|
||||||
|
val tvMeta: TextView = item.findViewById(R.id.tvTaskMeta)
|
||||||
|
val btnPlay: ImageView = item.findViewById(R.id.btnTaskPlay)
|
||||||
|
item.findViewById<View>(R.id.taskColorBar).background = ctx.roundBg(p.color, 2f)
|
||||||
|
|
||||||
|
// 顶部是「创建了就一直在」的任务清单:不划线、不变灰;
|
||||||
|
// 完成与否只体现在下面的完成记录里
|
||||||
|
tvTitle.text = task.title
|
||||||
|
tvTitle.setTextColor(ctx.col(R.color.text))
|
||||||
|
tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
||||||
|
|
||||||
|
// 任务时间(专注时长)· 最近完成 · 累计次数与累计专注
|
||||||
|
val parts = ArrayList<String>(3)
|
||||||
|
parts.add("${task.focusMinutes}分钟")
|
||||||
|
if (row.lastDoneAt > 0) {
|
||||||
|
val whenText = "${Dates.md(row.lastDoneAt)}·${Dates.hm(row.lastDoneAt)}"
|
||||||
|
parts.add(ctx.getString(R.string.project_task_last_done, whenText))
|
||||||
|
}
|
||||||
|
val totals = StringBuilder()
|
||||||
|
if (row.doneCount > 0) {
|
||||||
|
totals.append(ctx.getString(R.string.project_task_done_count, row.doneCount))
|
||||||
|
}
|
||||||
|
if (row.focusSeconds > 0) {
|
||||||
|
// 累计专注只写「数字分钟」,不加说明文案,也不留空格
|
||||||
|
totals.append(row.focusSeconds / 60).append("分钟")
|
||||||
|
}
|
||||||
|
if (totals.isNotEmpty()) parts.add(totals.toString())
|
||||||
|
tvMeta.text = parts.joinToString(" · ")
|
||||||
|
|
||||||
|
// 开始键常驻:已完成的创建任务同样可以再开始一轮,
|
||||||
|
// 由调用方把「已完成的行」换成系列里当前可计时的任务
|
||||||
|
btnPlay.visible(true)
|
||||||
|
btnPlay.tint(ctx.col(R.color.brand))
|
||||||
|
btnPlay.setOnClickListener { onStart(task) }
|
||||||
|
// 与任务页一致:点行打开编辑/删除弹窗
|
||||||
|
item.setOnClickListener { onEdit(task) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addCompletionRow(record: ProjectCompletion, p: Project) {
|
||||||
|
val ctx = itemView.context
|
||||||
|
val item = LayoutInflater.from(ctx)
|
||||||
|
.inflate(R.layout.item_project_task, taskList, false)
|
||||||
|
item.findViewById<View>(R.id.taskColorBar).background = ctx.roundBg(p.color, 2f)
|
||||||
|
|
||||||
|
val tvTitle: TextView = item.findViewById(R.id.tvTaskTitle)
|
||||||
|
val tvMeta: TextView = item.findViewById(R.id.tvTaskMeta)
|
||||||
|
val btnPlay: ImageView = item.findViewById(R.id.btnTaskPlay)
|
||||||
|
// 完成记录行只做历史展示:开始键只出现在上面的创建任务行
|
||||||
|
btnPlay.visible(false)
|
||||||
|
|
||||||
|
// 完成记录与任务页底部一致:任务名划线,完成原因跟在后面但不划线
|
||||||
|
val noteText = record.note.replace('\n', ' ')
|
||||||
|
val titleText = if (noteText.isBlank()) {
|
||||||
|
record.taskTitle
|
||||||
|
} else {
|
||||||
|
"${record.taskTitle} · $noteText"
|
||||||
|
}
|
||||||
|
val line = SpannableString(titleText)
|
||||||
|
if (record.taskTitle.isNotEmpty()) {
|
||||||
|
line.setSpan(
|
||||||
|
StrikethroughSpan(), 0, record.taskTitle.length,
|
||||||
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
tvTitle.text = line
|
||||||
|
tvTitle.setTextColor(ctx.col(R.color.text_secondary))
|
||||||
|
tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
||||||
|
|
||||||
|
// 与任务页完成记录同格式:日期 周几 起-止 · 专注X;没有真实时长就只写完成时刻
|
||||||
|
tvMeta.text = if (record.seconds > 0) {
|
||||||
|
"${Dates.dateWithWeek(record.startAt)} ${Dates.hms(record.startAt)}" +
|
||||||
|
"-${Dates.hms(record.endAt)} · 专注${Dates.duration(record.seconds)}"
|
||||||
|
} else {
|
||||||
|
"${Dates.dateWithWeek(record.endAt)} ${Dates.hms(record.endAt)}完成"
|
||||||
|
}
|
||||||
|
item.isClickable = false
|
||||||
|
item.setOnClickListener(null)
|
||||||
|
taskList.addView(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import androidx.appcompat.app.AlertDialog
|
|||||||
import com.focusbox.app.R
|
import com.focusbox.app.R
|
||||||
import com.focusbox.app.data.Store
|
import com.focusbox.app.data.Store
|
||||||
import com.focusbox.app.model.Project
|
import com.focusbox.app.model.Project
|
||||||
|
import com.focusbox.app.service.TimerCore
|
||||||
import com.focusbox.app.ui.SheetDialog
|
import com.focusbox.app.ui.SheetDialog
|
||||||
import com.focusbox.app.util.Palette
|
import com.focusbox.app.util.Palette
|
||||||
import com.focusbox.app.util.circleBg
|
import com.focusbox.app.util.circleBg
|
||||||
@@ -28,16 +29,27 @@ 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)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setContentView(root)
|
// 项目编辑含多个输入框:必须走满屏容器 + 键盘顶起,否则输入法会盖住弹层
|
||||||
|
fitOnIme(root)
|
||||||
|
// 满屏容器后仍保留“点弹层外关闭”,点弹层内部空白不关闭
|
||||||
|
(root.parent as? View)?.setOnClickListener { dismiss() }
|
||||||
|
root.setOnClickListener { }
|
||||||
root.findViewById<TextView>(R.id.sheetTitle).setText(
|
root.findViewById<TextView>(R.id.sheetTitle).setText(
|
||||||
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)
|
||||||
@@ -50,6 +62,11 @@ class ProjectSheet(
|
|||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.setPositiveButton(R.string.delete) { _, _ ->
|
.setPositiveButton(R.string.delete) { _, _ ->
|
||||||
Store.deleteProject(existing.id)
|
Store.deleteProject(existing.id)
|
||||||
|
// 项目下的任务行已经删掉了:正在计时的如果正好是其中一条,
|
||||||
|
// 必须先把计时解绑,否则这一轮结束时会写出一条挂不到任务上的记录
|
||||||
|
if (TimerCore.taskId > 0 && Store.task(TimerCore.taskId) == null) {
|
||||||
|
TimerCore.setTask(0, 0)
|
||||||
|
}
|
||||||
onSaved()
|
onSaved()
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
@@ -62,28 +79,46 @@ 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 20 色两行平铺(每行 10 个)。
|
||||||
|
*
|
||||||
|
* 从一行横向滑动改成两行:20 个色点若排成一行要滑很久才找得到,
|
||||||
|
* 两行 × 10 个刚好铺满一屏宽度(10 × 32dp = 320dp),窄屏仍可横向滑动兜底。
|
||||||
|
*/
|
||||||
private fun renderColors() {
|
private fun renderColors() {
|
||||||
val ctx = context
|
val ctx = context
|
||||||
colorRow.removeAllViews()
|
colorRow.removeAllViews()
|
||||||
Palette.colors.forEach { c ->
|
Palette.colors.toList().chunked(10).forEach { rowColors ->
|
||||||
|
val row = LinearLayout(ctx).apply { orientation = LinearLayout.HORIZONTAL }
|
||||||
|
colorRow.addView(row)
|
||||||
|
rowColors.forEach { c ->
|
||||||
val wrap = FrameLayout(ctx)
|
val wrap = FrameLayout(ctx)
|
||||||
val lp = LinearLayout.LayoutParams(dpi(40f), dpi(40f))
|
val lp = LinearLayout.LayoutParams(dpi(32f), dpi(32f))
|
||||||
lp.marginEnd = dpi(2f)
|
|
||||||
wrap.layoutParams = lp
|
wrap.layoutParams = lp
|
||||||
wrap.background = if (c == color) ctx.roundBg(Color.TRANSPARENT, 100f, c, 2f) else null
|
wrap.background = if (c == color) ctx.roundBg(Color.TRANSPARENT, 100f, c, 2f) else null
|
||||||
|
|
||||||
val dot = View(ctx)
|
val dot = View(ctx)
|
||||||
val dlp = FrameLayout.LayoutParams(dpi(26f), dpi(26f))
|
val dlp = FrameLayout.LayoutParams(dpi(20f), dpi(20f))
|
||||||
dlp.gravity = Gravity.CENTER
|
dlp.gravity = Gravity.CENTER
|
||||||
dot.layoutParams = dlp
|
dot.layoutParams = dlp
|
||||||
dot.background = circleBg(c)
|
dot.background = circleBg(c)
|
||||||
@@ -93,7 +128,8 @@ class ProjectSheet(
|
|||||||
color = c
|
color = c
|
||||||
renderColors()
|
renderColors()
|
||||||
}
|
}
|
||||||
colorRow.addView(wrap)
|
row.addView(wrap)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,12 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.focusbox.app.R
|
import com.focusbox.app.R
|
||||||
import com.focusbox.app.data.Store
|
import com.focusbox.app.data.Store
|
||||||
import com.focusbox.app.model.Project
|
import com.focusbox.app.model.Project
|
||||||
|
import com.focusbox.app.model.ProjectCompletion
|
||||||
|
import com.focusbox.app.model.ProjectTaskStat
|
||||||
|
import com.focusbox.app.service.TimerCore
|
||||||
import com.focusbox.app.ui.MainActivity
|
import com.focusbox.app.ui.MainActivity
|
||||||
import com.focusbox.app.ui.SheetDialog
|
import com.focusbox.app.ui.SheetDialog
|
||||||
|
import com.focusbox.app.ui.tasks.TaskSheet
|
||||||
import com.focusbox.app.util.col
|
import com.focusbox.app.util.col
|
||||||
import com.focusbox.app.util.visible
|
import com.focusbox.app.util.visible
|
||||||
|
|
||||||
@@ -25,6 +29,13 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
|||||||
|
|
||||||
private var showArchived = false
|
private var showArchived = false
|
||||||
|
|
||||||
|
/** 当前展开的项目 id;-1 表示全部收起。只展开一个,避免列表过长 */
|
||||||
|
private var expandedProjectId = -1L
|
||||||
|
private var taskStats: Map<Long, List<ProjectTaskStat>> = emptyMap()
|
||||||
|
private var completions: Map<Long, List<ProjectCompletion>> = emptyMap()
|
||||||
|
/** 项目任务下方的完成记录默认折叠,避免历史记录越积越长 */
|
||||||
|
private var showDoneInProject = false
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
recycler = view.findViewById(R.id.recycler)
|
recycler = view.findViewById(R.id.recycler)
|
||||||
@@ -33,9 +44,20 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
|||||||
btnArchived = view.findViewById(R.id.btnArchived)
|
btnArchived = view.findViewById(R.id.btnArchived)
|
||||||
|
|
||||||
adapter = ProjectAdapter(
|
adapter = ProjectAdapter(
|
||||||
onClick = { p -> (activity as? MainActivity)?.openProjectTasks(p.id) },
|
onToggleExpand = { p ->
|
||||||
|
val opening = expandedProjectId != p.id
|
||||||
|
expandedProjectId = if (opening) p.id else -1L
|
||||||
|
if (opening) showDoneInProject = false
|
||||||
|
reload()
|
||||||
|
},
|
||||||
onLongClick = { p -> showActions(p) },
|
onLongClick = { p -> showActions(p) },
|
||||||
onMore = { p -> showActions(p) },
|
onMore = { p -> showActions(p) },
|
||||||
|
onStart = { t -> (activity as? MainActivity)?.startFocusFrom(t.id) },
|
||||||
|
onEdit = { t -> TaskSheet(requireContext(), t, 0L) { reload() }.show() },
|
||||||
|
onToggleDone = {
|
||||||
|
showDoneInProject = !showDoneInProject
|
||||||
|
reload()
|
||||||
|
},
|
||||||
)
|
)
|
||||||
recycler.layoutManager = LinearLayoutManager(requireContext())
|
recycler.layoutManager = LinearLayoutManager(requireContext())
|
||||||
recycler.adapter = adapter
|
recycler.adapter = adapter
|
||||||
@@ -68,10 +90,16 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
|||||||
val archived = all.filter { it.archived }
|
val archived = all.filter { it.archived }
|
||||||
|
|
||||||
val shown = if (showArchived) all else active
|
val shown = if (showArchived) all else active
|
||||||
adapter.submit(shown)
|
// 展开态只在可见项目上加载统计;项目被删/归档后自动收起,不留悬空 id
|
||||||
|
if (expandedProjectId != -1L && shown.none { it.id == expandedProjectId }) {
|
||||||
|
expandedProjectId = -1L
|
||||||
|
}
|
||||||
|
taskStats = shown.associate { it.id to Store.projectTaskRows(it.id) }
|
||||||
|
completions = shown.associate { it.id to Store.projectCompletions(it.id) }
|
||||||
|
adapter.submit(shown, expandedProjectId, taskStats, completions, showDoneInProject)
|
||||||
|
|
||||||
tvSummary.text = getString(
|
tvSummary.text = getString(
|
||||||
R.string.project_summary, active.size, active.sumOf { it.openTasks }
|
R.string.project_summary, active.size, active.sumOf { it.totalTasks }
|
||||||
)
|
)
|
||||||
tvEmpty.visible(shown.isEmpty())
|
tvEmpty.visible(shown.isEmpty())
|
||||||
|
|
||||||
@@ -79,7 +107,7 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
|||||||
btnArchived.visible(false)
|
btnArchived.visible(false)
|
||||||
} else {
|
} else {
|
||||||
btnArchived.visible(true)
|
btnArchived.visible(true)
|
||||||
btnArchived.text = if (showArchived) "隐藏已归档" else "已归档 ${archived.size}"
|
btnArchived.text = if (showArchived) "隐藏已归档" else "已归档${archived.size}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +156,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)
|
||||||
@@ -144,6 +176,11 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
|||||||
) { which ->
|
) { which ->
|
||||||
if (which == 1) {
|
if (which == 1) {
|
||||||
Store.deleteProject(p.id)
|
Store.deleteProject(p.id)
|
||||||
|
// 项目下的任务行已随之删除:正在计时的若属于它们,先解绑,
|
||||||
|
// 否则这一轮结束会写成一条挂不到任务的「未关联」记录
|
||||||
|
if (TimerCore.taskId > 0 && Store.task(TimerCore.taskId) == null) {
|
||||||
|
TimerCore.setTask(0, 0)
|
||||||
|
}
|
||||||
reload()
|
reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,17 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
toggle(getString(R.string.vibrate), Prefs.vibrateOn) { Prefs.vibrateOn = it },
|
toggle(getString(R.string.vibrate), Prefs.vibrateOn) { Prefs.vibrateOn = it },
|
||||||
toggle(getString(R.string.keep_screen_on), Prefs.keepScreenOn) { Prefs.keepScreenOn = it },
|
toggle(getString(R.string.keep_screen_on), Prefs.keepScreenOn) { Prefs.keepScreenOn = it },
|
||||||
toggle(getString(R.string.lock_fullscreen_title), Prefs.lockFullscreen) { Prefs.lockFullscreen = it },
|
toggle(getString(R.string.lock_fullscreen_title), Prefs.lockFullscreen) { Prefs.lockFullscreen = it },
|
||||||
// 华为/鸿蒙默认拦截后台拉起页面,锁屏倒计时需要手动开两个权限;
|
// 悬浮窗权限:锁屏倒计时主链路(鸿蒙拦 Activity 后台启动,悬浮窗不受限)。
|
||||||
|
// 已授权时既没有右侧箭头也不可点——权限本身没有应用内开关,免得误以为能点进去设置
|
||||||
|
run {
|
||||||
|
val granted = com.focusbox.app.service.LockOverlay.canShow(requireContext())
|
||||||
|
if (granted) {
|
||||||
|
action(getString(R.string.overlay_perm_title), getString(R.string.perm_granted), showArrow = false)
|
||||||
|
} else {
|
||||||
|
action(getString(R.string.overlay_perm_title), getString(R.string.go_set)) { openOverlayPerm() }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 华为/鸿蒙默认拦截后台拉起页面,无悬浮窗权限时的 Activity 兜底链路也要这两项权限;
|
||||||
// 放在开关正下方,用户开了开关不生效时第一眼就能看到入口
|
// 放在开关正下方,用户开了开关不生效时第一眼就能看到入口
|
||||||
action(getString(R.string.lock_perm_title), getString(R.string.lock_perm_value)) { openLockPerm() },
|
action(getString(R.string.lock_perm_title), getString(R.string.lock_perm_value)) { openLockPerm() },
|
||||||
)
|
)
|
||||||
@@ -104,6 +114,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
stepper(
|
stepper(
|
||||||
getString(R.string.daily_goal),
|
getString(R.string.daily_goal),
|
||||||
getString(R.string.value_minutes, Prefs.dailyGoalMinutes),
|
getString(R.string.value_minutes, Prefs.dailyGoalMinutes),
|
||||||
|
// 数值支持直接点击输入;步进用于微调。Prefs 里没有上限
|
||||||
|
onEdit = { inputDailyGoal() },
|
||||||
) { delta ->
|
) { delta ->
|
||||||
Prefs.dailyGoalMinutes += delta * 15
|
Prefs.dailyGoalMinutes += delta * 15
|
||||||
build()
|
build()
|
||||||
@@ -126,6 +138,9 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
|
|
||||||
section(R.string.section_data)
|
section(R.string.section_data)
|
||||||
card(
|
card(
|
||||||
|
// 清理旧版本删除任务后残留的孤儿记录,排在「清空所有数据」前面:
|
||||||
|
// 它只动查不到任务的记录,比全清安全一档
|
||||||
|
action(getString(R.string.purge_orphan), "", danger = true) { confirmPurgeOrphan() },
|
||||||
action(getString(R.string.clear_data), "", danger = true) { confirmClear() },
|
action(getString(R.string.clear_data), "", danger = true) { confirmClear() },
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -175,7 +190,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
setBackgroundColor(col(R.color.divider))
|
setBackgroundColor(col(R.color.divider))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stepper(title: String, value: String, onChange: (Int) -> Unit): View {
|
/** onEdit 非空时点击数值可直接输入(目前只有每日目标用);onChange 为加减步进 */
|
||||||
|
private fun stepper(title: String, value: String, onEdit: (() -> Unit)? = null, onChange: (Int) -> Unit): View {
|
||||||
val ctx = requireContext()
|
val ctx = requireContext()
|
||||||
val row = LinearLayout(ctx).apply {
|
val row = LinearLayout(ctx).apply {
|
||||||
orientation = LinearLayout.HORIZONTAL
|
orientation = LinearLayout.HORIZONTAL
|
||||||
@@ -196,6 +212,7 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
gravity = Gravity.CENTER
|
gravity = Gravity.CENTER
|
||||||
setTextColor(col(R.color.title))
|
setTextColor(col(R.color.title))
|
||||||
layoutParams = LinearLayout.LayoutParams(dpi(74f), LinearLayout.LayoutParams.WRAP_CONTENT)
|
layoutParams = LinearLayout.LayoutParams(dpi(74f), LinearLayout.LayoutParams.WRAP_CONTENT)
|
||||||
|
if (onEdit != null) setOnClickListener { onEdit() }
|
||||||
})
|
})
|
||||||
row.addView(stepButton("+") { onChange(1) })
|
row.addView(stepButton("+") { onChange(1) })
|
||||||
return row
|
return row
|
||||||
@@ -237,13 +254,19 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun action(title: String, value: String, danger: Boolean = false, onClick: () -> Unit): View {
|
private fun action(
|
||||||
|
title: String,
|
||||||
|
value: String,
|
||||||
|
danger: Boolean = false,
|
||||||
|
showArrow: Boolean = true,
|
||||||
|
onClick: (() -> Unit)? = null,
|
||||||
|
): View {
|
||||||
val ctx = requireContext()
|
val ctx = requireContext()
|
||||||
val row = LinearLayout(ctx).apply {
|
val row = LinearLayout(ctx).apply {
|
||||||
orientation = LinearLayout.HORIZONTAL
|
orientation = LinearLayout.HORIZONTAL
|
||||||
gravity = Gravity.CENTER_VERTICAL
|
gravity = Gravity.CENTER_VERTICAL
|
||||||
minimumHeight = dpi(54f)
|
minimumHeight = dpi(54f)
|
||||||
setOnClickListener { onClick() }
|
if (onClick != null) setOnClickListener { onClick() }
|
||||||
}
|
}
|
||||||
row.addView(TextView(ctx).apply {
|
row.addView(TextView(ctx).apply {
|
||||||
text = title
|
text = title
|
||||||
@@ -259,11 +282,13 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
setPadding(0, 0, dpi(6f), 0)
|
setPadding(0, 0, dpi(6f), 0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (showArrow) {
|
||||||
row.addView(android.widget.ImageView(ctx).apply {
|
row.addView(android.widget.ImageView(ctx).apply {
|
||||||
setImageResource(R.drawable.ic_chevron_right)
|
setImageResource(R.drawable.ic_chevron_right)
|
||||||
tint(col(R.color.text_tertiary))
|
tint(col(R.color.text_tertiary))
|
||||||
layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f))
|
layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f))
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +344,92 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 每日目标:弹小窗直接输入分钟数(无上限,下限 15 由 Prefs 兜底) */
|
||||||
|
private fun inputDailyGoal() {
|
||||||
|
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.daily_goal)
|
||||||
|
textSize = 16f
|
||||||
|
typeface = Typeface.DEFAULT_BOLD
|
||||||
|
setTextColor(col(R.color.text))
|
||||||
|
})
|
||||||
|
val et = android.widget.EditText(ctx).apply {
|
||||||
|
inputType = android.text.InputType.TYPE_CLASS_NUMBER
|
||||||
|
setText(Prefs.dailyGoalMinutes.toString())
|
||||||
|
textSize = 15f
|
||||||
|
setTextColor(col(R.color.text))
|
||||||
|
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
|
||||||
|
setPadding(dpi(14f), dpi(12f), dpi(14f), dpi(12f))
|
||||||
|
layoutParams = LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
).apply { topMargin = dpi(14f) }
|
||||||
|
}
|
||||||
|
panel.addView(et)
|
||||||
|
et.requestFocus()
|
||||||
|
|
||||||
|
val btnRow = LinearLayout(ctx).apply {
|
||||||
|
orientation = LinearLayout.HORIZONTAL
|
||||||
|
gravity = Gravity.END
|
||||||
|
setPadding(0, dpi(12f), 0, 0)
|
||||||
|
}
|
||||||
|
fun btn(labelRes: Int, onClick: () -> Unit) = TextView(ctx).apply {
|
||||||
|
text = getString(labelRes)
|
||||||
|
textSize = 14f
|
||||||
|
typeface = Typeface.DEFAULT_BOLD
|
||||||
|
gravity = Gravity.CENTER
|
||||||
|
setTextColor(col(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) { dialog.dismiss() })
|
||||||
|
btnRow.addView(btn(R.string.save) {
|
||||||
|
val input = et.text.toString().trim().toIntOrNull()
|
||||||
|
if (input != null) {
|
||||||
|
Prefs.dailyGoalMinutes = input
|
||||||
|
dialog.dismiss()
|
||||||
|
build()
|
||||||
|
} else {
|
||||||
|
et.error = " "
|
||||||
|
}
|
||||||
|
}, LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT).apply {
|
||||||
|
marginStart = dpi(10f)
|
||||||
|
})
|
||||||
|
panel.addView(btnRow)
|
||||||
|
|
||||||
|
dialog.setContentView(panel)
|
||||||
|
dialog.show()
|
||||||
|
// 弹窗不自动抢输入法焦点,手动拉起软键盘
|
||||||
|
et.postDelayed({
|
||||||
|
val imm = ctx.getSystemService(android.content.Context.INPUT_METHOD_SERVICE)
|
||||||
|
as? android.view.inputmethod.InputMethodManager
|
||||||
|
imm?.showSoftInput(et, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||||
|
}, 100L)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 悬浮窗权限:标准 Android 特殊权限,有公开检测 API 和授权页,一键直达本应用 */
|
||||||
|
private fun openOverlayPerm() {
|
||||||
|
val ctx = requireContext()
|
||||||
|
if (com.focusbox.app.service.LockOverlay.canShow(ctx)) return
|
||||||
|
runCatching {
|
||||||
|
startActivity(
|
||||||
|
android.content.Intent(
|
||||||
|
android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||||
|
android.net.Uri.parse("package:${ctx.packageName}"),
|
||||||
|
).addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 锁屏显示权限:弹说明后直达华为「应用启动管理」,非华为/直达失败退回应用详情页 */
|
/** 锁屏显示权限:弹说明后直达华为「应用启动管理」,非华为/直达失败退回应用详情页 */
|
||||||
private fun openLockPerm() {
|
private fun openLockPerm() {
|
||||||
val ctx = requireContext()
|
val ctx = requireContext()
|
||||||
@@ -373,6 +484,71 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空未关联数据:弹窗结构与「清空所有数据」完全一致,只是正文会说清要删多少条。
|
||||||
|
*
|
||||||
|
* 删的是「找不到任务」的专注记录(旧版本删任务时把 task_id 清零留下的残骸、
|
||||||
|
* 以及没选任务直接开始的那几轮)。它们只能堆成饼图里的「未关联任务」,
|
||||||
|
* 占一块地方又查不到是谁的,所以单独给一个清理入口。
|
||||||
|
*/
|
||||||
|
private fun confirmPurgeOrphan() {
|
||||||
|
val ctx = requireContext()
|
||||||
|
val stat = Store.orphanSessions()
|
||||||
|
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.purge_orphan)
|
||||||
|
textSize = 16f
|
||||||
|
typeface = Typeface.DEFAULT_BOLD
|
||||||
|
setTextColor(col(R.color.text))
|
||||||
|
})
|
||||||
|
panel.addView(TextView(ctx).apply {
|
||||||
|
text = if (stat.count > 0) {
|
||||||
|
getString(R.string.purge_confirm, stat.count, Dates.duration(stat.seconds))
|
||||||
|
} else {
|
||||||
|
getString(R.string.purge_none)
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
if (stat.count > 0) Store.purgeOrphanSessions()
|
||||||
|
(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()
|
||||||
|
}
|
||||||
|
|
||||||
private fun confirmClear() {
|
private fun confirmClear() {
|
||||||
val ctx = requireContext()
|
val ctx = requireContext()
|
||||||
val dialog = android.app.Dialog(ctx)
|
val dialog = android.app.Dialog(ctx)
|
||||||
@@ -431,6 +607,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val VERSION = "1.0"
|
const val VERSION = "3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.focusbox.app.ui.stats
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
@@ -15,6 +16,7 @@ import com.focusbox.app.util.Dates
|
|||||||
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.widget.LabelDonutView
|
import com.focusbox.app.widget.LabelDonutView
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 「项目分布 / 任务分布」卡片:自带 日 / 周 / 月 / 年 四档与左右翻页。
|
* 「项目分布 / 任务分布」卡片:自带 日 / 周 / 月 / 年 四档与左右翻页。
|
||||||
@@ -42,6 +44,12 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
|||||||
private val btnNext = ImageView(context)
|
private val btnNext = ImageView(context)
|
||||||
private val donut = LabelDonutView(context)
|
private val donut = LabelDonutView(context)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环下方明细列表:环只标占比最高的 6 条,剩下的全部在这里逐条列出。
|
||||||
|
* 不合并成「其他」——被合并掉的任务在页面上等于消失,用户根本不知道自己漏了什么。
|
||||||
|
*/
|
||||||
|
private val legend = LinearLayout(context)
|
||||||
|
|
||||||
/** 当前粒度,默认按天 */
|
/** 当前粒度,默认按天 */
|
||||||
var scale = Scale.DAY
|
var scale = Scale.DAY
|
||||||
private set
|
private set
|
||||||
@@ -145,6 +153,90 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
|||||||
addView(donut, LayoutParams(LayoutParams.MATCH_PARENT, context.dpi(222f)).apply {
|
addView(donut, LayoutParams(LayoutParams.MATCH_PARENT, context.dpi(222f)).apply {
|
||||||
topMargin = context.dpi(2f)
|
topMargin = context.dpi(2f)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
legend.apply {
|
||||||
|
orientation = VERTICAL
|
||||||
|
visibility = GONE
|
||||||
|
}
|
||||||
|
addView(legend, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT).apply {
|
||||||
|
topMargin = context.dpi(6f)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ 明细列表
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把环上没有牵线的切片按「圆点 + 名称 / 时长 · 占比」两列铺开(参考图版式)。
|
||||||
|
* 每格宽度均分,名称超长省略,保证列对齐不来回跳。
|
||||||
|
*/
|
||||||
|
private fun renderLegend(rest: List<LabelDonutView.Slice>, total: Int) {
|
||||||
|
legend.removeAllViews()
|
||||||
|
if (rest.isEmpty() || total <= 0) {
|
||||||
|
legend.visibility = GONE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
legend.visibility = VISIBLE
|
||||||
|
|
||||||
|
rest.chunked(2).forEach { pair ->
|
||||||
|
val row = LinearLayout(context).apply { orientation = HORIZONTAL }
|
||||||
|
legend.addView(row, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))
|
||||||
|
pair.forEach { slice ->
|
||||||
|
row.addView(buildLegendCell(slice, total), LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
|
||||||
|
}
|
||||||
|
// 单数时补一个空位,最后一行不会因为权重拉伸变成通栏
|
||||||
|
if (pair.size == 1) {
|
||||||
|
row.addView(android.view.View(context), LayoutParams(0, 1, 1f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildLegendCell(slice: LabelDonutView.Slice, total: Int): LinearLayout {
|
||||||
|
val cell = LinearLayout(context).apply {
|
||||||
|
orientation = HORIZONTAL
|
||||||
|
setPadding(0, context.dpi(7f), context.dpi(8f), context.dpi(7f))
|
||||||
|
}
|
||||||
|
|
||||||
|
val dot = android.view.View(context).apply {
|
||||||
|
background = GradientDrawable().apply {
|
||||||
|
shape = GradientDrawable.OVAL
|
||||||
|
setColor(slice.color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 8dp 圆点,下移 5dp 与名称首行的视觉中心对齐
|
||||||
|
cell.addView(dot, LayoutParams(context.dpi(8f), context.dpi(8f)).apply {
|
||||||
|
topMargin = context.dpi(5f)
|
||||||
|
})
|
||||||
|
|
||||||
|
val text = LinearLayout(context).apply {
|
||||||
|
orientation = VERTICAL
|
||||||
|
setPadding(context.dpi(8f), 0, 0, 0)
|
||||||
|
}
|
||||||
|
cell.addView(text, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
|
||||||
|
|
||||||
|
text.addView(TextView(context).apply {
|
||||||
|
this.text = slice.name
|
||||||
|
setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f)
|
||||||
|
setTextColor(context.col(R.color.title))
|
||||||
|
maxLines = 1
|
||||||
|
ellipsize = android.text.TextUtils.TruncateAt.END
|
||||||
|
includeFontPadding = false
|
||||||
|
})
|
||||||
|
|
||||||
|
val pct = slice.seconds * 100f / total
|
||||||
|
val pctText = if (pct < 1f) "<1%" else "${pct.roundToInt()}%"
|
||||||
|
text.addView(TextView(context).apply {
|
||||||
|
this.text = context.getString(
|
||||||
|
R.string.legend_meta,
|
||||||
|
Dates.duration(slice.seconds),
|
||||||
|
pctText,
|
||||||
|
)
|
||||||
|
setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f)
|
||||||
|
setTextColor(context.col(R.color.text_secondary))
|
||||||
|
maxLines = 1
|
||||||
|
includeFontPadding = false
|
||||||
|
})
|
||||||
|
|
||||||
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------ 交互
|
// ------------------------------------------------------------------ 交互
|
||||||
@@ -204,9 +296,9 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
donut.centerText = Dates.durationBrief(raw.sumOf { it.seconds })
|
val total = raw.sumOf { it.seconds }
|
||||||
donut.centerCaption =
|
donut.centerText = Dates.durationBrief(total)
|
||||||
context.getString(if (byTask) R.string.task_share else R.string.total_focus)
|
renderLegend(donut.unlabeled, total)
|
||||||
|
|
||||||
tvPeriod.text = periodLabel(from, to)
|
tvPeriod.text = periodLabel(from, to)
|
||||||
applySegments()
|
applySegments()
|
||||||
|
|||||||
@@ -71,6 +71,25 @@ class TaskAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题与图标之间的间距:旧版用三个空格,视觉偏宽。
|
||||||
|
* 改用无字形占位,宽度精确等于三个空格的一半,避免随字体变化忽大忽小。
|
||||||
|
*/
|
||||||
|
private fun appendIconGap(title: SpannableStringBuilder) {
|
||||||
|
title.append(" ")
|
||||||
|
title.setSpan(IconGapSpan(), title.length - 1, title.length, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 间距与图标必须各占一个字符。若把两个 ReplacementSpan 套在同一字符上,
|
||||||
|
* 后设置的图标会覆盖间距,视觉上就贴住了。
|
||||||
|
*/
|
||||||
|
private fun appendIconSpan(title: SpannableStringBuilder, span: Any) {
|
||||||
|
appendIconGap(title)
|
||||||
|
title.append(" ")
|
||||||
|
title.setSpan(span, title.length - 1, title.length, 0)
|
||||||
|
}
|
||||||
|
|
||||||
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 tvMeta: TextView = v.findViewById(R.id.tvMeta)
|
private val tvMeta: TextView = v.findViewById(R.id.tvMeta)
|
||||||
@@ -85,23 +104,25 @@ class TaskAdapter(
|
|||||||
val ctx = itemView.context
|
val ctx = itemView.context
|
||||||
|
|
||||||
// 标题右侧的属性图标,未完成与已完成都显示:
|
// 标题右侧的属性图标,未完成与已完成都显示:
|
||||||
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→
|
// 置顶圆圈箭头(「随时」未完成任务)→ 重要度圆圈数字 → 紧急度五角星。
|
||||||
// 紧急度五角星 → 随时上箭头。
|
// 置顶与重要度两个圆圈统一自绘:同一尺寸(0.85 倍字号)、同一描边(s/10),
|
||||||
// 各字形在字体里的字面尺寸不同:以圆圈数字 0.85 为基准,
|
// 保证粗细与高度完全一致;五角星仍用字形,0.95 倍不作参照。
|
||||||
// 上箭头与圆圈同高;五角星 0.95 不作参照
|
|
||||||
val title = SpannableStringBuilder(task.title)
|
val title = SpannableStringBuilder(task.title)
|
||||||
|
val iconSize = tvTitle.textSize * 0.85f
|
||||||
|
|
||||||
val (badge, badgeColor) = when (task.priority) {
|
// 置顶图标前移到重要度圆圈之前(品牌蓝圆圈内向上箭头)
|
||||||
2 -> " ③" to R.color.urgent_high
|
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
|
||||||
1 -> " ②" to R.color.urgent_mid
|
appendIconSpan(title, PinIconSpan(ctx.col(R.color.brand), iconSize))
|
||||||
else -> " ①" to R.color.urgent_low
|
|
||||||
}
|
}
|
||||||
title.append(badge)
|
|
||||||
title.setSpan(
|
// 重要度圆圈:3 高 / 2 中 / 1 普通,颜色与紧急度同色系
|
||||||
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)),
|
val (digit, badgeColor) = when (task.priority) {
|
||||||
title.length - badge.length, title.length, 0
|
2 -> "3" to R.color.urgent_high
|
||||||
)
|
1 -> "2" to R.color.urgent_mid
|
||||||
title.setSpan(RelativeSizeSpan(0.85f), title.length - badge.length, title.length, 0)
|
else -> "1" to R.color.urgent_low
|
||||||
|
}
|
||||||
|
// 与标题、与置顶圆圈各留半个旧间距,避免图标贴在一起又不显得散
|
||||||
|
appendIconSpan(title, PriorityBadgeSpan(ctx.col(badgeColor), iconSize, digit))
|
||||||
|
|
||||||
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰
|
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰
|
||||||
val (stars, starColor) = when (task.urgency) {
|
val (stars, starColor) = when (task.urgency) {
|
||||||
@@ -116,24 +137,15 @@ class TaskAdapter(
|
|||||||
)
|
)
|
||||||
title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0)
|
title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0)
|
||||||
|
|
||||||
// 「随时」任务:标题后带品牌蓝上箭头表示置顶,列表里排在未完成最前面。
|
// 完成横线只画任务名本身(MidStrikeSpan 限定区间,且划线取文字墨迹
|
||||||
// ↑ 字形窄、两侧留白大,全角空格会显得左边距比五角星宽,
|
// 的垂直中点——系统 StrikethroughSpan 用整字面半高定位,数字/汉字
|
||||||
// 改用细空格(U+2009)让两侧间隙与星标一致。
|
// 会让线显得偏下)。重要度/紧急度/置顶图标不跟着划线。
|
||||||
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
|
// 注意:span 必须在 tvTitle.text = title 之前挂好
|
||||||
title.append("\u2009↑")
|
if (task.done) {
|
||||||
title.setSpan(
|
title.setSpan(MidStrikeSpan(), 0, task.title.length, 0)
|
||||||
android.text.style.ForegroundColorSpan(ctx.col(R.color.brand)),
|
|
||||||
title.length - 2, title.length, 0
|
|
||||||
)
|
|
||||||
title.setSpan(RelativeSizeSpan(0.85f), title.length - 2, title.length, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tvTitle.text = title
|
tvTitle.text = title
|
||||||
tvTitle.paintFlags = if (task.done) {
|
tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
||||||
tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
|
||||||
} else {
|
|
||||||
tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
|
||||||
}
|
|
||||||
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
|
||||||
|
|
||||||
@@ -203,3 +215,156 @@ class TaskAdapter(
|
|||||||
private const val TYPE_FOOTER = 1
|
private const val TYPE_FOOTER = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图标间距占位:宽度等于旧版三个空格的一半,且不绘制任何字形。
|
||||||
|
* 用 ReplacementSpan 而不是固定 dp,间距会随字号等比缩放。
|
||||||
|
*/
|
||||||
|
private class IconGapSpan : android.text.style.ReplacementSpan() {
|
||||||
|
|
||||||
|
override fun getSize(
|
||||||
|
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
|
||||||
|
): Int = (paint.measureText(" ") / 2f).toInt().coerceAtLeast(1)
|
||||||
|
|
||||||
|
override fun draw(
|
||||||
|
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
|
||||||
|
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
|
||||||
|
) = Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务名删除线:系统 StrikethroughSpan 的划线位置按"字体半高"(baseline + ascent/2)
|
||||||
|
* 计算,但数字/汉字的实际墨迹顶比字体 ascent 低不少,划线视觉上偏下。
|
||||||
|
* 这里自绘:按实际墨迹边界(getTextBounds)取垂直中点,线严格穿过文字中间。
|
||||||
|
*/
|
||||||
|
private class MidStrikeSpan : android.text.style.ReplacementSpan() {
|
||||||
|
|
||||||
|
override fun getSize(
|
||||||
|
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
|
||||||
|
): Int = paint.measureText(text, start, end).toInt()
|
||||||
|
|
||||||
|
override fun draw(
|
||||||
|
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
|
||||||
|
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
|
||||||
|
) {
|
||||||
|
// 先按原样式画字(无删除线标志)
|
||||||
|
canvas.drawText(text, start, end, x, baseline.toFloat(), paint)
|
||||||
|
val s = text.toString()
|
||||||
|
val bounds = android.graphics.Rect()
|
||||||
|
paint.getTextBounds(s, start, end, bounds)
|
||||||
|
// 墨迹垂直中点:bounds.top/bottom 相对基线的偏移(top 为负)
|
||||||
|
val lineY = baseline + (bounds.top + bounds.bottom) / 2f
|
||||||
|
val w = paint.measureText(text, start, end)
|
||||||
|
val line = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
line.color = paint.color
|
||||||
|
line.strokeWidth = (paint.textSize / 28f).coerceAtLeast(1f)
|
||||||
|
canvas.drawLine(x, lineY, x + w, lineY, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 置顶与重要度共用的圆环绘制:同尺寸、同描边(s/10),保证两个圆圈粗细一致。 */
|
||||||
|
private fun drawBadgeRing(
|
||||||
|
canvas: android.graphics.Canvas, cx: Float, cy: Float, size: Float, ringColor: Int,
|
||||||
|
) {
|
||||||
|
val ring = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
|
this.color = ringColor
|
||||||
|
style = android.graphics.Paint.Style.STROKE
|
||||||
|
strokeWidth = size / 10f
|
||||||
|
strokeCap = android.graphics.Paint.Cap.ROUND
|
||||||
|
}
|
||||||
|
canvas.drawCircle(cx, cy, size / 2f - ring.strokeWidth / 2f, ring)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重要度圆圈数字:自绘圆环 + 数字,与置顶圆圈共用 drawBadgeRing,
|
||||||
|
* 高度(0.85 倍字号)与描边(s/10)严格一致,不再依赖系统字形 ①②③ 的墨迹差异。
|
||||||
|
*/
|
||||||
|
private class PriorityBadgeSpan(
|
||||||
|
private val badgeColor: Int,
|
||||||
|
private val size: Float,
|
||||||
|
private val digit: String,
|
||||||
|
) : android.text.style.ReplacementSpan() {
|
||||||
|
|
||||||
|
override fun getSize(
|
||||||
|
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
|
||||||
|
): Int {
|
||||||
|
val s = size.toInt()
|
||||||
|
if (fm != null) {
|
||||||
|
fm.ascent = -s
|
||||||
|
fm.descent = 0
|
||||||
|
fm.top = fm.ascent
|
||||||
|
fm.bottom = fm.descent
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw(
|
||||||
|
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
|
||||||
|
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
|
||||||
|
) {
|
||||||
|
val s = size
|
||||||
|
val cy = baseline - s * 0.45f
|
||||||
|
val cx = x + s / 2f
|
||||||
|
drawBadgeRing(canvas, cx, cy, s, badgeColor)
|
||||||
|
val num = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
|
this.color = badgeColor
|
||||||
|
textSize = s * 0.60f
|
||||||
|
typeface = Typeface.DEFAULT
|
||||||
|
textAlign = Paint.Align.CENTER
|
||||||
|
}
|
||||||
|
val fm = num.fontMetrics
|
||||||
|
canvas.drawText(digit, cx, cy - (fm.ascent + fm.descent) / 2f, num)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 置顶图标:圆圈内向上箭头。
|
||||||
|
* 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符,
|
||||||
|
* 画出来才能精确控制圆圈与箭头同色、且和重要度圆圈数字(0.85 倍字号)等高。
|
||||||
|
* 颜色用品牌蓝(R.color.brand,深浅色主题各有一版),与之前的 ↑ 字符颜色一致。
|
||||||
|
*/
|
||||||
|
private class PinIconSpan(
|
||||||
|
private val iconColor: Int,
|
||||||
|
private val size: Float,
|
||||||
|
) : android.text.style.ReplacementSpan() {
|
||||||
|
|
||||||
|
override fun getSize(
|
||||||
|
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
|
||||||
|
): Int {
|
||||||
|
val s = size.toInt()
|
||||||
|
if (fm != null) {
|
||||||
|
// 占位与字形等高(顶部到基线),避免行高被图标撑开
|
||||||
|
fm.ascent = -s
|
||||||
|
fm.descent = 0
|
||||||
|
fm.top = fm.ascent
|
||||||
|
fm.bottom = fm.descent
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw(
|
||||||
|
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
|
||||||
|
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
|
||||||
|
) {
|
||||||
|
val s = size
|
||||||
|
// 与 ①②③ 底部对齐:字体里的圆圈数字底缘略微越过基线(约 -0.05 个图标高),
|
||||||
|
// 圆心取基线上方 0.45 个图标高,比之前 0.50 略下移,底部不再"悬空"显偏上
|
||||||
|
val cx = x + s / 2f
|
||||||
|
val cy = baseline - s * 0.45f
|
||||||
|
// 与重要度圆圈共用同一绘制函数:同尺寸、同 1/10 描边,粗细与高度严格一致
|
||||||
|
drawBadgeRing(canvas, cx, cy, s, iconColor)
|
||||||
|
|
||||||
|
// 箭头比圈线更细(约 1/15 图标高),整体落在圆内
|
||||||
|
val arrow = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
arrow.color = iconColor
|
||||||
|
arrow.style = Paint.Style.STROKE
|
||||||
|
arrow.strokeWidth = s / 15f
|
||||||
|
arrow.strokeCap = Paint.Cap.ROUND
|
||||||
|
val head = s * 0.18f
|
||||||
|
val yTop = cy - s * 0.16f
|
||||||
|
val yBot = cy + s * 0.18f
|
||||||
|
canvas.drawLine(cx, yBot, cx, yTop, arrow)
|
||||||
|
canvas.drawLine(cx - head, yTop + head, cx, yTop, arrow)
|
||||||
|
canvas.drawLine(cx + head, yTop + head, cx, yTop, arrow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class TaskSheet(
|
|||||||
context: Context,
|
context: Context,
|
||||||
private val existing: Task?,
|
private val existing: Task?,
|
||||||
presetProjectId: Long,
|
presetProjectId: Long,
|
||||||
private val onSaved: () -> Unit,
|
private val onSaved: (Long) -> Unit,
|
||||||
) : SheetDialog(context) {
|
) : SheetDialog(context) {
|
||||||
|
|
||||||
private val root = LayoutInflater.from(context).inflate(R.layout.sheet_task, null)
|
private val root = LayoutInflater.from(context).inflate(R.layout.sheet_task, null)
|
||||||
@@ -105,12 +105,13 @@ class TaskSheet(
|
|||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.setPositiveButton(R.string.delete) { _, _ ->
|
.setPositiveButton(R.string.delete) { _, _ ->
|
||||||
existing?.let {
|
existing?.let {
|
||||||
Store.deleteTask(it.id)
|
// 删除会连同整个任务系列(重复实例 + 完成记录副本)及其专注记录一起删掉,
|
||||||
// 删除的正是当前选中任务时必须解除绑定:
|
// 只要当前计时绑在这一系列的任意一行上就要解绑,
|
||||||
// 否则计时继续走,到点后完成记录会落成"未关联任务"
|
// 否则到点后完成记录会挂到一个已经不存在的任务上
|
||||||
if (TimerCore.taskId == it.id) TimerCore.setTask(0, 0)
|
val removed = Store.deleteTask(it.id)
|
||||||
|
if (TimerCore.taskId in removed) TimerCore.setTask(0, 0)
|
||||||
}
|
}
|
||||||
onSaved()
|
onSaved(0L)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
@@ -258,7 +259,8 @@ class TaskSheet(
|
|||||||
periodic && due <= 0 -> Dates.todayStart()
|
periodic && due <= 0 -> Dates.todayStart()
|
||||||
else -> due
|
else -> due
|
||||||
}
|
}
|
||||||
if (existing == null) {
|
// 回传任务 id:专注页「没有任务 → 立即创建」需要拿新行 id 自动选中
|
||||||
|
val savedId = if (existing == null) {
|
||||||
Store.addTask(title, note, projectId, priority, focusMin, effectiveDue, repeatType, every, urgency)
|
Store.addTask(title, note, projectId, priority, focusMin, effectiveDue, repeatType, every, urgency)
|
||||||
} else {
|
} else {
|
||||||
Store.updateTask(
|
Store.updateTask(
|
||||||
@@ -274,8 +276,9 @@ class TaskSheet(
|
|||||||
repeatEvery = every,
|
repeatEvery = every,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
existing.id
|
||||||
}
|
}
|
||||||
onSaved()
|
onSaved(savedId)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import com.focusbox.app.util.visible
|
|||||||
*
|
*
|
||||||
* 项目 / 时间 / 重要度 / 紧急度 / 状态,每栏单选,行内放不下自动换行。
|
* 项目 / 时间 / 重要度 / 紧急度 / 状态,每栏单选,行内放不下自动换行。
|
||||||
* 筛选面板默认收起,只显示一行当前条件摘要;点摘要展开,选中任意胶囊后自动收起。
|
* 筛选面板默认收起,只显示一行当前条件摘要;点摘要展开,选中任意胶囊后自动收起。
|
||||||
* 默认「项目=全部 · 时间=全部 · 重要度=全部 · 紧急度=全部 · 状态=未完成」,
|
* 默认「项目=全部 · 时间=全部 · 重要度=全部 · 紧急度=全部 · 状态=全部」,
|
||||||
* 与旧版「完成后从列表消失」的行为一致;想看历史切到「已完成」。
|
* 逾期任务与完成记录都在同一列表里;只想看待办可切到「未完成」。
|
||||||
*/
|
*/
|
||||||
class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
||||||
|
|
||||||
@@ -83,7 +83,8 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
|||||||
adapter = TaskAdapter(
|
adapter = TaskAdapter(
|
||||||
onEdit = { openSheet(it) },
|
onEdit = { openSheet(it) },
|
||||||
onToggle = { task ->
|
onToggle = { task ->
|
||||||
Store.setTaskDone(task.id, !task.done)
|
// 手动勾选完成:备注写「手动完成」,这一次不算专注,不进累计与饼图
|
||||||
|
Store.setTaskDone(task.id, !task.done, markManual = true)
|
||||||
reload()
|
reload()
|
||||||
},
|
},
|
||||||
onStart = { task -> (activity as? MainActivity)?.startFocusOn(task) },
|
onStart = { task -> (activity as? MainActivity)?.startFocusOn(task) },
|
||||||
@@ -282,7 +283,7 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
|||||||
|
|
||||||
// 有任一条件偏离默认值时摘要高亮,提示当前列表被筛过
|
// 有任一条件偏离默认值时摘要高亮,提示当前列表被筛过
|
||||||
val filtered = filterProjectId > 0L || timeFilter != TIME_ALL ||
|
val filtered = filterProjectId > 0L || timeFilter != TIME_ALL ||
|
||||||
priorityFilter >= 0 || urgencyFilter >= 0 || statusFilter != 0
|
priorityFilter >= 0 || urgencyFilter >= 0 || statusFilter != -1
|
||||||
tvFilterSummary.setTextColor(
|
tvFilterSummary.setTextColor(
|
||||||
ctx.col(if (filtered) R.color.brand else R.color.text_secondary)
|
ctx.col(if (filtered) R.color.brand else R.color.text_secondary)
|
||||||
)
|
)
|
||||||
@@ -382,7 +383,10 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
|||||||
|
|
||||||
private fun toRow(task: Task, spans: Map<Long, SessionSpan>): TaskAdapter.Row.Item {
|
private fun toRow(task: Task, spans: Map<Long, SessionSpan>): TaskAdapter.Row.Item {
|
||||||
val project = projects.firstOrNull { it.id == task.projectId }
|
val project = projects.firstOrNull { it.id == task.projectId }
|
||||||
val overdue = task.due > 0 && task.due < Dates.todayStart()
|
// 重复任务按周期滚动,本轮没做不算逾期(下一轮生成时会自动结束旧实例);
|
||||||
|
// 只有不重复的任务才标「已逾期」
|
||||||
|
val overdue = task.due > 0 && task.due < Dates.todayStart() &&
|
||||||
|
task.repeatType == com.focusbox.app.model.Repeat.NONE
|
||||||
return TaskAdapter.Row.Item(
|
return TaskAdapter.Row.Item(
|
||||||
task = task,
|
task = task,
|
||||||
projectName = project?.name ?: getString(R.string.inbox),
|
projectName = project?.name ?: getString(R.string.inbox),
|
||||||
@@ -414,7 +418,7 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openSheet(task: Task?) {
|
private fun openSheet(task: Task?) {
|
||||||
// 新建任务时默认归到当前筛选的项目;全部/收件箱则不预选
|
// 新建任务时默认归到当前筛选的项目;全部/未分类则不预选
|
||||||
TaskSheet(requireContext(), task, filterProjectId.takeIf { it > 0 } ?: 0L) { reload() }.show()
|
TaskSheet(requireContext(), task, filterProjectId.takeIf { it > 0 } ?: 0L) { reload() }.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
package com.focusbox.app.util
|
package com.focusbox.app.util
|
||||||
|
|
||||||
/** 项目配色。八色一组,两两之间在色相上有足够间距,圆点上也能分辨。 */
|
/**
|
||||||
|
* 项目配色:20 色,按色相环顺序排列,冷暖交替铺开。
|
||||||
|
*
|
||||||
|
* 排布原则:
|
||||||
|
* 1. 前 8 个保持 v3.13 及以前的顺序不变 —— 老项目的颜色不能因为扩容而整体位移;
|
||||||
|
* 2. 新增 12 个按色相插空补齐(红橙 → 黄绿 → 青 → 蓝紫 → 紫红 → 酒红),
|
||||||
|
* 相邻两个至少差 15° 色相,圆点(20dp)和饼图上都能分清;
|
||||||
|
* 3. 统一压到中等明度(HSB 的 B ≈ 60–75%,S ≈ 40–65%),
|
||||||
|
* 深色主题下不刺眼、浅色主题下不吃掉白字,也不会盖过品牌色。
|
||||||
|
*/
|
||||||
object Palette {
|
object Palette {
|
||||||
|
|
||||||
val colors = intArrayOf(
|
val colors = intArrayOf(
|
||||||
|
// ---- 原有 8 色(顺序保持不变)
|
||||||
0xFFC75B45.toInt(), // 陶土红
|
0xFFC75B45.toInt(), // 陶土红
|
||||||
0xFFD98324.toInt(), // 琥珀
|
0xFFD98324.toInt(), // 琥珀
|
||||||
0xFFC9A227.toInt(), // 芥黄
|
0xFFC9A227.toInt(), // 芥黄
|
||||||
@@ -12,9 +22,22 @@ object Palette {
|
|||||||
0xFF3B7DD8.toInt(), // 靛蓝
|
0xFF3B7DD8.toInt(), // 靛蓝
|
||||||
0xFF6C5CE7.toInt(), // 紫
|
0xFF6C5CE7.toInt(), // 紫
|
||||||
0xFFB7548E.toInt(), // 玫红
|
0xFFB7548E.toInt(), // 玫红
|
||||||
|
// ---- 新增 12 色:暖色 6 个 + 冷色 6 个
|
||||||
|
0xFFE0703C.toInt(), // 柚橙(暖)
|
||||||
|
0xFFA8B33A.toInt(), // 柠黄绿(暖偏中性)
|
||||||
|
0xFF6E8B3D.toInt(), // 橄榄(暖绿)
|
||||||
|
0xFFA34A52.toInt(), // 酒红(暖)
|
||||||
|
0xFFD96C93.toInt(), // 玫瑰粉(暖)
|
||||||
|
0xFFA9663A.toInt(), // 焦糖(暖)
|
||||||
|
0xFF2E7D57.toInt(), // 森林绿(冷)
|
||||||
|
0xFF45B08C.toInt(), // 薄荷(冷)
|
||||||
|
0xFF2E9AAE.toInt(), // 青蓝(冷)
|
||||||
|
0xFF4B9CD3.toInt(), // 天蓝(冷)
|
||||||
|
0xFF5B6BC0.toInt(), // 靛紫(冷)
|
||||||
|
0xFF9A7BD0.toInt(), // 丁香紫(冷)
|
||||||
)
|
)
|
||||||
|
|
||||||
/** 收件箱用中性灰,避免和自建项目争注意力 */
|
/** 未分类用中性灰,避免和自建项目争注意力 */
|
||||||
const val INBOX = 0xFF7A756C.toInt()
|
const val INBOX = 0xFF7A756C.toInt()
|
||||||
|
|
||||||
fun colorAt(index: Int): Int = colors[index.mod(colors.size)]
|
fun colorAt(index: Int): Int = colors[index.mod(colors.size)]
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ object Prefs {
|
|||||||
|
|
||||||
fun init(context: Context) {
|
fun init(context: Context) {
|
||||||
sp = context.getSharedPreferences("focusbox", Context.MODE_PRIVATE)
|
sp = context.getSharedPreferences("focusbox", Context.MODE_PRIVATE)
|
||||||
|
// 一次性把旧的默认「未完成」改为「全部」:任务页要同时看到逾期与完成记录。
|
||||||
|
// 用户之后仍可手动切回「未完成」,迁移只执行一次。
|
||||||
|
if (!sp.getBoolean("ui_filter_status_all_migrated", false)) {
|
||||||
|
if (sp.getInt("ui_filter_status", 0) == 0) {
|
||||||
|
sp.edit().putInt("ui_filter_status", -1).apply()
|
||||||
|
}
|
||||||
|
sp.edit().putBoolean("ui_filter_status_all_migrated", true).apply()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- 时长 ----
|
// ---- 时长 ----
|
||||||
@@ -62,9 +70,10 @@ object Prefs {
|
|||||||
set(v) = sp.edit().putBoolean("lock_fullscreen", v).apply()
|
set(v) = sp.edit().putBoolean("lock_fullscreen", v).apply()
|
||||||
|
|
||||||
// ---- 目标 ----
|
// ---- 目标 ----
|
||||||
|
// 无上限:输入多大存多大(下限 15 防止误输 0/负数把目标显示搞崩)
|
||||||
var dailyGoalMinutes: Int
|
var dailyGoalMinutes: Int
|
||||||
get() = sp.getInt("daily_goal", 120)
|
get() = sp.getInt("daily_goal", 120)
|
||||||
set(v) = sp.edit().putInt("daily_goal", v.coerceIn(15, 720)).apply()
|
set(v) = sp.edit().putInt("daily_goal", v.coerceAtLeast(15)).apply()
|
||||||
|
|
||||||
/** 0 跟随系统 / 1 浅色 / 2 深色 */
|
/** 0 跟随系统 / 1 浅色 / 2 深色 */
|
||||||
var themeMode: Int
|
var themeMode: Int
|
||||||
@@ -164,7 +173,7 @@ object Prefs {
|
|||||||
set(v) = sp.edit().putInt("ui_filter_urgency", v).apply()
|
set(v) = sp.edit().putInt("ui_filter_urgency", v).apply()
|
||||||
|
|
||||||
var uiFilterStatus: Int
|
var uiFilterStatus: Int
|
||||||
get() = sp.getInt("ui_filter_status", 0)
|
get() = sp.getInt("ui_filter_status", -1)
|
||||||
set(v) = sp.edit().putInt("ui_filter_status", v).apply()
|
set(v) = sp.edit().putInt("ui_filter_status", v).apply()
|
||||||
|
|
||||||
var uiFilterExpanded: Boolean
|
var uiFilterExpanded: Boolean
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.focusbox.app.util.col
|
|||||||
import com.focusbox.app.util.dpf
|
import com.focusbox.app.util.dpf
|
||||||
import com.focusbox.app.util.spf
|
import com.focusbox.app.util.spf
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.roundToInt
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,16 +44,28 @@ class LabelDonutView @JvmOverloads constructor(
|
|||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 环中心的小字(总专注 / 任务占比) */
|
/**
|
||||||
var centerCaption: String = ""
|
* 环上最多给几条切片牵引线标注(取占比最高的若干条)。
|
||||||
set(value) {
|
*
|
||||||
field = value
|
* 超出部分**不再合并成「其他」**:环本身照旧把每一块都按真实占比画出来,
|
||||||
invalidate()
|
* 只是没牵到线的切片记进 [unlabeled],由调用方在图表下方完整列出。
|
||||||
}
|
* 6 条(每侧 3 条)在 222dp 高度里间距仍舒展,再往上夹逼会把相邻标注压到一起。
|
||||||
|
*/
|
||||||
/** 最多画几条引线标注,多出来的合并成「其他」,避免标注挤成一团 */
|
|
||||||
var maxLabels: Int = 6
|
var maxLabels: Int = 6
|
||||||
|
|
||||||
|
/** 扇区张角小于该值时不牵线:引线会叠在同一个点上,约 0.8% 以下的占比 */
|
||||||
|
private val minLabelSweep = 3f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环上没能牵线的切片(占比排在 [maxLabels] 之外,或扇区太窄),按占比从高到低。
|
||||||
|
* 调用方必须把它们全部列在图表下方,否则这些任务/项目在视觉上就"消失"了。
|
||||||
|
*/
|
||||||
|
var unlabeled: List<Slice> = emptyList()
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** 已经牵到线的切片,按同一套规则算出,供绘制使用 */
|
||||||
|
private var labeled: List<Slice> = emptyList()
|
||||||
|
|
||||||
private val strokeW = context.dpf(28f)
|
private val strokeW = context.dpf(28f)
|
||||||
|
|
||||||
private val arcPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
private val arcPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
@@ -76,13 +89,7 @@ class LabelDonutView @JvmOverloads constructor(
|
|||||||
textAlign = Paint.Align.CENTER
|
textAlign = Paint.Align.CENTER
|
||||||
isFakeBoldText = true
|
isFakeBoldText = true
|
||||||
}
|
}
|
||||||
private val captionPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE
|
||||||
textSize = context.spf(10f)
|
|
||||||
color = context.col(R.color.text_tertiary)
|
|
||||||
textAlign = Paint.Align.CENTER
|
|
||||||
}
|
|
||||||
private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
||||||
style = Paint.Style.STROKE
|
|
||||||
strokeWidth = context.dpf(1.2f)
|
strokeWidth = context.dpf(1.2f)
|
||||||
}
|
}
|
||||||
private val dotPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
|
private val dotPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
|
||||||
@@ -96,9 +103,29 @@ class LabelDonutView @JvmOverloads constructor(
|
|||||||
|
|
||||||
fun setSlices(list: List<Slice>) {
|
fun setSlices(list: List<Slice>) {
|
||||||
slices = list
|
slices = list
|
||||||
|
plan(list)
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标注计划:按占比排序,前 [maxLabels] 名里扇区够宽的才牵线,
|
||||||
|
* 其余(含前 N 名但太窄的)全部落到 [unlabeled]。
|
||||||
|
*/
|
||||||
|
private fun plan(list: List<Slice>) {
|
||||||
|
val total = list.sumOf { it.seconds }
|
||||||
|
val sorted = list.sortedByDescending { it.seconds }
|
||||||
|
val head = if (total <= 0) emptyList() else sorted.take(maxLabels).filter {
|
||||||
|
it.seconds.toFloat() / total * 360f >= minLabelSweep
|
||||||
|
}
|
||||||
|
labeled = head
|
||||||
|
// 用「逐个摘除」而不是 toSet 差集:同名同色同时长的两条切片也能各算一次
|
||||||
|
val left = head.toMutableList()
|
||||||
|
unlabeled = sorted.filter { s ->
|
||||||
|
val i = left.indexOf(s)
|
||||||
|
if (i >= 0) { left.removeAt(i); false } else true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private data class Tag(
|
private data class Tag(
|
||||||
val slice: Slice,
|
val slice: Slice,
|
||||||
val midDeg: Float,
|
val midDeg: Float,
|
||||||
@@ -123,21 +150,25 @@ class LabelDonutView @JvmOverloads constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val shown = collapse(slices)
|
|
||||||
val box = RectF(cx - r, cy - r, cx + r, cy + r)
|
val box = RectF(cx - r, cy - r, cx + r, cy + r)
|
||||||
val gapDeg = if (shown.size > 1) 2.2f else 0f
|
// 不再合并「其他」后切片可能有几十条,固定 2.2° 的缝隙累计起来会吃掉小半个环
|
||||||
|
// (40 条就是 88°),因此按条数摊薄,总缝隙不超过约 14°
|
||||||
|
val gapDeg = if (slices.size > 1) minOf(2.2f, 14f / slices.size) else 0f
|
||||||
|
|
||||||
// ---- 弧与百分比
|
// ---- 弧与百分比:每一块都按真实占比画,绝不合并
|
||||||
var start = -90f
|
var start = -90f
|
||||||
val tags = ArrayList<Tag>(shown.size)
|
val tags = ArrayList<Tag>(labeled.size)
|
||||||
shown.forEach { s ->
|
val pending = labeled.toMutableList()
|
||||||
|
slices.forEach { s ->
|
||||||
val sweep = s.seconds.toFloat() / total * 360f
|
val sweep = s.seconds.toFloat() / total * 360f
|
||||||
val midDeg = start + sweep / 2f
|
val midDeg = start + sweep / 2f
|
||||||
arcPaint.color = s.color
|
arcPaint.color = s.color
|
||||||
canvas.drawArc(box, start + gapDeg / 2f, (sweep - gapDeg).coerceAtLeast(0.5f), false, arcPaint)
|
canvas.drawArc(box, start + gapDeg / 2f, (sweep - gapDeg).coerceAtLeast(0.2f), false, arcPaint)
|
||||||
|
|
||||||
val arcLen = sweep / 360f * (2 * Math.PI.toFloat() * r)
|
val arcLen = sweep / 360f * (2 * Math.PI.toFloat() * r)
|
||||||
val pct = "${(s.seconds * 100f / total).toInt().coerceAtLeast(1)}%"
|
// 与下方明细用同一套舍入(四舍五入),否则 7.6% 环上写 7、列表写 8,
|
||||||
|
// 看起来就像「排第 7 的都牵了线,前 6 反而没牵」
|
||||||
|
val pct = "${(s.seconds * 100.0 / total).roundToInt().coerceAtLeast(1)}%"
|
||||||
// 环加粗后百分比必须完整落在色带里:按实测字宽缩字号,两侧各留 5dp 边距
|
// 环加粗后百分比必须完整落在色带里:按实测字宽缩字号,两侧各留 5dp 边距
|
||||||
var pctSize = 11f
|
var pctSize = 11f
|
||||||
pctPaint.textSize = context.spf(pctSize)
|
pctPaint.textSize = context.spf(pctSize)
|
||||||
@@ -154,14 +185,16 @@ class LabelDonutView @JvmOverloads constructor(
|
|||||||
canvas.drawText(pct, px, py - (fm.ascent + fm.descent) / 2f, pctPaint)
|
canvas.drawText(pct, px, py - (fm.ascent + fm.descent) / 2f, pctPaint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 太薄的扇区不牵线,否则几条线会叠在同一个点上
|
// 只有进了标注计划的切片才牵线;pending 逐个摘除,重复切片也各算一次
|
||||||
if (sweep >= 5f) {
|
if (sweep >= minLabelSweep && pending.remove(s)) {
|
||||||
val cosA = cos(radians(midDeg))
|
val cosA = cos(radians(midDeg))
|
||||||
val sinA = sin(radians(midDeg))
|
val sinA = sin(radians(midDeg))
|
||||||
tags.add(
|
tags.add(
|
||||||
Tag(
|
Tag(
|
||||||
slice = s,
|
slice = s,
|
||||||
midDeg = midDeg,
|
midDeg = midDeg,
|
||||||
|
// 只看扇区中线在左半还是右半:标注就该贴在自己那块色旁边。
|
||||||
|
// v3.14 试过强行左右均分,被分到对面的扇区引线必然横穿圆环,已撤回。
|
||||||
side = if (cosA >= 0.0) 1 else -1,
|
side = if (cosA >= 0.0) 1 else -1,
|
||||||
anchorY = cy + ((r + strokeW) * sinA).toFloat(),
|
anchorY = cy + ((r + strokeW) * sinA).toFloat(),
|
||||||
)
|
)
|
||||||
@@ -177,24 +210,15 @@ class LabelDonutView @JvmOverloads constructor(
|
|||||||
|
|
||||||
private fun radians(deg: Float): Double = Math.toRadians(deg.toDouble())
|
private fun radians(deg: Float): Double = Math.toRadians(deg.toDouble())
|
||||||
|
|
||||||
private fun collapse(list: List<Slice>): List<Slice> {
|
/**
|
||||||
if (list.size <= maxLabels) return list
|
* 环中心只画一行:累计时间(或空态提示)。
|
||||||
val head = list.take(maxLabels - 1)
|
* 之前按 cy + 2dp 硬偏移定位,字面重心偏下;改为按字体度量
|
||||||
val rest = list.drop(maxLabels - 1)
|
* 把墨迹垂直中心落在圆心,并删除原来的小字说明行。
|
||||||
return head + Slice(
|
*/
|
||||||
name = context.getString(R.string.slice_other),
|
|
||||||
seconds = rest.sumOf { it.seconds },
|
|
||||||
color = context.col(R.color.text_tertiary),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun drawCenter(canvas: Canvas, cx: Float, cy: Float, emptyHint: String?) {
|
private fun drawCenter(canvas: Canvas, cx: Float, cy: Float, emptyHint: String?) {
|
||||||
val big = centerText.takeIf { it.isNotBlank() } ?: "0m"
|
val text = emptyHint ?: centerText.ifBlank { "0m" }
|
||||||
canvas.drawText(big, cx, cy + context.dpf(2f), centerPaint)
|
val fm = centerPaint.fontMetrics
|
||||||
val cap = emptyHint ?: centerCaption
|
canvas.drawText(text, cx, cy - (fm.ascent + fm.descent) / 2f, centerPaint)
|
||||||
if (cap.isNotBlank()) {
|
|
||||||
canvas.drawText(cap, cx, cy + context.dpf(18f), captionPaint)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -256,7 +280,8 @@ class LabelDonutView @JvmOverloads constructor(
|
|||||||
|
|
||||||
linePaint.color = color
|
linePaint.color = color
|
||||||
linePaint.alpha = 200
|
linePaint.alpha = 200
|
||||||
// 从环外缘斜出到折点,再水平指向外侧圆点
|
// 标注永远在扇区自己那一侧,从环外缘斜出到折点,再水平指向外侧圆点,
|
||||||
|
// 引线不会跨过圆环(v3.14 的三段式是为强制左右均分服务的,已随均分一起撤回)。
|
||||||
canvas.drawLine(startX, startY, kneeX, tag.y, linePaint)
|
canvas.drawLine(startX, startY, kneeX, tag.y, linePaint)
|
||||||
canvas.drawLine(kneeX, tag.y, dotX, tag.y, linePaint)
|
canvas.drawLine(kneeX, tag.y, dotX, tag.y, linePaint)
|
||||||
|
|
||||||
|
|||||||
87
src/main/res/layout-land/activity_lock_screen.xml
Normal file
87
src/main/res/layout-land/activity_lock_screen.xml
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
锁屏全屏倒计时·横屏专属排版(区别于竖屏的纯纵向堆叠):
|
||||||
|
左右对称分栏——左侧倒计时(大)+ 任务名,右侧时钟(大)+ 日期星期,
|
||||||
|
两侧主字号统一 130sp,视觉左右对应;无「工作中/休息中」提示。
|
||||||
|
|
||||||
|
分割线:保持最初可见版本的原始实现——静态 View 直接放在两栏之间,
|
||||||
|
固定 dp 高度,无任何运行时改动(此前的 View.post / fontMetrics /
|
||||||
|
match_parent 结构化三版方案在锁屏/悬浮窗链路上全部失效)。
|
||||||
|
高度 150dp ≈ 130sp 时间文字的墨迹高度(1.17 × 130sp),仅分割两块大时间。
|
||||||
|
|
||||||
|
v2.2/v2.3 位置对齐:分割线作为横排直系子 View 时,center_vertical 相对「整个
|
||||||
|
左右两栏(时间+10dp间距+15sp小字)」居中,下方多出的一截把线的中心往下拉。
|
||||||
|
v2.2 只在分割线外套锚点 FrameLayout,但锚点列比侧栏矮(没有补小字占位),
|
||||||
|
三列各自居中后锚点中心仍落在屏幕中心,位置不变、修复无效。
|
||||||
|
v2.3 改为中列完整镜像左右两栏(时间锚点 + 同规格小字占位),三列同高同顶,
|
||||||
|
锚点中心严格等于时间文字中心;纯静态 XML,不受锁屏/悬浮窗特殊窗口运行时
|
||||||
|
调整失效问题影响,字体缩放变化也同步。
|
||||||
|
-->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/lockRoot"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/black"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<!-- 左:倒计时 + 任务名 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockCountdown"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="130sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockTask"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxWidth="320dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="#99FFFFFF"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 中列分割线已按用户要求移除(v2.9):左右两栏各占一半宽度,文字各自居中 -->
|
||||||
|
|
||||||
|
<!-- 右:时钟(大)+ 日期星期在时钟下面 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockClock"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="130sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockDate"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:textColor="#99FFFFFF"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -38,15 +38,6 @@
|
|||||||
android:textSize="96sp"
|
android:textSize="96sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvLockMode"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="14dp"
|
|
||||||
android:letterSpacing="0.2"
|
|
||||||
android:textColor="#66FFFFFF"
|
|
||||||
android:textSize="13sp" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvLockTask"
|
android:id="@+id/tvLockTask"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="vertical"
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:background="@drawable/bg_card"
|
android:background="@drawable/bg_card"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_marginStart="20dp"
|
||||||
android:layout_marginEnd="20dp"
|
android:layout_marginEnd="20dp"
|
||||||
@@ -13,6 +12,15 @@
|
|||||||
android:paddingTop="14dp"
|
android:paddingTop="14dp"
|
||||||
android:paddingBottom="14dp">
|
android:paddingBottom="14dp">
|
||||||
|
|
||||||
|
<!-- 项目头:点击整行展开/收起任务列表 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/projectHeader"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/colorBar"
|
android:id="@+id/colorBar"
|
||||||
android:layout_width="4dp"
|
android:layout_width="4dp"
|
||||||
@@ -63,4 +71,25 @@
|
|||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:src="@drawable/ic_more"
|
android:src="@drawable/ic_more"
|
||||||
android:contentDescription="@string/edit" />
|
android:contentDescription="@string/edit" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 展开区:该项目下添加过的任务(含已完成),默认收起 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/taskList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTaskEmpty"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="18dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/project_no_tasks"
|
||||||
|
android:textColor="@color/text_tertiary"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:visibility="gone" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
58
src/main/res/layout/item_project_task.xml
Normal file
58
src/main/res/layout/item_project_task.xml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 项目卡展开后的任务行:结构与任务列表一致,但不显示分类(项目名)。
|
||||||
|
顶部任务行 meta =「专注时长 · 最近完成 · 累计次数+累计专注」,不划线;
|
||||||
|
完成记录行同一布局,任务名划线、meta 为「日期 周几 起-止 · 专注X」。
|
||||||
|
两种行右侧都常驻开始键(btnTaskPlay),点击即开始该任务。 -->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:paddingStart="18dp"
|
||||||
|
android:paddingEnd="10dp"
|
||||||
|
android:paddingTop="9dp"
|
||||||
|
android:paddingBottom="9dp">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/taskColorBar"
|
||||||
|
android:layout_width="3dp"
|
||||||
|
android:layout_height="30dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginStart="11dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTaskTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:ellipsize="end" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTaskMeta"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:ellipsize="end"
|
||||||
|
style="@style/T.Caption" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/btnTaskPlay"
|
||||||
|
android:layout_width="34dp"
|
||||||
|
android:layout_height="34dp"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:padding="9dp"
|
||||||
|
android:background="@drawable/bg_play_circle"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_play"
|
||||||
|
android:contentDescription="@string/start" />
|
||||||
|
</LinearLayout>
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
android:layout_marginTop="6dp"
|
android:layout_marginTop="6dp"
|
||||||
android:background="@drawable/bg_btn_ghost"
|
android:background="@drawable/bg_btn_ghost"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="@string/clear_task"
|
android:text="@string/create_now"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:textColor="@color/text_secondary"
|
android:textColor="@color/text_secondary"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -52,7 +91,7 @@
|
|||||||
android:text="@string/project_color"
|
android:text="@string/project_color"
|
||||||
style="@style/T.Section" />
|
style="@style/T.Section" />
|
||||||
|
|
||||||
<!-- 八色圆点横向可滑,末位颜色不再被弹层右边缘裁掉 -->
|
<!-- 20 色圆点排成两行(每行 10 个),屏幕再窄也是在容器内横向滑动,不会被弹层右边缘裁掉 -->
|
||||||
<HorizontalScrollView
|
<HorizontalScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -65,7 +104,7 @@
|
|||||||
android:id="@+id/colorRow"
|
android:id="@+id/colorRow"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="vertical"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="4dp"
|
||||||
android:paddingBottom="4dp" />
|
android:paddingBottom="4dp" />
|
||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
<string name="mode_long_break">长休息</string>
|
<string name="mode_long_break">长休息</string>
|
||||||
|
|
||||||
<string name="start">开始专注</string>
|
<string name="start">开始专注</string>
|
||||||
|
<string name="create_now">立即创建</string>
|
||||||
|
<string name="task_created">任务已创建,已选为当前任务</string>
|
||||||
<string name="start_break">开始休息</string>
|
<string name="start_break">开始休息</string>
|
||||||
<string name="start_timing">开始计时</string>
|
<string name="start_timing">开始计时</string>
|
||||||
<string name="pause">暂停</string>
|
<string name="pause">暂停</string>
|
||||||
@@ -49,14 +51,16 @@
|
|||||||
<string name="no_task">未选择任务 · 直接开始也可以</string>
|
<string name="no_task">未选择任务 · 直接开始也可以</string>
|
||||||
<string name="pick_task">选择任务</string>
|
<string name="pick_task">选择任务</string>
|
||||||
<string name="task_selected">已选任务</string>
|
<string name="task_selected">已选任务</string>
|
||||||
|
<!-- 计时进行中,任务已锁定:右侧不再显示「已选任务」 -->
|
||||||
|
<string name="task_focusing">正在专注</string>
|
||||||
<string name="pick_project">选择项目</string>
|
<string name="pick_project">选择项目</string>
|
||||||
<string name="pick_back">返回上一步</string>
|
<string name="pick_back">返回上一步</string>
|
||||||
<string name="clear_task">不选择任务,直接开始</string>
|
<string name="clear_task">立即创建</string>
|
||||||
<string name="pick_step">第 %1$d 步 / 共 2 步</string>
|
<string name="pick_step">第 %1$d 步 / 共 2 步</string>
|
||||||
<string name="pick_project_hint">先选项目,再从这个项目里挑一件要做的事</string>
|
<string name="pick_project_hint">先选项目,再从这个项目里挑一件要做的事</string>
|
||||||
<string name="pick_task_hint">选中的任务会自动套用它设定的专注时长</string>
|
<string name="pick_task_hint">选中的任务会自动套用它设定的专注时长</string>
|
||||||
<string name="pick_project_meta">%1$d 项待办</string>
|
<string name="pick_project_meta">%1$d 项任务</string>
|
||||||
<string name="pick_task_empty">这个项目还没有待办任务,点返回换个项目</string>
|
<string name="pick_task_empty">这个项目还没有任务,点返回换个项目</string>
|
||||||
<string name="no_task_to_pick">还没有待办任务,先去「任务」新建一个</string>
|
<string name="no_task_to_pick">还没有待办任务,先去「任务」新建一个</string>
|
||||||
<string name="rounds_today">今天第 %1$d 个番茄</string>
|
<string name="rounds_today">今天第 %1$d 个番茄</string>
|
||||||
|
|
||||||
@@ -122,14 +126,21 @@
|
|||||||
<string name="archive">归档</string>
|
<string name="archive">归档</string>
|
||||||
<string name="unarchive">取消归档</string>
|
<string name="unarchive">取消归档</string>
|
||||||
<string name="archived">已归档</string>
|
<string name="archived">已归档</string>
|
||||||
<string name="delete_task_confirm">删除这个任务?专注记录会保留。</string>
|
<string name="delete_task_confirm">删除这个任务?该任务的专注记录与统计会一并删除,不可恢复。</string>
|
||||||
<string name="delete_project_confirm">删除项目「%1$s」?项目下的任务会移到收件箱。</string>
|
<string name="delete_project_confirm">删除项目「%1$s」?项目下的任务、这些任务的专注记录与统计会一并删除,不可恢复。</string>
|
||||||
|
|
||||||
<string name="projects_title">项目</string>
|
<string name="projects_title">项目</string>
|
||||||
<string name="project_summary">%1$d 个项目 · %2$d 个待办</string>
|
<string name="project_no_tasks">还没有添加任务</string>
|
||||||
|
<string name="project_tasks_total">%1$d个任务</string>
|
||||||
|
<string name="project_tasks_done">%1$d已完成</string>
|
||||||
|
<string name="project_task_last_done">最近%1$s完成</string>
|
||||||
|
<string name="project_task_done_count">累计%1$d次</string>
|
||||||
|
<string name="project_expand_done">展开完成记录(%1$d)</string>
|
||||||
|
<string name="project_collapse_done">收起完成记录(%1$d)</string>
|
||||||
|
<string name="project_summary">%1$d个项目 · %2$d个任务</string>
|
||||||
<string name="add_project">新建项目</string>
|
<string name="add_project">新建项目</string>
|
||||||
<string name="project_name_hint">项目名称</string>
|
<string name="project_name_hint">项目名称</string>
|
||||||
<string name="inbox">收件箱</string>
|
<string name="inbox">未分类</string>
|
||||||
<string name="project_color">颜色</string>
|
<string name="project_color">颜色</string>
|
||||||
<string name="show_archived">显示已归档</string>
|
<string name="show_archived">显示已归档</string>
|
||||||
<string name="empty_projects">还没有项目\n按用途分组,统计里就能看到时间花在哪</string>
|
<string name="empty_projects">还没有项目\n按用途分组,统计里就能看到时间花在哪</string>
|
||||||
@@ -160,9 +171,11 @@
|
|||||||
<string name="period_month">%1$d年%2$d月</string>
|
<string name="period_month">%1$d年%2$d月</string>
|
||||||
<string name="period_year">%1$d年</string>
|
<string name="period_year">%1$d年</string>
|
||||||
<string name="slice_other">其他</string>
|
<string name="slice_other">其他</string>
|
||||||
|
<!-- 环图下方明细行:「时长 · 占比」 -->
|
||||||
|
<string name="legend_meta">%1$s · %2$s</string>
|
||||||
<string name="no_record">暂无记录</string>
|
<string name="no_record">暂无记录</string>
|
||||||
<string name="summary_title">累计</string>
|
<string name="summary_title">累计</string>
|
||||||
<string name="streak_days">连续打卡</string>
|
<string name="streak_days">连续专注</string>
|
||||||
<string name="streak_value">%1$d天</string>
|
<string name="streak_value">%1$d天</string>
|
||||||
<string name="total_focus">总专注</string>
|
<string name="total_focus">总专注</string>
|
||||||
<string name="total_pomo">总番茄</string>
|
<string name="total_pomo">总番茄</string>
|
||||||
@@ -190,7 +203,12 @@
|
|||||||
<string name="lock_fullscreen_title">锁屏全屏倒计时</string>
|
<string name="lock_fullscreen_title">锁屏全屏倒计时</string>
|
||||||
<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="overlay_perm_title">悬浮窗权限(锁屏显示)</string>
|
||||||
|
<string name="perm_granted">已开启</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>
|
||||||
@@ -200,6 +218,9 @@
|
|||||||
<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="purge_orphan">清空未关联数据</string>
|
||||||
|
<string name="purge_confirm">将删除 %1$d 条没有关联任务的专注记录(合计 %2$s)。\n这些记录在统计里只记作「未关联任务」,删掉后饼图对应分块会消失,此操作不可恢复。</string>
|
||||||
|
<string name="purge_none">当前没有未关联任务的专注记录,无需清理。</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">V%1$s</string>
|
<string name="about_version">V%1$s</string>
|
||||||
@@ -217,7 +238,7 @@
|
|||||||
<string name="notif_action_stop">结束</string>
|
<string name="notif_action_stop">结束</string>
|
||||||
<string name="notif_no_task">未选择任务</string>
|
<string name="notif_no_task">未选择任务</string>
|
||||||
<string name="notif_focus_done">任务完成</string>
|
<string name="notif_focus_done">任务完成</string>
|
||||||
<string name="notif_focus_done_text">恭喜你,再接再厉,休息下再继续</string>
|
<string name="notif_focus_done_text">再接再厉,短暂的休息下再继续</string>
|
||||||
<string name="notif_break_done">休息结束</string>
|
<string name="notif_break_done">休息结束</string>
|
||||||
<string name="notif_break_done_text">准备好就开始下一轮</string>
|
<string name="notif_break_done_text">准备好就开始下一轮</string>
|
||||||
|
|
||||||
@@ -231,5 +252,5 @@
|
|||||||
<string name="task_card_meta">%1$s · %2$d 分钟 · 已完成 %3$d 次</string>
|
<string name="task_card_meta">%1$s · %2$d 分钟 · 已完成 %3$d 次</string>
|
||||||
<string name="stat_today_minutes">%1$d分钟</string>
|
<string name="stat_today_minutes">%1$d分钟</string>
|
||||||
<!-- %1$d 连续天数 / %2$d 每日目标分钟 -->
|
<!-- %1$d 连续天数 / %2$d 每日目标分钟 -->
|
||||||
<string name="stat_streak">连续打卡%1$d天 · 目标%2$d分钟</string>
|
<string name="stat_streak">连续专注%1$d天 · 目标%2$d分钟</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user