From 995758274e4d376949399f191cb27c1fe1cd7c03 Mon Sep 17 00:00:00 2001 From: gallonyin Date: Thu, 7 Sep 2023 23:01:09 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E9=B8=BF=E8=92=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worktool/service/WeworkOperationImpl.kt | 159 +++++++++++------- 1 file changed, 96 insertions(+), 63 deletions(-) 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 61146e0..700e23a 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt @@ -442,9 +442,38 @@ object WeworkOperationImpl { AccessibilityUtil.performClick(imageViewList[1]) val shareFileButton = AccessibilityUtil.findOneByDesc(getRoot(), "以原文件分享", "用其他应用打开") AccessibilityUtil.performClick(shareFileButton) - var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事") - sleep(Constant.POP_WINDOW_INTERVAL) - if (shareToWorkButton == null) { + val tvFlag = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事", "选择联系人", "选择参与人") + val flagText = tvFlag?.text?.toString() ?: "" + if (flagText.contains("发送给同事")) { + var shareToWorkButton = tvFlag + sleep(Constant.POP_WINDOW_INTERVAL) + if (shareToWorkButton == null) { + LogUtils.e("未找到发送给同事: $objectName") + if (retryCount > 0) { + return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1) + } + uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) + return false + } + AccessibilityUtil.performClick(shareToWorkButton) + sleep(Constant.POP_WINDOW_INTERVAL) + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") + LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) + val time = System.currentTimeMillis() + var currentTime = time + while (currentTime - time < 5000) { + if (shareToWorkButton != null + && WeworkController.weworkService.currentPackage != Constant.PACKAGE_NAMES) { + LogUtils.e("尝试手势点击!!!!!") + AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) + sleep(Constant.CHANGE_PAGE_INTERVAL) + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") + } else { + break + } + currentTime = System.currentTimeMillis() + } + } else if (flagText !in arrayOf("选择联系人", "选择参与人")) { LogUtils.e("未找到发送给同事: $objectName") if (retryCount > 0) { return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1) @@ -452,24 +481,6 @@ object WeworkOperationImpl { uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) return false } - AccessibilityUtil.performClick(shareToWorkButton) - sleep(Constant.POP_WINDOW_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") - LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) - val time = System.currentTimeMillis() - var currentTime = time - while (currentTime - time < 5000) { - if (shareToWorkButton != null - && WeworkController.weworkService.currentPackage != Constant.PACKAGE_NAMES) { - LogUtils.e("尝试手势点击!!!!!") - AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) - sleep(Constant.CHANGE_PAGE_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") - } else { - break - } - currentTime = System.currentTimeMillis() - } if (relaySelectTarget(titleList, extraText, timeout = 10000)) { val stayButton = AccessibilityUtil.findOneByText(getRoot(), "留在企业微信") AccessibilityUtil.performClick(stayButton) @@ -710,9 +721,38 @@ object WeworkOperationImpl { newFile.writeBytes(body.bytes()) LogUtils.i("文件存储本地成功 $filePath") ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile) - var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事") - sleep(Constant.POP_WINDOW_INTERVAL) - if (shareToWorkButton == null) { + val tvFlag = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事", "选择联系人", "选择参与人") + val flagText = tvFlag?.text?.toString() ?: "" + if (flagText.contains("发送给同事")) { + var shareToWorkButton = tvFlag + sleep(Constant.POP_WINDOW_INTERVAL) + if (shareToWorkButton == null) { + LogUtils.e("未找到发送给同事: $objectName") + if (retryCount > 0) { + return pushFile(message, titleList, objectName, fileUrl, fileBase64, fileType, extraText, retryCount - 1) + } + uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) + return false + } + AccessibilityUtil.performClick(shareToWorkButton) + sleep(Constant.POP_WINDOW_INTERVAL) + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") + LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) + val time = System.currentTimeMillis() + var currentTime = time + while (currentTime - time < 5000) { + if (shareToWorkButton != null + && WeworkController.weworkService.currentPackage != Constant.PACKAGE_NAMES) { + LogUtils.e("尝试手势点击!!!!!") + AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) + sleep(Constant.CHANGE_PAGE_INTERVAL) + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") + } else { + break + } + currentTime = System.currentTimeMillis() + } + } else if (flagText !in arrayOf("选择联系人", "选择参与人")) { LogUtils.e("未找到发送给同事: $objectName") if (retryCount > 0) { return pushFile(message, titleList, objectName, fileUrl, fileBase64, fileType, extraText, retryCount - 1) @@ -720,24 +760,6 @@ object WeworkOperationImpl { uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) return false } - AccessibilityUtil.performClick(shareToWorkButton) - sleep(Constant.POP_WINDOW_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") - LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) - val time = System.currentTimeMillis() - var currentTime = time - while (currentTime - time < 5000) { - if (shareToWorkButton != null - && WeworkController.weworkService.currentPackage != Constant.PACKAGE_NAMES) { - LogUtils.e("尝试手势点击!!!!!") - AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) - sleep(Constant.CHANGE_PAGE_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") - } else { - break - } - currentTime = System.currentTimeMillis() - } if (relaySelectTarget(titleList, extraText, timeout = 10000)) { val stayButton = AccessibilityUtil.findOneByText(getRoot(), "留在企业微信") AccessibilityUtil.performClick(stayButton) @@ -780,9 +802,38 @@ object WeworkOperationImpl { newFile.writeBytes(EncodeUtils.base64Decode(fileBase64)) LogUtils.i("文件存储本地成功 $filePath") ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile) - var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事") - sleep(Constant.POP_WINDOW_INTERVAL) - if (shareToWorkButton == null) { + val tvFlag = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事", "选择联系人", "选择参与人") + val flagText = tvFlag?.text?.toString() ?: "" + if (flagText.contains("发送给同事")) { + var shareToWorkButton = tvFlag + sleep(Constant.POP_WINDOW_INTERVAL) + if (shareToWorkButton == null) { + LogUtils.e("未找到发送给同事: $objectName") + if (retryCount > 0) { + return pushFile(message, titleList, objectName, fileUrl, fileBase64, fileType, extraText, retryCount - 1) + } + uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) + return false + } + AccessibilityUtil.performClick(shareToWorkButton) + sleep(Constant.POP_WINDOW_INTERVAL) + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") + LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) + val time = System.currentTimeMillis() + var currentTime = time + while (currentTime - time < 5000) { + if (shareToWorkButton != null + && WeworkController.weworkService.currentPackage != Constant.PACKAGE_NAMES) { + LogUtils.e("尝试手势点击!!!!!") + AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) + sleep(Constant.CHANGE_PAGE_INTERVAL) + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") + } else { + break + } + currentTime = System.currentTimeMillis() + } + } else if (flagText !in arrayOf("选择联系人", "选择参与人")) { LogUtils.e("未找到发送给同事: $objectName") if (retryCount > 0) { return pushFile(message, titleList, objectName, fileUrl, fileBase64, fileType, extraText, retryCount - 1) @@ -790,24 +841,6 @@ object WeworkOperationImpl { uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) return false } - AccessibilityUtil.performClick(shareToWorkButton) - sleep(Constant.POP_WINDOW_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") - LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) - val time = System.currentTimeMillis() - var currentTime = time - while (currentTime - time < 5000) { - if (shareToWorkButton != null - && WeworkController.weworkService.currentPackage != Constant.PACKAGE_NAMES) { - LogUtils.e("尝试手势点击!!!!!") - AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) - sleep(Constant.CHANGE_PAGE_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") - } else { - break - } - currentTime = System.currentTimeMillis() - } if (relaySelectTarget(titleList, extraText, timeout = 10000)) { val stayButton = AccessibilityUtil.findOneByText(getRoot(), "留在企业微信") AccessibilityUtil.performClick(stayButton)