From d5b500585f342ee61e0f9c959acfb8b6b25b5cd6 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 11 May 2023 21:31:30 -0400 Subject: [PATCH] fully fix version code ignoring Signed-off-by: androidacy-user --- app/build.gradle.kts | 2 +- .../background/BackgroundUpdateChecker.java | 27 ++++++++---- .../com/fox2code/mmm/module/ModuleHolder.java | 42 ++++++++++--------- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ce280f3..bac9414 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -38,7 +38,7 @@ android { applicationId = "com.fox2code.mmm" minSdk = 24 targetSdk = 33 - versionCode = 72 + versionCode = 73 versionName = "2.1.1" vectorDrawables { useSupportLibrary = true diff --git a/app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java b/app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java index a6dbcb3..959c867 100644 --- a/app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java +++ b/app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java @@ -147,9 +147,12 @@ public class BackgroundUpdateChecker extends Worker { // oh, and because i hate myself, i made ^ at the beginning match that version and newer, and $ at the end match that version and older Set stringSet = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>()); String version = ""; - if (stringSet.contains(localModuleInfo.id)) { - // get the one matching - version = stringSet.stream().filter(s -> s.startsWith(localModuleInfo.id)).findFirst().orElse(""); + for (String s : stringSet) { + if (s.startsWith(localModuleInfo.id)) { + version = s; + Timber.d("igV: %s", version); + break; + } } RepoModule repoModule = repoModules.get(localModuleInfo.id); localModuleInfo.checkModuleUpdate(); @@ -158,24 +161,30 @@ public class BackgroundUpdateChecker extends Worker { remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode); } if (!version.isEmpty()) { - int localVersionCode = Integer.parseInt(String.valueOf(localModuleInfo.versionCode)); + Timber.d("igV found: %s", version); int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode); int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", "")); // now find out if user wants up to and including this version, or this version and newer // if it starts with ^, it's this version and newer, if it ends with $, it's this version and older + version = version.split(":")[1]; if (version.startsWith("^")) { - // this version and newer - if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) { + Timber.d("igV: newer"); + // the wantsversion and newer + if (remoteVersionCodeInt >= wantsVersion) { + Timber.d("igV: skipping"); // if it is, we skip it continue; } } else if (version.endsWith("$")) { - // this version and older - if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) { + Timber.d("igV: older"); + // this wantsversion and older + if (remoteVersionCodeInt <= wantsVersion) { + Timber.d("igV: skipping"); // if it is, we skip it continue; } - } else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) { + } else if (wantsVersion == remoteVersionCodeInt) { + Timber.d("igV: equal"); // if it is, we skip it continue; } diff --git a/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java b/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java index 98461c9..6be3d0e 100644 --- a/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java +++ b/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java @@ -148,13 +148,15 @@ public final class ModuleHolder implements Comparable { // oh, and because i hate myself, i made ^ at the beginning match that version and newer, and $ at the end match that version and older Set stringSetT = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>()); String version = ""; - Set stringSet = stringSetT; - Timber.d(stringSet.toString()); - if (stringSet.contains(this.moduleInfo.id)) { - // get the one matching - Timber.d("found mod in ig ver"); - version = stringSet.stream().filter(s -> s.startsWith(this.moduleInfo.id)).findFirst().orElse(""); - Timber.d("igV:%s", version); + Timber.d(stringSetT.toString()); + // unfortunately, stringsett.contains() doesn't work for partial matches + // so we have to iterate through the set + for (String s : stringSetT) { + if (s.startsWith(this.moduleInfo.id)) { + version = s; + Timber.d("igV: %s", version); + break; + } } String remoteVersionCode = String.valueOf(moduleInfo.updateVersionCode); if (repoModule != null) { @@ -162,32 +164,34 @@ public final class ModuleHolder implements Comparable { } if (!version.isEmpty()) { // now, coerce everything into an int - int localVersionCode = Integer.parseInt(String.valueOf(moduleInfo.versionCode)); int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode); int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", "")); // now find out if user wants up to and including this version, or this version and newer - // if it starts with ^, it's this version and newer, if it ends with $, it's this version and older + Timber.d("igV start with"); + version = version.split(":")[1]; + // this version and newer if (version.startsWith("^")) { - Timber.d("igV start with"); - // this version and newer - if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) { + Timber.d("igV: newer"); + // the wantsversion and newer + if (remoteVersionCodeInt >= wantsVersion) { + Timber.d("igV: skipping"); // if it is, we skip it - Timber.d("igu true"); ignoreUpdate = true; } } else if (version.endsWith("$")) { - Timber.d("igV end with"); - // this version and older - if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) { + Timber.d("igV: older"); + // this wantsversion and older + if (remoteVersionCodeInt <= wantsVersion) { + Timber.d("igV: skipping"); // if it is, we skip it - Timber.d("igu true"); ignoreUpdate = true; } - } else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) { + } else if (wantsVersion == remoteVersionCodeInt) { + Timber.d("igV: equal"); // if it is, we skip it - Timber.d("igu true"); ignoreUpdate = true; } + } if (ignoreUpdate) { Timber.d("Module %s has update, but is ignored", this.moduleId);