Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit b112330

Browse files
committed
Fix modules json self update mechanism! (Fix #49)
1 parent 44472aa commit b112330

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

app/src/main/java/com/fox2code/mmm/ActionButtonType.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
import com.fox2code.mmm.manager.LocalModuleInfo;
1616
import com.fox2code.mmm.manager.ModuleInfo;
1717
import com.fox2code.mmm.manager.ModuleManager;
18+
import com.fox2code.mmm.utils.Http;
1819
import com.fox2code.mmm.utils.IntentHelper;
1920
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
2021

22+
import java.nio.charset.StandardCharsets;
23+
24+
import io.noties.markwon.Markwon;
25+
2126
public enum ActionButtonType {
2227
INFO(R.drawable.ic_baseline_info_24) {
2328
@Override
@@ -71,28 +76,23 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
7176
new MaterialAlertDialogBuilder(button.getContext());
7277
builder.setTitle(moduleInfo.name).setCancelable(true)
7378
.setIcon(R.drawable.ic_baseline_extension_24);
74-
String desc;
79+
CharSequence desc = moduleInfo.description;
80+
final boolean noPatch;
7581
if (moduleInfo instanceof LocalModuleInfo) {
7682
LocalModuleInfo localModuleInfo = (LocalModuleInfo) moduleInfo;
77-
desc = localModuleInfo.updateChangeLog.isEmpty() ?
78-
moduleInfo.description : localModuleInfo.updateChangeLog;
83+
if (!localModuleInfo.updateChangeLog.isEmpty()) {
84+
Markwon markwon = MainApplication.getINSTANCE().getMarkwon();
85+
// Re-render each time in cse of config changes
86+
desc = markwon.render(markwon.parse(localModuleInfo.updateChangeLog));
87+
}
88+
noPatch = true;
7989
} else {
80-
desc = moduleInfo.description;
90+
noPatch = false;
8191
}
8292

83-
if (desc == null || desc.isEmpty()) {
93+
if (desc == null || desc.length() == 0) {
8494
builder.setMessage(R.string.no_desc_found);
8595
} else {
86-
if (desc.length() == 1000) {
87-
int lastDot = desc.lastIndexOf('.');
88-
if (lastDot == -1) {
89-
int lastSpace = desc.lastIndexOf(' ');
90-
if (lastSpace == -1)
91-
desc = desc.substring(0, lastSpace);
92-
} else {
93-
desc = desc.substring(0, lastDot + 1);
94-
}
95-
}
9696
builder.setMessage(desc);
9797
}
9898
Log.d("Test", "URL: " + updateZipUrl);
@@ -103,7 +103,7 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
103103
R.string.update_module : R.string.install_module, (x, y) -> {
104104
String updateZipChecksum = moduleHolder.getUpdateZipChecksum();
105105
IntentHelper.openInstaller(button.getContext(), updateZipUrl,
106-
moduleInfo.name, moduleInfo.config, updateZipChecksum);
106+
moduleInfo.name, moduleInfo.config, updateZipChecksum, noPatch);
107107
});
108108
}
109109
int dim5dp = CompatDisplay.dpToPixel(5);

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ public void install(String moduleUrl, String installTitle,String checksum) {
8686
Uri uri = Uri.parse(moduleUrl);
8787
if (uri.getScheme().equals("https") && uri.getHost().endsWith(".androidacy.com")) {
8888
this.activity.backOnResume = true;
89-
IntentHelper.openInstaller(this.activity,
90-
moduleUrl, installTitle, null, checksum);
89+
IntentHelper.openInstaller(
90+
this.activity, moduleUrl, installTitle,
91+
null, checksum, true);
9192
} else {
9293
this.activity.forceBackPressed();
9394
}

app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
import org.json.JSONObject;
1010

11+
import java.io.IOException;
1112
import java.nio.charset.StandardCharsets;
1213

14+
import io.noties.markwon.Markwon;
15+
1316
public class LocalModuleInfo extends ModuleInfo {
1417
public String updateVersion;
1518
public long updateVersionCode = Long.MIN_VALUE;
1619
public String updateZipUrl;
20+
public String updateChangeLogUrl;
1721
public String updateChangeLog = "";
1822
public String updateChecksum;
1923

@@ -25,11 +29,21 @@ public void checkModuleUpdate() {
2529
if (this.updateJson != null) {
2630
try {
2731
JSONObject jsonUpdate = new JSONObject(new String(Http.doHttpGet(
28-
this.updateJson, false), StandardCharsets.UTF_8));
32+
this.updateJson, true), StandardCharsets.UTF_8));
2933
this.updateVersion = jsonUpdate.optString("version");
3034
this.updateVersionCode = jsonUpdate.getLong("versionCode");
3135
this.updateZipUrl = jsonUpdate.getString("zipUrl");
32-
this.updateChangeLog = jsonUpdate.optString("changelog");
36+
this.updateChangeLogUrl = jsonUpdate.optString("changelog");
37+
try {
38+
String desc = new String(Http.doHttpGet(
39+
this.updateChangeLogUrl, true), StandardCharsets.UTF_8);
40+
if (desc.length() > 1000) {
41+
desc = desc.substring(0, 1000);
42+
}
43+
this.updateChangeLog = desc;
44+
} catch (IOException ioe) {
45+
this.updateChangeLog = "";
46+
}
3347
this.updateChecksum = jsonUpdate.optString("checksum");
3448
if (this.updateZipUrl.isEmpty()) throw FastException.INSTANCE;
3549
this.updateVersion = PropUtils.shortenVersionName(

app/src/main/java/com/fox2code/mmm/utils/IntentHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ public static void openInstaller(Context context, String url, String title,
125125
openInstaller(context, url, title, config, checksum, false, false);
126126
}
127127

128+
public static void openInstaller(Context context, String url, String title, String config,
129+
String checksum, boolean noPatch) {
130+
openInstaller(context, url, title, config, checksum, noPatch, false);
131+
}
132+
128133
public static void openInstaller(Context context, String url, String title, String config,
129134
String checksum, boolean noPatch,boolean testDebug) {
130135
try {

0 commit comments

Comments
 (0)