Skip to content

Commit 4162230

Browse files
ignore updates in UI too
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 295e847 commit 4162230

1 file changed

Lines changed: 52 additions & 3 deletions

File tree

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

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import com.fox2code.mmm.utils.io.net.Http;
2020

2121
import java.util.Comparator;
22+
import java.util.HashSet;
2223
import java.util.List;
2324
import java.util.Locale;
2425
import java.util.Objects;
26+
import java.util.Set;
2527

2628
import timber.log.Timber;
2729

@@ -135,13 +137,62 @@ public Type getType() {
135137
} else if (this.moduleInfo == null) {
136138
return Type.INSTALLABLE;
137139
} else if (this.moduleInfo.versionCode < this.moduleInfo.updateVersionCode || (this.repoModule != null && this.moduleInfo.versionCode < this.repoModule.moduleInfo.versionCode)) {
138-
Timber.d("Module %s has update", this.moduleId);
140+
boolean ignoreUpdate = false;
141+
try {
142+
if (Objects.requireNonNull(MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes", new HashSet<>())).contains(moduleInfo.id))
143+
ignoreUpdate = true;
144+
} catch (Exception ignored) {
145+
}
146+
// now, we just had to make it more fucking complicated, didn't we?
147+
// we now have pref_background_update_check_excludes_version, which is a id:version stringset of versions the user may want to "skip"
148+
// 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
149+
Set<String> stringSet = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>());
150+
String version = "";
151+
if (stringSet.contains(moduleInfo.id)) {
152+
// get the one matching
153+
version = stringSet.stream().filter(s -> s.startsWith(moduleInfo.id)).findFirst().orElse("");
154+
}
155+
String remoteVersion = moduleInfo.updateVersion;
156+
String remoteVersionCode = String.valueOf(moduleInfo.updateVersionCode);
157+
if (repoModule != null) {
158+
remoteVersion = repoModule.moduleInfo.version;
159+
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
160+
}
161+
// now, coerce everything into an int
162+
int localVersionCode = Integer.parseInt(String.valueOf(moduleInfo.versionCode));
163+
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
164+
// we also have to match the version name
165+
int localVersion = Integer.parseInt(moduleInfo.version);
166+
int remoteVersionInt = Integer.parseInt(remoteVersion);
167+
int wantsVersion = Integer.parseInt(version.split(":")[1]);
168+
// 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+
if (version.startsWith("^")) {
171+
// this version and newer
172+
if (wantsVersion > localVersion || wantsVersion > remoteVersionInt || wantsVersion > remoteVersionCodeInt || wantsVersion < localVersionCode) {
173+
// if it is, we skip it
174+
ignoreUpdate = true;
175+
}
176+
} else if (version.endsWith("$")) {
177+
// this version and older
178+
if (wantsVersion < localVersion || wantsVersion < remoteVersionInt || wantsVersion < remoteVersionCodeInt || wantsVersion > localVersionCode) {
179+
// if it is, we skip it
180+
ignoreUpdate = true;
181+
}
182+
} else if (wantsVersion == localVersion || wantsVersion == remoteVersionInt || wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
183+
// if it is, we skip it
184+
ignoreUpdate = true;
185+
}
139186
MainApplication.getINSTANCE().modulesHaveUpdates = true;
140187
if (!MainApplication.getINSTANCE().updateModules.contains(this.moduleId)) {
141188
MainApplication.getINSTANCE().updateModules.add(this.moduleId);
142189
MainApplication.getINSTANCE().updateModuleCount++;
143190
}
144191
Timber.d("modulesHaveUpdates = %s, updateModuleCount = %s", MainApplication.getINSTANCE().modulesHaveUpdates, MainApplication.getINSTANCE().updateModuleCount);
192+
if (ignoreUpdate) {
193+
Timber.d("Module %s has update, but is ignored", this.moduleId);
194+
return Type.INSTALLABLE;
195+
}
145196
Timber.d("Module %s has update", this.moduleId);
146197
return Type.UPDATABLE;
147198
} else {
@@ -160,8 +211,6 @@ public Type getCompareType(Type type) {
160211
}
161212

162213
public boolean shouldRemove() {
163-
// okay so this is quite possibly the hackiest fucking piece of code i've ever written
164-
// basically, if we have a repomodule that has moduleinfo but no update, remove it-
165214
if (this.repoModule != null && this.moduleInfo != null && !hasUpdate()) {
166215
return true;
167216
}

0 commit comments

Comments
 (0)