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

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

View File

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