导入 v0.1.0 / v0.2.0 源码:五模块首版、交互重构、重复任务、任务分布
- 源码镜像 src/main(81 个文件):首页双模式、任务、项目、统计、设置 - 补齐 README / LICENSE / CHANGELOG / CONTRIBUTING / .gitignore - 不含构建配置、签名材料、编译产物与备份数据
This commit is contained in:
71
src/main/java/com/focusbox/app/ui/projects/ProjectAdapter.kt
Normal file
71
src/main/java/com/focusbox/app/ui/projects/ProjectAdapter.kt
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.focusbox.app.ui.projects
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.model.Project
|
||||
import com.focusbox.app.util.Dates
|
||||
import com.focusbox.app.util.col
|
||||
import com.focusbox.app.util.roundBg
|
||||
import com.focusbox.app.util.tint
|
||||
|
||||
class ProjectAdapter(
|
||||
private val onClick: (Project) -> Unit,
|
||||
private val onLongClick: (Project) -> Unit,
|
||||
private val onMore: (Project) -> Unit,
|
||||
) : RecyclerView.Adapter<ProjectAdapter.VH>() {
|
||||
|
||||
private var items: List<Project> = emptyList()
|
||||
|
||||
fun submit(list: List<Project>) {
|
||||
items = list
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH =
|
||||
VH(LayoutInflater.from(parent.context).inflate(R.layout.item_project, parent, false))
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int) = holder.bind(items[position])
|
||||
|
||||
inner class VH(v: View) : RecyclerView.ViewHolder(v) {
|
||||
private val name: TextView = v.findViewById(R.id.tvName)
|
||||
private val meta: TextView = v.findViewById(R.id.tvMeta)
|
||||
private val progress: ProgressBar = v.findViewById(R.id.progress)
|
||||
private val colorBar: View = v.findViewById(R.id.colorBar)
|
||||
private val more: ImageView = v.findViewById(R.id.btnMore)
|
||||
|
||||
fun bind(p: Project) {
|
||||
val ctx = itemView.context
|
||||
name.text = p.name
|
||||
colorBar.background = ctx.roundBg(p.color, 2f)
|
||||
|
||||
// 只看任务与时长,不再显示番茄数
|
||||
val parts = ArrayList<String>(3)
|
||||
parts.add("${p.openTasks} 待办")
|
||||
if (p.doneTasks > 0) parts.add("${p.doneTasks} 已完成")
|
||||
if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds))
|
||||
meta.text = parts.joinToString(" · ")
|
||||
|
||||
progress.progress = (p.progress * 100).toInt()
|
||||
progress.progressTintList = ColorStateList.valueOf(p.color)
|
||||
progress.progressBackgroundTintList = ColorStateList.valueOf(ctx.col(R.color.ring_track))
|
||||
|
||||
more.tint(ctx.col(R.color.text_tertiary))
|
||||
more.setOnClickListener { onMore(p) }
|
||||
|
||||
itemView.setOnClickListener { onClick(p) }
|
||||
itemView.setOnLongClickListener {
|
||||
onLongClick(p)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
99
src/main/java/com/focusbox/app/ui/projects/ProjectSheet.kt
Normal file
99
src/main/java/com/focusbox/app/ui/projects/ProjectSheet.kt
Normal file
@@ -0,0 +1,99 @@
|
||||
package com.focusbox.app.ui.projects
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.data.Store
|
||||
import com.focusbox.app.model.Project
|
||||
import com.focusbox.app.ui.SheetDialog
|
||||
import com.focusbox.app.util.Palette
|
||||
import com.focusbox.app.util.circleBg
|
||||
import com.focusbox.app.util.dpi
|
||||
import com.focusbox.app.util.roundBg
|
||||
import com.focusbox.app.util.visible
|
||||
|
||||
class ProjectSheet(
|
||||
context: Context,
|
||||
private val existing: Project?,
|
||||
private val onSaved: () -> Unit,
|
||||
) : SheetDialog(context) {
|
||||
|
||||
private val root = LayoutInflater.from(context).inflate(R.layout.sheet_project, null)
|
||||
private val etName: EditText = root.findViewById(R.id.etName)
|
||||
private val colorRow: LinearLayout = root.findViewById(R.id.colorRow)
|
||||
|
||||
private var color: Int = existing?.color ?: Palette.colorAt(0)
|
||||
|
||||
init {
|
||||
setContentView(root)
|
||||
root.findViewById<TextView>(R.id.sheetTitle).setText(
|
||||
if (existing == null) R.string.add_project else R.string.edit
|
||||
)
|
||||
etName.setText(existing?.name ?: "")
|
||||
renderColors()
|
||||
|
||||
val btnDelete = root.findViewById<TextView>(R.id.btnDelete)
|
||||
val deletable = existing != null && existing.id != Store.INBOX_ID
|
||||
btnDelete.visible(deletable)
|
||||
btnDelete.setOnClickListener {
|
||||
existing ?: return@setOnClickListener
|
||||
AlertDialog.Builder(context)
|
||||
.setMessage(context.getString(R.string.delete_project_confirm, existing.name))
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
Store.deleteProject(existing.id)
|
||||
onSaved()
|
||||
dismiss()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
root.findViewById<View>(R.id.btnSave).setOnClickListener {
|
||||
val name = etName.text.toString().trim()
|
||||
if (name.isEmpty()) {
|
||||
etName.error = context.getString(R.string.project_name_hint)
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (existing == null) {
|
||||
Store.addProject(name, color)
|
||||
} else {
|
||||
Store.updateProject(existing.id, name, color, existing.archived)
|
||||
}
|
||||
onSaved()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderColors() {
|
||||
val ctx = context
|
||||
colorRow.removeAllViews()
|
||||
Palette.colors.forEach { c ->
|
||||
val wrap = FrameLayout(ctx)
|
||||
val lp = LinearLayout.LayoutParams(dpi(40f), dpi(40f))
|
||||
lp.marginEnd = dpi(2f)
|
||||
wrap.layoutParams = lp
|
||||
wrap.background = if (c == color) ctx.roundBg(Color.TRANSPARENT, 100f, c, 2f) else null
|
||||
|
||||
val dot = View(ctx)
|
||||
val dlp = FrameLayout.LayoutParams(dpi(26f), dpi(26f))
|
||||
dlp.gravity = Gravity.CENTER
|
||||
dot.layoutParams = dlp
|
||||
dot.background = circleBg(c)
|
||||
wrap.addView(dot)
|
||||
|
||||
wrap.setOnClickListener {
|
||||
color = c
|
||||
renderColors()
|
||||
}
|
||||
colorRow.addView(wrap)
|
||||
}
|
||||
}
|
||||
}
|
||||
118
src/main/java/com/focusbox/app/ui/projects/ProjectsFragment.kt
Normal file
118
src/main/java/com/focusbox/app/ui/projects/ProjectsFragment.kt
Normal file
@@ -0,0 +1,118 @@
|
||||
package com.focusbox.app.ui.projects
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.data.Store
|
||||
import com.focusbox.app.model.Project
|
||||
import com.focusbox.app.ui.MainActivity
|
||||
import com.focusbox.app.util.visible
|
||||
|
||||
class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
|
||||
private lateinit var recycler: RecyclerView
|
||||
private lateinit var tvSummary: TextView
|
||||
private lateinit var tvEmpty: TextView
|
||||
private lateinit var btnArchived: TextView
|
||||
private lateinit var adapter: ProjectAdapter
|
||||
|
||||
private var showArchived = false
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
recycler = view.findViewById(R.id.recycler)
|
||||
tvSummary = view.findViewById(R.id.tvSummary)
|
||||
tvEmpty = view.findViewById(R.id.tvEmpty)
|
||||
btnArchived = view.findViewById(R.id.btnArchived)
|
||||
|
||||
adapter = ProjectAdapter(
|
||||
onClick = { p -> (activity as? MainActivity)?.openProjectTasks(p.id) },
|
||||
onLongClick = { p -> showActions(p) },
|
||||
onMore = { p -> showActions(p) },
|
||||
)
|
||||
recycler.layoutManager = LinearLayoutManager(requireContext())
|
||||
recycler.adapter = adapter
|
||||
recycler.itemAnimator = null
|
||||
|
||||
view.findViewById<View>(R.id.btnAdd).setOnClickListener {
|
||||
ProjectSheet(requireContext(), null) { reload() }.show()
|
||||
}
|
||||
btnArchived.setOnClickListener {
|
||||
showArchived = !showArchived
|
||||
reload()
|
||||
}
|
||||
reload()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (view != null) reload()
|
||||
}
|
||||
|
||||
override fun onHiddenChanged(hidden: Boolean) {
|
||||
super.onHiddenChanged(hidden)
|
||||
if (!hidden && view != null) reload()
|
||||
}
|
||||
|
||||
fun reload() {
|
||||
if (view == null) return
|
||||
val all = Store.projects(includeArchived = true)
|
||||
val active = all.filter { !it.archived }
|
||||
val archived = all.filter { it.archived }
|
||||
|
||||
val shown = if (showArchived) all else active
|
||||
adapter.submit(shown)
|
||||
|
||||
tvSummary.text = getString(
|
||||
R.string.project_summary, active.size, active.sumOf { it.openTasks }
|
||||
)
|
||||
tvEmpty.visible(shown.isEmpty())
|
||||
|
||||
if (archived.isEmpty()) {
|
||||
btnArchived.visible(false)
|
||||
} else {
|
||||
btnArchived.visible(true)
|
||||
btnArchived.text = if (showArchived) "隐藏已归档" else "已归档 ${archived.size}"
|
||||
}
|
||||
}
|
||||
|
||||
private fun showActions(p: Project) {
|
||||
val isInbox = p.id == Store.INBOX_ID
|
||||
val actions = ArrayList<String>()
|
||||
actions.add(getString(R.string.edit))
|
||||
if (!isInbox) {
|
||||
actions.add(getString(if (p.archived) R.string.unarchive else R.string.archive))
|
||||
actions.add(getString(R.string.delete))
|
||||
}
|
||||
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setTitle(p.name)
|
||||
.setItems(actions.toTypedArray()) { _, which ->
|
||||
when {
|
||||
which == 0 -> ProjectSheet(requireContext(), p) { reload() }.show()
|
||||
which == 1 && !isInbox -> {
|
||||
Store.updateProject(p.id, p.name, p.color, !p.archived)
|
||||
reload()
|
||||
}
|
||||
which == 2 && !isInbox -> confirmDelete(p)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun confirmDelete(p: Project) {
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setMessage(getString(R.string.delete_project_confirm, p.name))
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
Store.deleteProject(p.id)
|
||||
reload()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user