feat: EditTextContent

Closes #1069
This commit is contained in:
hd
2024-07-11 16:59:57 +08:00
parent 2728de0592
commit 6a3bde0d87
5 changed files with 137 additions and 17 deletions

View File

@@ -36,7 +36,8 @@ import io.github.duzhaokun123.hook.MessageTTSHook
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.hook.BasePersistBackgroundHook
import io.github.qauxv.util.Initiator
import me.hd.hook.CopyMarkdown
import me.hd.hook.menu.CopyMarkdown
import me.hd.hook.menu.EditTextContent
import me.ketal.hook.PicCopyToClipboard
import top.xunflash.hook.MiniAppDirectJump
import java.lang.reflect.Method
@@ -55,6 +56,7 @@ object MenuBuilderHook : BasePersistBackgroundHook() {
MiniAppDirectJump,
CopyMarkdown,
MessageTTSHook,
EditTextContent,
)
override fun initOnce(): Boolean {

View File

@@ -20,7 +20,7 @@
* <https://github.com/cinit/QAuxiliary/blob/master/LICENSE.md>.
*/
package me.hd.hook
package me.hd.hook.menu
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
import com.xiaoniu.dispatcher.OnMenuBuilder
@@ -56,7 +56,7 @@ object CopyMarkdown : CommonSwitchFunctionHook(
override val targetComponentTypes = arrayOf("com.tencent.mobileqq.aio.msglist.holder.component.markdown.AIOMarkdownContentComponent")
override fun onGetMenuNt(msg: Any, componentType: String, param: XC_MethodHook.MethodHookParam) {
if (!isEnabled) return
val item = CustomMenu.createItemIconNt(msg, "复制内容", R.drawable.ic_item_copy_72dp, R.id.item_copy_code) {
val item = CustomMenu.createItemIconNt(msg, "复制内容", R.drawable.ic_item_copy_72dp, R.id.item_copy_md) {
val ctx = ContextUtils.getCurrentActivity()
val msgRecord = XposedHelpers.callMethod(msg, "getMsgRecord") as MsgRecord
msgRecord.elements.forEach { element ->

View File

@@ -0,0 +1,101 @@
/*
* QAuxiliary - An Xposed module for QQ/TIM
* Copyright (C) 2019-2024 QAuxiliary developers
* https://github.com/cinit/QAuxiliary
*
* This software is an opensource software: you can redistribute it
* and/or modify it under the terms of the General Public License
* as published by the Free Software Foundation; either
* version 3 of the License, or any later version as published
* by QAuxiliary contributors.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the General Public License for more details.
*
* You should have received a copy of the General Public License
* along with this software.
* If not, see
* <https://github.com/cinit/QAuxiliary/blob/master/LICENSE.md>.
*/
package me.hd.hook.menu
import android.annotation.SuppressLint
import android.widget.EditText
import cc.ioctl.util.hookAfterIfEnabled
import com.github.kyuubiran.ezxhelper.utils.findField
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
import com.xiaoniu.dispatcher.OnMenuBuilder
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedHelpers
import io.github.qauxv.R
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.dsl.FunctionEntryRouter
import io.github.qauxv.hook.CommonSwitchFunctionHook
import io.github.qauxv.util.CustomMenu
import io.github.qauxv.util.QQVersion
import io.github.qauxv.util.Toasts
import io.github.qauxv.util.dexkit.AIO_InputRootInit_QQNT
import io.github.qauxv.util.dexkit.AbstractQQCustomMenuItem
import io.github.qauxv.util.dexkit.DexKit
import io.github.qauxv.util.requireMinQQVersion
@SuppressLint("StaticFieldLeak")
@FunctionHookEntry
@UiItemAgentEntry
object EditTextContent : CommonSwitchFunctionHook(
targets = arrayOf(
AbstractQQCustomMenuItem,
AIO_InputRootInit_QQNT,
)
), OnMenuBuilder {
override val name = "重新编辑消息"
override val uiItemLocation = FunctionEntryRouter.Locations.Auxiliary.MESSAGE_CATEGORY
override val isAvailable = requireMinQQVersion(QQVersion.QQ_8_9_88)
private var editText: EditText? = null
override fun initOnce(): Boolean {
hookAfterIfEnabled(DexKit.requireMethodFromCache(AIO_InputRootInit_QQNT)) { param ->
param.thisObject.javaClass.findField {
type == EditText::class.java
}.let {
editText = it.get(param.thisObject) as EditText
}
}
return true
}
private const val TEXT_CONTEXT = "com.tencent.mobileqq.aio.msglist.holder.component.text.AIOTextContentComponent"
private const val MIX_CONTEXT = "com.tencent.mobileqq.aio.msglist.holder.component.mix.AIOMixContentComponent"
override val targetComponentTypes = arrayOf(TEXT_CONTEXT, MIX_CONTEXT)
@SuppressLint("SetTextI18n")
override fun onGetMenuNt(msg: Any, componentType: String, param: XC_MethodHook.MethodHookParam) {
if (!isEnabled) return
val item = CustomMenu.createItemIconNt(msg, "编辑重发", R.drawable.ic_item_edit_72dp, R.id.item_edit_to_send) {
val msgRecord = XposedHelpers.callMethod(msg, "getMsgRecord") as MsgRecord
when (componentType) {
TEXT_CONTEXT -> {
val stringBuilder = StringBuilder()
msgRecord.elements.forEach { element ->
element.textElement?.let { textElement ->
stringBuilder.append(textElement.content)
}
}
editText?.setText(stringBuilder.toString())
}
MIX_CONTEXT -> {
// TODO: 待开发
Toasts.show("快了快了, 已经新建文件夹了!")
}
}
}
param.result = listOf(item) + param.result as List<*>
}
}

View File

@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="72dp"
android:height="72dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M744.5,544.4c-10.6,0 -21.1,-4 -29.2,-12.1 -16.1,-16.1 -16.1,-42.3 0,-58.4l122.5,-122.5L670.4,184 547.7,306.4c-16.1,16.1 -42.3,16.1 -58.4,0s-16.1,-42.3 0,-58.4l124.9,-124.9c30.9,-30.9 79,-33.1 107.2,-4.8l182,182c28.2,28.2 26,76.3 -4.9,107.2L773.6,532.3c-8,8.1 -18.6,12.1 -29.1,12.1z"
android:fillColor="#ffffff"/>
<path
android:pathData="M746.5,542.3c-10.6,0 -21.1,-4 -29.2,-12.1L491.4,304.3c-16.1,-16.1 -16.1,-42.3 0,-58.4s42.3,-16.1 58.4,0l225.9,225.9c16.1,16.1 16.1,42.3 0,58.4 -8,8.1 -18.6,12.1 -29.2,12.1z"
android:fillColor="#ffffff"/>
<path
android:pathData="M153.9,924.1c-15,0 -29.4,-5.8 -39.9,-16.4 -13.1,-13.1 -18.8,-32.1 -15.3,-50.8l43.6,-231.4c4.6,-24.3 17,-47.5 35,-65.5l312.1,-312c16.1,-16.1 42.3,-16.1 58.4,0s16.1,42.3 0,58.4L235.7,618.5c-6.4,6.4 -10.7,14.3 -12.2,22.4l-36.6,194 194,-36.6c8.1,-1.5 16,-5.9 22.4,-12.2L715.4,474c16.1,-16.1 42.3,-16.1 58.4,0s16.1,42.3 0,58.4l-312.2,312c-18,18 -41.2,30.4 -65.4,35L164.7,923c-3.6,0.7 -7.2,1.1 -10.8,1.1z"
android:fillColor="#ffffff"/>
</vector>

View File

@@ -1,21 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="item_tts" />
<item type="id" name="item_tts2" />
<item type="id" name="item_showPicMd5"/>
<item type="id" name="item_copyToClipboard"/>
<item type="id" name="item_free_copy" />
<item type="id" name="item_copy_code" />
<item type="id" name="item_translate" />
<item type="id" name="item_jump_to_app" />
<item type="id" name="item_ptt_save" />
<item type="id" name="item_ptt_forward" />
<item type="id" name="item_repeat" />
<item type="id" name="item_save_to_panel" />
<item type="id" name="rootBounceScrollView"/>
<item type="id" name="rootMainLayout"/>
<item type="id" name="rootMainList"/>
<item type="id" name="fragmentMainRecyclerView"/>
<item type="id" name="item_showPicMd5" />
<item type="id" name="item_ptt_forward" />
<item type="id" name="item_ptt_save" />
<item type="id" name="item_copy_code" />
<item type="id" name="item_free_copy" />
<item type="id" name="item_copyToClipboard" />
<item type="id" name="item_jump_to_app" />
<item type="id" name="item_copy_md" />
<item type="id" name="item_tts" />
<item type="id" name="item_tts2" />
<item type="id" name="item_edit_to_send" />
<item type="id" name="item_translate" />
<item type="id" name="rootBounceScrollView" />
<item type="id" name="rootMainLayout" />
<item type="id" name="rootMainList" />
<item type="id" name="fragmentMainRecyclerView" />
<item type="id" name="root_content_toolbarLayout" />
<item type="id" name="jefsRulesMainSwitch" />
<item type="id" name="jefsRulesTextView" />