Skip to content

Commit d5b5005

Browse files
fully fix version code ignoring
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 8d7f919 commit d5b5005

3 files changed

Lines changed: 42 additions & 29 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ android {
3838
applicationId = "com.fox2code.mmm"
3939
minSdk = 24
4040
targetSdk = 33
41-
versionCode = 72
41+
versionCode = 73
4242
versionName = "2.1.1"
4343
vectorDrawables {
4444
useSupportLibrary = true

app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ static void doCheck(Context context) {
147147
// 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
148148
Set<String> stringSet = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>());
149149
String version = "";
150-
if (stringSet.contains(localModuleInfo.id)) {
151-
// get the one matching
152-
version = stringSet.stream().filter(s -> s.startsWith(localModuleInfo.id)).findFirst().orElse("");
150+
for (String s : stringSet) {
151+
if (s.startsWith(localModuleInfo.id)) {
152+
version = s;
153+
Timber.d("igV: %s", version);
154+
break;
155+
}
153156
}
154157
RepoModule repoModule = repoModules.get(localModuleInfo.id);
155158
localModuleInfo.checkModuleUpdate();
@@ -158,24 +161,30 @@ static void doCheck(Context context) {
158161
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
159162
}
160163
if (!version.isEmpty()) {
161-
int localVersionCode = Integer.parseInt(String.valueOf(localModuleInfo.versionCode));
164+
Timber.d("igV found: %s", version);
162165
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
163166
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", ""));
164167
// now find out if user wants up to and including this version, or this version and newer
165168
// if it starts with ^, it's this version and newer, if it ends with $, it's this version and older
169+
version = version.split(":")[1];
166170
if (version.startsWith("^")) {
167-
// this version and newer
168-
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) {
171+
Timber.d("igV: newer");
172+
// the wantsversion and newer
173+
if (remoteVersionCodeInt >= wantsVersion) {
174+
Timber.d("igV: skipping");
169175
// if it is, we skip it
170176
continue;
171177
}
172178
} else if (version.endsWith("$")) {
173-
// this version and older
174-
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) {
179+
Timber.d("igV: older");
180+
// this wantsversion and older
181+
if (remoteVersionCodeInt <= wantsVersion) {
182+
Timber.d("igV: skipping");
175183
// if it is, we skip it
176184
continue;
177185
}
178-
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
186+
} else if (wantsVersion == remoteVersionCodeInt) {
187+
Timber.d("igV: equal");
179188
// if it is, we skip it
180189
continue;
181190
}

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,46 +148,50 @@ public Type getType() {
148148
// 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
149149
Set<String> stringSetT = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>());
150150
String version = "";
151-
Set<String> stringSet = stringSetT;
152-
Timber.d(stringSet.toString());
153-
if (stringSet.contains(this.moduleInfo.id)) {
154-
// get the one matching
155-
Timber.d("found mod in ig ver");
156-
version = stringSet.stream().filter(s -> s.startsWith(this.moduleInfo.id)).findFirst().orElse("");
157-
Timber.d("igV:%s", version);
151+
Timber.d(stringSetT.toString());
152+
// unfortunately, stringsett.contains() doesn't work for partial matches
153+
// so we have to iterate through the set
154+
for (String s : stringSetT) {
155+
if (s.startsWith(this.moduleInfo.id)) {
156+
version = s;
157+
Timber.d("igV: %s", version);
158+
break;
159+
}
158160
}
159161
String remoteVersionCode = String.valueOf(moduleInfo.updateVersionCode);
160162
if (repoModule != null) {
161163
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
162164
}
163165
if (!version.isEmpty()) {
164166
// now, coerce everything into an int
165-
int localVersionCode = Integer.parseInt(String.valueOf(moduleInfo.versionCode));
166167
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
167168
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", ""));
168169
// now find out if user wants up to and including this version, or this version and newer
169-
// if it starts with ^, it's this version and newer, if it ends with $, it's this version and older
170+
Timber.d("igV start with");
171+
version = version.split(":")[1];
172+
// this version and newer
170173
if (version.startsWith("^")) {
171-
Timber.d("igV start with");
172-
// this version and newer
173-
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) {
174+
Timber.d("igV: newer");
175+
// the wantsversion and newer
176+
if (remoteVersionCodeInt >= wantsVersion) {
177+
Timber.d("igV: skipping");
174178
// if it is, we skip it
175-
Timber.d("igu true");
176179
ignoreUpdate = true;
177180
}
178181
} else if (version.endsWith("$")) {
179-
Timber.d("igV end with");
180-
// this version and older
181-
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) {
182+
Timber.d("igV: older");
183+
// this wantsversion and older
184+
if (remoteVersionCodeInt <= wantsVersion) {
185+
Timber.d("igV: skipping");
182186
// if it is, we skip it
183-
Timber.d("igu true");
184187
ignoreUpdate = true;
185188
}
186-
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
189+
} else if (wantsVersion == remoteVersionCodeInt) {
190+
Timber.d("igV: equal");
187191
// if it is, we skip it
188-
Timber.d("igu true");
189192
ignoreUpdate = true;
190193
}
194+
191195
}
192196
if (ignoreUpdate) {
193197
Timber.d("Module %s has update, but is ignored", this.moduleId);

0 commit comments

Comments
 (0)