update 主动加好友优化;真@提醒;双击获取未读消息;获取我的信息优化

This commit is contained in:
尹甲仑
2022-08-17 12:16:57 +08:00
parent 00600be4c1
commit 439bdbf37e
7 changed files with 159 additions and 96 deletions

View File

@@ -9,8 +9,8 @@ android {
applicationId "org.yameida.worktool"
minSdkVersion 23
targetSdkVersion 30
versionCode 2
versionName "2.0"
versionCode 211
versionName "2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@@ -139,6 +139,8 @@ public class WeworkMessageBean {
public String receivedName;
//内容移除了@me
public String receivedContent;
//想要at的昵称
public String at;
//原始内容text
public String originalContent;
//多选(转发等)
@@ -231,6 +233,7 @@ public class WeworkMessageBean {
public String corporation;
public String phone;
public String job;
public String sumInfo;
}
//添加好友

View File

@@ -42,12 +42,13 @@ object WeworkController {
* @see WeworkMessageBean.SEND_MESSAGE
* @param message#titleList 房间名称
* @param message#receivedContent 回复内容
* @param message#at 要at的昵称
* @see WeworkMessageBean.TEXT_TYPE
*/
@RequestMapping
fun sendMessage(message: WeworkMessageBean): Boolean {
LogUtils.d("sendMessage(): ${message.titleList} ${message.receivedContent}")
return WeworkOperationImpl.sendMessage(message.titleList, message.receivedContent)
LogUtils.d("sendMessage(): ${message.titleList} ${message.receivedContent} ${message.at}")
return WeworkOperationImpl.sendMessage(message.titleList, message.receivedContent, message.at)
}
/**

View File

@@ -7,6 +7,7 @@ import org.yameida.worktool.model.WeworkMessageBean
import org.yameida.worktool.utils.AccessibilityUtil
import org.yameida.worktool.utils.Views
import org.yameida.worktool.utils.WeworkRoomUtil
import java.lang.StringBuilder
/**
* 获取数据类型 500 实现类
@@ -55,13 +56,34 @@ object WeworkGetImpl {
sleep(Constant.CHANGE_PAGE_INTERVAL)
val newFirstTv = AccessibilityUtil.findOneByClazz(getRoot(), Views.TextView)
val nickname = newFirstTv?.text?.toString()
AccessibilityUtil.performClick(firstTv)
if (nickname != null) {
var corp: String? = null
val info = StringBuilder()
if (AccessibilityUtil.performClick(newFirstTv)) {
sleep(Constant.CHANGE_PAGE_INTERVAL)
val rv = AccessibilityUtil.findOneByClazz(getRoot(), Views.RecyclerView)
if (rv != null && rv.childCount > 0) {
val myInfoLayout = rv.getChild(0)
val tvList = AccessibilityUtil.findAllByClazz(myInfoLayout, Views.TextView)
.filter { it.text != null }
if (tvList.isNotEmpty()) {
corp = tvList[0].text.toString()
tvList.forEach { info.append(it.text).append("-") }
info.setLength(info.length - 1)
LogUtils.v("corp", corp)
LogUtils.v("info", info.toString())
}
}
}
Constant.myName = nickname
LogUtils.d("我的昵称: ${Constant.myName}")
val weworkMessageBean = WeworkMessageBean()
weworkMessageBean.type = WeworkMessageBean.GET_MY_INFO
weworkMessageBean.myInfo = WeworkMessageBean.MyInfo().apply { name = nickname }
weworkMessageBean.myInfo = WeworkMessageBean.MyInfo().apply {
name = nickname
corporation = corp
sumInfo = info.toString()
}
WeworkController.weworkService.webSocketManager.send(weworkMessageBean)
return true
} else {

View File

@@ -200,6 +200,24 @@ object WeworkLoopImpl {
private fun getChatroomList(): Boolean {
if (Constant.autoReply == 0) return true
if (!isAtHome()) return true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val list = AccessibilityUtil.findAllOnceByText(getRoot(), "消息", exact = true)
for (item in list) {
if (item.parent.parent.parent.childCount == 5) {
if (item.parent.childCount > 1) {
LogUtils.d("消息有红点")
AccessibilityUtil.clickByNode(WeworkController.weworkService, item)
sleep(100)
AccessibilityUtil.clickByNode(WeworkController.weworkService, item)
}
}
}
if (logIndex % 120 == 0) {
goHomeTab("通讯录")
goHomeTab("消息")
}
} else {
if (logIndex % 3 == 0) {
AccessibilityUtil.performScrollUp(getRoot(), 0)
AccessibilityUtil.performScrollUp(getRoot(), 0)
@@ -207,6 +225,7 @@ object WeworkLoopImpl {
} else if (logIndex % 120 < 3) {
AccessibilityUtil.performScrollDown(getRoot(), 0)
}
}
if (!isAtHome()) return true
if (logIndex++ % 15 == 0) {
LogUtils.i("读取首页聊天列表")

View File

@@ -21,12 +21,13 @@ object WeworkOperationImpl {
* 在房间内发送消息
* @param titleList 房间名称
* @param receivedContent 回复内容
* @param at 要at的昵称
* @see WeworkMessageBean.TEXT_TYPE
*/
fun sendMessage(titleList: List<String>, receivedContent: String): Boolean {
fun sendMessage(titleList: List<String>, receivedContent: String, at: String? = null): Boolean {
for (title in titleList) {
if (WeworkRoomUtil.intoRoom(title)) {
sendChatMessage(receivedContent)
sendChatMessage(receivedContent, at = at)
LogUtils.d("$title: 发送成功")
} else {
LogUtils.d("$title: 发送失败")
@@ -440,8 +441,9 @@ object WeworkOperationImpl {
AccessibilityUtil.findTextAndClick(getRoot(), "搜索手机号添加")
AccessibilityUtil.findTextInput(getRoot(), friend.phone.trim())
if (AccessibilityUtil.findTextAndClick(getRoot(), "网络查找手机")) {
val bothUsedTv = AccessibilityUtil.findOneByText(getRoot(), "对方同时使用", timeout = 2000)
if (bothUsedTv != null) {
val bothUsedTv = AccessibilityUtil.findOneByText(getRoot(), "对方同时使用", "标签", "电话")
val bothUsedText = bothUsedTv?.text
if (bothUsedText != null && bothUsedText.contains("对方同时使用")) {
AccessibilityUtil.performClick(
AccessibilityUtil.findOnceByClazz(
AccessibilityUtil.findBackNode(bothUsedTv),
@@ -449,10 +451,7 @@ object WeworkOperationImpl {
)
)
}
} else {
LogUtils.e("未找到查找手机选项")
}
if (AccessibilityUtil.findOneByText(getRoot(), "标签") != null) {
if (AccessibilityUtil.findOneByText(getRoot(), "标签", "电话") != null) {
var markTv = AccessibilityUtil.findOnceByText(getRoot(), "设置备注和描述")
if (markTv == null) {
markTv = AccessibilityUtil.findOnceByText(getRoot(), "企业")
@@ -516,6 +515,9 @@ object WeworkOperationImpl {
} else {
LogUtils.e("未找到标签")
}
} else {
LogUtils.e("未找到查找手机选项")
}
} else {
LogUtils.e("未找到添加客户按钮")
}
@@ -821,10 +823,29 @@ object WeworkOperationImpl {
}
/**
* 发送消息
* 发送消息+@at
*/
private fun sendChatMessage(text: String, prefix: String = "") {
if (AccessibilityUtil.findTextInput(getRoot(), prefix + text)) {
private fun sendChatMessage(text: String, prefix: String = "", at: String? = null) {
var atFailed = false
if (!at.isNullOrEmpty()) {
AccessibilityUtil.findTextInput(getRoot(), "@")
val atFlag = AccessibilityUtil.findOneByText(getRoot(), "选择提醒的人", timeout = 2000)
if (atFlag != null) {
val rv = AccessibilityUtil.findOneByClazz(getRoot(), Views.RecyclerView)
AccessibilityUtil.findTextInput(getRoot(), at)
val atNode = AccessibilityUtil.findOneByText(rv, at, root = false, timeout = 2000)
if (atNode != null) {
AccessibilityUtil.performClick(atNode)
} else {
LogUtils.e("未找到at人: $at")
atFailed = true
backPress()
}
sleep(Constant.POP_WINDOW_INTERVAL)
}
}
val content = if (atFailed) "@$at $prefix$text" else "$prefix$text"
if (AccessibilityUtil.findTextInput(getRoot(), content, append = !atFailed)) {
val sendButton = AccessibilityUtil.findAllByClazz(getRoot(), Views.Button)
.firstOrNull { it.text == "发送" }
if (sendButton != null) {

View File

@@ -76,24 +76,21 @@ object AccessibilityUtil {
}
//寻找第一个EditView编辑框并输入文本
fun findTextInput(nodeInfo: AccessibilityNodeInfo?, text: String, root: Boolean = true): Boolean {
if (root) {
val editText = findOneByClazz(nodeInfo, "android.widget.EditText") ?: return false
val arguments = Bundle()
arguments.putCharSequence(
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
text
)
editText.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)
fun findTextInput(nodeInfo: AccessibilityNodeInfo?, text: String, root: Boolean = true, append: Boolean = false): Boolean {
val editText = if (root) {
findOneByClazz(nodeInfo, "android.widget.EditText") ?: return false
} else {
val editText = findOnceByClazz(nodeInfo, "android.widget.EditText") ?: return false
findOnceByClazz(nodeInfo, "android.widget.EditText") ?: return false
}
editText.refresh()
val oldText = if (editText.text != null) editText.text.toString() else ""
LogUtils.v("findTextInput oldText: $oldText")
val arguments = Bundle()
arguments.putCharSequence(
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
text
if (append) (oldText + text) else text
)
editText.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)
}
return true
}
@@ -710,15 +707,15 @@ object AccessibilityUtil {
val builder = GestureDescription.Builder()
val path = Path()
path.moveTo(point.x.toFloat(), point.y.toFloat())
builder.addStroke(StrokeDescription(path, 0L, 100L))
builder.addStroke(StrokeDescription(path, 0L, 10L))
val gesture = builder.build()
return service.dispatchGesture(gesture, object : GestureResultCallback() {
override fun onCompleted(gestureDescription: GestureDescription) {
LogUtils.e("click okk onCompleted")
LogUtils.d("click okk onCompleted")
}
override fun onCancelled(gestureDescription: GestureDescription) {
LogUtils.e("click okk onCancelled")
LogUtils.d("click okk onCancelled")
}
}, null)
}