diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4eaaaf2..3d9384f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -13,8 +13,8 @@ android { applicationId = "com.jieliu.app" minSdk = 26 targetSdk = 35 - versionCode = 42 - versionName = "0.1.41" + versionCode = 44 + versionName = "0.1.43" } compileOptions { diff --git a/app/src/main/java/com/jieliu/app/platform/KuaishouComments.kt b/app/src/main/java/com/jieliu/app/platform/KuaishouComments.kt index 7a44d81..bb9c3a3 100644 --- a/app/src/main/java/com/jieliu/app/platform/KuaishouComments.kt +++ b/app/src/main/java/com/jieliu/app/platform/KuaishouComments.kt @@ -83,6 +83,39 @@ internal class KuaishouComments( } == true } + fun expandReceiptPanel(): Boolean { + ui.pace() + val opened = ui.inspect { page -> + val panel = panel(page) ?: return@inspect false + if (page.hasKuaishouCommentDraft()) return@inspect false + panel.full?.let { ui.click(it) } ?: true + } == true + return opened && ui.await(3_500) { + ui.inspect { page -> + val panel = panel(page) ?: return@inspect null + true.takeIf { panel.full == null && !page.hasKuaishouCommentDraft() } + } + } == true + } + + fun rewindReceipt(): Boolean { + ui.pace() + val backward = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD + val before = ui.inspect { page -> + if (page.hasKuaishouCommentDraft()) return@inspect null + val list = panel(page)?.list?.takeIf { it.supports(backward) } ?: return@inspect null + val positions = positions(page, list) + positions.takeIf { it.isNotEmpty() && list.act(backward) } + } ?: return false + return ui.await(2_500) { + ui.inspect { page -> + val list = panel(page)?.list ?: return@inspect null + val after = positions(page, list) + true.takeIf { after.isNotEmpty() && before != after } + } + } == true + } + fun close() { val session = active ?: return ui.pace() @@ -233,7 +266,8 @@ internal class KuaishouComments( } private fun readRow(page: UiPage, list: UiNode, container: UiNode, key: String): Row? { - val members = page.nodes.filter { it.isDescendantOf(container) && container.bounds.contains(it.bounds) } + val descendants = page.nodes.filter { it.isDescendantOf(container) } + val members = descendants.filter { container.bounds.contains(it.bounds) } val author = members.singleOrNull { it.resourceId == "name" && it.text.isNotBlank() } ?: return null val body = members.singleOrNull { it.resourceId == "comment" && it.text.isNotBlank() } ?: return null val time = members.singleOrNull { @@ -245,18 +279,51 @@ internal class KuaishouComments( it.resourceId == "comment_reply" && it.labels() == listOf("回复") && it.enabled && it.clickable && it.bounds.top >= body.bounds.bottom && list.bounds.contains(it.bounds) } - val pictures = members.filter { it.resourceId == "comment_image" } - val pictureGroups = members.filter { it.resourceId == "layout_emotion_image" } - val photos = pictures.takeIf { images -> - pictureGroups.all { group -> images.any { it.isDescendantOf(group) } } && - images.all { it.bounds.top >= body.bounds.bottom && it.bounds.bottom <= time.bounds.top && - pictureGroups.count { group -> it.isDescendantOf(group) } == 1 && list.bounds.contains(it.bounds) } - }?.sortedWith(compareBy({ it.bounds.top }, { it.bounds.left })) + val photos = readPhotos(descendants, list, container, body, time) val target = CommentTarget(targetKey(key, author.text, body.text), body.text, author.text) val own = members.any { it.resourceId == "comment_author_tag" && it.labels() == listOf("本人") } return Row(target, container, body, reply, time.text, photos, own) } + private fun readPhotos(nodes: List, list: UiNode, row: UiNode, body: UiNode, time: UiNode): List? { + fun insideContent(node: UiNode): Boolean = !node.bounds.isEmpty && row.bounds.contains(node.bounds) && + list.bounds.contains(node.bounds) && node.bounds.top >= body.bounds.bottom && node.bounds.bottom <= time.bounds.top + + val single = nodes.filter { it.resourceId == "comment_image" } + val singleGroups = nodes.filter { it.resourceId == "layout_emotion_image" } + val grids = nodes.filter { it.resourceId == "layout_multi_image" } + val multiImages = nodes.filter { it.resourceId == "comment_multi_media_image" } + val multiTiles = nodes.filter { it.resourceId.startsWith("comment_image_item_") } + if (grids.isEmpty() && multiImages.isEmpty() && multiTiles.isEmpty()) { + return single.takeIf { images -> + singleGroups.all { group -> images.any { it.isDescendantOf(group) } } && + images.all { image -> insideContent(image) && + singleGroups.count { group -> image.isDescendantOf(group) } == 1 } + }?.sortedWith(compareBy({ it.bounds.top }, { it.bounds.left })) + } + if (single.isNotEmpty() || singleGroups.isNotEmpty()) return null + val grid = grids.singleOrNull()?.takeIf { insideContent(it) && it.className == "android.widget.LinearLayout" && + !it.scrollable && it.directParent()?.resourceId == "comment_shop_sku_body" && + it.directParent()?.directParent()?.resourceId == "layout_comment_content" && + body.directParent()?.resourceId == "comment_content_wrapper" && + body.directParent()?.directParent() === it.directParent() + } ?: return null + val ordered = nodes.filter { it.directParent() === grid } + .sortedWith(compareBy({ it.bounds.top }, { it.bounds.left })) + if (ordered.size < 2 || ordered.size != multiTiles.size || ordered.size != multiImages.size) return null + return ordered.mapIndexed { index, tile -> + if (tile.resourceId != "comment_image_item_$index" || tile.className != "android.view.ViewGroup" || + !tile.clickable || !insideContent(tile) || !grid.bounds.contains(tile.bounds) || + tile.bounds.width() != tile.bounds.height() || ordered.take(index).any { Rect.intersects(it.bounds, tile.bounds) } + ) return null + nodes.filter { it.isDescendantOf(tile) }.singleOrNull()?.takeIf { + it.directParent() === tile && it.resourceId == "comment_multi_media_image" && + it.className == "android.widget.ImageView" && + it.labels() == listOf("图片") && it.bounds == tile.bounds + } ?: return null + } + } + private fun positions(page: UiPage, list: UiNode): List, Rect>> = page.nodes .filter { it.isDescendantOf(list) && it.labels().isNotEmpty() && list.bounds.contains(it.bounds) } .map { it.labels() to Rect(it.bounds) } diff --git a/app/src/main/java/com/jieliu/app/platform/KuaishouNavigation.kt b/app/src/main/java/com/jieliu/app/platform/KuaishouNavigation.kt index c72ed66..25148e9 100644 --- a/app/src/main/java/com/jieliu/app/platform/KuaishouNavigation.kt +++ b/app/src/main/java/com/jieliu/app/platform/KuaishouNavigation.kt @@ -83,7 +83,7 @@ internal class KuaishouNavigation(private val spec: PlatformSpec, private val ui private fun openSearch() { repeat(6) { - val action = ui.await(5_000) { + val action = ui.await(12_000) { ui.inspect { page -> if (page.hasKuaishouCommentDraft()) throw PlatformException("请先处理快手中打开的评论草稿") if (page.searchEditor() != null) return@inspect "ready" diff --git a/app/src/main/java/com/jieliu/app/platform/KuaishouReplies.kt b/app/src/main/java/com/jieliu/app/platform/KuaishouReplies.kt index 178dc61..888aed0 100644 --- a/app/src/main/java/com/jieliu/app/platform/KuaishouReplies.kt +++ b/app/src/main/java/com/jieliu/app/platform/KuaishouReplies.kt @@ -42,7 +42,10 @@ internal class KuaishouReplies( private data class Receipt(val window: Int, val key: String, val images: List) private data class DraftImage(val area: Rect, val close: Rect) private enum class Role { OWN, OTHER } - private data class RoleMenu(val window: Int, val role: Role?) + private data class RoleMenu(val window: Int, val list: UiNode, val actions: List) + private class RoleMenuBinding(val window: Int, val list: UiNodeSource, val actions: List) : Closeable { + override fun close() = list.close() + } private var prepared: Prepared? = null private val picker = KuaishouPhotoPicker(ui) @@ -142,26 +145,55 @@ internal class KuaishouReplies( val age = System.currentTimeMillis() - armedAt if (armedAt <= 0 || age !in 0..RECHECK_WINDOW_MS) return CommentPublishResult.UNCERTAIN val references = photos.readReceiptPixels(attachments) ?: return CommentPublishResult.UNCERTAIN + if (ui.await(5_000) { + ui.inspect { page -> true.takeIf { comments.panel(page) != null && !page.hasKuaishouCommentDraft() } } + } != true + ) { + diagnostic("快手回复框尚未退出,等待核对原评论") + return CommentPublishResult.UNCERTAIN + } + if (!comments.expandReceiptPanel()) { + diagnostic("快手未能在原作品内展开已核对的评论区") + return CommentPublishResult.UNCERTAIN + } + fun originalVisible() = comments.readThread(key, author) { _, _, _ -> true } == true + for (attempt in 0 until RECEIPT_REWIND_SCREENS) { + if (originalVisible() || !comments.rewindReceipt()) break + } repeat(RECEIPT_SCREENS) { screen -> - val visible = comments.readThread(key, author) { _, _, _ -> true } == true - if (visible) { - if (!comments.ensureThread(key, author)) return CommentPublishResult.UNCERTAIN - val before = ui.await(4_500) { readReceipt(key, author, text, references.size, armedAt) } - ?: return CommentPublishResult.UNCERTAIN - val captured = ui.screenshotPhotos(before.window, before.images) ?: return CommentPublishResult.UNCERTAIN - if (readReceipt(key, author, text, references.size, armedAt) != before || !matchPhotos(references, captured)) { + if (originalVisible()) { + if (!comments.ensureThread(key, author)) { + diagnostic("快手已定位原评论,回复线程尚不能完整读取") return CommentPublishResult.UNCERTAIN } - if (inspectRole(key, author, key, before) != Role.OTHER || - inspectRole(key, author, before.key, before) != Role.OWN || + val before = ui.await(4_500) { + val row = readReceipt(key, author, text, references.size, armedAt) ?: return@await null + val captured = ui.screenshotPhotos(row.window, row.images) ?: return@await null + row.takeIf { readReceipt(key, author, text, references.size, armedAt) == it && + matchPhotos(references, captured) } + } + if (before == null) { + diagnostic("快手未能核对原评论下同一条回复的正文、时间和图片") + return CommentPublishResult.UNCERTAIN + } + diagnostic("快手已核对原评论下的回复正文及 ${references.size} 张图片,正在核对本人身份") + if (inspectRole(key, author, key, before) != Role.OTHER) { + diagnostic("快手未能核对原评论的身份菜单") + return CommentPublishResult.UNCERTAIN + } + if (inspectRole(key, author, before.key, before) != Role.OWN || readReceipt(key, author, text, references.size, armedAt) != before) { + diagnostic("快手未能核对同一条回复的本人身份") return CommentPublishResult.UNCERTAIN } diagnostic("快手已核对原评论下的本人回复正文及 ${references.size} 张图片") if (references.isNotEmpty()) photos.cleanupStaged() return CommentPublishResult.CONFIRMED } - if (screen == RECEIPT_SCREENS - 1 || !comments.scroll()) return CommentPublishResult.UNCERTAIN + if (screen == RECEIPT_SCREENS - 1 || !comments.scroll()) { + diagnostic("快手未在已核对的评论区找到原评论") + return CommentPublishResult.UNCERTAIN + } } return CommentPublishResult.UNCERTAIN } @@ -300,36 +332,67 @@ internal class KuaishouReplies( ui.touch(bounds.exactCenterX(), bounds.exactCenterY(), bounds.exactCenterX(), bounds.exactCenterY(), 650) page.windowId.takeIf { shown } } ?: return null - val menu = ui.await(3_500) { ui.inspect { readRoleMenu(it, sourceWindow) } } ?: return null - val closed = ui.inspect { page -> readRoleMenu(page, sourceWindow) == menu && ui.back() } == true - if (!closed || ui.await(3_500) { + val menu = ui.await(3_500) { + ui.inspect { page -> + readRoleMenu(page, sourceWindow)?.takeIf { it.actions.count { action -> action == "复制评论" } == 1 } + ?.let { RoleMenuBinding(it.window, it.list.retainSource(), it.actions) } + } + } ?: return null + val role = menu.use { binding -> + val resolved = findMenuRole(sourceWindow, binding) + val closed = ui.inspect { page -> boundMenu(page, sourceWindow, binding) != null && ui.back() } == true + resolved.takeIf { closed } + } + if (role == null || ui.await(3_500) { comments.readThread(key, author) { page, _, thread -> true.takeIf { page.windowId == sourceWindow && thread.complete && (rowKey == key || thread.replies.count { it.target.key == rowKey } == 1) } } } != true ) return null - return menu.role + return role } + private fun findMenuRole(sourceWindow: Int, binding: RoleMenuBinding): Role? { + var actions = binding.actions + repeat(3) { screen -> + val deletion = actions.count { it == "删除评论" || it == "删除" } + val reporting = actions.count { it == "举报评论" } + if (deletion == 1 && reporting == 0) return Role.OWN + if (deletion == 0 && reporting == 1) return Role.OTHER + if (deletion > 0 || reporting > 0 || screen == 2) return null + + val before = actions + ui.pace() + val moved = ui.inspect { page -> + val menu = boundMenu(page, sourceWindow, binding) ?: return@inspect false + menu.actions == before && menu.list.scrollable && ui.scrollUpInside(menu.list.bounds) + } == true + if (!moved) return null + actions = ui.await(2_500) { + ui.inspect { page -> boundMenu(page, sourceWindow, binding)?.actions?.takeIf { it != before } } + } ?: return null + } + return null + } + + private fun boundMenu(page: UiPage, sourceWindow: Int, binding: RoleMenuBinding): RoleMenu? = + readRoleMenu(page, sourceWindow)?.takeIf { it.window == binding.window && it.list.hasSource(binding.list) } + private fun readRoleMenu(page: UiPage, previousWindow: Int): RoleMenu? { if (!page.complete || page.windowId == previousWindow || page.hasKuaishouCommentDraft()) return null val sheet = page.nodes.singleOrNull { it.resourceId == "design_bottom_sheet" && it.directParent()?.resourceId == "coordinator" && page.bounds.contains(it.bounds) } ?: return null + val list = page.nodes.singleOrNull { + it.resourceId == "recycler_view" && it.className == "androidx.recyclerview.widget.RecyclerView" && + it.isDescendantOf(sheet) && sheet.bounds.contains(it.bounds) + } ?: return null val labels = page.nodes.filter { - it.resourceId == "item_title" && it.isDescendantOf(sheet) && sheet.bounds.contains(it.bounds) + it.resourceId == "item_title" && it.isDescendantOf(list) && list.bounds.contains(it.bounds) }.map(UiNode::text) - if (labels.count { it == "复制评论" } != 1) return null - val deletion = labels.count { it == "删除评论" || it == "删除" } - val reporting = labels.count { it == "举报评论" } - val role = when { - deletion == 1 && reporting == 0 -> Role.OWN - deletion == 0 && reporting == 1 -> Role.OTHER - else -> null - } - return RoleMenu(page.windowId, role) + return RoleMenu(page.windowId, list, labels).takeIf { labels.isNotEmpty() } } private fun matchesTime(label: String?, armedAt: Long, now: Long): Boolean { @@ -343,6 +406,7 @@ internal class KuaishouReplies( } private companion object { + const val RECEIPT_REWIND_SCREENS = 4 const val RECEIPT_SCREENS = 13 val relativeTime = Regex("([1-9]\\d?)\\s*(秒|分钟)前(?:\\s+\\S+)?") val attachmentNodes = setOf("preview_image_layout", "preview_image", "preview_close", "comment_image") diff --git a/docs/开发进度.md b/docs/开发进度.md index 51e3b21..2240b86 100644 --- a/docs/开发进度.md +++ b/docs/开发进度.md @@ -1,6 +1,15 @@ # 拾见开发进度 -最近更新于 2026-11-27 15:22(UTC+8)。以下按开发轮次倒序记录。 +最近更新于 2026-11-27 15:52(UTC+8)。以下按开发轮次倒序记录。 + +## 2026-11-27 · 拾见 0.1.43 快手图文实发与回执定位 + +- 0.1.41 快手适配已推送至 `main`,提交为 `d5ea316`。15:34:33 从「开始任务」启动视频验收,按内容类型搜索,15:35:04 命中预检的原评论,随后提交正文和两张绑定图。同一次运行重新定位原作品和评论区,15:35:54 以待核对结束。原线程出现本次的完整回复和两张图,截图回放按绑定顺序逐张匹配。该任务没有写入 `SENT`,原提交记录保留。 +- 真机已确认多图回复采用独立的图片区,每张图有原生序号。0.1.42 增加这组节点的识别和完整性检查,并在回复框关闭、评论区恢复后开始回读。本人操作菜单需要滚动才能看到「删除评论」,程序在同一原生菜单内滚动并核对身份。冷启动后搜索栏出现较晚时,延长等待入口就绪的时间。 +- 0.1.42 于 15:43:28 从「开始任务」启动图片作品验收,15:43:52 命中另一条原评论,随后提交正文和按顺序绑定的两张图。原线程中再次看到完整正文和两张图,截图比对顺序一致。任务于 15:44:25 以待核对结束,未写入 `SENT`。两轮均为一次提交,按独立任务保留。手机保留图片任务待核对记录,视频任务和之前的检查点已归档,原配置、无障碍和相册权限已恢复。 +- 图片轮提交后的首帧只显示新回复,原评论滑出了列表。0.1.43 在已确认的评论面板内先展开评论区,再有界向列表顶部回找原评论,并等待同一条回复的图片区域稳定后重新比对。继续要求原评论、正文、时间、图片顺序和本人证据同时成立。新增回执阶段日志,便于定位评论区、线程、图片或身份核对的中断。 +- 0.1.43 使用两次实发的原生快照、截图裁片和本人菜单离线回放。覆盖原评论裁切后的展开、同面板反向滚动、首次截图无效后的重试、多图顺序、本人菜单滚动,以及窗口或列表切换后保留待核对。两种作品的新任务实发到自动写入 `SENT` 仍待真机验收。 +- 0.1.43 离线构建成功,74 项 JVM 单测通过,Lint 为 0 个错误、3 个既有警告。调试 APK 通过 v2 签名校验。覆盖安装后核对 APK、原配置与图片轮待核对检查点。 ## 2026-11-27 · 拾见 0.1.41 接入快手