Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed Jul 19, 2024
1 parent d0380da commit 9972e1b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,9 @@ private void setRuleInView(RuleItem ruleItem, View view) {
case "background-image" -> {
if (!(declaration.get(0) instanceof TermURI uri)) continue;
var draw = cacheImages.getDrawable(uri.getValue(), view.getWidth(), view.getHeight());
// log("background-image: " + uri.getValue() + " " + draw);
if (draw == null) continue;
if (XposedHelpers.getAdditionalInstanceField(view, "mHookedBackground") != null || XposedHelpers.getAdditionalInstanceField(view, "mHookedDrawable") != null)
continue;
log("set background " + uri.getValue());
setHookedDrawable(view, draw);
}
case "background-size" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.os.Handler;
import android.os.Looper;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -133,6 +135,7 @@ private void setSetupSeparate(ViewGroup view) {

// Inicialize com a primeira aba selecionada
updateContent(0);
new Handler(Looper.getMainLooper()).postDelayed(() -> setFilter(0), 500);

// Definir o layout principal como a visualização de conteúdo
container.addView(mainLayout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void doHook() throws Exception {

propsBoolean.put(6798, true); // show all status
propsBoolean.put(3575, animationEmojis); // auto play emojis settings
propsBoolean.put(9757, animationEmojis); // auto play emojis settings

propsBoolean.put(7589, true); // Media select quality
propsBoolean.put(6972, false); // Media select quality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.WppCore;
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
import com.wmods.wppenhacer.xposed.core.db.MessageStore;
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
import com.wmods.wppenhacer.xposed.utils.HKDF;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
import com.wmods.wppenhacer.xposed.utils.ResId;
import com.wmods.wppenhacer.xposed.utils.Utils;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -82,7 +83,6 @@ public void doHook() throws Throwable {

if (!prefs.getBoolean("media_preview", true)) return;

var getFieldIdMessage = Unobfuscator.loadSetEditMessageField(classLoader);
var videoViewContainerClass = Unobfuscator.loadVideoViewContainerClass(classLoader);
XposedBridge.hookAllConstructors(videoViewContainerClass, new XC_MethodHook() {
@Override
Expand All @@ -108,9 +108,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
prevBtn.setBackground(DesignUtils.getDrawableByName("download_background"));
prevBtn.setScaleType(ImageView.ScaleType.FIT_CENTER);
linearLayout.addView(prevBtn);
var objmessage = XposedHelpers.callMethod(param.thisObject, "getFMessage");
var id = new FMessageWpp(objmessage).getRowId();
prevBtn.setOnClickListener((v) -> {
var objmessage = XposedHelpers.callMethod(param.thisObject, "getFMessage");
var id = (long) ReflectionUtils.getField(getFieldIdMessage, objmessage);
var userJid = WppCore.getCurrentRawJID();
startPlayer(id, context, userJid != null && userJid.contains("@newsletter"));
});
Expand Down Expand Up @@ -157,9 +157,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (prevBtn.getVisibility() != controlFrame.getVisibility())
prevBtn.setVisibility(controlFrame.getVisibility());
});
var objmessage = XposedHelpers.callMethod(param.thisObject, "getFMessage");
var id = new FMessageWpp(objmessage).getRowId();
prevBtn.setOnClickListener((v) -> {
var objmessage = XposedHelpers.callMethod(param.thisObject, "getFMessage");
var id = (long) ReflectionUtils.getField(getFieldIdMessage, objmessage);
var userJid = WppCore.getCurrentRawJID();
startPlayer(id, context, userJid != null && userJid.contains("@newsletter"));
});
Expand Down Expand Up @@ -209,7 +209,6 @@ private void startPlayer(long id, Context context, boolean isNewsletter) {
});
dialog = alertDialog.create();
dialog.show();

executor.execute(() -> decodeMedia(url.get(), media_key, mine_type, executor, webView, isNewsletter));
}
} catch (Exception e) {
Expand All @@ -228,8 +227,8 @@ private void startPlayer(long id, Context context, boolean isNewsletter) {
* @param url A URL da mídia.
* @param mediaKey A chave de mídia.
* @param mimeType O tipo MIME da mídia.
* @param executor O executor de tarefas.
* @param webView A visualização da web.
* @param executor O executor de tarefas.
* @param webView A visualização da web.
* @param isNewsletter Indica se a mensagem é de um boletim informativo.
*/
private void decodeMedia(String url, String mediaKey, String mimeType, ExecutorService executor, WebView webView, boolean isNewsletter) {
Expand Down Expand Up @@ -267,7 +266,11 @@ private void decodeMedia(String url, String mediaKey, String mimeType, ExecutorS
}
});
} catch (Exception e) {
Utils.showToast(e.getMessage(), Toast.LENGTH_LONG);
if (e instanceof InvocationTargetException) {
Utils.showToast(Objects.requireNonNull(e.getCause()).getMessage(), Toast.LENGTH_LONG);
} else {
Utils.showToast(e.getMessage(), Toast.LENGTH_LONG);
}
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.wmods.wppenhacer.xposed.features.others;

import android.util.Pair;

import androidx.annotation.NonNull;

import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
Expand All @@ -25,12 +22,14 @@ public ChatFilters(@NonNull ClassLoader classLoader, @NonNull XSharedPreferences
@Override
public void doHook() throws Throwable {
if (!prefs.getBoolean("separategroups", false)) return;

var filterAdaperClass = Unobfuscator.loadFilterAdaperClass(classLoader);
XposedBridge.hookAllConstructors(filterAdaperClass, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var argResult = IntStream.range(0, param.args.length).mapToObj(i -> new Pair<>(i, param.args[i])).filter(p -> p.second instanceof List).findFirst().orElse(null);
if (argResult != null) {
var list = ReflectionUtils.findArrayOfType(param.args, List.class);
if (!list.isEmpty()) {
var argResult = list.get(0);
var newList = new ArrayList<Object>((List) argResult.second);
newList.removeIf(item -> {
var name = XposedHelpers.getObjectField(item, "A01");
Expand All @@ -40,7 +39,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
}
});
var methodSetFilter = Arrays.stream(filterAdaperClass.getDeclaredMethods()).filter(m -> m.getParameterCount() == 1 && m.getParameterTypes()[0].equals(int.class)).findFirst().orElse(null);
var methodSetFilter = ReflectionUtils.findMethodUsingFilter(filterAdaperClass, method -> method.getParameterCount() == 1 && method.getParameterTypes()[0].equals(int.class));

XposedBridge.hookMethod(methodSetFilter, new XC_MethodHook() {
@Override
Expand Down

0 comments on commit 9972e1b

Please sign in to comment.