Skip to content

Commit

Permalink
fully fix version code ignoring
Browse files Browse the repository at this point in the history
Signed-off-by: androidacy-user <[email protected]>
  • Loading branch information
androidacy-user committed May 12, 2023
1 parent 8d7f919 commit d5b5005
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
applicationId = "com.fox2code.mmm"
minSdk = 24
targetSdk = 33
versionCode = 72
versionCode = 73
versionName = "2.1.1"
vectorDrawables {
useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@ static void doCheck(Context context) {
// 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<>());
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();
Expand All @@ -158,24 +161,30 @@ static void doCheck(Context context) {
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;
}
Expand Down
42 changes: 23 additions & 19 deletions app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,46 +148,50 @@ public Type getType() {
// 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<>());
String version = "";
Set<String> 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) {
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
}
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);
Expand Down

0 comments on commit d5b5005

Please sign in to comment.