Skip to content

Commit ae41a47

Browse files
partial impl of #9
also misc fixes Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 6408bb7 commit ae41a47

8 files changed

Lines changed: 63 additions & 20 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ dependencies {
413413
// implementation("com.google.protobuf:protobuf-javalite:3.22.2")
414414

415415
// google guava, maybe fix a bug
416-
implementation("com.google.guava:guava:31.1-jre")
416+
implementation("com.google.guava:guava:31.1-android")
417417

418418

419419
val libsuVersion = "5.0.5"

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.fox2code.foxcompat.app.FoxActivity;
1313
import com.fox2code.mmm.utils.io.net.Http;
1414
import com.google.android.material.bottomnavigation.BottomNavigationItemView;
15-
import com.google.android.material.button.MaterialButton;
15+
import com.google.android.material.bottomnavigation.BottomNavigationView;
1616
import com.google.android.material.progressindicator.LinearProgressIndicator;
1717
import com.google.android.material.textview.MaterialTextView;
1818

@@ -42,8 +42,9 @@ protected void onCreate(Bundle savedInstanceState) {
4242
// Get the progress bar and make it indeterminate for now
4343
LinearProgressIndicator progressIndicator = findViewById(R.id.update_progress);
4444
progressIndicator.setIndeterminate(true);
45-
// get update_cancel button
46-
MaterialButton updateCancel = findViewById(R.id.update_cancel_button);
45+
// get update_cancel item on bottom navigation
46+
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
47+
BottomNavigationItemView updateCancel = bottomNavigationView.findViewById(R.id.update_cancel_button);
4748
// get status text view
4849
MaterialTextView statusTextView = findViewById(R.id.update_progress_text);
4950
// set status text to please wait
@@ -85,8 +86,7 @@ public void run() {
8586
} else if (action == ACTIONS.DOWNLOAD) {
8687
try {
8788
downloadUpdate();
88-
} catch (
89-
JSONException e) {
89+
} catch (JSONException e) {
9090
runOnUiThread(() -> {
9191
// set status text to error
9292
statusTextView.setText(R.string.error_download_update);
@@ -97,7 +97,7 @@ public void run() {
9797
}
9898
} else if (action == ACTIONS.INSTALL) {
9999
// ensure path was passed and points to a file within our cache directory. replace .. and url encoded characters
100-
String path = getIntent().getStringExtra("path").trim().replaceAll("\\.\\.", "").replaceAll("%2e%2e", "");
100+
String path = Objects.requireNonNull(getIntent().getStringExtra("path")).trim().replaceAll("\\.\\.", "").replaceAll("%2e%2e", "");
101101
if (path.isEmpty()) {
102102
runOnUiThread(() -> {
103103
// set status text to error
@@ -119,8 +119,7 @@ public void run() {
119119
if (parentFile == null || !parentFile.getCanonicalPath().startsWith(getCacheDir().getCanonicalPath())) {
120120
throw new SecurityException("Path is not in cache directory: " + path);
121121
}
122-
} catch (
123-
IOException e) {
122+
} catch (IOException e) {
124123
throw new SecurityException("Path is not in cache directory: " + path);
125124
}
126125
if (!file.exists()) {
@@ -164,6 +163,7 @@ public void run() {
164163
updateThread.start();
165164
}
166165

166+
@SuppressLint("RestrictedApi")
167167
public void checkForUpdate() {
168168
// get status text view
169169
MaterialTextView statusTextView = findViewById(R.id.update_progress_text);
@@ -184,7 +184,9 @@ public void checkForUpdate() {
184184
statusTextView.setText(R.string.update_available);
185185
// set button text to download
186186
BottomNavigationItemView button = findViewById(R.id.action_update);
187-
button.setTooltipText(R.string.download_update);
187+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
188+
button.setTooltipText(getString(R.string.download_update));
189+
}
188190
button.setEnabled(true);
189191
});
190192
// return
@@ -211,8 +213,7 @@ public void downloadUpdate() throws JSONException {
211213
byte[] lastestJSON = new byte[0];
212214
try {
213215
lastestJSON = Http.doHttpGet(AppUpdateManager.RELEASES_API_URL, false);
214-
} catch (
215-
Exception e) {
216+
} catch (Exception e) {
216217
// when logging, REMOVE the json from the log
217218
Timber.e(e, "Error downloading update info");
218219
runOnUiThread(() -> {
@@ -274,8 +275,7 @@ public void downloadUpdate() throws JSONException {
274275
// update status text
275276
statusTextView.setText(getString(R.string.downloading_update, (int) (((float) downloaded / (float) total) * 100)));
276277
}));
277-
} catch (
278-
Exception e) {
278+
} catch (Exception e) {
279279
runOnUiThread(() -> {
280280
progressIndicator.setIndeterminate(false);
281281
progressIndicator.setProgressCompat(100, false);
@@ -320,8 +320,7 @@ public void downloadUpdate() throws JSONException {
320320
updateFile = new File(getCacheDir(), "update.apk");
321321
fileOutputStream = new FileOutputStream(updateFile);
322322
fileOutputStream.write(update);
323-
} catch (
324-
IOException e) {
323+
} catch (IOException e) {
325324
runOnUiThread(() -> {
326325
progressIndicator.setIndeterminate(false);
327326
progressIndicator.setProgressCompat(100, false);
@@ -333,8 +332,7 @@ public void downloadUpdate() throws JSONException {
333332
}
334333
try {
335334
Objects.requireNonNull(fileOutputStream).close();
336-
} catch (
337-
IOException ignored) {
335+
} catch (IOException ignored) {
338336
}
339337
}
340338
// install the update

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import androidx.annotation.Nullable;
77

88
import com.fox2code.mmm.BuildConfig;
9+
import com.fox2code.mmm.utils.io.net.Http;
910

11+
import java.io.IOException;
1012
import java.util.Objects;
1113

1214
public enum AndroidacyUtil {
@@ -103,4 +105,33 @@ public static String getChecksumFromURL(String moduleUrl) {
103105
}
104106
return null;
105107
}
108+
109+
/**
110+
* Check if the url is a premium direct download link
111+
* @param url url to check
112+
* @return true if it is a premium direct download link
113+
* @noinspection unused
114+
*/
115+
public static boolean isPremiumDirectDownloadLink(String url) {
116+
return url.contains("/magisk/ddl/");
117+
}
118+
119+
/**
120+
* Returns the markdown directly from the API for rendering. Premium only, and internal testing only currently.
121+
* @param url URL to get markdown from
122+
* @return String of markdown
123+
* @noinspection unused
124+
*/
125+
public static String getMarkdownFromAPI(String url) {
126+
byte[] md;
127+
try {
128+
md = Http.doHttpGet(url, false);
129+
} catch (IOException ignored) {
130+
return null;
131+
}
132+
if (md == null) {
133+
return null;
134+
}
135+
return new String(md);
136+
}
106137
}

app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ public boolean update(ModuleHolder moduleHolder) {
300300
} else {
301301
this.cardView.setClickable(moduleHolder.onClickListener != null);
302302
this.titleText.setTypeface(Typeface.DEFAULT);
303+
this.titleText.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium);
304+
this.titleText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19);
303305
}
304306
}
305307
if (type == ModuleHolder.Type.SEPARATOR) {

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
511511
}
512512
Preference debugNotification = findPreference("pref_background_update_check_debug");
513513
Preference updateCheckExcludes = findPreference("pref_background_update_check_excludes");
514+
Preference updateCheckVersionExcludes = findPreference("pref_background_update_check_excludes_version");
514515
debugNotification.setEnabled(MainApplication.isBackgroundUpdateCheckEnabled());
515516
debugNotification.setVisible(MainApplication.isDeveloper() && !MainApplication.isWrapped() && MainApplication.isBackgroundUpdateCheckEnabled());
516517
debugNotification.setOnPreferenceClickListener(preference -> {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,6 @@
416416
<string name="warning_pls_restart">Please note that some settings may not take effect until you restart the app.</string>
417417
<string name="reinstall">Reinstall</string>
418418
<string name="setup_scroll_down_v2">To enable the finish button, scroll to the bottom and acknowledge you have read and agree to the EULA and license(s).</string>
419+
<string name="notification_update_ignore_version_desc">Ignore specific versions when checking for module updates. Disabling update checks per-module above overrides this setting!</string>
420+
<string name="notification_update_ignore_version_pref">Exclude version(s) from update checks</string>
419421
</resources>

app/src/main/res/xml/root_preferences.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@
7373
app:summary="@string/notification_update_ignore_desc"
7474
app:title="@string/notification_update_ignore_pref" />
7575

76+
<!-- exclude specific versions -->
77+
78+
<Preference
79+
app:icon="@drawable/baseline_block_24"
80+
app:key="pref_background_update_check_excludes_version"
81+
app:singleLineTitle="false"
82+
app:summary="@string/notification_update_ignore_version_desc"
83+
app:title="@string/notification_update_ignore_version_pref" />
84+
7685
<Preference
7786
app:icon="@drawable/baseline_notification_important_24"
7887
app:key="pref_background_update_check_debug"

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
# This option should only be used with decoupled projects. More details, visit
1111
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1212
# org.gradle.parallel=true
13-
#Tue Apr 25 12:57:16 EDT 2023
13+
#Mon May 08 13:44:15 EDT 2023
1414
android.defaults.buildfeatures.buildconfig=true
1515
android.enableJetifier=false
1616
android.enableR8.fullMode=true
1717
android.useAndroidX=true
1818
org.gradle.caching=true
1919
org.gradle.configuration-cache=true
2020
org.gradle.configuration-cache.problems=warn
21-
org.gradle.jvmargs=-Xmx1536M -Dkotlin.daemon.jvm.options\="-Xmx1536M" -Dfile.encoding\=UTF-8 -XX\:+UseParallelGC -XX\:ReservedCodeCacheSize\=768m
21+
org.gradle.jvmargs=-Xmx1024M -Dkotlin.daemon.jvm.options\="-Xmx1024M" -Dfile.encoding\=UTF-8 -XX\:+UseParallelGC -XX\:ReservedCodeCacheSize\=768m
2222
org.gradle.parallel=true

0 commit comments

Comments
 (0)