Skip to content

Commit

Permalink
big changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed Jun 22, 2024
1 parent 21e6b01 commit 70b513f
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 249 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/com/wmods/wppenhacer/App.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.wmods.wppenhacer;

import android.app.Application;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;

import com.wmods.wppenhacer.xposed.core.Utils;
import com.wmods.wppenhacer.xposed.core.MainFeatures;

import java.io.File;
import java.lang.reflect.Field;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -58,4 +57,9 @@ public static Handler getMainHandler() {
}


public void restartApp(String packageWpp) {
Intent intent = new Intent(BuildConfig.APPLICATION_ID + ".WHATSAPP.RESTART");
intent.putExtra("PKG", MainFeatures.PACKAGE_WPP);
sendBroadcast(intent);
}
}
113 changes: 66 additions & 47 deletions app/src/main/java/com/wmods/wppenhacer/ui/fragments/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
import com.wmods.wppenhacer.databinding.FragmentHomeBinding;
import com.wmods.wppenhacer.ui.fragments.base.BaseFragment;
import com.wmods.wppenhacer.xposed.core.MainFeatures;
import com.wmods.wppenhacer.xposed.core.Utils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.Objects;

import rikka.core.util.IOUtils;

Expand Down Expand Up @@ -62,62 +65,70 @@ public void onReceive(Context context, Intent intent) {
}, intentFilter, ContextCompat.RECEIVER_EXPORTED);
}

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
binding = FragmentHomeBinding.inflate(inflater, container, false);

checkStateWpp(requireActivity());

binding.rebootBtn.setOnClickListener(view -> {
App.getInstance().restartApp(MainFeatures.PACKAGE_WPP);
disableWpp(requireActivity());
});

binding.rebootBtn2.setOnClickListener(view -> {
App.getInstance().restartApp(MainFeatures.PACKAGE_BUSINESS);
disableBusiness(requireActivity());
});

binding.exportBtn.setOnClickListener(view -> saveConfigs(this.getContext()));
binding.importBtn.setOnClickListener(view -> importConfigs(this.getContext()));
binding.resetBtn.setOnClickListener(view -> resetConfigs(this.getContext()));

return binding.getRoot();
}

@SuppressLint("StringFormatInvalid")
private void receiverBroadcastBusiness(Context context, Intent intent) {
binding.statusTitle3.setText(R.string.business_in_background);
var version = intent.getStringExtra("VERSION");
var supported_list = Arrays.asList(context.getResources().getStringArray(R.array.supported_versions_business));
if (supported_list.contains(version)) {
binding.statusSummary3.setText(String.format(getString(R.string.version_s), version));
binding.statusSummary3.setText(getString(R.string.version_s, version));
binding.status3.setCardBackgroundColor(context.getColor(rikka.material.R.color.material_green_500));
} else {
binding.statusSummary3.setText(String.format(getString(R.string.version_s_not_listed), version));
binding.statusSummary3.setText(getString(R.string.version_s_not_listed, version));
binding.status3.setCardBackgroundColor(context.getColor(rikka.material.R.color.material_yellow_500));
}
binding.rebootBtn2.setVisibility(View.VISIBLE);
binding.statusSummary3.setVisibility(View.VISIBLE);
binding.statusIcon3.setImageResource(R.drawable.ic_round_check_circle_24);
}

@SuppressLint("StringFormatInvalid")
private void receiverBroadcastWpp(Context context, Intent intent) {
binding.statusTitle2.setText(R.string.whatsapp_in_background);
var version = intent.getStringExtra("VERSION");
var supported_list = Arrays.asList(context.getResources().getStringArray(R.array.supported_versions_wpp));

if (supported_list.contains(version)) {
binding.statusSummary1.setText(String.format(getString(R.string.version_s), version));
binding.statusSummary1.setText(getString(R.string.version_s, version));
binding.status2.setCardBackgroundColor(context.getColor(rikka.material.R.color.material_green_500));
} else {
binding.statusSummary1.setText(String.format(getString(R.string.version_s_not_listed), version));
binding.statusSummary1.setText(getString(R.string.version_s_not_listed, version));
binding.status2.setCardBackgroundColor(context.getColor(rikka.material.R.color.material_yellow_500));
}
binding.rebootBtn.setVisibility(View.VISIBLE);
binding.statusSummary1.setVisibility(View.VISIBLE);
binding.statusIcon2.setImageResource(R.drawable.ic_round_check_circle_24);
}

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
binding = FragmentHomeBinding.inflate(inflater, container, false);

checkStateWpp(requireActivity());

binding.rebootBtn.setOnClickListener(view -> {
Intent intent = new Intent(BuildConfig.APPLICATION_ID + ".WHATSAPP.RESTART");
intent.putExtra("PKG", MainFeatures.PACKAGE_WPP);
requireActivity().sendBroadcast(intent);
disableWpp(requireActivity());
});

binding.rebootBtn2.setOnClickListener(view -> {
Intent intent = new Intent(BuildConfig.APPLICATION_ID + ".WHATSAPP.RESTART");
intent.putExtra("PKG", MainFeatures.PACKAGE_BUSINESS);
requireActivity().sendBroadcast(intent);
disableBusiness(requireActivity());
});

binding.exportBtn.setOnClickListener(view -> saveConfigs(this.getContext()));
binding.importBtn.setOnClickListener(view -> importConfigs(this.getContext()));

return binding.getRoot();
private void resetConfigs(Context context) {
var prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.getAll().forEach((key, value) -> prefs.edit().remove(key).apply());
App.getInstance().restartApp(MainFeatures.PACKAGE_WPP);
App.getInstance().restartApp(MainFeatures.PACKAGE_BUSINESS);
Utils.showToast(context.getString(R.string.configs_reset), Toast.LENGTH_SHORT);
}

private void saveConfigs(Context context) {
Expand All @@ -128,9 +139,13 @@ private void saveConfigs(Context context) {
var entries = prefs.getAll();
var JSOjsonObject = new JSONObject();
for (var entry : entries.entrySet()) {
JSOjsonObject.put(entry.getKey(), entry.getValue());
var keyValue = entry.getValue();
if (keyValue instanceof HashSet<?> hashSet) {
keyValue = new JSONArray(new ArrayList<>(hashSet));
}
JSOjsonObject.put(entry.getKey(), keyValue);
}
output.write(JSOjsonObject.toString().getBytes());
Objects.requireNonNull(output).write(JSOjsonObject.toString().getBytes());
}
Toast.makeText(context, context.getString(R.string.configs_saved), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Expand All @@ -154,34 +169,36 @@ private void importConfigs(Context context) {
while (key.hasNext()) {
var keyName = key.next();
var value = jsonObject.get(keyName);
if (value instanceof String stringValue) {
if (stringValue.startsWith("[") && stringValue.endsWith("]")) {
if (stringValue.length() > 2) {
var arr = Arrays.stream(stringValue.substring(1, stringValue.length() - 1).split(",")).map(String::trim).collect(Collectors.toList());
prefs.edit().putStringSet(keyName, new HashSet<>(arr)).apply();
}
} else {
prefs.edit().putString(keyName, value.toString()).apply();
if (value instanceof JSONArray jsonArray) {
HashSet<String> hashSet = new HashSet<>();
for (var i = 0; i < jsonArray.length(); i++) {
hashSet.add(jsonArray.getString(i));
}
} else if (value instanceof Boolean) {
prefs.edit().putBoolean(keyName, (boolean) value).apply();
} else if (value instanceof Integer) {
prefs.edit().putInt(keyName, (int) value).apply();
} else if (value instanceof Long) {
prefs.edit().putLong(keyName, (long) value).apply();
} else if (value instanceof Float) {
prefs.edit().putFloat(keyName, (float) value).apply();
prefs.edit().putStringSet(keyName, hashSet).apply();
} else if (value instanceof String stringValue) {
prefs.edit().putString(keyName, stringValue).apply();
} else if (value instanceof Boolean booleanValue) {
prefs.edit().putBoolean(keyName, booleanValue).apply();
} else if (value instanceof Integer intValue) {
prefs.edit().putInt(keyName, intValue).apply();
} else if (value instanceof Long longValue) {
prefs.edit().putLong(keyName, longValue).apply();
} else if (value instanceof Float floatValue) {
prefs.edit().putFloat(keyName, floatValue).apply();
}
}
}
Toast.makeText(context, context.getString(R.string.configs_imported), Toast.LENGTH_SHORT).show();
App.getInstance().restartApp(MainFeatures.PACKAGE_WPP);
App.getInstance().restartApp(MainFeatures.PACKAGE_BUSINESS);
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
FilePicker.fileCapture.launch(new String[]{"application/json"});
}

@SuppressLint("StringFormatInvalid")
private void checkStateWpp(FragmentActivity activity) {

if (MainActivity.isXposedEnabled()) {
Expand Down Expand Up @@ -227,13 +244,15 @@ private void disableBusiness(FragmentActivity activity) {
binding.statusTitle3.setText(R.string.business_is_not_running_or_has_not_been_activated_in_lsposed);
binding.status3.setCardBackgroundColor(activity.getColor(rikka.material.R.color.material_red_500));
binding.statusSummary3.setVisibility(View.GONE);
binding.rebootBtn2.setVisibility(View.GONE);
}

private void disableWpp(FragmentActivity activity) {
binding.statusIcon2.setImageResource(R.drawable.ic_round_error_outline_24);
binding.statusTitle2.setText(R.string.whatsapp_is_not_running_or_has_not_been_activated_in_lsposed);
binding.status2.setCardBackgroundColor(activity.getColor(rikka.material.R.color.material_red_500));
binding.statusSummary1.setVisibility(View.GONE);
binding.rebootBtn.setVisibility(View.GONE);
}

private static void checkWpp(FragmentActivity activity) {
Expand Down
36 changes: 27 additions & 9 deletions app/src/main/java/com/wmods/wppenhacer/xposed/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import android.util.TypedValue;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.wmods.wppenhacer.App;
import com.wmods.wppenhacer.xposed.utils.MimeTypeUtils;

import java.io.File;
Expand All @@ -33,8 +36,9 @@

public class Utils {

@NonNull
public static Application getApplication() {
return MainFeatures.mApp;
return MainFeatures.mApp == null ? App.getInstance() : MainFeatures.mApp;
}

public static boolean doRestart(Context context) {
Expand Down Expand Up @@ -148,11 +152,11 @@ public static void debugMethods(Class<?> cls, Object thisObject) {
}
}

public static String getDestination(SharedPreferences prefs, File file, String name) {
public static String getDestination(SharedPreferences prefs, String name) {
var folderPath = prefs.getString("localdownload", Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download") + "/WhatsApp/Wa Enhancer/" + name + "/";
var filePath = new File(folderPath);
if (!filePath.exists()) filePath.mkdirs();
return filePath.getAbsolutePath() + "/" + (file == null ? "" : file.getName());
return filePath.getAbsolutePath() + "/";
}

public static String copyFile(File srcFile, File destFile) {
Expand All @@ -166,12 +170,6 @@ public static String copyFile(File srcFile, File destFile) {
if (read <= 0) {
in.close();
out.close();
MediaScannerConnection.scanFile(Utils.getApplication(),
new String[]{destFile.getAbsolutePath()},
new String[]{MimeTypeUtils.getMimeTypeFromExtension(srcFile.getAbsolutePath())},
(path, uri) -> {
});

return "";
}
out.write(bArr, 0, read);
Expand All @@ -196,4 +194,24 @@ public static void setToClipboard(String string) {
ClipData clip = ClipData.newPlainText("label", string);
clipboard.setPrimaryClip(clip);
}

public static String generateName(Object userJid, String fileFormat) {
var contactName = WppCore.getContactName(userJid);
var number = WppCore.stripJID(WppCore.getRawString(userJid));
return padronizarNome(contactName) + "_" + number + "_" + new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(new Date()) + "." + fileFormat;
}

@NonNull
public static String padronizarNome(@NonNull String nome) {
String nomePadronizado = nome.replaceAll("[^a-zA-Z0-9 _]", "");
nomePadronizado = nomePadronizado.replace(' ', '_');
return nomePadronizado;
}

public static void scanFile(File file) {
MediaScannerConnection.scanFile(Utils.getApplication(),
new String[]{file.getAbsolutePath()},
new String[]{MimeTypeUtils.getMimeTypeFromExtension(file.getAbsolutePath())},
null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import android.view.Menu;
import android.widget.Toast;

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

import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;

import java.io.File;
Expand Down Expand Up @@ -139,6 +141,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {

// Load wa database
loadDatabase();

FMessageWpp.init(loader);
}

public static void loadDatabase() {
Expand Down Expand Up @@ -177,10 +181,10 @@ public static int getDefaultTheme() {
return startup_prefs.getInt("night_mode", 0);
}

@Nullable
@NonNull
public static String getContactName(Object userJid) {
loadDatabase();
if (mWaDatabase == null) return "";
if (mWaDatabase == null || userJid == null) return "";
var rawJid = getRawString(userJid);
var cursor = mWaDatabase.query("wa_contacts", new String[]{"display_name"}, "jid = ?", new String[]{rawJid}, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
Expand Down
Loading

0 comments on commit 70b513f

Please sign in to comment.