项目列表点击就地展开任务与统计,任务页零改动(v3.0)
This commit is contained in:
@@ -10,6 +10,8 @@ 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.model.ProjectTaskStat
|
||||
import com.focusbox.app.model.Task
|
||||
import com.focusbox.app.ui.MainActivity
|
||||
import com.focusbox.app.ui.SheetDialog
|
||||
import com.focusbox.app.util.col
|
||||
@@ -25,6 +27,10 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
|
||||
private var showArchived = false
|
||||
|
||||
/** 当前展开的项目 id;-1 表示全部收起。只展开一个,避免列表过长 */
|
||||
private var expandedProjectId = -1L
|
||||
private var taskStats: Map<Long, List<ProjectTaskStat>> = emptyMap()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
recycler = view.findViewById(R.id.recycler)
|
||||
@@ -33,9 +39,13 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
btnArchived = view.findViewById(R.id.btnArchived)
|
||||
|
||||
adapter = ProjectAdapter(
|
||||
onClick = { p -> (activity as? MainActivity)?.openProjectTasks(p.id) },
|
||||
onToggleExpand = { p ->
|
||||
expandedProjectId = if (expandedProjectId == p.id) -1L else p.id
|
||||
reload()
|
||||
},
|
||||
onLongClick = { p -> showActions(p) },
|
||||
onMore = { p -> showActions(p) },
|
||||
onStart = { t -> (activity as? MainActivity)?.startFocusOn(t) },
|
||||
)
|
||||
recycler.layoutManager = LinearLayoutManager(requireContext())
|
||||
recycler.adapter = adapter
|
||||
@@ -68,7 +78,12 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
val archived = all.filter { it.archived }
|
||||
|
||||
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) }
|
||||
adapter.submit(shown, expandedProjectId, taskStats)
|
||||
|
||||
tvSummary.text = getString(
|
||||
R.string.project_summary, active.size, active.sumOf { it.openTasks }
|
||||
|
||||
Reference in New Issue
Block a user