Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit d4ee572

Browse files
committed
Finish custom repos implementation + add more default repos.
1 parent 1488f13 commit d4ee572

File tree

13 files changed

+563
-58
lines changed

13 files changed

+563
-58
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ android {
3737
buildConfigField(
3838
"java.util.List<String>",
3939
"ENABLED_REPOS",
40-
"java.util.Arrays.asList(\"magisk_alt_repo\", \"androidacy_repo\")",
40+
"java.util.Arrays.asList(\"magisk_alt_repo\", \"dg_magisk_repo\", \"androidacy_repo\")",
4141
)
4242
}
4343

app/src/main/java/com/fox2code/mmm/MainActivity.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ public void commonNext() {
171171
});
172172
Log.i(TAG, "Scanning for modules!");
173173
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
174+
if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
175+
Log.w(TAG, "Need update on create?");
176+
}
174177
RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () ->
175178
progressIndicator.setProgressCompat(
176179
(int) (value * PRECISION), true) :() ->
@@ -326,6 +329,19 @@ public void commonNext() {
326329
else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
327330
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
328331
RepoManager.getINSTANCE().updateEnabledStates();
332+
if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
333+
runOnUiThread(() -> {
334+
progressIndicator.setIndeterminate(false);
335+
progressIndicator.setMax(PRECISION);
336+
});
337+
RepoManager.getINSTANCE().update(value -> runOnUiThread(() ->
338+
progressIndicator.setProgressCompat(
339+
(int) (value * PRECISION), true)));
340+
runOnUiThread(() -> {
341+
progressIndicator.setProgressCompat(PRECISION, true);
342+
progressIndicator.setVisibility(View.GONE);
343+
});
344+
}
329345
moduleViewListBuilder.appendRemoteModules();
330346
Log.i(TAG, "Common Before applyTo");
331347
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);

app/src/main/java/com/fox2code/mmm/XHooks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import androidx.annotation.Keep;
99

1010
import com.fox2code.mmm.manager.ModuleManager;
11+
import com.fox2code.mmm.repo.RepoData;
1112
import com.fox2code.mmm.repo.RepoManager;
1213

1314
/**
@@ -45,7 +46,7 @@ public static void onWebViewInitialize(WebView webView,boolean allowInstall) {
4546

4647
@Keep
4748
public static XRepo addXRepo(String url, String fallbackName) {
48-
return RepoManager.getINSTANCE().addOrGet(url);
49+
return RepoManager.getINSTANCE().addOrGet(url, fallbackName);
4950
}
5051

5152
@Keep

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.StringRes;
1919
import androidx.cardview.widget.CardView;
20+
import androidx.core.graphics.ColorUtils;
2021
import androidx.recyclerview.widget.RecyclerView;
2122

2223
import com.fox2code.foxcompat.FoxDisplay;
@@ -365,6 +366,9 @@ public boolean update(ModuleHolder moduleHolder) {
365366
if (bgColor == Color.WHITE) {
366367
bgColor = 0xFFF8F8F8;
367368
}
369+
if (theme.getResources().getBoolean(R.bool.force_transparency)) {
370+
bgColor = ColorUtils.setAlphaComponent(bgColor, 0x80);
371+
}
368372
this.titleText.setTextColor(fgColor);
369373
this.buttonAction.setColorFilter(fgColor);
370374
this.cardView.setCardBackgroundColor(bgColor);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.fox2code.mmm.repo;
2+
3+
import android.content.SharedPreferences;
4+
5+
import com.fox2code.mmm.utils.Http;
6+
7+
import org.json.JSONException;
8+
import org.json.JSONObject;
9+
10+
import java.io.File;
11+
import java.io.IOException;
12+
import java.nio.charset.StandardCharsets;
13+
import java.util.List;
14+
15+
public final class CustomRepoData extends RepoData {
16+
boolean loadedExternal;
17+
String override;
18+
19+
CustomRepoData(String url, File cacheRoot, SharedPreferences cachedPreferences) {
20+
super(url, cacheRoot, cachedPreferences);
21+
}
22+
23+
@Override
24+
public boolean isEnabledByDefault() {
25+
return this.override != null || this.loadedExternal;
26+
}
27+
28+
@Override
29+
public String getPreferenceId() {
30+
return this.override == null ?
31+
this.id : this.override;
32+
}
33+
34+
@Override
35+
public boolean isLimited() {
36+
return true;
37+
}
38+
39+
public void quickPrePopulate() throws IOException, JSONException {
40+
JSONObject jsonObject = new JSONObject(
41+
new String(Http.doHttpGet(this.getUrl(),
42+
false), StandardCharsets.UTF_8));
43+
this.name = jsonObject.getString("name").trim();
44+
this.website = jsonObject.optString("website");
45+
this.support = jsonObject.optString("support");
46+
this.donate = jsonObject.optString("donate");
47+
this.submitModule = jsonObject.optString("submitModule");
48+
}
49+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package com.fox2code.mmm.repo;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
import com.fox2code.mmm.MainApplication;
7+
8+
public class CustomRepoManager {
9+
private static final boolean AUTO_RECOMPILE = true;
10+
public static final int MAX_CUSTOM_REPOS = 3;
11+
private final MainApplication mainApplication;
12+
private final RepoManager repoManager;
13+
private final String[] customRepos;
14+
private int customReposCount;
15+
boolean dirty;
16+
17+
CustomRepoManager(MainApplication mainApplication, RepoManager repoManager) {
18+
this.mainApplication = mainApplication;
19+
this.repoManager = repoManager;
20+
this.customRepos = new String[MAX_CUSTOM_REPOS];
21+
this.customReposCount = 0;
22+
SharedPreferences sharedPreferences = this.getSharedPreferences();
23+
int lastFilled = 0;
24+
for (int i = 0; i < MAX_CUSTOM_REPOS; i++) {
25+
String repo = sharedPreferences.getString("repo_" + i, "");
26+
if (!repo.isEmpty() && !RepoManager.isBuiltInRepo(repo)) {
27+
lastFilled = i;
28+
int index = AUTO_RECOMPILE ?
29+
this.customReposCount : i;
30+
this.customRepos[index] = repo;
31+
this.customReposCount++;
32+
((CustomRepoData) this.repoManager.addOrGet(repo))
33+
.override = "custom_repo_" + index;
34+
}
35+
}
36+
if (AUTO_RECOMPILE && (lastFilled + 1) != this.customReposCount) {
37+
SharedPreferences.Editor editor = sharedPreferences.edit().clear();
38+
for (int i = 0; i < MAX_CUSTOM_REPOS; i++) {
39+
if (this.customRepos[i] != null)
40+
editor.putString("repo_" + i, this.customRepos[i]);
41+
}
42+
editor.apply();
43+
}
44+
}
45+
46+
private SharedPreferences getSharedPreferences() {
47+
return this.mainApplication.getSharedPreferences(
48+
"mmm_custom_repos", Context.MODE_PRIVATE);
49+
}
50+
51+
public CustomRepoData addRepo(String repo) {
52+
if (RepoManager.isBuiltInRepo(repo))
53+
throw new IllegalArgumentException("Can't add built-in repo to custom repos");
54+
for (String repoEntry : this.customRepos) {
55+
if (repo.equals(repoEntry))
56+
return (CustomRepoData) this.repoManager.get(repoEntry);
57+
}
58+
int i = 0;
59+
while (customRepos[i] != null) i++;
60+
customRepos[i] = repo;
61+
this.getSharedPreferences().edit()
62+
.putString("repo_" + i, repo).apply();
63+
this.dirty = true;
64+
CustomRepoData customRepoData = (CustomRepoData)
65+
this.repoManager.addOrGet(repo);
66+
customRepoData.override = "custom_repo_" + i;
67+
customRepoData.updateEnabledState();
68+
return customRepoData;
69+
}
70+
71+
public CustomRepoData getRepo(int index) {
72+
if (index >= MAX_CUSTOM_REPOS) return null;
73+
String repo = customRepos[index];
74+
return repo == null ? null :
75+
(CustomRepoData) this.repoManager.get(repo);
76+
}
77+
78+
public void removeRepo(int index) {
79+
String oldRepo = customRepos[index];
80+
if (oldRepo != null) {
81+
customRepos[index] = null;
82+
customReposCount--;
83+
CustomRepoData customRepoData =
84+
(CustomRepoData) this.repoManager.get(oldRepo);
85+
if (customRepoData != null) {
86+
customRepoData.setEnabled(false);
87+
customRepoData.override = null;
88+
}
89+
this.getSharedPreferences().edit()
90+
.remove("repo_" + index).apply();
91+
this.dirty = true;
92+
}
93+
}
94+
95+
public boolean hasRepo(String repo) {
96+
for (String repoEntry : this.customRepos) {
97+
if (repo.equals(repoEntry))
98+
return true;
99+
}
100+
return false;
101+
}
102+
103+
public boolean canAddRepo() {
104+
return this.customReposCount < MAX_CUSTOM_REPOS;
105+
}
106+
107+
public boolean canAddRepo(String repo) {
108+
if (RepoManager.isBuiltInRepo(repo) ||
109+
this.hasRepo(repo) || !this.canAddRepo())
110+
return false;
111+
return repo.startsWith("https://") &&
112+
repo.indexOf('/', 9) != -1;
113+
}
114+
115+
public boolean needUpdate() {
116+
boolean needUpdate = this.dirty;
117+
if (needUpdate) this.dirty = false;
118+
return needUpdate;
119+
}
120+
121+
}

app/src/main/java/com/fox2code/mmm/repo/LimitedRepoData.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/src/main/java/com/fox2code/mmm/repo/RepoData.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferenc
4848
this.metaDataCache = new File(cacheRoot, "modules.json");
4949
this.moduleHashMap = new HashMap<>();
5050
this.name = this.url; // Set url as default name
51-
this.enabled = MainApplication.getSharedPreferences()
51+
this.enabled = !this.isLimited() && MainApplication.getSharedPreferences()
5252
.getBoolean("pref_" + this.id + "_enabled", this.isEnabledByDefault());
5353
this.defaultName = url;
5454
this.defaultWebsite = "https://" + Uri.parse(url).getHost() + "/";
@@ -103,6 +103,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
103103
String moduleZipUrl = module.getString("zip_url");
104104
String moduleChecksum = module.optString("checksum");
105105
String moduleStars = module.optString("stars");
106+
String moduleDownloads = module.optString("downloads");
106107
RepoModule repoModule = this.moduleHashMap.get(moduleId);
107108
if (repoModule == null) {
108109
repoModule = new RepoModule(this, moduleId);
@@ -121,11 +122,16 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
121122
repoModule.propUrl = modulePropsUrl;
122123
repoModule.zipUrl = moduleZipUrl;
123124
repoModule.checksum = moduleChecksum;
124-
if (!moduleStars.isEmpty() && !this.isLimited()) {
125+
if (!moduleStars.isEmpty()) {
125126
try {
126127
repoModule.qualityValue = Integer.parseInt(moduleStars);
127128
repoModule.qualityText = R.string.module_stars;
128129
} catch (NumberFormatException ignored) {}
130+
} else if (!moduleDownloads.isEmpty()) {
131+
try {
132+
repoModule.qualityValue = Integer.parseInt(moduleDownloads);
133+
repoModule.qualityText = R.string.module_downloads;
134+
} catch (NumberFormatException ignored) {}
129135
}
130136
}
131137
// Remove no longer existing modules

0 commit comments

Comments
 (0)