From 7987aea230750ae21c4d49d10629ea75143af796 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Mon, 1 May 2023 17:36:34 -0400 Subject: [PATCH] fix online repo Signed-off-by: androidacy-user --- .../java/com/fox2code/mmm/MainActivity.java | 1 + .../com/fox2code/mmm/module/ModuleHolder.java | 102 +++++++----------- 2 files changed, 37 insertions(+), 66 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/MainActivity.java b/app/src/main/java/com/fox2code/mmm/MainActivity.java index 4a9a900..dcc3adf 100644 --- a/app/src/main/java/com/fox2code/mmm/MainActivity.java +++ b/app/src/main/java/com/fox2code/mmm/MainActivity.java @@ -532,6 +532,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe if (BuildConfig.DEBUG) Timber.i("Apply"); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilderOnline::appendRemoteModules); Timber.i("Common Before applyTo"); + moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter); moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline); Timber.i("Common After"); } 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 3988631..7f5648a 100644 --- a/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java +++ b/app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java @@ -72,30 +72,19 @@ public final class ModuleHolder implements Comparable { } public ModuleInfo getMainModuleInfo() { - return this.repoModule != null && (this.moduleInfo == null || - this.moduleInfo.versionCode < this.repoModule.moduleInfo.versionCode) - ? this.repoModule.moduleInfo : this.moduleInfo; + return this.repoModule != null && (this.moduleInfo == null || this.moduleInfo.versionCode < this.repoModule.moduleInfo.versionCode) ? this.repoModule.moduleInfo : this.moduleInfo; } public String getUpdateZipUrl() { - return this.moduleInfo == null || (this.repoModule != null && - this.moduleInfo.updateVersionCode < - this.repoModule.moduleInfo.versionCode) ? - this.repoModule.zipUrl : this.moduleInfo.updateZipUrl; + return this.moduleInfo == null || (this.repoModule != null && this.moduleInfo.updateVersionCode < this.repoModule.moduleInfo.versionCode) ? this.repoModule.zipUrl : this.moduleInfo.updateZipUrl; } public String getUpdateZipRepo() { - return this.moduleInfo == null || (this.repoModule != null && - this.moduleInfo.updateVersionCode < - this.repoModule.moduleInfo.versionCode) ? - this.repoModule.repoData.id : "update_json"; + return this.moduleInfo == null || (this.repoModule != null && this.moduleInfo.updateVersionCode < this.repoModule.moduleInfo.versionCode) ? this.repoModule.repoData.id : "update_json"; } public String getUpdateZipChecksum() { - return this.moduleInfo == null || (this.repoModule != null && - this.moduleInfo.updateVersionCode < - this.repoModule.moduleInfo.versionCode) ? - this.repoModule.checksum : this.moduleInfo.updateChecksum; + return this.moduleInfo == null || (this.repoModule != null && this.moduleInfo.updateVersionCode < this.repoModule.moduleInfo.versionCode) ? this.repoModule.checksum : this.moduleInfo.updateChecksum; } public String getMainModuleName() { @@ -121,8 +110,7 @@ public final class ModuleHolder implements Comparable { public String getUpdateTimeText() { if (this.repoModule == null) return ""; long timeStamp = this.repoModule.lastUpdated; - return timeStamp <= 0 ? "" : - MainApplication.formatTime(timeStamp); + return timeStamp <= 0 ? "" : MainApplication.formatTime(timeStamp); } public String getRepoName() { @@ -135,19 +123,19 @@ public final class ModuleHolder implements Comparable { } public Type getType() { - Timber.d("Getting type for %s", this.moduleId); if (this.footerPx != -1) { + Timber.i("Module %s is footer", this.moduleId); return Type.FOOTER; } else if (this.separator != null) { + Timber.i("Module %s is separator", this.moduleId); + Thread.dumpStack(); return Type.SEPARATOR; } else if (this.notificationType != null) { + Timber.i("Module %s is notification", this.moduleId); return Type.NOTIFICATION; } else if (this.moduleInfo == null) { - Timber.d("Module %s is not installed", this.moduleId); return Type.INSTALLABLE; - } else if (this.moduleInfo.versionCode < this.moduleInfo.updateVersionCode || - (this.repoModule != null && this.moduleInfo.versionCode < - this.repoModule.moduleInfo.versionCode)) { + } else if (this.moduleInfo.versionCode < this.moduleInfo.updateVersionCode || (this.repoModule != null && this.moduleInfo.versionCode < this.repoModule.moduleInfo.versionCode)) { Timber.d("Module %s has update", this.moduleId); MainApplication.getINSTANCE().modulesHaveUpdates = true; if (!MainApplication.getINSTANCE().updateModules.contains(this.moduleId)) { @@ -158,7 +146,6 @@ public final class ModuleHolder implements Comparable { Timber.d("Module %s has update", this.moduleId); return Type.UPDATABLE; } else { - Timber.d("Module %s is installed", this.moduleId); return Type.INSTALLED; } } @@ -166,8 +153,7 @@ public final class ModuleHolder implements Comparable { public Type getCompareType(Type type) { if (this.separator != null) { return this.separator; - } else if (this.notificationType != null && - this.notificationType.special) { + } else if (this.notificationType != null && this.notificationType.special) { return Type.SPECIAL_NOTIFICATIONS; } else { return type; @@ -175,11 +161,12 @@ public final class ModuleHolder implements Comparable { } public boolean shouldRemove() { - return this.notificationType != null ? this.notificationType.shouldRemove() : - this.footerPx == -1 && this.moduleInfo == null && - (this.repoModule == null || !this.repoModule.repoData.isEnabled() || - (PropUtils.isLowQualityModule(this.repoModule.moduleInfo) && - !MainApplication.isDisableLowQualityModuleFilter())); + // okay so this is quite possibly the hackiest fucking piece of code i've ever written + // basically, if we have a repomodule that has moduleinfo but no update, remove it- + if (this.repoModule != null && this.moduleInfo != null && !hasUpdate()) { + return true; + } + return this.notificationType != null ? this.notificationType.shouldRemove() : this.footerPx == -1 && this.moduleInfo == null && (this.repoModule == null || !this.repoModule.repoData.isEnabled() || (PropUtils.isLowQualityModule(this.repoModule.moduleInfo) && !MainApplication.isDisableLowQualityModuleFilter())); } public void getButtons(Context context, List buttonTypeList, boolean showcaseMode) { @@ -195,8 +182,7 @@ public final class ModuleHolder implements Comparable { if (this.repoModule != null && this.repoModule.notesUrl != null) { buttonTypeList.add(ActionButtonType.INFO); } - if ((this.repoModule != null || (localModuleInfo != null && - localModuleInfo.updateZipUrl != null))) { + if ((this.repoModule != null || (localModuleInfo != null && localModuleInfo.updateZipUrl != null))) { buttonTypeList.add(ActionButtonType.UPDATE_INSTALL); } String config = this.getMainModuleConfig(); @@ -209,8 +195,7 @@ public final class ModuleHolder implements Comparable { XHooks.checkConfigTargetExists(context, pkg, config); buttonTypeList.add(ActionButtonType.CONFIG); } catch (PackageManager.NameNotFoundException e) { - Timber.w("Config package \"" + pkg + - "\" missing for module \"" + this.moduleId + "\""); + Timber.w("Config package \"" + pkg + "\" missing for module \"" + this.moduleId + "\""); } } } @@ -233,8 +218,7 @@ public final class ModuleHolder implements Comparable { } public boolean hasUpdate() { - return this.moduleInfo != null && this.repoModule != null && - this.moduleInfo.versionCode < this.repoModule.moduleInfo.versionCode; + return this.moduleInfo != null && this.repoModule != null && this.moduleInfo.versionCode < this.repoModule.moduleInfo.versionCode; } @Override @@ -245,29 +229,30 @@ public final class ModuleHolder implements Comparable { Type selfType = this.getCompareType(selfTypeReal); Type otherType = o.getCompareType(otherTypeReal); int compare = selfType.compareTo(otherType); - return compare != 0 ? compare : - selfTypeReal == otherTypeReal ? - selfTypeReal.compare(this, o) : - selfTypeReal.compareTo(otherTypeReal); + return compare != 0 ? compare : selfTypeReal == otherTypeReal ? selfTypeReal.compare(this, o) : selfTypeReal.compareTo(otherTypeReal); + } + + @NonNull + @Override + public String toString() { + return "ModuleHolder{" + "moduleId='" + moduleId + '\'' + ", notificationType=" + notificationType + ", separator=" + separator + ", footerPx=" + footerPx + '}'; } public enum Type implements Comparator { - HEADER(R.string.loading, false, false), - SEPARATOR(R.string.loading, false, false) { + HEADER(R.string.loading, false, false), SEPARATOR(R.string.loading, false, false) { @Override @SuppressWarnings("ConstantConditions") public int compare(ModuleHolder o1, ModuleHolder o2) { return o1.separator.compareTo(o2.separator); } - }, - NOTIFICATION(R.string.loading, true, false) { + }, NOTIFICATION(R.string.loading, true, false) { @Override @SuppressWarnings("ConstantConditions") public int compare(ModuleHolder o1, ModuleHolder o2) { + Thread.dumpStack(); return o1.notificationType.compareTo(o2.notificationType); } - }, - UPDATABLE(R.string.updatable, true, true) { + }, UPDATABLE(R.string.updatable, true, true) { @Override public int compare(ModuleHolder o1, ModuleHolder o2) { int cmp = Integer.compare(o1.filterLevel, o2.filterLevel); @@ -278,18 +263,15 @@ public final class ModuleHolder implements Comparable { if (cmp != 0) return cmp; return o1.getMainModuleName().compareTo(o2.getMainModuleName()); } - }, - INSTALLED(R.string.installed, true, true) { + }, INSTALLED(R.string.installed, true, true) { + // get stacktrace for debugging @Override public int compare(ModuleHolder o1, ModuleHolder o2) { int cmp = Integer.compare(o1.filterLevel, o2.filterLevel); if (cmp != 0) return cmp; - return o1.getMainModuleNameLowercase() - .compareTo(o2.getMainModuleNameLowercase()); + return o1.getMainModuleNameLowercase().compareTo(o2.getMainModuleNameLowercase()); } - }, - SPECIAL_NOTIFICATIONS(R.string.loading, true, false), - INSTALLABLE(R.string.online_repo, true, true) { + }, SPECIAL_NOTIFICATIONS(R.string.loading, true, false), INSTALLABLE(R.string.online_repo, true, true) { @Override public int compare(ModuleHolder o1, ModuleHolder o2) { int cmp = Integer.compare(o1.filterLevel, o2.filterLevel); @@ -300,8 +282,7 @@ public final class ModuleHolder implements Comparable { if (cmp != 0) return cmp; return o1.getMainModuleName().compareTo(o2.getMainModuleName()); } - }, - FOOTER(R.string.loading, false, false); + }, FOOTER(R.string.loading, false, false); @StringRes public final int title; @@ -328,15 +309,4 @@ public final class ModuleHolder implements Comparable { } } } - - @NonNull - @Override - public String toString() { - return "ModuleHolder{" + - "moduleId='" + moduleId + '\'' + - ", notificationType=" + notificationType + - ", separator=" + separator + - ", footerPx=" + footerPx + - '}'; - } }