Skip to content

Commit

Permalink
refactor: wip: use entity agent instead of ui item agent for backgrou…
Browse files Browse the repository at this point in the history
…nd hooks
  • Loading branch information
cinit committed Sep 27, 2024
1 parent f935707 commit 4ea7df5
Show file tree
Hide file tree
Showing 29 changed files with 236 additions and 127 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/cc/hicore/hook/RepeaterPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord;
import com.xiaoniu.dispatcher.OnMenuBuilder;
import com.xiaoniu.util.ContextUtils;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.util.xpcompat.XposedBridge;
import io.github.qauxv.util.xpcompat.XposedHelpers;
Expand Down Expand Up @@ -154,13 +155,13 @@ public MutableStateFlow<String> getValueState() {
}

@Override
public Function2<IUiItemAgent, Context, CharSequence> getSummaryProvider() {
public Function2<IEntityAgent, Context, CharSequence> getSummaryProvider() {
return (agent, context) -> "点击设置自定义+1图标和显示位置";
}

@NonNull
@Override
public Function1<IUiItemAgent, String> getTitleProvider() {
public Function1<IEntityAgent, String> getTitleProvider() {
return agent -> "消息+1 Plus";
}
};
Expand Down
16 changes: 4 additions & 12 deletions app/src/main/java/cc/ioctl/fragment/DatabaseListFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package cc.ioctl.fragment

import android.app.Activity
import android.content.Context
import android.graphics.Typeface
import android.os.Bundle
import android.text.Spannable
Expand All @@ -45,14 +44,13 @@ import cc.ioctl.util.ui.FaultyDialog
import com.tencent.mobileqq.widget.BounceScrollView
import io.github.qauxv.R
import io.github.qauxv.activity.SettingsUiFragmentHostActivity
import io.github.qauxv.base.ISwitchCellAgent
import io.github.qauxv.base.IEntityAgent
import io.github.qauxv.base.IUiItemAgent
import io.github.qauxv.base.IUiItemAgentProvider
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.dsl.FunctionEntryRouter
import io.github.qauxv.fragment.BaseRootLayoutFragment
import io.github.qauxv.hook.CommonClickableStaticFunctionItem
import io.github.qauxv.util.Toasts
import kotlinx.coroutines.flow.MutableStateFlow
import java.io.File
import java.security.MessageDigest
import java.util.Locale
Expand Down Expand Up @@ -176,17 +174,11 @@ class DatabaseListFragment : BaseRootLayoutFragment() {
}

@UiItemAgentEntry
object DatabaseShrinkItemEntry : IUiItemAgentProvider, IUiItemAgent {
override val titleProvider: (IUiItemAgent) -> String = { "清理聊天记录数据库" }
override val summaryProvider: ((IUiItemAgent, Context) -> String?)? = null
override val valueState: MutableStateFlow<String?>? = null
override val validator: ((IUiItemAgent) -> Boolean)? = null
override val switchProvider: ISwitchCellAgent? = null
object DatabaseShrinkItemEntry : CommonClickableStaticFunctionItem() {
override val titleProvider: (IEntityAgent) -> String = { "清理聊天记录数据库" }
override val onClickListener: ((IUiItemAgent, Activity, View) -> Unit) = { _, activity, _ ->
SettingsUiFragmentHostActivity.startFragmentWithContext(activity, DatabaseListFragment::class.java)
}
override val extraSearchKeywordProvider: ((IUiItemAgent, Context) -> Array<String>?)? = null
override val uiItemAgent: IUiItemAgent = this
override val uiItemLocation: Array<String> = FunctionEntryRouter.Locations.Auxiliary.MESSAGE_CATEGORY
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@
import com.tencent.mobileqq.widget.BounceScrollView;
import io.github.qauxv.R;
import io.github.qauxv.activity.SettingsUiFragmentHostActivity;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.base.ISwitchCellAgent;
import io.github.qauxv.base.IUiItemAgent;
import io.github.qauxv.base.IUiItemAgentProvider;
import io.github.qauxv.base.annotation.UiItemAgentEntry;
import io.github.qauxv.bridge.AppRuntimeHelper;
import io.github.qauxv.dsl.FunctionEntryRouter;
import io.github.qauxv.fragment.BaseRootLayoutFragment;
import io.github.qauxv.hook.CommonClickableStaticFunctionItem;
import io.github.qauxv.util.Toasts;
import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -380,7 +381,7 @@ private static String getDefaultOutputFile(@NonNull Context ctx) {
}

@UiItemAgentEntry
public static class ItemEntry implements IUiItemAgentProvider, IUiItemAgent {
public static class ItemEntry extends CommonClickableStaticFunctionItem {

public static final ItemEntry INSTANCE = new ItemEntry();

Expand All @@ -407,13 +408,13 @@ public String getItemAgentProviderUniqueIdentifier() {

@NonNull
@Override
public Function1<IUiItemAgent, String> getTitleProvider() {
public Function1<IEntityAgent, String> getTitleProvider() {
return agent -> "导出好友列表";
}

@Nullable
@Override
public Function2<IUiItemAgent, Context, CharSequence> getSummaryProvider() {
public Function2<IEntityAgent, Context, CharSequence> getSummaryProvider() {
return (agent, ctx) -> "支持 CSV/JSON 格式";
}

Expand Down
33 changes: 4 additions & 29 deletions app/src/main/java/cc/ioctl/hook/entertainment/AddAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import cc.ioctl.util.LayoutHelper;
import io.github.qauxv.base.ISwitchCellAgent;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.base.IUiItemAgent;
import io.github.qauxv.base.IUiItemAgentProvider;
import io.github.qauxv.base.annotation.UiItemAgentEntry;
import io.github.qauxv.dsl.FunctionEntryRouter.Locations.Entertainment;
import io.github.qauxv.hook.CommonClickableStaticFunctionItem;
import io.github.qauxv.ui.CommonContextWrapper;
import io.github.qauxv.util.Toasts;
import java.io.File;
Expand All @@ -48,10 +48,9 @@
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.functions.Function3;
import kotlinx.coroutines.flow.MutableStateFlow;

@UiItemAgentEntry
public class AddAccount implements IUiItemAgent, IUiItemAgentProvider {
public class AddAccount extends CommonClickableStaticFunctionItem {

public static final AddAccount INSTANCE = new AddAccount();

Expand Down Expand Up @@ -102,34 +101,10 @@ public static void onAddAccountClick(@NonNull Context baseContext) {

@NonNull
@Override
public Function1<IUiItemAgent, String> getTitleProvider() {
public Function1<IEntityAgent, String> getTitleProvider() {
return (agent) -> "添加账号";
}

@Nullable
@Override
public Function2<IUiItemAgent, Context, CharSequence> getSummaryProvider() {
return null;
}

@Nullable
@Override
public MutableStateFlow<String> getValueState() {
return null;
}

@Nullable
@Override
public Function1<IUiItemAgent, Boolean> getValidator() {
return null;
}

@Nullable
@Override
public ISwitchCellAgent getSwitchProvider() {
return null;
}

@Nullable
@Override
public Function3<IUiItemAgent, Activity, View, Unit> getOnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import androidx.annotation.Nullable;
import cc.ioctl.fragment.FakeBatteryConfigFragment;
import cc.ioctl.util.HostInfo;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.util.xpcompat.XposedBridge;
import io.github.qauxv.util.xpcompat.XposedHelpers;
Expand Down Expand Up @@ -400,13 +401,13 @@ public IUiItemAgent getUiItemAgent() {

@NonNull
@Override
public Function1<IUiItemAgent, String> getTitleProvider() {
public Function1<IEntityAgent, String> getTitleProvider() {
return (agent) -> "自定义电量";
}

@Nullable
@Override
public Function2<IUiItemAgent, Context, CharSequence> getSummaryProvider() {
public Function2<IEntityAgent, Context, CharSequence> getSummaryProvider() {
return null;
}

Expand Down
33 changes: 4 additions & 29 deletions app/src/main/java/cc/ioctl/hook/friend/CheckCommonGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,21 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import cc.ioctl.util.LayoutHelper;
import io.github.qauxv.base.ISwitchCellAgent;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.base.IUiItemAgent;
import io.github.qauxv.base.IUiItemAgentProvider;
import io.github.qauxv.base.annotation.UiItemAgentEntry;
import io.github.qauxv.dsl.FunctionEntryRouter.Locations.Auxiliary;
import io.github.qauxv.hook.CommonClickableStaticFunctionItem;
import io.github.qauxv.ui.CommonContextWrapper;
import io.github.qauxv.util.Initiator;
import io.github.qauxv.util.Toasts;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.functions.Function3;
import kotlinx.coroutines.flow.MutableStateFlow;

@UiItemAgentEntry
public class CheckCommonGroup implements IUiItemAgentProvider, IUiItemAgent {
public class CheckCommonGroup extends CommonClickableStaticFunctionItem {

public static final CheckCommonGroup INSTANCE = new CheckCommonGroup();

Expand Down Expand Up @@ -108,34 +107,10 @@ public static void onClick(Context baseContext) {

@NonNull
@Override
public Function1<IUiItemAgent, String> getTitleProvider() {
public Function1<IEntityAgent, String> getTitleProvider() {
return agent -> "查找共同群";
}

@Nullable
@Override
public Function2<IUiItemAgent, Context, CharSequence> getSummaryProvider() {
return null;
}

@Nullable
@Override
public MutableStateFlow<String> getValueState() {
return null;
}

@Nullable
@Override
public Function1<IUiItemAgent, Boolean> getValidator() {
return null;
}

@Nullable
@Override
public ISwitchCellAgent getSwitchProvider() {
return null;
}

@Override
public Function3<IUiItemAgent, Activity, View, Unit> getOnClickListener() {
return (agent, ctx, view) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import cc.ioctl.fragment.ExfriendListFragment
import cc.ioctl.hook.DeletionObserver
import cc.ioctl.util.ExfriendManager
import io.github.qauxv.activity.SettingsUiFragmentHostActivity.Companion.startFragmentWithContext
import io.github.qauxv.base.IEntityAgent
import io.github.qauxv.base.ISwitchCellAgent
import io.github.qauxv.base.IUiItemAgent
import io.github.qauxv.base.annotation.FunctionHookEntry
Expand All @@ -42,8 +43,8 @@ import kotlinx.coroutines.flow.MutableStateFlow
@UiItemAgentEntry
object FriendDeletionNotification : BaseFunctionHook(defaultEnabled = true), IUiItemAgent {

override val titleProvider: (IUiItemAgent) -> String = { "被删好友检测通知" }
override val summaryProvider: ((IUiItemAgent, Context) -> CharSequence?) = { _, _ -> "检测到被删好友时将发出通知" }
override val titleProvider: (IEntityAgent) -> String = { "被删好友检测通知" }
override val summaryProvider: ((IEntityAgent, Context) -> CharSequence?)? = { _, _ -> "检测到被删好友时将发出通知" }
override val uiItemAgent = this
override val runtimeErrors: List<Throwable> get() = DeletionObserver.INSTANCE.runtimeErrors
override val uiItemLocation: Array<String> = FunctionEntryRouter.Locations.Auxiliary.FRIEND_CATEGORY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.appcompat.app.AlertDialog
import cc.hicore.QApp.QAppUtils
import cc.ioctl.util.LayoutHelper
import cc.ioctl.util.ui.FaultyDialog
import io.github.qauxv.base.IEntityAgent
import io.github.qauxv.base.ISwitchCellAgent
import io.github.qauxv.base.IUiItemAgent
import io.github.qauxv.base.IUiItemAgentProvider
Expand All @@ -48,8 +49,8 @@ import kotlinx.coroutines.flow.MutableStateFlow

@UiItemAgentEntry
object OpenFriendChatHistory : IUiItemAgent, IUiItemAgentProvider {
override val titleProvider: (IUiItemAgent) -> String = { "打开好友聊天记录" }
override val summaryProvider: ((IUiItemAgent, Context) -> String?) = { _, _ -> "仅支持本地聊天记录" }
override val titleProvider: (IEntityAgent) -> String = { "打开好友聊天记录" }
override val summaryProvider: ((IEntityAgent, Context) -> String?) = { _, _ -> "仅支持本地聊天记录" }
override val valueState: MutableStateFlow<String?>? = null
override val validator: ((IUiItemAgent) -> Boolean)? = null
override val switchProvider: ISwitchCellAgent? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cc.ioctl.hook.friend

import android.content.Context
import android.view.View
import io.github.qauxv.base.IEntityAgent
import io.github.qauxv.base.ISwitchCellAgent
import io.github.qauxv.base.IUiItemAgent
import io.github.qauxv.base.IUiItemAgentProvider
Expand All @@ -33,8 +34,8 @@ import kotlinx.coroutines.flow.MutableStateFlow

@UiItemAgentEntry
object ShowDeletedFriendListEntry : IUiItemAgent, IUiItemAgentProvider, ISwitchCellAgent {
override val titleProvider: (IUiItemAgent) -> String = { _ -> "显示历史好友入口" }
override val summaryProvider: (IUiItemAgent, Context) -> String? = { _, _ -> "在好友列表下方显示历史好友入口" }
override val titleProvider: (IEntityAgent) -> String = { _ -> "显示历史好友入口" }
override val summaryProvider: (IEntityAgent, Context) -> String? = { _, _ -> "在好友列表下方显示历史好友入口" }
override val valueState: MutableStateFlow<String?>? = null
override val validator: ((IUiItemAgent) -> Boolean)? = null
override val switchProvider: ISwitchCellAgent = this
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/cc/ioctl/hook/msg/OpenMultiFwdMsg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import cc.ioctl.util.LayoutHelper
import cc.ioctl.util.ui.FaultyDialog
import io.github.qauxv.base.IEntityAgent
import io.github.qauxv.base.ISwitchCellAgent
import io.github.qauxv.base.IUiItemAgent
import io.github.qauxv.base.IUiItemAgentProvider
Expand All @@ -47,8 +48,8 @@ import kotlinx.coroutines.flow.MutableStateFlow

@UiItemAgentEntry
object OpenMultiFwdMsg : IUiItemAgent, IUiItemAgentProvider {
override val titleProvider: (IUiItemAgent) -> String = { "打开合并转发消息" }
override val summaryProvider: ((IUiItemAgent, Context) -> String?)? = null
override val titleProvider: (IEntityAgent) -> String = { "打开合并转发消息" }
override val summaryProvider: ((IEntityAgent, Context) -> String?)? = null
override val valueState: MutableStateFlow<String?>? = null
override val validator: ((IUiItemAgent) -> Boolean)? = null
override val switchProvider: ISwitchCellAgent? = null
Expand Down
13 changes: 4 additions & 9 deletions app/src/main/java/cc/ioctl/hook/profile/OpenProfileCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
import androidx.appcompat.app.AlertDialog;
import cc.ioctl.hook.misc.QSecO3AddRiskRequestMitigation;
import cc.ioctl.util.Reflex;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.base.ISwitchCellAgent;
import io.github.qauxv.base.IUiItemAgent;
import io.github.qauxv.base.IUiItemAgentProvider;
import io.github.qauxv.base.annotation.UiItemAgentEntry;
import io.github.qauxv.dsl.FunctionEntryRouter.Locations.Auxiliary;
import io.github.qauxv.hook.CommonClickableStaticFunctionItem;
import io.github.qauxv.ui.CommonContextWrapper;
import io.github.qauxv.util.Initiator;
import io.github.qauxv.util.Log;
Expand All @@ -57,7 +58,7 @@
import kotlinx.coroutines.flow.MutableStateFlow;

@UiItemAgentEntry
public class OpenProfileCard implements IUiItemAgent, IUiItemAgentProvider {
public class OpenProfileCard extends CommonClickableStaticFunctionItem {

public static final OpenProfileCard INSTANCE = new OpenProfileCard();

Expand Down Expand Up @@ -184,16 +185,10 @@ public static void openUserProfileCard(@NonNull Context ctx, long uin, long troo

@NonNull
@Override
public Function1<IUiItemAgent, String> getTitleProvider() {
public Function1<IEntityAgent, String> getTitleProvider() {
return (agent) -> "打开资料卡";
}

@Nullable
@Override
public Function2<IUiItemAgent, Context, CharSequence> getSummaryProvider() {
return null;
}

@Nullable
@Override
public MutableStateFlow<String> getValueState() {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/cc/ioctl/hook/ui/chat/RepeaterHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import cc.ioctl.util.HostInfo;
import cc.ioctl.util.LayoutHelper;
import cc.ioctl.util.Reflex;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.base.ISwitchCellAgent;
import io.github.qauxv.base.IUiItemAgent;
Expand Down Expand Up @@ -140,13 +141,13 @@ public MutableStateFlow<String> getValueState() {
}

@Override
public Function2<IUiItemAgent, Context, CharSequence> getSummaryProvider() {
public Function2<IEntityAgent, Context, CharSequence> getSummaryProvider() {
return (agent, context) -> "此功能不支持较新的版本,推荐使用消息+1 Plus。点击设置自定义+1图标";
}

@NonNull
@Override
public Function1<IUiItemAgent, String> getTitleProvider() {
public Function1<IEntityAgent, String> getTitleProvider() {
return agent -> "消息+1";
}
};
Expand Down
Loading

0 comments on commit 4ea7df5

Please sign in to comment.