From f1a6c6a2bf109143c6731f97db9d6e484f3a1a41 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Fri, 10 Feb 2023 21:31:14 -0500 Subject: [PATCH] more work on trying to fix cache Signed-off-by: androidacy-user --- .../java/com/fox2code/mmm/MainActivity.java | 2 +- .../mmm/androidacy/AndroidacyRepoData.java | 1 + .../java/com/fox2code/mmm/repo/RepoData.java | 7 +++++++ .../com/fox2code/mmm/repo/RepoManager.java | 2 ++ .../com/fox2code/mmm/repo/RepoModule.java | 20 +++++++++++++++++++ .../com/fox2code/mmm/repo/RepoUpdater.java | 2 +- .../com/fox2code/mmm/utils/io/PropUtils.java | 3 ++- app/src/main/res/layout/module_entry.xml | 10 +++++++++- 8 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/MainActivity.java b/app/src/main/java/com/fox2code/mmm/MainActivity.java index dce3cf6..e7e9b83 100644 --- a/app/src/main/java/com/fox2code/mmm/MainActivity.java +++ b/app/src/main/java/com/fox2code/mmm/MainActivity.java @@ -545,7 +545,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder); RepoManager.getINSTANCE().updateEnabledStates(); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilderOnline::appendRemoteModules); - this.moduleViewListBuilderOnline.applyTo(moduleList, moduleViewAdapter); + this.moduleViewListBuilderOnline.applyTo(moduleListOnline, moduleViewAdapterOnline); }, "Repo update thread").start(); } diff --git a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java index 34449f9..87601e0 100644 --- a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java +++ b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java @@ -359,6 +359,7 @@ public final class AndroidacyRepoData extends RepoData { moduleInfo.mmtReborn = jsonObject.optBoolean("mmtReborn", false); moduleInfo.support = filterURL(jsonObject.optString("support")); moduleInfo.donate = filterURL(jsonObject.optString("donate")); + moduleInfo.safe = (jsonObject.has("vt_status") && jsonObject.getString("vt_status").equalsIgnoreCase("clean")) || jsonObject.optBoolean("safe", false); String config = jsonObject.optString("config", ""); moduleInfo.config = config.isEmpty() ? null : config; PropUtils.applyFallbacks(moduleInfo); // Apply fallbacks diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoData.java b/app/src/main/java/com/fox2code/mmm/repo/RepoData.java index b5adc87..4360fa0 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoData.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoData.java @@ -161,7 +161,10 @@ public class RepoData extends XRepo { List newModules = new ArrayList<>(); synchronized (this.populateLock) { String name = jsonObject.getString("name").trim(); + // if Official is present, remove it, or (Official), or [Official]. We don't want to show it in the UI String nameForModules = name.endsWith(" (Official)") ? name.substring(0, name.length() - 11) : name; + nameForModules = nameForModules.endsWith(" [Official]") ? nameForModules.substring(0, nameForModules.length() - 11) : nameForModules; + nameForModules = nameForModules.contains("Official") ? nameForModules.replace("Official", "").trim() : nameForModules; long lastUpdate = jsonObject.getLong("last_update"); for (RepoModule repoModule : this.moduleHashMap.values()) { repoModule.processed = false; @@ -203,6 +206,8 @@ public class RepoData extends XRepo { repoModule.propUrl = modulePropsUrl; repoModule.zipUrl = moduleZipUrl; repoModule.checksum = moduleChecksum; + // safety check must be overriden per repo. only androidacy repo has this flag currently + // repoModule.safe = module.optBoolean("safe", false); if (!moduleStars.isEmpty()) { try { repoModule.qualityValue = Integer.parseInt(moduleStars); @@ -271,6 +276,8 @@ public class RepoData extends XRepo { throw new RuntimeException("Failed to delete invalid metadata file"); } } + } else { + Timber.d("Metadata file not found for %s", repoModule.id); } repoModule.moduleInfo.flags |= ModuleInfo.FLAG_METADATA_INVALID; return false; diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java b/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java index a5b5b59..5ab5548 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoManager.java @@ -305,6 +305,8 @@ public final class RepoManager extends SyncManager { } else if (repoModule.moduleInfo.versionCode > registeredRepoModule.moduleInfo.versionCode) { this.modules.put(repoModule.id, repoModule); } + } else { + repoModule.moduleInfo.flags |= ModuleInfo.FLAG_METADATA_INVALID; } } catch ( Exception e) { diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoModule.java b/app/src/main/java/com/fox2code/mmm/repo/RepoModule.java index 86fc84b..a0d6784 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoModule.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoModule.java @@ -18,6 +18,7 @@ public class RepoModule { @StringRes public int qualityText; public int qualityValue; + public boolean safe; public RepoModule(RepoData repoData, String id) { this.repoData = repoData; @@ -25,5 +26,24 @@ public class RepoModule { this.id = id; this.moduleInfo.flags |= ModuleInfo.FLAG_METADATA_INVALID; + this.safe = this.moduleInfo.safe; + } + + // allows all fields to be set- + public RepoModule(RepoData repoData, String id, String name, String description, String author, String donate, String config, String support, String version, int versionCode) { + this.repoData = repoData; + this.moduleInfo = new ModuleInfo(id); + this.id = id; + this.moduleInfo.name = name; + this.moduleInfo.description = description; + this.moduleInfo.author = author; + this.moduleInfo.donate = donate; + this.moduleInfo.config = config; + this.moduleInfo.support = support; + this.moduleInfo.version = version; + this.moduleInfo.versionCode = versionCode; + this.moduleInfo.flags |= + ModuleInfo.FLAG_METADATA_INVALID; + this.safe = this.moduleInfo.safe; } } diff --git a/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java b/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java index e41a39e..30d67de 100644 --- a/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java +++ b/app/src/main/java/com/fox2code/mmm/repo/RepoUpdater.java @@ -58,7 +58,7 @@ public class RepoUpdater { this.toUpdate = Collections.emptyList(); this.toApply = new HashSet<>(); for (ModuleListCache moduleListCache : results) { - this.toApply.add(new RepoModule(this.repoData, moduleListCache.getId())); + this.toApply.add(new RepoModule(this.repoData, moduleListCache.getId(), moduleListCache.getName(), moduleListCache.getDescription(), moduleListCache.getAuthor(), moduleListCache.getDonate(), moduleListCache.getConfig(), moduleListCache.getSupport(), moduleListCache.getVersion(), moduleListCache.getVersionCode())); } Timber.d("Fetched %d modules from cache for %s, from %s records", this.toApply.size(), this.repoData.id, results.size()); // close realm diff --git a/app/src/main/java/com/fox2code/mmm/utils/io/PropUtils.java b/app/src/main/java/com/fox2code/mmm/utils/io/PropUtils.java index 33a1643..0473e3e 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/io/PropUtils.java +++ b/app/src/main/java/com/fox2code/mmm/utils/io/PropUtils.java @@ -379,7 +379,8 @@ public enum PropUtils { || moduleInfo.author == null || !TextUtils.isGraphic(moduleInfo.author) || isNullString(description = moduleInfo.description) || !TextUtils.isGraphic(description) || description.toLowerCase(Locale.ROOT).equals(moduleInfo.name.toLowerCase(Locale.ROOT)) - || (getFlagsForModule(moduleInfo.id) & FLAG_COMPAT_LOW_QUALITY) != 0; + || (getFlagsForModule(moduleInfo.id) & FLAG_COMPAT_LOW_QUALITY) != 0 + || (moduleInfo.id.startsWith(".")); } private static boolean isInvalidValue(String name) { diff --git a/app/src/main/res/layout/module_entry.xml b/app/src/main/res/layout/module_entry.xml index a4904da..839b9a0 100644 --- a/app/src/main/res/layout/module_entry.xml +++ b/app/src/main/res/layout/module_entry.xml @@ -65,7 +65,7 @@ + android:layout_height="wrap_content" /> + +