Skip to content

Commit

Permalink
fix bug in CustomToolbar
Browse files Browse the repository at this point in the history
Signed-off-by: Dev4Mod <wellingtonmods@gmail.com>
  • Loading branch information
Dev4Mod committed Jan 14, 2025
1 parent 47316dd commit 362c580
Showing 1 changed file with 28 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
Expand All @@ -18,7 +14,7 @@
import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.WppCore;
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
import com.wmods.wppenhacer.xposed.features.general.Others;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
import com.wmods.wppenhacer.xposed.utils.ResId;
import com.wmods.wppenhacer.xposed.utils.Utils;
Expand Down Expand Up @@ -50,6 +46,8 @@ public void doHook() throws Exception {
var typeArchive = prefs.getString("typearchive", "0");
var methodHook = new MethodHook(showName, showBio, typeArchive);
XposedHelpers.findAndHookMethod("com.whatsapp.HomeActivity", classLoader, "onCreate", Bundle.class, methodHook);
Others.propsBoolean.put(6481, false);
Others.propsBoolean.put(5353, true);
expirationAboutInfo();
}

Expand Down Expand Up @@ -133,84 +131,38 @@ public void onMultiClick(View v) {
}

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

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

if (showName) {
methods[1].invoke(actionbar, name);
}
if (showName) {
methods[1].invoke(actionbar, name);
}

if (showBio) {
methods[0].invoke(actionbar, bio);
}
if (showBio) {
methods[0].invoke(actionbar, bio);
}

XposedBridge.hookMethod(methods[1], new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var name = WppCore.getMyName();
var bio = WppCore.getMyBio();
if (showBio && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
ReflectionUtils.callMethod(methods[0], param.thisObject, bio);
} else {
ReflectionUtils.callMethod(methods[0], param.thisObject, "");
}
if (showName && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
param.args[0] = name;
}
if (logo instanceof ViewStub stub) {
var layoutParams = stub.getLayoutParams();
layoutParams.width = 1;
layoutParams.height = 200;
stub.setLayoutParams(layoutParams);
}
XposedBridge.hookMethod(methods[1], new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var name = WppCore.getMyName();
var bio = WppCore.getMyBio();
if (showBio && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
ReflectionUtils.callMethod(methods[0], param.thisObject, bio);
} else {
ReflectionUtils.callMethod(methods[0], param.thisObject, "");
}
if (showName && (param.args[0] == "" || param.args[0] == "WhatsApp")) {
param.args[0] = name;
}
});

return;
}
LinearLayout layout;
if (parent instanceof LinearLayout) {
layout = (LinearLayout) parent;
} else {
layout = new LinearLayout(homeActivity);
layout.setOrientation(LinearLayout.VERTICAL);
toolbar.removeAllViews();
parent.addView(layout, 0);
var clazzWDS = XposedHelpers.findClass("com.whatsapp.wds.components.topbar.WDSToolbar", homeActivity.getClassLoader());
if (clazzWDS.isInstance(toolbar)) {
XposedHelpers.callMethod(toolbar, "setTitle", (CharSequence) null);
XposedHelpers.findAndHookMethod(clazzWDS, "setTitle", CharSequence.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.thisObject != toolbar) return;
param.setResult(null);
}
});
var layoutParams = logo.getLayoutParams();
layoutParams.width = 1;
layoutParams.height = 1;
logo.setLayoutParams(layoutParams);

}
}
var mTitle = new TextView(homeActivity);
mTitle.setText(showName ? name : "WhatsApp");
mTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
mTitle.setTextSize(18f);
mTitle.setTextColor(DesignUtils.getPrimaryTextColor());
layout.addView(mTitle);
if (showBio) {
TextView mSubtitle = new TextView(homeActivity);
mSubtitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
mSubtitle.setText(bio);
mSubtitle.setTextSize(12f);
mSubtitle.setTextColor(DesignUtils.getPrimaryTextColor());
mSubtitle.setMarqueeRepeatLimit(-1);
mSubtitle.setEllipsize(TextUtils.TruncateAt.MARQUEE);
mSubtitle.setSingleLine();
mSubtitle.setSelected(true);
layout.addView(mSubtitle);
} else {
mTitle.setGravity(Gravity.CENTER);
}
parent.removeView(logo);
});
}
}
}

0 comments on commit 362c580

Please sign in to comment.