fix: 通知累积+点击跳转修复

Bug 1: setupBannerClick每次事件覆盖onClick,丢失之前累积的taskIds
修复: 点击时从notificationManager.pendingTaskIds取所有累积ID

Bug 2: 多任务点击跳到接单池全量列表,无法区分新旧
修复: TaskListFragment支持taskIds参数过滤,只显示通知中的任务

Bug 3: allIds.toLongArray()编译错误(List<String>无此方法)
修复: mapNotNull{toLongOrNull()}.toLongArray()

nav_main.xml: taskListFragment新增taskIds可选参数(long[]nullable)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dongliang
2026-04-29 15:15:33 +09:30
parent 47e8ed0776
commit 1ffdefc887
3 changed files with 27 additions and 9 deletions

View File

@@ -515,21 +515,27 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
/**
* 设置通知横幅点击回调
* 1 个任务 → 跳任务详情;多个 → 跳任务列表
* 点击时从 notificationManager.pendingTaskIds 取所有累积的任务 ID
* 1 个任务 → 跳任务详情;多个 → 跳任务列表(传 taskIds 只显示新任务)
*/
private fun setupBannerClick(taskIds: List<String>) {
val mainActivity = activity as? com.xiaoqu.watch.app.MainActivity ?: return
mainActivity.notificationBanner.onClick = {
val currentDest = findNavController().currentDestination?.id
if (currentDest == R.id.homeFragment) {
if (taskIds.size == 1) {
// 取所有累积的任务 ID不是事件参数的防覆盖丢失
val allIds = notificationManager.pendingTaskIds
if (allIds.size == 1) {
// 1 个任务 → 直接跳详情
val taskId = taskIds.first().toLongOrNull() ?: 0L
val taskId = allIds.first().toLongOrNull() ?: 0L
val bundle = bundleOf("taskId" to taskId)
findNavController().navigate(R.id.action_home_to_taskDetail, bundle)
} else {
// 多个任务 → 跳任务列表(传 taskIds
val bundle = bundleOf("tableStatus" to 2) // 默认接单池
} else if (allIds.isNotEmpty()) {
// 多个任务 → 跳任务列表(传 taskIds 只显示新任务
val bundle = bundleOf(
"tableStatus" to 2,
"taskIds" to allIds.mapNotNull { it.toLongOrNull() }.toLongArray()
)
findNavController().navigate(R.id.action_home_to_taskList, bundle)
}
// 清除所有红点和未读

View File

@@ -51,6 +51,8 @@ class TaskListFragment : BaseFragment<FragmentTaskListBinding>() {
/** 当前状态筛选 */
private var currentStatus = 2
/** 通知跳转传入的任务 ID 列表(非空时只显示这些任务) */
private var filterTaskIds: LongArray? = null
/** 是否执行过操作(操作后列表为空时自动返回) */
private var hasActioned = false
@@ -71,6 +73,7 @@ class TaskListFragment : BaseFragment<FragmentTaskListBinding>() {
// 从导航参数获取初始状态
currentStatus = arguments?.getInt("tableStatus", 2) ?: 2
filterTaskIds = arguments?.getLongArray("taskIds")
// 初始化弹窗
val dialogContainer = requireActivity().findViewById<FrameLayout>(R.id.dialog_container)
@@ -123,8 +126,16 @@ class TaskListFragment : BaseFragment<FragmentTaskListBinding>() {
when (result) {
is ApiResult.Success -> {
taskList = result.data ?: emptyList()
Timber.d("任务列表: status=$currentStatus, count=${taskList.size}")
var list = result.data ?: emptyList()
// 如果有 taskIds 过滤(通知跳转),只保留指定任务
val ids = filterTaskIds
if (ids != null && ids.isNotEmpty()) {
list = list.filter { item ->
ids.any { it.toString() == item.id.toString() }
}
}
taskList = list
Timber.d("任务列表: status=$currentStatus, count=${taskList.size}, filter=${ids?.size ?: 0}")
if (taskList.isNotEmpty()) {
// 确保 taskIndex 在范围内
if (taskIndex >= taskList.size) taskIndex = taskList.size - 1