Skip to content

Commit

Permalink
separate features
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed Jun 22, 2024
1 parent d1443b7 commit 21e6b01
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,31 @@
import com.wmods.wppenhacer.xposed.features.general.CallType;
import com.wmods.wppenhacer.xposed.features.general.ChatLimit;
import com.wmods.wppenhacer.xposed.features.general.DeleteStatus;
import com.wmods.wppenhacer.xposed.features.general.DndMode;
import com.wmods.wppenhacer.xposed.features.general.MediaPreview;
import com.wmods.wppenhacer.xposed.features.general.MediaQuality;
import com.wmods.wppenhacer.xposed.features.general.NewChat;
import com.wmods.wppenhacer.xposed.features.general.Others;
import com.wmods.wppenhacer.xposed.features.general.PinnedLimit;
import com.wmods.wppenhacer.xposed.features.general.SeenTick;
import com.wmods.wppenhacer.xposed.features.general.ShareLimit;
import com.wmods.wppenhacer.xposed.features.general.ShowEditMessage;
import com.wmods.wppenhacer.xposed.features.general.StatusDownload;
import com.wmods.wppenhacer.xposed.features.general.Tasker;
import com.wmods.wppenhacer.xposed.features.general.ViewOnce;
import com.wmods.wppenhacer.xposed.features.media.DownloadProfile;
import com.wmods.wppenhacer.xposed.features.media.DownloadViewOnce;
import com.wmods.wppenhacer.xposed.features.media.MediaPreview;
import com.wmods.wppenhacer.xposed.features.media.MediaQuality;
import com.wmods.wppenhacer.xposed.features.media.StatusDownload;
import com.wmods.wppenhacer.xposed.features.others.Channels;
import com.wmods.wppenhacer.xposed.features.others.ChatFilters;
import com.wmods.wppenhacer.xposed.features.others.GroupAdmin;
import com.wmods.wppenhacer.xposed.features.others.Stickers;
import com.wmods.wppenhacer.xposed.features.privacy.CallPrivacy;
import com.wmods.wppenhacer.xposed.features.privacy.DndMode;
import com.wmods.wppenhacer.xposed.features.privacy.FreezeLastSeen;
import com.wmods.wppenhacer.xposed.features.privacy.GhostMode;
import com.wmods.wppenhacer.xposed.features.privacy.HideArchive;
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.ViewOnce;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -215,7 +221,13 @@ private static void plugins(@NonNull ClassLoader loader, @NonNull XSharedPrefere
MediaPreview.class,
FilterGroups.class,
Tasker.class,
DeleteStatus.class
DeleteStatus.class,
DownloadViewOnce.class,
Channels.class,
DownloadProfile.class,
ChatFilters.class,
GroupAdmin.class,
Stickers.class
};

for (var classe : classes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ public class WaCallback implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
WppCore.mCurrentActivity = activity;
WppCore.activities.add(activity);
}

@Override
public void onActivityStarted(@NonNull Activity activity) {
WppCore.mCurrentActivity = activity;
triggerActivityState(activity, WppCore.ActivityChangeState.ChangeType.START);
WppCore.activities.add(activity);
}

@SuppressLint("ApplySharedPref")
@Override
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 {
Expand All @@ -52,6 +55,7 @@ public void onActivityPaused(@NonNull Activity activity) {
@Override
public void onActivityStopped(@NonNull Activity activity) {
triggerActivityState(activity, WppCore.ActivityChangeState.ChangeType.END);
WppCore.activities.remove(activity);
}

private static void triggerActivityState(@NonNull Activity activity, WppCore.ActivityChangeState.ChangeType type) {
Expand All @@ -67,6 +71,6 @@ public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bun

@Override
public void onActivityDestroyed(@NonNull Activity activity) {

WppCore.activities.remove(activity);
}
}
22 changes: 18 additions & 4 deletions app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;

Expand All @@ -44,6 +45,7 @@ public class WppCore {
private static Object mActionUser;
@SuppressLint("StaticFieldLeak")
static Activity mCurrentActivity;
static LinkedHashSet<Activity> activities = new LinkedHashSet<>();
private static SQLiteDatabase mWaDatabase;

public static void addMenuItemClass(Class<?> aClass, OnMenuCreate listener) {
Expand All @@ -61,12 +63,15 @@ public static void sendMessage(String number, String message) {
return;
}
var newObject = new Object[senderMethod.getParameterCount()];
for (int i = 0; i < newObject.length; i++) {
var param = senderMethod.getParameterTypes()[i];
if (param.isPrimitive()) {
newObject[i] = 0;
}
}

var index = ReflectionUtils.findIndexOfType(senderMethod.getParameterTypes(), String.class);
newObject[index - 1] = 0;
newObject[index] = message;
newObject[newObject.length - 1] = false;
newObject[newObject.length - 2] = false;
newObject[newObject.length - 3] = false;
var index2 = ReflectionUtils.findIndexOfType(senderMethod.getParameterTypes(), List.class);
newObject[index2] = Collections.singletonList(userJid);
senderMethod.invoke(mActionUser, newObject);
Expand Down Expand Up @@ -150,6 +155,15 @@ public static Activity getCurrentActivity() {
return mCurrentActivity;
}

public static Activity getActivityBySimpleName(String name) {
for (var activity : activities) {
if (activity.getClass().getSimpleName().equals(name)) {
return activity;
}
}
return null;
}


public static int getDefaultTheme() {
if (mStartUpConfig != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.Unobfuscator;
import com.wmods.wppenhacer.xposed.core.Utils;
import com.wmods.wppenhacer.xposed.core.WppCore;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -35,6 +35,7 @@ public class IGStatus extends Feature {
public static ArrayList<Object> itens = new ArrayList<>();
@SuppressLint("StaticFieldLeak")
private static IGStatusView mStatusContainer;
private WeakReference<Activity> homeActivity;

public IGStatus(@NonNull ClassLoader loader, @NonNull XSharedPreferences preferences) {
super(loader, preferences);
Expand All @@ -52,9 +53,9 @@ public void doHook() throws Throwable {
@Override
@SuppressLint("DiscouragedApi")
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var homeActivity = (Activity) param.thisObject;
homeActivity = new WeakReference<>((Activity) param.thisObject);
// create status container
mStatusContainer = new IGStatusView(homeActivity);
mStatusContainer = new IGStatusView(homeActivity.get());
var layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, Utils.dipToPixels(105));
layoutParams.gravity = Gravity.TOP;

Expand All @@ -70,7 +71,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {

mStatusContainer.setLayoutParams(layoutParams);
mStatusContainer.setBackgroundColor(Color.TRANSPARENT);
var mainContainer = homeActivity.findViewById(Utils.getID("main_container", "id"));
var mainContainer = homeActivity.get().findViewById(Utils.getID("main_container", "id"));
var pagerView = (ViewGroup) mainContainer.findViewById(Utils.getID("pager", "id"));
var pager_holder = (ViewGroup) pagerView.getParent();
pager_holder.addView(mStatusContainer);
Expand All @@ -84,7 +85,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.hookMethod(onScrollPagerMethod, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var scroll = -(float) XposedHelpers.getIntField(WppCore.getCurrentActivity(), "A02");
var scroll = -(float) XposedHelpers.getIntField(homeActivity.get(), "A02");
if (mStatusContainer.isShown())
mStatusContainer.setTranslationY(scroll);
}
Expand All @@ -100,7 +101,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (view == null) return;
var mainView = (ListView) view.findViewById(android.R.id.list);
mainView.setNestedScrollingEnabled(true);
var paddingView = new View(WppCore.getCurrentActivity());
var paddingView = new View(homeActivity.get());
paddingView.setClickable(true);
var layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, Utils.dipToPixels(105));
paddingView.setLayoutParams(layoutParams);
Expand All @@ -121,8 +122,8 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!Unobfuscator.isCalledFromClass(clazz) && !Unobfuscator.isCalledFromClass(onMenuItemClick2) && !Unobfuscator.isCalledFromClass(onMenuItemClick))
return;
var index = (int) param.args[0];
WppCore.getCurrentActivity().runOnUiThread(() -> {
XposedHelpers.setObjectField(WppCore.getCurrentActivity(), "A02", 0);
homeActivity.get().runOnUiThread(() -> {
XposedHelpers.setObjectField(homeActivity.get(), "A02", 0);
var visible = View.GONE;
if (index == SeparateGroup.tabs.indexOf(SeparateGroup.CHATS) || (separateGroups && index == SeparateGroup.tabs.indexOf(SeparateGroup.GROUPS))) {
visible = View.VISIBLE;
Expand All @@ -145,7 +146,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
itens.add(0, null);
IGStatusAdapter mStatusAdapter = new IGStatusAdapter(WppCore.getCurrentActivity(), statusInfoClass);
IGStatusAdapter mStatusAdapter = new IGStatusAdapter(homeActivity.get(), statusInfoClass);
mStatusContainer.setAdapter(mStatusAdapter);
mStatusContainer.updateList();
}
Expand Down
Loading

0 comments on commit 21e6b01

Please sign in to comment.