Skip to content

Commit

Permalink
2.0.7
Browse files Browse the repository at this point in the history
Fix install button not working
Check for update at app launch
UI improvements
  • Loading branch information
AbdurazaaqMohammed committed Sep 15, 2024
1 parent d4f9abb commit 02d1280
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 106 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = "com.abdurazaaqmohammed.AntiSplit"
minSdk = 21
targetSdk = 35
versionCode = 37
versionName = "2.0.6"
versionCode = 38
versionName = "2.0.7"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
Expand All @@ -30,7 +28,6 @@
import android.os.Handler;
import android.os.Looper;
import android.provider.OpenableColumns;
import android.support.v4.content.FileProvider;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
Expand All @@ -39,8 +36,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
Expand Down Expand Up @@ -145,7 +140,7 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().setNavigationBarContrastEnforced(true);
}
// Fetch settings from SharedPreferences
checkForUpdates = settings.getBoolean("checkForUpdates", true);
if(checkForUpdates = settings.getBoolean("checkForUpdates", true)) new CheckForUpdatesTask(this, false).execute();
signApk = settings.getBoolean("signApk", true);
showDialog = settings.getBoolean("showDialog", false);
selectSplitsForDevice = settings.getBoolean("selectSplitsForDevice", false);
Expand Down Expand Up @@ -287,12 +282,7 @@ public void afterTextChanged(Editable s) {
CompoundButton updateSwitch = settingsDialog.findViewById(R.id.updateToggle);
updateSwitch.setChecked(checkForUpdates);
updateSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> checkUpdateNow.setVisibility((checkForUpdates = isChecked) ? View.GONE : View.VISIBLE));
if(checkForUpdates) {
checkUpdateNow.setVisibility(View.GONE);
new CheckForUpdatesTask(this, false).execute();
} else {
checkUpdateNow.setVisibility(View.VISIBLE);
}
checkUpdateNow.setVisibility(checkForUpdates ? View.GONE : View.VISIBLE);
checkUpdateNow.setOnClickListener(v1 -> new CheckForUpdatesTask(this, true).execute());

CompoundButton logSwitch = settingsDialog.findViewById(R.id.logToggle);
Expand Down Expand Up @@ -383,14 +373,6 @@ public void afterTextChanged(Editable s) {
}
}

private GradientDrawable createBorderDrawable(int borderWidth, int cornerRadius) {
GradientDrawable drawable = new GradientDrawable();
drawable.setStroke(borderWidth, android.R.attr.colorPrimary); // Set border width and color
drawable.setCornerRadius(cornerRadius); // Set corner radius
drawable.setColor(Color.TRANSPARENT); // Set the background color
return drawable;
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Expand Down Expand Up @@ -738,7 +720,6 @@ private void process(Uri outputUri) {
fabs.setAlpha(0.5f);
View cancelButton = findViewById(R.id.cancelButton);
cancelButton.setVisibility(View.VISIBLE);

cancelButton.setOnClickListener(v -> {
try {
if(doesNotHaveStoragePerm(this)) AndroidXI.getInstance().with(this).delete(launcher, outputUri);
Expand Down Expand Up @@ -772,19 +753,15 @@ private static class CheckForUpdatesTask extends AsyncTask<Void, Void, String[]>

@Override
protected String[] doInBackground(Void... voids) {
HttpURLConnection conn;
String currentBranch;
try {
Context activity = context.get();
String currentVer = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
currentBranch = TextUtils.isEmpty(currentVer) ? "2" : currentVer.split("\\.")[0];

conn = (HttpURLConnection) new URL("https://api.github.com/repos/AbdurazaaqMohammed/AntiSplit-M/releases").openConnection();
HttpURLConnection conn = (HttpURLConnection) new URL("https://api.github.com/repos/AbdurazaaqMohammed/AntiSplit-M/releases").openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0");
conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
try (InputStream inputStream = conn.getInputStream();
InputStreamReader in = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(in)) {
String line;
String ver = "";
String changelog = "";
Expand All @@ -794,8 +771,7 @@ protected String[] doInBackground(Void... voids) {
if(line.contains("browser_download_url")) {
dl = line.split("\"")[3];
ver = line.split("/")[7];

rightBranch = ver.split("\\.")[0].equals(currentBranch);
rightBranch = ver.charAt(0) == '2';
} else if(line.contains("body") && rightBranch) {
changelog = line.split("\"")[3];
break;
Expand Down Expand Up @@ -825,7 +801,7 @@ protected void onPostExecute(String[] result) {
currentVer = null;
}
boolean newVer = false;
char[] curr = TextUtils.isEmpty(currentVer) ? new char[] {'2', '0', '5'} : currentVer.replace(".", "").toCharArray();
char[] curr = TextUtils.isEmpty(currentVer) ? new char[] {'2', '0', '7'} : currentVer.replace(".", "").toCharArray();
char[] latest = latestVersion.replace(".", "").toCharArray();

int maxLength = Math.max(curr.length, latest.length);
Expand All @@ -847,8 +823,8 @@ protected void onPostExecute(String[] result) {
String link = result[2].endsWith(ending) ? result[2] : result[2] + File.separator + filename;
MaterialTextView changelogText = new MaterialTextView(activity);
String linebreak = "<br />";
changelogText.setText(Html.fromHtml(rss.getString(R.string.new_ver) + " (" + latestVersion + ")" + linebreak + "Changelog:" + linebreak + result[1].replace("\\r\\n", linebreak)));
int padding = 5;
changelogText.setText(Html.fromHtml(rss.getString(R.string.new_ver) + " (" + latestVersion + ")" + linebreak + linebreak + "Changelog:" + linebreak + result[1].replace("\\r\\n", linebreak)));
int padding = 16;
changelogText.setPadding(padding, padding, padding, padding);
changelogText.setGravity(Gravity.CENTER);
MaterialTextView title = new MaterialTextView(activity);
Expand All @@ -863,7 +839,7 @@ protected void onPostExecute(String[] result) {
.setTitle(filename).setDescription(filename).setMimeType("application/vnd.android.package-archive")
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE | DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED));
}).setNeutralButton("Go to GitHub Release", (dialog, which) -> activity.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/AbdurazaaqMohammed/AntiSplit-M/releases/latest")))).setNegativeButton(rss.getString(R.string.cancel), null).create()::show);
}).setNegativeButton("Go to GitHub Release", (dialog, which) -> activity.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/AbdurazaaqMohammed/AntiSplit-M/releases/latest")))).setNeutralButton(rss.getString(R.string.cancel), null).create()::show);
} else if (toast) activity.runOnUiThread(() -> Toast.makeText(activity, rss.getString(R.string.no_update_found), Toast.LENGTH_SHORT).show());
} catch (Exception ignored) {
if (toast) activity.runOnUiThread(() -> Toast.makeText(activity, "Failed to check for update", Toast.LENGTH_SHORT).show());
Expand Down Expand Up @@ -985,14 +961,13 @@ private void showSuccess() {
final String success = rss.getString(R.string.success_saved);
LogUtil.logMessage(success);
runOnUiThread(() -> Toast.makeText(this, success, Toast.LENGTH_SHORT).show());
File output;
if(signApk && (output = Merger.signedApk) != null && output.exists() && output.length() > 999) {
if(signApk && Merger.signedApk != null) {
installButton.setVisibility(View.VISIBLE);
installButton.setOnClickListener(v -> //if (supportsFileChannel && !getPackageManager().canRequestPackageInstalls()) startActivityForResult(new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).setData(Uri.parse(String.format("package:%s", getPackageName()))), 1234);
startActivity(new Intent(Intent.ACTION_INSTALL_PACKAGE)
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.setData(FileProvider.getUriForFile(this, "com.abdurazaaqmohammed.AntiSplit.provider", output))));
.setData(Merger.signedApk)));
} else installButton.setVisibility(View.GONE);
}
}
Expand All @@ -1003,49 +978,42 @@ private void copyText(CharSequence text) {
}

private void showError(Exception e) {
if(!(e instanceof ClosedByInterruptException)) {
if (!(e instanceof ClosedByInterruptException)) {
final String mainErr = e.toString();
errorOccurred = !mainErr.equals(rss.getString(R.string.sign_failed));
toggleAnimation(this, false);

StringBuilder stackTrace = new StringBuilder().append(mainErr).append('\n');
for(StackTraceElement line : e.getStackTrace()) stackTrace.append(line).append('\n');
for (StackTraceElement line : e.getStackTrace()) {
stackTrace.append(line).append('\n');
}
StringBuilder fullLog = new StringBuilder(stackTrace.toString());
fullLog.append('\n').append(((TextView) findViewById(R.id.logField)).getText());

getHandler().post(() -> runOnUiThread(() -> {
View dialogView = getLayoutInflater().inflate(R.layout.dialog_button_layout, null);
ScrollView sv = new ScrollView(this);
sv.addView(dialogView);
AlertDialog ad = new MaterialAlertDialogBuilder(this).setView(sv).setTitle(mainErr).create();

findViewById(R.id.cancelButton).setVisibility(View.GONE);

Button positiveButton = dialogView.findViewById(R.id.positiveButton);
Button negativeButton = dialogView.findViewById(R.id.negativeButton);
Button neutralButton = dialogView.findViewById(R.id.neutralButton);

positiveButton.setContentDescription(rss.getString(R.string.create_issue));
positiveButton.setOnClickListener(v -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/AbdurazaaqMohammed/AntiSplit-M/issues/new?title=Crash%20Report&body=" + fullLog)));
ad.dismiss();
});

negativeButton.setContentDescription(rss.getString(R.string.cancel));
negativeButton.setOnClickListener(v -> ad.dismiss());

neutralButton.setContentDescription(rss.getString(R.string.copy_log));
neutralButton.setOnClickListener(v -> {
copyText(fullLog);
ad.dismiss();
});

((TextView) dialogView.findViewById(R.id.errorD)).setText(stackTrace);

ad.show();
Window w = ad.getWindow();
if (w != null) {
w.getDecorView().setLayoutParams(new WindowManager.LayoutParams((int) (rss.getDisplayMetrics().widthPixels * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT));
}
AlertDialog alertDialog = new MaterialAlertDialogBuilder(this)
.setTitle(mainErr)
.setView(dialogView)
.setPositiveButton(rss.getString(R.string.create_issue), (dialog, which) -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/AbdurazaaqMohammed/AntiSplit-M/issues/new?title=Crash%20Report&body=" + fullLog)));
dialog.dismiss();
})
.setNegativeButton(rss.getString(R.string.cancel), (dialog, which) -> dialog.dismiss())
.setNeutralButton(rss.getString(R.string.copy_log), (dialog, which) -> {
copyText(fullLog);
dialog.dismiss();
})
.create();
alertDialog.show();
ScrollView scrollView = dialogView.findViewById(R.id.errorView);

ViewGroup.LayoutParams params = scrollView.getLayoutParams();
params.height = (int) (rss.getDisplayMetrics().heightPixels * 0.5);
scrollView.setLayoutParams(params);
}));
}
}
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/reandroid/apkeditor/merge/Merger.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.content.Context;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;

import com.abdurazaaqmohammed.AntiSplit.R;
Expand Down Expand Up @@ -218,12 +219,12 @@ public static void run(ApkBundle bundle, File cacheDir, Uri out, Context context
logMessage(MainActivity.rss.getString(R.string.signing));
boolean noPerm = MainActivity.doesNotHaveStoragePerm(context);
String p;
File stupid = signedApk = new File(noPerm || (noPerm = TextUtils.isEmpty(p = FileUtils.getPath(out, context))) ? (cacheDir + File.separator + "stupid.apk") : p);
File stupid = new File(noPerm || (noPerm = TextUtils.isEmpty(p = FileUtils.getPath(out, context))) ? (cacheDir + File.separator + "stupid.apk") : p);
try {
SignUtil.signDebugKey(context, temp, stupid);
if (noPerm) try(OutputStream os = context.getContentResolver().openOutputStream(out)) {
if (noPerm) try(OutputStream os = context.getContentResolver().openOutputStream(signedApk = out)) {
FileUtils.copyFile(stupid, os);
}
} else signedApk = FileProvider.getUriForFile(context, "com.abdurazaaqmohammed.AntiSplit.provider", stupid);
} catch (Exception e) {
SignUtil.signPseudoApkSigner(temp, context, out, e);
}
Expand All @@ -233,7 +234,7 @@ public static void run(ApkBundle bundle, File cacheDir, Uri out, Context context
}
}

public static File signedApk;
public static Uri signedApk;

public static void run(Uri in, File cacheDir, Uri out, Context context, List<String> splits, boolean signApk) throws Exception {
logMessage(com.abdurazaaqmohammed.AntiSplit.main.MainActivity.rss.getString(R.string.searching));
Expand Down
33 changes: 3 additions & 30 deletions app/src/main/res/layout/dialog_button_layout.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/errorView"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_gravity="center_vertical"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/negativeButton"
style="@style/Widget.Material3.Button.IconButton"
app:icon="@android:drawable/ic_menu_close_clear_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/positiveButton"
style="@style/Widget.Material3.Button.IconButton"
app:icon="@android:drawable/ic_menu_upload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/neutralButton"
style="@style/Widget.Material3.Button.IconButton"
app:icon="@drawable/copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -48,4 +21,4 @@
android:layout_height="wrap_content"/>
</com.google.android.material.card.MaterialCardView>

</LinearLayout>
</ScrollView>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/dialog_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="🔍"
android:hint=""
app:endIconMode="clear_text"
app:boxBackgroundMode="outline"
android:layout_marginStart="16dp"
android:layout_marginTop="5dp"
app:boxCornerRadiusTopStart="24dp"
app:boxCornerRadiusTopEnd="24dp"
app:boxCornerRadiusBottomStart="24dp"
Expand Down

0 comments on commit 02d1280

Please sign in to comment.