Skip to content

Commit

Permalink
Merge branch 'Dev4Mod:master' into theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Strange-IPmart authored Nov 13, 2024
2 parents 4e5afec + 4bba0b2 commit e4cf5a8
Show file tree
Hide file tree
Showing 38 changed files with 882 additions and 482 deletions.
11 changes: 0 additions & 11 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions app/src/main/java/com/wmods/wppenhacer/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.wmods.wppenhacer;

import android.app.Activity;
import android.app.AlertDialog;
import android.text.Html;

import com.wmods.wppenhacer.xposed.core.WppCore;
import com.wmods.wppenhacer.xposed.utils.Utils;

import java.util.Objects;

import de.robv.android.xposed.XposedBridge;
import okhttp3.OkHttpClient;

public class UpdateChecker implements Runnable {

private final Activity mActivity;

public UpdateChecker(Activity activity) {
this.mActivity = activity;
}


@Override
public void run() {
try {
var client = new OkHttpClient();
var request = new okhttp3.Request.Builder()
.url("https://t.me/s/waenhancher")
.build();
var response = client.newCall(request).execute();
var body = response.body();
if (body == null) return;
var content = body.string();
var indexHash = content.lastIndexOf("WaEnhancer_debug_");
var lastindexHash = content.indexOf(".apk", indexHash);
var hash = content.substring(indexHash + 17, lastindexHash);
var appInfo = mActivity.getPackageManager().getPackageInfo(BuildConfig.APPLICATION_ID, 0);
if (!appInfo.versionName.toLowerCase().contains(hash.toLowerCase().trim()) && !Objects.equals(WppCore.getPrivString("ignored_version", ""), hash)) {
var changelogIndex = content.indexOf("<div class=\"tgme_widget_message_text js-message_text\" dir=\"auto\">", lastindexHash);
var closeTag = content.indexOf("</div>", changelogIndex);
var changelogText = content.substring(changelogIndex, closeTag + 6);
var changelog = Html.fromHtml(changelogText, Html.FROM_HTML_MODE_COMPACT).toString();
mActivity.runOnUiThread(() -> {
AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity);
dialog.setTitle("WAE - New version available!");
dialog.setMessage("Changelog:\n\n" + changelog);
dialog.setNegativeButton("Ignore", (dialog1, which) -> {
WppCore.setPrivString("ignored_version", hash);
dialog1.dismiss();
});
dialog.setPositiveButton("Update", (dialog1, which) -> {
Utils.openLink(mActivity, "https://t.me/waenhancher");
dialog1.dismiss();
});
dialog.show();
});
}
} catch (Exception e) {
XposedBridge.log(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup

tabdialog.addTab(activity.getString(ResId.string.edit_text), iconEdit, (view) -> {
Intent A09 = new Intent();
A09.setClassName(activity.getPackageName(), "com.whatsapp.textstatuscomposer.TextStatusComposerActivityV2");
if (XposedHelpers.findClassIfExists("com.whatsapp.textstatuscomposer.TextStatusComposerActivity", activity.getClassLoader()) != null) {
A09.setClassName(activity.getPackageName(), "com.whatsapp.textstatuscomposer.TextStatusComposerActivity");
} else {
A09.setClassName(activity.getPackageName(), "com.whatsapp.textstatuscomposer.TextStatusComposerActivityV2");
}
activity.startActivity(A09);
dialog.dismissDialog();
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.wmods.wppenhacer.listeners;

import android.view.View;

public abstract class OnMultiClickListener implements View.OnClickListener {

private final int targetClicks;
private final long delay;
private long lastClick = 0;
private int clicks = 0;

public OnMultiClickListener(int targetClicks, long delay) {
if (targetClicks < 2) {
throw new IllegalArgumentException("targetClicks must be greater than 1");
}
this.targetClicks = targetClicks;
this.delay = delay;
}

@Override
public void onClick(View v) {
if (this.lastClick == 0 || System.currentTimeMillis() - this.lastClick < this.delay) {
this.lastClick = System.currentTimeMillis();
this.clicks++;
} else {
this.lastClick = 0;
this.clicks = 0;
}
if (this.clicks >= this.targetClicks) {
this.clicks = 0;
this.lastClick = 0;
onMultiClick(v);
}
}

abstract public void onMultiClick(View v);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.core.content.ContextCompat;

import com.wmods.wppenhacer.BuildConfig;
import com.wmods.wppenhacer.UpdateChecker;
import com.wmods.wppenhacer.xposed.core.components.AlertDialogWpp;
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
import com.wmods.wppenhacer.xposed.core.components.SharedPreferencesWrapper;
Expand Down Expand Up @@ -70,7 +71,7 @@
import com.wmods.wppenhacer.xposed.features.privacy.HideReceipt;
import com.wmods.wppenhacer.xposed.features.privacy.HideSeen;
import com.wmods.wppenhacer.xposed.features.privacy.HideTagForward;
import com.wmods.wppenhacer.xposed.features.privacy.TypePrivacy;
import com.wmods.wppenhacer.xposed.features.privacy.TypingPrivacy;
import com.wmods.wppenhacer.xposed.features.privacy.ViewOnce;
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
import com.wmods.wppenhacer.xposed.utils.ResId;
Expand Down Expand Up @@ -178,6 +179,35 @@ private static void initComponents(ClassLoader loader, XSharedPreferences pref)
AlertDialogWpp.initDialog(loader);
FMessageWpp.init(loader);
Utils.init(loader);
WppCore.addListenerActivity((activity, state) -> {
// Check for Change Preferences
if (state == WppCore.ActivityChangeState.ChangeType.RESUME) {
checkUpdate(activity);
}

// Check for Update
if (activity.getClass().getSimpleName().equals("HomeActivity") && state == WppCore.ActivityChangeState.ChangeType.START) {
CompletableFuture.runAsync(new UpdateChecker(activity));
}
});

}

private static void checkUpdate(@NonNull Activity activity) {
if (WppCore.getPrivBoolean("need_restart", false)) {
WppCore.setPrivBoolean("need_restart", false);
try {
new AlertDialogWpp(activity).
setMessage(activity.getString(ResId.string.restart_wpp)).
setPositiveButton(activity.getString(ResId.string.yes), (dialog, which) -> {
if (!Utils.doRestart(activity))
Toast.makeText(activity, "Unable to rebooting activity", Toast.LENGTH_SHORT).show();
})
.setNegativeButton(activity.getString(ResId.string.no), null)
.show();
} catch (Exception ignored) {
}
}
}

private static void registerReceivers() {
Expand Down Expand Up @@ -243,7 +273,7 @@ private static void plugins(@NonNull ClassLoader loader, @NonNull XSharedPrefere
ShowOnline.class,
DndMode.class,
FreezeLastSeen.class,
TypePrivacy.class,
TypingPrivacy.class,
HideChat.class,
HideReceipt.class,
HideSeen.class,
Expand Down
19 changes: 0 additions & 19 deletions app/src/main/java/com/wmods/wppenhacer/xposed/core/WaCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.wmods.wppenhacer.xposed.core.components.AlertDialogWpp;
import com.wmods.wppenhacer.xposed.utils.ResId;
import com.wmods.wppenhacer.xposed.utils.Utils;

public class WaCallback implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
Expand All @@ -32,20 +27,6 @@ public void onActivityStarted(@NonNull Activity activity) {
public void onActivityResumed(@NonNull Activity activity) {
WppCore.mCurrentActivity = activity;
WppCore.activities.add(activity);
if (WppCore.getPrivBoolean("need_restart", false)) {
WppCore.setPrivBoolean("need_restart", false);
try {
new AlertDialogWpp(activity).
setMessage(activity.getString(ResId.string.restart_wpp)).
setPositiveButton(activity.getString(ResId.string.yes), (dialog, which) -> {
if (!Utils.doRestart(activity))
Toast.makeText(activity, "Unable to rebooting activity", Toast.LENGTH_SHORT).show();
})
.setNegativeButton(activity.getString(ResId.string.no), null)
.show();
} catch (Exception ignored) {
}
}
triggerActivityState(activity, WppCore.ActivityChangeState.ChangeType.RESUME);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public static WaeIIFace getClientBridge() throws Exception {

public interface ActivityChangeState {

void onChange(Object object, ChangeType type);
void onChange(Activity activity, ChangeType type);

enum ChangeType {
START, END, RESUME, PAUSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

Expand All @@ -21,6 +22,7 @@ public class FMessageWpp {
private static Method messageWithMediaMethod;
private static Field mediaTypeField;
private static Method getOriginalMessageKey;
private static Class abstractMediaMessageClass;
private final Object fmessage;

public FMessageWpp(Object fMessage) {
Expand All @@ -47,6 +49,7 @@ public static void init(ClassLoader classLoader) throws Exception {
deviceJidMethod = ReflectionUtils.findMethodUsingFilter(TYPE, method -> method.getReturnType().equals(XposedHelpers.findClass("com.whatsapp.jid.DeviceJid", classLoader)));
mediaTypeField = Unobfuscator.loadMediaTypeField(classLoader);
getOriginalMessageKey = Unobfuscator.loadOriginalMessageKey(classLoader);
abstractMediaMessageClass = Unobfuscator.loadAbstractMediaMessageClass(classLoader);
}

public Object getUserJid() {
Expand Down Expand Up @@ -110,6 +113,31 @@ public String getMessageStr() {
}
}

public boolean isMediaFile() {
try {
return abstractMediaMessageClass.isInstance(fmessage);
} catch (Exception e) {
return false;
}
}

public File getMediaFile() {
try {
if (!isMediaFile()) return null;
for (var field : abstractMediaMessageClass.getDeclaredFields()) {
if (field.getType().isPrimitive()) continue;
var fileField = ReflectionUtils.getFieldByType(field.getType(), File.class);
if (fileField != null) {
var mediaFile = ReflectionUtils.getField(field, fmessage);
return (File) fileField.get(mediaFile);
}
}
} catch (Exception e) {
XposedBridge.log(e);
}
return null;
}


public int getMediaType() {
try {
Expand Down
Loading

0 comments on commit e4cf5a8

Please sign in to comment.