Skip to content

Commit a8be399

Browse files
committed
Fix bug in Target Class on CustomView
Signed-off-by: Dev4Mod <[email protected]>
1 parent 19fa312 commit a8be399

File tree

1 file changed

+30
-31
lines changed
  • app/src/main/java/com/wmods/wppenhacer/xposed/features/customization

1 file changed

+30
-31
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/features/customization/CustomView.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,39 +147,34 @@ public void doHook() throws Throwable {
147147

148148
public void registerView(StyleSheet sheet) {
149149
var mapIds = new HashMap<Integer, ArrayList<RuleItem>>();
150-
151-
try {
152-
for (var selector : sheet) {
153-
var ruleSet = (RuleSet) selector;
154-
for (var selectorItem : ruleSet.getSelectors()) {
155-
var item = selectorItem.get(0);
156-
String className;
157-
String name;
158-
if ((className = item.getClassName()) != null) {
159-
className = className.replaceAll("_", ".").trim();
160-
var clazz = XposedHelpers.findClass(className, classLoader);
161-
if (clazz == null || !clazz.isInstance(WppCore.getCurrentActivity()))
162-
continue;
163-
name = selectorItem.get(1).getIDName().trim();
164-
} else {
165-
name = selectorItem.get(0).getIDName().trim();
166-
}
167-
int id = 0;
168-
if (name.contains("android_")) {
169-
try {
170-
id = android.R.id.class.getField(name.substring(8)).getInt(null);
171-
} catch (NoSuchFieldException | IllegalAccessException ignored) {
172-
}
173-
} else {
174-
id = Utils.getID(name, "id");
150+
for (var selector : sheet) {
151+
Class<?> targetClass = null;
152+
var ruleSet = (RuleSet) selector;
153+
for (var selectorItem : ruleSet.getSelectors()) {
154+
var item = selectorItem.get(0);
155+
String className;
156+
String name;
157+
if ((className = item.getClassName()) != null) {
158+
className = className.replaceAll("_", ".").trim();
159+
targetClass = XposedHelpers.findClassIfExists(className, classLoader);
160+
name = selectorItem.get(1).getIDName().trim();
161+
} else {
162+
name = selectorItem.get(0).getIDName().trim();
163+
}
164+
int id = 0;
165+
if (name.contains("android_")) {
166+
try {
167+
id = android.R.id.class.getField(name.substring(8)).getInt(null);
168+
} catch (NoSuchFieldException | IllegalAccessException ignored) {
175169
}
176-
if (id <= 0) continue;
177-
var list = mapIds.getOrDefault(id, new ArrayList<>());
178-
list.add(new RuleItem(selectorItem, ruleSet));
179-
mapIds.put(id, list);
170+
} else {
171+
id = Utils.getID(name, "id");
180172
}
173+
if (id <= 0) continue;
174+
var list = mapIds.getOrDefault(id, new ArrayList<>());
175+
list.add(new RuleItem(selectorItem, ruleSet, targetClass));
176+
mapIds.put(id, list);
181177
}
182-
} catch (Throwable ignored) {
183178
}
184179
XposedHelpers.findAndHookMethod(View.class, "invalidate", boolean.class, new XC_MethodHook() {
185180
@Override
@@ -192,6 +187,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
192187
CompletableFuture.runAsync(() -> {
193188
for (var item : list) {
194189
try {
190+
if (item.targetActivityClass != null && !item.targetActivityClass.isInstance(WppCore.getCurrentActivity()))
191+
continue;
195192
setCssRule(view, item);
196193
} catch (Throwable ignored) {
197194
}
@@ -793,10 +790,12 @@ private static class CachedDrawable {
793790
public static class RuleItem {
794791
public CombinedSelector selector;
795792
public RuleSet rule;
793+
public Class<?> targetActivityClass;
796794

797-
public RuleItem(CombinedSelector selectorItem, RuleSet ruleSet) {
795+
public RuleItem(CombinedSelector selectorItem, RuleSet ruleSet, Class<?> targetActivityClass) {
798796
this.selector = selectorItem;
799797
this.rule = ruleSet;
798+
this.targetActivityClass = targetActivityClass;
800799
}
801800
}
802801

0 commit comments

Comments
 (0)