Skip to content

Commit 4c15e06

Browse files
committed
Add lite mode
Signed-off-by: Dev4Mod <[email protected]>
1 parent 65e0e3a commit 4c15e06

File tree

14 files changed

+272
-42
lines changed

14 files changed

+272
-42
lines changed

app/src/main/java/com/wmods/wppenhacer/ui/fragments/base/BasePreferenceFragment.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ private boolean checkStoragePermission(Object newValue) {
104104
@SuppressLint("ApplySharedPref")
105105
private void chanceStates(String key) {
106106

107+
var lite_mode = mPrefs.getBoolean("lite_mode", false);
108+
109+
if (lite_mode) {
110+
setPreferenceState("changecolor", false);
111+
setPreferenceState("wallpaper", false);
112+
setPreferenceState("custom_filters", false);
113+
setPreferenceState("download_local", false);
114+
}
115+
116+
107117
if (Objects.equals(key, "thememode")) {
108118
var mode = Integer.parseInt(mPrefs.getString("thememode", "0"));
109119
App.setThemeMode(mode);

app/src/main/java/com/wmods/wppenhacer/xposed/core/FeatureLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.wmods.wppenhacer.xposed.features.general.CallType;
4040
import com.wmods.wppenhacer.xposed.features.general.ChatLimit;
4141
import com.wmods.wppenhacer.xposed.features.general.DeleteStatus;
42+
import com.wmods.wppenhacer.xposed.features.general.LiteMode;
4243
import com.wmods.wppenhacer.xposed.features.general.MenuStatus;
4344
import com.wmods.wppenhacer.xposed.features.general.NewChat;
4445
import com.wmods.wppenhacer.xposed.features.general.Others;
@@ -125,7 +126,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
125126
var timemillis = System.currentTimeMillis();
126127
SharedPreferencesWrapper.hookInit(mApp.getClassLoader());
127128
UnobfuscatorCache.init(mApp);
128-
WppCore.Initialize(loader);
129+
WppCore.Initialize(loader, pref);
129130
if (supportedVersions.stream().noneMatch(s -> packageInfo.versionName.startsWith(s.replace(".xx", ""))) && !pref.getBoolean("bypass_version_check", false)) {
130131
throw new Exception("Unsupported version: " + packageInfo.versionName);
131132
}
@@ -284,6 +285,7 @@ private static void plugins(@NonNull ClassLoader loader, @NonNull XSharedPrefere
284285
HideTagForward.class,
285286
HideTabs.class,
286287
IGStatus.class,
288+
LiteMode.class,
287289
MediaQuality.class,
288290
NewChat.class,
289291
Others.class,

app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.concurrent.CompletableFuture;
4141

4242
import de.robv.android.xposed.XC_MethodHook;
43+
import de.robv.android.xposed.XSharedPreferences;
4344
import de.robv.android.xposed.XposedBridge;
4445
import de.robv.android.xposed.XposedHelpers;
4546

@@ -62,7 +63,7 @@ public class WppCore {
6263
private static Object mCachedMessageStore;
6364

6465

65-
public static void Initialize(ClassLoader loader) throws Exception {
66+
public static void Initialize(ClassLoader loader, XSharedPreferences pref) throws Exception {
6667
privPrefs = Utils.getApplication().getSharedPreferences("WaGlobal", Context.MODE_PRIVATE);
6768

6869
// init UserJID
@@ -105,7 +106,11 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
105106

106107
// Load wa database
107108
loadWADatabase();
108-
initBridge(Utils.getApplication());
109+
110+
if (!pref.getBoolean("lite_mode", false)) {
111+
initBridge(Utils.getApplication());
112+
}
113+
109114
}
110115

111116
public static void initBridge(Context context) throws Exception {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ private static void replaceColor(String drawableName, int color) {
4040
@Override
4141
public void doHook() throws Exception {
4242

43+
if (prefs.getBoolean("lite_mode", false)) return;
44+
4345
Properties properties = Utils.extractProperties(prefs.getString("custom_css", ""));
4446

4547
if (!prefs.getBoolean("bubble_color", false) && !Objects.equals(properties.getProperty("bubble_colors"), "true"))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public CustomTheme(ClassLoader loader, XSharedPreferences preferences) {
6565

6666
@Override
6767
public void doHook() throws Exception {
68+
if (prefs.getBoolean("lite_mode", false)) return;
6869
properties = Utils.extractProperties(prefs.getString("custom_css", ""));
6970
hookColors();
7071
hookWallpaper();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public CustomView(@NonNull ClassLoader loader, @NonNull XSharedPreferences prefe
8282

8383
@Override
8484
public void doHook() throws Throwable {
85+
86+
if (prefs.getBoolean("lite_mode", false)) return;
87+
8588
var filter_itens = prefs.getString("css_theme", "");
8689
var folder_theme = prefs.getString("folder_theme", "");
8790
var custom_css = prefs.getString("custom_css", "");
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package com.wmods.wppenhacer.xposed.features.general;
2+
3+
import static com.wmods.wppenhacer.xposed.features.others.MenuHome.menuItems;
4+
5+
import android.app.Activity;
6+
import android.content.Context;
7+
import android.content.Intent;
8+
import android.content.pm.PackageManager;
9+
import android.net.Uri;
10+
import android.os.Build;
11+
import android.os.Bundle;
12+
import android.os.Environment;
13+
import android.provider.DocumentsContract;
14+
import android.provider.MediaStore;
15+
import android.view.Menu;
16+
17+
import androidx.annotation.NonNull;
18+
19+
import com.wmods.wppenhacer.utils.RealPathUtil;
20+
import com.wmods.wppenhacer.xposed.core.Feature;
21+
import com.wmods.wppenhacer.xposed.core.WppCore;
22+
import com.wmods.wppenhacer.xposed.core.components.AlertDialogWpp;
23+
import com.wmods.wppenhacer.xposed.utils.ResId;
24+
25+
import de.robv.android.xposed.XC_MethodHook;
26+
import de.robv.android.xposed.XSharedPreferences;
27+
import de.robv.android.xposed.XposedHelpers;
28+
29+
public class LiteMode extends Feature {
30+
31+
private static final int REQUEST_FOLDER = 852583;
32+
33+
34+
public LiteMode(@NonNull ClassLoader classLoader, @NonNull XSharedPreferences preferences) {
35+
super(classLoader, preferences);
36+
}
37+
38+
private static Uri getDownloadsUri() {
39+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
40+
return MediaStore.Downloads.EXTERNAL_CONTENT_URI;
41+
} else {
42+
return Uri.fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
43+
}
44+
}
45+
46+
private static void showDialogUriPermission(Activity activity) {
47+
new AlertDialogWpp(activity).setTitle(activity.getString(ResId.string.download_folder_permission))
48+
.setMessage(activity.getString(ResId.string.ask_download_folder))
49+
.setPositiveButton(activity.getString(ResId.string.allow), (dialog, which) -> {
50+
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
51+
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, getDownloadsUri());
52+
activity.startActivityForResult(intent, REQUEST_FOLDER);
53+
}).setNegativeButton(activity.getString(ResId.string.cancel), (dialog, which) -> dialog.dismiss()).show();
54+
}
55+
56+
@Override
57+
public void doHook() throws Throwable {
58+
if (!prefs.getBoolean("lite_mode", false)) return;
59+
60+
menuItems.add(this::InsertDownloadFolderButton);
61+
62+
XposedHelpers.findAndHookMethod("com.whatsapp.HomeActivity", classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
63+
@Override
64+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
65+
var activity = (Activity) param.thisObject;
66+
67+
var wae = WppCore.getPrivString("download_folder", null);
68+
if (wae == null || !isUriPermissionGranted(activity, Uri.parse(wae))) {
69+
showDialogUriPermission(activity);
70+
}
71+
}
72+
});
73+
74+
XposedHelpers.findAndHookMethod(Activity.class, "onActivityResult", int.class, int.class, Intent.class, new XC_MethodHook() {
75+
@Override
76+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
77+
super.afterHookedMethod(param);
78+
var activity = (Activity) param.thisObject;
79+
if ((int) param.args[0] == REQUEST_FOLDER && (int) param.args[1] == Activity.RESULT_OK) {
80+
var uri = ((Intent) param.args[2]).getData();
81+
WppCore.setPrivString("download_folder", uri.toString());
82+
activity.getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
83+
}
84+
}
85+
});
86+
87+
}
88+
89+
private void InsertDownloadFolderButton(Menu menu, Activity activity) {
90+
var waeMenu = prefs.getBoolean("open_wae", true);
91+
if (!waeMenu) return;
92+
var itemMenu = menu.add(0, 0, 9999, "Download Folder");
93+
var iconDraw = activity.getDrawable(ResId.drawable.download);
94+
iconDraw.setTint(0xff8696a0);
95+
itemMenu.setIcon(iconDraw);
96+
itemMenu.setOnMenuItemClickListener(item -> {
97+
98+
var folder = WppCore.getPrivString("download_folder", null);
99+
if (folder != null) {
100+
try {
101+
folder = RealPathUtil.getRealFolderPath(activity, Uri.parse(folder));
102+
} catch (Exception ignored) {
103+
}
104+
}
105+
AlertDialogWpp dialog = new AlertDialogWpp(activity);
106+
dialog.setTitle("Download Folder");
107+
dialog.setMessage("Current Folder to download is " + folder);
108+
dialog.setNegativeButton("Cancel", (dialog1, which) -> dialog.dismiss());
109+
dialog.setPositiveButton("Select", (dialog1, which) -> {
110+
showDialogUriPermission(activity);
111+
}).show();
112+
return true;
113+
});
114+
}
115+
116+
private boolean isUriPermissionGranted(Context context, Uri uri) {
117+
int takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
118+
int permissionCheck = context.checkUriPermission(uri, android.os.Process.myPid(), android.os.Process.myUid(), takeFlags);
119+
return permissionCheck == PackageManager.PERMISSION_GRANTED;
120+
}
121+
122+
@NonNull
123+
@Override
124+
public String getPluginName() {
125+
return "Lite Mode";
126+
}
127+
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/media/DownloadProfile.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import com.wmods.wppenhacer.xposed.utils.ResId;
1515
import com.wmods.wppenhacer.xposed.utils.Utils;
1616

17-
import java.io.File;
18-
1917
import de.robv.android.xposed.XC_MethodHook;
2018
import de.robv.android.xposed.XSharedPreferences;
2119
import de.robv.android.xposed.XposedHelpers;
@@ -46,9 +44,15 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
4644
var jidObj = ReflectionUtils.getObjectField(loadProfileInfoField, ReflectionUtils.getObjectField(field, param.thisObject));
4745
var jid = WppCore.stripJID(WppCore.getRawString(jidObj));
4846
var file = WppCore.getContactPhotoFile(jid);
49-
var destPath = Utils.getDestination("Profile Photo");
47+
String destPath;
48+
try {
49+
destPath = Utils.getDestination("Profile Photo");
50+
} catch (Exception e) {
51+
Utils.showToast(e.toString(), 1);
52+
return true;
53+
}
5054
var name = Utils.generateName(jidObj, "jpg");
51-
var error = Utils.copyFile(file, new File(destPath, name));
55+
var error = Utils.copyFile(file, destPath, name);
5256
if (TextUtils.isEmpty(error)) {
5357
Toast.makeText(Utils.getApplication(), Utils.getApplication().getString(ResId.string.saved_to) + destPath, Toast.LENGTH_LONG).show();
5458
} else {

app/src/main/java/com/wmods/wppenhacer/xposed/features/media/DownloadViewOnce.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public DownloadViewOnce(@NonNull ClassLoader classLoader, @NonNull XSharedPrefer
2929
super(classLoader, preferences);
3030
}
3131

32-
private static void downloadFile(Object userJid, File file) {
32+
private static void downloadFile(Object userJid, File file) throws Exception {
3333
var dest = Utils.getDestination("View Once");
3434
var fileExtension = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".") + 1);
3535
var name = Utils.generateName(userJid, fileExtension);
36-
var error = Utils.copyFile(file, new File(dest, name));
36+
var error = Utils.copyFile(file, dest, name);
3737
if (TextUtils.isEmpty(error)) {
3838
Utils.showToast(Utils.getApplication().getString(ResId.string.saved_to) + dest, Toast.LENGTH_LONG);
3939
} else {
@@ -89,7 +89,11 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
8989
var fmessage = new FMessageWpp(fmessageObj);
9090
var file = fmessage.getMediaFile();
9191
var userJid = fmessage.getKey().remoteJid;
92-
downloadFile(userJid, file);
92+
try {
93+
downloadFile(userJid, file);
94+
} catch (Exception e) {
95+
Utils.showToast(e.getMessage(), Toast.LENGTH_LONG);
96+
}
9397
});
9498
return true;
9599
});

app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,11 @@ private void downloadFile(FMessageWpp fMessage) {
103103
var file = fMessage.getMediaFile();
104104
var userJid = fMessage.getUserJid();
105105
var fileType = file.getName().substring(file.getName().lastIndexOf(".") + 1);
106-
var destination = getPathDestination(file);
106+
var destination = getStatusDestination(file);
107107
var name = Utils.generateName(userJid, fileType);
108-
var destinationFile = new File(destination, name);
109-
var error = Utils.copyFile(file, destinationFile);
108+
var error = Utils.copyFile(file, destination, name);
110109
if (TextUtils.isEmpty(error)) {
111-
Utils.showToast(Utils.getApplication().getString(ResId.string.saved_to) + destinationFile.getAbsolutePath(), Toast.LENGTH_SHORT);
110+
Utils.showToast(Utils.getApplication().getString(ResId.string.saved_to) + destination, Toast.LENGTH_SHORT);
112111
} else {
113112

114113
Utils.showToast(Utils.getApplication().getString(ResId.string.error_when_saving_try_again) + ": " + error, Toast.LENGTH_SHORT);
@@ -126,14 +125,9 @@ public String getPluginName() {
126125

127126

128127
@NonNull
129-
private String getPathDestination(@NonNull File f) {
128+
private String getStatusDestination(@NonNull File f) throws Exception {
130129
var fileName = f.getName().toLowerCase();
131-
var mediaPath = getStatusFolderPath(MimeTypeUtils.getMimeTypeFromExtension(fileName));
132-
return mediaPath + "/";
133-
}
134-
135-
@NonNull
136-
private File getStatusFolderPath(@NonNull String mimeType) {
130+
var mimeType = MimeTypeUtils.getMimeTypeFromExtension(fileName);
137131
var folderPath = "";
138132
if (mimeType.contains("video")) {
139133
folderPath = "Status Videos";
@@ -144,9 +138,7 @@ private File getStatusFolderPath(@NonNull String mimeType) {
144138
} else {
145139
folderPath = "Status Media";
146140
}
147-
var folder = new File(Utils.getDestination(folderPath));
148-
if (!folder.exists())
149-
folder.mkdirs();
150-
return folder;
141+
return Utils.getDestination(folderPath);
151142
}
143+
152144
}

0 commit comments

Comments
 (0)