fully fix version code ignoring

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 2 years ago
parent 8d7f919464
commit d5b500585f

@ -38,7 +38,7 @@ android {
applicationId = "com.fox2code.mmm" applicationId = "com.fox2code.mmm"
minSdk = 24 minSdk = 24
targetSdk = 33 targetSdk = 33
versionCode = 72 versionCode = 73
versionName = "2.1.1" versionName = "2.1.1"
vectorDrawables { vectorDrawables {
useSupportLibrary = true useSupportLibrary = true

@ -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 // 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<String> stringSet = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>()); Set<String> stringSet = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>());
String version = ""; String version = "";
if (stringSet.contains(localModuleInfo.id)) { for (String s : stringSet) {
// get the one matching if (s.startsWith(localModuleInfo.id)) {
version = stringSet.stream().filter(s -> s.startsWith(localModuleInfo.id)).findFirst().orElse(""); version = s;
Timber.d("igV: %s", version);
break;
}
} }
RepoModule repoModule = repoModules.get(localModuleInfo.id); RepoModule repoModule = repoModules.get(localModuleInfo.id);
localModuleInfo.checkModuleUpdate(); localModuleInfo.checkModuleUpdate();
@ -158,24 +161,30 @@ public class BackgroundUpdateChecker extends Worker {
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode); remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
} }
if (!version.isEmpty()) { if (!version.isEmpty()) {
int localVersionCode = Integer.parseInt(String.valueOf(localModuleInfo.versionCode)); Timber.d("igV found: %s", version);
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode); int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", "")); 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 // 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 // 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("^")) { if (version.startsWith("^")) {
// this version and newer Timber.d("igV: newer");
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) { // the wantsversion and newer
if (remoteVersionCodeInt >= wantsVersion) {
Timber.d("igV: skipping");
// if it is, we skip it // if it is, we skip it
continue; continue;
} }
} else if (version.endsWith("$")) { } else if (version.endsWith("$")) {
// this version and older Timber.d("igV: older");
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) { // this wantsversion and older
if (remoteVersionCodeInt <= wantsVersion) {
Timber.d("igV: skipping");
// if it is, we skip it // if it is, we skip it
continue; continue;
} }
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) { } else if (wantsVersion == remoteVersionCodeInt) {
Timber.d("igV: equal");
// if it is, we skip it // if it is, we skip it
continue; continue;
} }

@ -148,13 +148,15 @@ public final class ModuleHolder implements Comparable<ModuleHolder> {
// 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 // 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<String> stringSetT = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>()); Set<String> stringSetT = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>());
String version = ""; String version = "";
Set<String> stringSet = stringSetT; Timber.d(stringSetT.toString());
Timber.d(stringSet.toString()); // unfortunately, stringsett.contains() doesn't work for partial matches
if (stringSet.contains(this.moduleInfo.id)) { // so we have to iterate through the set
// get the one matching for (String s : stringSetT) {
Timber.d("found mod in ig ver"); if (s.startsWith(this.moduleInfo.id)) {
version = stringSet.stream().filter(s -> s.startsWith(this.moduleInfo.id)).findFirst().orElse(""); version = s;
Timber.d("igV:%s", version); Timber.d("igV: %s", version);
break;
}
} }
String remoteVersionCode = String.valueOf(moduleInfo.updateVersionCode); String remoteVersionCode = String.valueOf(moduleInfo.updateVersionCode);
if (repoModule != null) { if (repoModule != null) {
@ -162,32 +164,34 @@ public final class ModuleHolder implements Comparable<ModuleHolder> {
} }
if (!version.isEmpty()) { if (!version.isEmpty()) {
// now, coerce everything into an int // now, coerce everything into an int
int localVersionCode = Integer.parseInt(String.valueOf(moduleInfo.versionCode));
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode); int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", "")); 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 // 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("^")) { if (version.startsWith("^")) {
Timber.d("igV start with"); Timber.d("igV: newer");
// this version and newer // the wantsversion and newer
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) { if (remoteVersionCodeInt >= wantsVersion) {
Timber.d("igV: skipping");
// if it is, we skip it // if it is, we skip it
Timber.d("igu true");
ignoreUpdate = true; ignoreUpdate = true;
} }
} else if (version.endsWith("$")) { } else if (version.endsWith("$")) {
Timber.d("igV end with"); Timber.d("igV: older");
// this version and older // this wantsversion and older
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) { if (remoteVersionCodeInt <= wantsVersion) {
Timber.d("igV: skipping");
// if it is, we skip it // if it is, we skip it
Timber.d("igu true");
ignoreUpdate = true; ignoreUpdate = true;
} }
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) { } else if (wantsVersion == remoteVersionCodeInt) {
Timber.d("igV: equal");
// if it is, we skip it // if it is, we skip it
Timber.d("igu true");
ignoreUpdate = true; ignoreUpdate = true;
} }
} }
if (ignoreUpdate) { if (ignoreUpdate) {
Timber.d("Module %s has update, but is ignored", this.moduleId); Timber.d("Module %s has update, but is ignored", this.moduleId);

Loading…
Cancel
Save