diff --git a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt index 2640e6e..21ceaa0 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt @@ -56,7 +56,7 @@ object WeworkOperationImpl { successFlag = false } if (!successFlag) { - if (WeworkRoomUtil.intoRoom(title)) { + if (WeworkRoomUtil.intoRoom(title, fastIn = false)) { if (sendChatMessage(receivedContent, at = at, atList = atList)) { successList.add(title) LogUtils.d("$title: 发送成功") @@ -107,7 +107,7 @@ object WeworkOperationImpl { val successList = arrayListOf() val failList = arrayListOf() for (title in titleList) { - if (WeworkRoomUtil.intoRoom(title)) { + if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) { if (WeworkTextUtil.longClickMessageItem( //聊天消息列表 1ListView 0RecycleView xViewGroup AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView), @@ -180,7 +180,7 @@ object WeworkOperationImpl { ): Boolean { val startTime = System.currentTimeMillis() for (title in titleList) { - if (WeworkRoomUtil.intoRoom(title)) { + if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) { if (!receivedName.isNullOrEmpty()) { if (WeworkTextUtil.longClickMessageItem( //聊天消息列表 1ListView 0RecycleView xViewGroup @@ -328,7 +328,7 @@ object WeworkOperationImpl { removeList: List? ): Boolean { val startTime = System.currentTimeMillis() - if (!WeworkRoomUtil.intoRoom(groupName)) { + if (!WeworkRoomUtil.intoRoom(groupName, fastIn = false)) { uploadCommandResult(message, ExecCallbackBean.ERROR_INTO_ROOM, "进入房间失败 $groupName", startTime, listOf(), listOf(groupName)) return false } @@ -372,7 +372,7 @@ object WeworkOperationImpl { groupName: String ): Boolean { val startTime = System.currentTimeMillis() - if (WeworkRoomUtil.intoRoom(groupName) && WeworkRoomUtil.intoGroupManager()) { + if ((WeworkRoomUtil.intoRoom(groupName) || WeworkRoomUtil.intoRoom(groupName, fastIn = false)) && WeworkRoomUtil.intoGroupManager()) { val groupManagerTv = AccessibilityUtil.findOneByText(getRoot(), "群管理", exact = true, timeout = 2000) if (groupManagerTv != null) { @@ -845,7 +845,7 @@ object WeworkOperationImpl { ): Boolean { val startTime = System.currentTimeMillis() for (title in titleList) { - if (WeworkRoomUtil.intoRoom(title)) { + if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) { if (WeworkTextUtil.longClickMyMessageItem( //聊天消息列表 1ListView 0RecycleView xViewGroup AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView), @@ -993,7 +993,7 @@ object WeworkOperationImpl { } } } - if (WeworkRoomUtil.intoRoom(groupName)) { + if (WeworkRoomUtil.intoRoom(groupName) || WeworkRoomUtil.intoRoom(groupName, fastIn = false)) { if (WeworkTextUtil.longClickMyMessageItem( //聊天消息列表 1ListView 0RecycleView xViewGroup AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView), @@ -1089,7 +1089,7 @@ object WeworkOperationImpl { return relayMessage(message, titleList, receivedName, originalContent, textType, nameList, extraText) } for (title in titleList) { - if (WeworkRoomUtil.intoRoom(title)) { + if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) { var hasOpenMulti = false for (subMessageBean in messageList) { val receivedName = subMessageBean.nameList?.firstOrNull() diff --git a/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt b/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt index ed23c0a..44f96d6 100644 --- a/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt +++ b/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt @@ -1325,26 +1325,26 @@ object AccessibilityUtil { /** * 等待页面消失 - * @param clazz 页面Class + * @param clazzList 页面Class * @param timeout 检查超时时间 */ fun waitForPageMissing( - clazz: String, + vararg clazzList: String, timeout: Long = 5000 ): Boolean { val service = WeworkController.weworkService val startTime = System.currentTimeMillis() var currentTime = startTime while (currentTime - startTime <= timeout) { - if (service.currentClass == clazz || service.currentClass.split(".").last() == clazz) { + if (service.currentClass in clazzList || service.currentClass.split(".").last() in clazzList) { } else { - Log.v(tag, "pageMissing: $clazz") + Log.v(tag, "pageMissing: ${clazzList.joinToString()}") return true } sleep(SHORT_INTERVAL) currentTime = System.currentTimeMillis() } - Log.e(tag, "pageMissing: not found: $clazz current: ${service.currentClass}") + Log.e(tag, "pageMissing: not found: ${clazzList.joinToString()} current: ${service.currentClass}") return false } diff --git a/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt b/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt index a07d767..ef39ced 100644 --- a/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt +++ b/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt @@ -76,32 +76,25 @@ object WeworkRoomUtil { /** * 进入房间(单聊或群聊) */ - fun intoRoom(title: String): Boolean { - LogUtils.d("intoRoom(): $title") - val titleList = getRoomTitle(false) - val roomType = getRoomType() - if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN - && titleList.count { - it.replace("…", "").replace("\\(.*?\\)".toRegex(), "") == title.replace("…", "") - .replace("\\(.*?\\)".toRegex(), "") - } > 0 - ) { - intoRoomPreInit() - LogUtils.d("当前正在房间") + fun intoRoom(title: String, fastIn: Boolean = true): Boolean { + if (checkRoom(title)) { return true } goHome() val list = findOneByClazz(getRoot(), Views.RecyclerView, Views.ListView, Views.ViewGroup) - if (list != null && list.childCount >= 2) { - for (i in 0 until list.childCount) { - val item = list.getChild(i) - val tvList = findAllOnceByClazz(item, Views.TextView).mapNotNull { it.text } - if (tvList.isNotEmpty() && title == tvList[0].toString()) { - intoRoomPreInit() - AccessibilityUtil.performClick(item) - LogUtils.d("快捷进入房间: $title") - sleep(Constant.CHANGE_PAGE_INTERVAL) - return true + if (fastIn) { + if (list != null && list.childCount >= 2) { + for (i in 0 until list.childCount) { + val item = list.getChild(i) + val tvList = findAllOnceByClazz(item, Views.TextView).mapNotNull { it.text } + if (tvList.isNotEmpty() && title == tvList[0].toString()) { + intoRoomPreInit() + AccessibilityUtil.performClick(item) + LogUtils.d("快捷进入房间: $title") + AccessibilityUtil.waitForPageMissing("WwMainActivity", "GlobalSearchActivity") + sleep(Constant.CHANGE_PAGE_INTERVAL) + return checkRoom(title) + } } } } @@ -141,8 +134,9 @@ object WeworkRoomUtil { intoRoomPreInit() AccessibilityUtil.performClick(searchItem) LogUtils.d("进入房间: $title") + AccessibilityUtil.waitForPageMissing("WwMainActivity", "GlobalSearchActivity") sleep(Constant.CHANGE_PAGE_INTERVAL) - return true + return checkRoom(title) } else { LogUtils.e("搜索到已退出群聊") } @@ -250,6 +244,26 @@ object WeworkRoomUtil { return intoRoom(groupName) } + /** + * 检查当前房间 + */ + private fun checkRoom(title: String): Boolean { + LogUtils.d("checkRoom(): $title") + val titleList = getRoomTitle(false) + val roomType = getRoomType() + if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN + && titleList.count { + it.replace("…", "").replace("\\(.*?\\)".toRegex(), "") == title.replace("…", "") + .replace("\\(.*?\\)".toRegex(), "") + } > 0 + ) { + intoRoomPreInit() + LogUtils.d("当前正在房间") + return true + } + return false + } + /** * 是否是群聊 * 群名最后有(\d)显示群人数