Skip to content

Commit 0f821cd

Browse files
committed
Refactor search bar handling and filter options
Signed-off-by: Dev4Mod <[email protected]>
1 parent 7978c14 commit 0f821cd

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,4 +2033,24 @@ public static Field loadWaContactFromContactInfo(ClassLoader classLoader) throws
20332033
});
20342034

20352035
}
2036+
2037+
public static Method loadViewAddSearchBarMethod(ClassLoader classLoader) throws Exception {
2038+
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> findFirstMethodUsingStrings(classLoader, StringMatchType.Contains, "ConversationsList/Search/addHeaderView"));
2039+
}
2040+
2041+
public static Method loadAddOptionSearchBarMethod(ClassLoader classLoader) throws Exception {
2042+
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> {
2043+
var classData = Objects.requireNonNull(dexkit.getClassData(WppCore.getHomeActivityClass(classLoader)));
2044+
MethodDataList methodData = classData.findMethod(FindMethod.create()
2045+
.matcher(MethodMatcher.create().addUsingNumber(Utils.getID("menuitem_search", "id"))
2046+
.addUsingNumber(200)
2047+
.paramCount(1)
2048+
.addParamType(Menu.class)
2049+
));
2050+
if (methodData.isEmpty())
2051+
throw new NoSuchMethodError("MenuSearch not found in HomeActivity");
2052+
2053+
return methodData.get(0).getMethodInstance(classLoader);
2054+
});
2055+
}
20362056
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/general/Others.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.json.JSONObject;
2828
import org.luckypray.dexkit.query.enums.StringMatchType;
2929

30+
import java.lang.reflect.Field;
31+
import java.lang.reflect.Method;
3032
import java.lang.reflect.Modifier;
3133
import java.util.ArrayList;
3234
import java.util.HashMap;
@@ -85,8 +87,6 @@ public void doHook() throws Exception {
8587
propsBoolean.put(4023, newSettings);
8688
propsInteger.put(18564, newSettings ? 1 : 0);
8789

88-
if (disableMetaAI)
89-
propsBoolean.put(8013, Objects.equals(filterChats, "2"));
9090
propsBoolean.put(2889, floatingMenu);
9191

9292
// new text composer
@@ -186,7 +186,7 @@ public void doHook() throws Exception {
186186

187187

188188
hookProps();
189-
hookMenuOptions(filterChats);
189+
hookSearchbar(filterChats);
190190

191191
if (disable_sensor_proximity) {
192192
disableSensorProximity();
@@ -602,7 +602,48 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
602602
});
603603
}
604604

605-
private void hookMenuOptions(String filterChats) {
605+
private void hookSearchbar(String filterChats) throws Exception {
606+
Method searchbar = Unobfuscator.loadViewAddSearchBarMethod(classLoader);
607+
XposedBridge.hookMethod(searchbar, new XC_MethodHook() {
608+
@Override
609+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
610+
if (!Objects.equals(filterChats, "2")) {
611+
param.setResult(null);
612+
}
613+
}
614+
});
615+
616+
Method addSeachBar = Unobfuscator.loadAddOptionSearchBarMethod(classLoader);
617+
618+
XposedBridge.hookMethod(addSeachBar, new XC_MethodHook() {
619+
private Object homeActivity;
620+
private Field pageIdField;
621+
private int originPageId;
622+
623+
@Override
624+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
625+
if (!Objects.equals(filterChats, "1"))
626+
return;
627+
homeActivity = param.thisObject;
628+
if (Modifier.isStatic(param.method.getModifiers())) {
629+
homeActivity = param.args[0];
630+
}
631+
pageIdField = XposedHelpers.findField(homeActivity.getClass(), "A01");
632+
originPageId = 0;
633+
if (pageIdField.getType() == int.class) {
634+
originPageId = pageIdField.getInt(homeActivity);
635+
pageIdField.setInt(homeActivity, 1);
636+
}
637+
}
638+
639+
@Override
640+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
641+
if (originPageId != 0) {
642+
pageIdField.setInt(homeActivity, originPageId);
643+
}
644+
}
645+
});
646+
606647
XposedHelpers.findAndHookMethod(WppCore.getHomeActivityClass(classLoader), "onPrepareOptionsMenu", Menu.class, new XC_MethodHook() {
607648
@Override
608649
protected void afterHookedMethod(MethodHookParam param) throws Throwable {

app/src/main/res/xml/preference_general_homescreen.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
<ListPreference
7777
app:entries="@array/chatfilter_buttons"
7878
app:entryValues="@array/chatfilter_values"
79+
app:defaultValue="2"
7980
app:key="chatfilter"
80-
app:dependency="metaai"
8181
app:summary="@string/novofiltro_sum"
8282
app:title="@string/novofiltro" />
8383

0 commit comments

Comments
 (0)