Skip to content

Commit 362c580

Browse files
committed
fix bug in CustomToolbar
Signed-off-by: Dev4Mod <[email protected]>
1 parent 47316dd commit 362c580

File tree

1 file changed

+28
-76
lines changed

1 file changed

+28
-76
lines changed

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

Lines changed: 28 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
import android.app.Activity;
55
import android.content.Intent;
66
import android.os.Bundle;
7-
import android.text.TextUtils;
8-
import android.view.Gravity;
97
import android.view.View;
108
import android.view.ViewGroup;
11-
import android.view.ViewStub;
12-
import android.widget.LinearLayout;
139
import android.widget.TextView;
1410

1511
import androidx.annotation.NonNull;
@@ -18,7 +14,7 @@
1814
import com.wmods.wppenhacer.xposed.core.Feature;
1915
import com.wmods.wppenhacer.xposed.core.WppCore;
2016
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
21-
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
17+
import com.wmods.wppenhacer.xposed.features.general.Others;
2218
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
2319
import com.wmods.wppenhacer.xposed.utils.ResId;
2420
import com.wmods.wppenhacer.xposed.utils.Utils;
@@ -50,6 +46,8 @@ public void doHook() throws Exception {
5046
var typeArchive = prefs.getString("typearchive", "0");
5147
var methodHook = new MethodHook(showName, showBio, typeArchive);
5248
XposedHelpers.findAndHookMethod("com.whatsapp.HomeActivity", classLoader, "onCreate", Bundle.class, methodHook);
49+
Others.propsBoolean.put(6481, false);
50+
Others.propsBoolean.put(5353, true);
5351
expirationAboutInfo();
5452
}
5553

@@ -133,84 +131,38 @@ public void onMultiClick(View v) {
133131
}
134132

135133
if (!showBio && !showName) return;
136-
var parent = (ViewGroup) logo.getParent();
137134

138-
if (!(parent instanceof LinearLayout) && logo.getVisibility() == View.VISIBLE) {
139-
var methods = Arrays.stream(actionbar.getClass().getDeclaredMethods()).filter(m -> m.getParameterCount() == 1 && m.getParameterTypes()[0] == CharSequence.class).toArray(Method[]::new);
135+
var methods = Arrays.stream(actionbar.getClass().getDeclaredMethods()).filter(m -> m.getParameterCount() == 1 && m.getParameterTypes()[0] == CharSequence.class).toArray(Method[]::new);
140136

141-
if (showName) {
142-
methods[1].invoke(actionbar, name);
143-
}
137+
if (showName) {
138+
methods[1].invoke(actionbar, name);
139+
}
144140

145-
if (showBio) {
146-
methods[0].invoke(actionbar, bio);
147-
}
141+
if (showBio) {
142+
methods[0].invoke(actionbar, bio);
143+
}
148144

149-
XposedBridge.hookMethod(methods[1], new XC_MethodHook() {
150-
@Override
151-
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
152-
var name = WppCore.getMyName();
153-
var bio = WppCore.getMyBio();
154-
if (showBio && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
155-
ReflectionUtils.callMethod(methods[0], param.thisObject, bio);
156-
} else {
157-
ReflectionUtils.callMethod(methods[0], param.thisObject, "");
158-
}
159-
if (showName && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
160-
param.args[0] = name;
161-
}
162-
if (logo instanceof ViewStub stub) {
163-
var layoutParams = stub.getLayoutParams();
164-
layoutParams.width = 1;
165-
layoutParams.height = 200;
166-
stub.setLayoutParams(layoutParams);
167-
}
145+
XposedBridge.hookMethod(methods[1], new XC_MethodHook() {
146+
@Override
147+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
148+
var name = WppCore.getMyName();
149+
var bio = WppCore.getMyBio();
150+
if (showBio && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
151+
ReflectionUtils.callMethod(methods[0], param.thisObject, bio);
152+
} else {
153+
ReflectionUtils.callMethod(methods[0], param.thisObject, "");
154+
}
155+
if (showName && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
156+
param.args[0] = name;
168157
}
169-
});
170158

171-
return;
172-
}
173-
LinearLayout layout;
174-
if (parent instanceof LinearLayout) {
175-
layout = (LinearLayout) parent;
176-
} else {
177-
layout = new LinearLayout(homeActivity);
178-
layout.setOrientation(LinearLayout.VERTICAL);
179-
toolbar.removeAllViews();
180-
parent.addView(layout, 0);
181-
var clazzWDS = XposedHelpers.findClass("com.whatsapp.wds.components.topbar.WDSToolbar", homeActivity.getClassLoader());
182-
if (clazzWDS.isInstance(toolbar)) {
183-
XposedHelpers.callMethod(toolbar, "setTitle", (CharSequence) null);
184-
XposedHelpers.findAndHookMethod(clazzWDS, "setTitle", CharSequence.class, new XC_MethodHook() {
185-
@Override
186-
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
187-
if (param.thisObject != toolbar) return;
188-
param.setResult(null);
189-
}
190-
});
159+
var layoutParams = logo.getLayoutParams();
160+
layoutParams.width = 1;
161+
layoutParams.height = 1;
162+
logo.setLayoutParams(layoutParams);
163+
191164
}
192-
}
193-
var mTitle = new TextView(homeActivity);
194-
mTitle.setText(showName ? name : "WhatsApp");
195-
mTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
196-
mTitle.setTextSize(18f);
197-
mTitle.setTextColor(DesignUtils.getPrimaryTextColor());
198-
layout.addView(mTitle);
199-
if (showBio) {
200-
TextView mSubtitle = new TextView(homeActivity);
201-
mSubtitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
202-
mSubtitle.setText(bio);
203-
mSubtitle.setTextSize(12f);
204-
mSubtitle.setTextColor(DesignUtils.getPrimaryTextColor());
205-
mSubtitle.setMarqueeRepeatLimit(-1);
206-
mSubtitle.setEllipsize(TextUtils.TruncateAt.MARQUEE);
207-
mSubtitle.setSingleLine();
208-
mSubtitle.setSelected(true);
209-
layout.addView(mSubtitle);
210-
} else {
211-
mTitle.setGravity(Gravity.CENTER);
212-
}
213-
parent.removeView(logo);
165+
});
214166
}
215167
}
216168
}

0 commit comments

Comments
 (0)