完成任务删除线只画任务名;置顶改圆圈箭头图标;饼图中心删小字居中;悬浮窗权限已开启不可点;每日目标可输入去上限,版本 1.6

This commit is contained in:
XIGE
2026-11-29 23:09:39 +08:00
parent 1d355693be
commit e7089ae76b
6 changed files with 190 additions and 51 deletions

View File

@@ -94,15 +94,16 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
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.lock_fullscreen_title), Prefs.lockFullscreen) { Prefs.lockFullscreen = it },
// 悬浮窗权限:锁屏倒计时主链路(鸿蒙拦 Activity 后台启动,悬浮窗不受限)
action(
getString(R.string.overlay_perm_title),
if (com.focusbox.app.service.LockOverlay.canShow(requireContext())) {
getString(R.string.perm_granted)
// 悬浮窗权限:锁屏倒计时主链路(鸿蒙拦 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 {
getString(R.string.go_set)
},
) { openOverlayPerm() },
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() },
@@ -113,6 +114,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
stepper(
getString(R.string.daily_goal),
getString(R.string.value_minutes, Prefs.dailyGoalMinutes),
// 数值支持直接点击输入;步进用于微调。Prefs 里没有上限
onEdit = { inputDailyGoal() },
) { delta ->
Prefs.dailyGoalMinutes += delta * 15
build()
@@ -184,7 +187,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
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 row = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
@@ -205,6 +209,7 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
gravity = Gravity.CENTER
setTextColor(col(R.color.title))
layoutParams = LinearLayout.LayoutParams(dpi(74f), LinearLayout.LayoutParams.WRAP_CONTENT)
if (onEdit != null) setOnClickListener { onEdit() }
})
row.addView(stepButton("+") { onChange(1) })
return row
@@ -246,13 +251,19 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
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 row = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.CENTER_VERTICAL
minimumHeight = dpi(54f)
setOnClickListener { onClick() }
if (onClick != null) setOnClickListener { onClick() }
}
row.addView(TextView(ctx).apply {
text = title
@@ -268,11 +279,13 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
setPadding(0, 0, dpi(6f), 0)
})
}
row.addView(android.widget.ImageView(ctx).apply {
setImageResource(R.drawable.ic_chevron_right)
tint(col(R.color.text_tertiary))
layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f))
})
if (showArrow) {
row.addView(android.widget.ImageView(ctx).apply {
setImageResource(R.drawable.ic_chevron_right)
tint(col(R.color.text_tertiary))
layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f))
})
}
return row
}
@@ -328,6 +341,78 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
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()
@@ -454,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
}
companion object {
const val VERSION = "1.5"
const val VERSION = "1.6"
}
}