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

Commit 5ee90a1

Browse files
committed
Allow to disable/enable built-in repos.
1 parent 08e0edb commit 5ee90a1

File tree

11 files changed

+98
-24
lines changed

11 files changed

+98
-24
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
<!-- Supposed to fix bugs with old firmware, only requested on pre Marshmallow -->
1717
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1818
android:maxSdkVersion="22" />
19-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
20-
android:maxSdkVersion="22" />
2119

2220
<application
2321
android:name=".MainApplication"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public void commonNext() {
214214
moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
215215
else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
216216
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
217+
RepoManager.getINSTANCE().updateEnabledStates();
217218
moduleViewListBuilder.appendRemoteModules();
218219
Log.i(TAG, "Common Before applyTo");
219220
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ public Type getCompareType(Type type) {
143143

144144
public boolean shouldRemove() {
145145
return this.notificationType != null ? this.notificationType.shouldRemove() :
146-
this.footerPx == 0 && this.moduleInfo == null && (this.repoModule == null ||
147-
(PropUtils.isLowQualityModule(this.repoModule.moduleInfo) &&
148-
!MainApplication.isDisableLowQualityModuleFilter()));
146+
this.footerPx == 0 && this.moduleInfo == null &&
147+
(this.repoModule == null || !this.repoModule.repoData.isEnabled() ||
148+
(PropUtils.isLowQualityModule(this.repoModule.moduleInfo) &&
149+
!MainApplication.isDisableLowQualityModuleFilter()));
149150
}
150151

151152
public void getButtons(Context context, List<ActionButtonType> buttonTypeList, boolean showcaseMode) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void appendRemoteModules() {
7373
repoManager.runAfterUpdate(() -> {
7474
Log.i(TAG, "A2: " + repoManager.getModules().size());
7575
for (RepoModule repoModule : repoManager.getModules().values()) {
76+
if (!repoModule.repoData.isEnabled()) continue;
7677
ModuleInfo moduleInfo = repoModule.moduleInfo;
7778
if (!showIncompatible && (moduleInfo.minApi > Build.VERSION.SDK_INT ||
7879
(moduleInfo.maxApi != 0 && moduleInfo.maxApi < Build.VERSION.SDK_INT) ||

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
111111
lastLastUpdate = Math.max(lastLastUpdate, lastUpdate);
112112
RepoModule repoModule = this.moduleHashMap.get(moduleId);
113113
if (repoModule == null) {
114-
repoModule = new RepoModule(moduleId);
114+
repoModule = new RepoModule(this, moduleId);
115115
repoModule.moduleInfo.flags = 0;
116116
this.moduleHashMap.put(moduleId, repoModule);
117117
newModules.add(repoModule);

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import androidx.annotation.NonNull;
88

9+
import com.fox2code.mmm.MainApplication;
910
import com.fox2code.mmm.R;
1011
import com.fox2code.mmm.manager.ModuleInfo;
1112
import com.fox2code.mmm.utils.Files;
@@ -33,13 +34,15 @@ public class RepoData {
3334
private static final String TAG = "RepoData";
3435
private final Object populateLock = new Object();
3536
public final String url;
37+
public final String id;
3638
public final File cacheRoot;
3739
public final SharedPreferences cachedPreferences;
3840
public final File metaDataCache;
3941
public final boolean special;
4042
public final HashMap<String, RepoModule> moduleHashMap;
4143
public long lastUpdate;
4244
public String name;
45+
private boolean enabled; // Cache for speed
4346
private final Map<String, SpecialData> specialData;
4447
private long specialLastUpdate;
4548

@@ -49,12 +52,15 @@ protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferenc
4952

5053
RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences,boolean special) {
5154
this.url = url;
55+
this.id = RepoManager.internalIdOfUrl(url);
5256
this.cacheRoot = cacheRoot;
5357
this.cachedPreferences = cachedPreferences;
5458
this.metaDataCache = new File(cacheRoot, "modules.json");
5559
this.special = special;
5660
this.moduleHashMap = new HashMap<>();
5761
this.name = this.url; // Set url as default name
62+
this.enabled = MainApplication.getSharedPreferences()
63+
.getBoolean("pref_" + this.id + "_enabled", true);
5864
this.specialData = special ? new HashMap<>() : Collections.emptyMap();
5965
if (!this.cacheRoot.isDirectory()) {
6066
this.cacheRoot.mkdirs();
@@ -141,7 +147,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
141147
}
142148
RepoModule repoModule = this.moduleHashMap.get(moduleId);
143149
if (repoModule == null) {
144-
repoModule = new RepoModule(moduleId);
150+
repoModule = new RepoModule(this, moduleId);
145151
this.moduleHashMap.put(moduleId, repoModule);
146152
newModules.add(repoModule);
147153
} else {
@@ -254,6 +260,21 @@ public String getNameOrFallback(String fallback) {
254260
fallback : this.name;
255261
}
256262

263+
public boolean isEnabled() {
264+
return this.enabled;
265+
}
266+
267+
public void setEnabled(boolean enabled) {
268+
this.enabled = enabled;
269+
MainApplication.getSharedPreferences().edit()
270+
.putBoolean("pref_" + this.id + "_enabled", enabled).apply();
271+
}
272+
273+
public void updateEnabledState() {
274+
this.enabled = MainApplication.getSharedPreferences()
275+
.getBoolean("pref_" + this.id + "_enabled", true);
276+
}
277+
257278
private static class SpecialData {
258279
SpecialData(long time, int stars) {
259280
this.time = time; this.stars = stars;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ private boolean scanInternal(UpdateListener updateListener) {
228228
return hasInternet;
229229
}
230230

231+
public void updateEnabledStates() {
232+
for (RepoData repoData:this.repoData.values())
233+
repoData.updateEnabledState();
234+
}
235+
231236
public HashMap<String, RepoModule> getModules() {
232237
this.afterUpdate();
233238
return this.modules;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fox2code.mmm.manager.ModuleInfo;
66

77
public class RepoModule {
8+
public final RepoData repoData;
89
public final ModuleInfo moduleInfo;
910
public final String id;
1011
public String repoName;
@@ -18,7 +19,8 @@ public class RepoModule {
1819
public int qualityText;
1920
public int qualityValue;
2021

21-
public RepoModule(String id) {
22+
public RepoModule(RepoData repoData, String id) {
23+
this.repoData = repoData;
2224
this.moduleInfo = new ModuleInfo(id);
2325
this.id = id;
2426
this.moduleInfo.flags |=

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public RepoUpdater(RepoData repoData) {
2626
}
2727

2828
public int fetchIndex() {
29+
if (!this.repoData.isEnabled()) {
30+
this.indexRaw = null;
31+
this.toUpdate = Collections.emptyList();
32+
this.toApply = Collections.emptySet();
33+
return 0;
34+
}
2935
try {
3036
if (!this.repoData.prepare()) {
3137
return 0;

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import android.os.Bundle;
44
import android.widget.Toast;
55

6+
import androidx.annotation.NonNull;
67
import androidx.annotation.StringRes;
78
import androidx.fragment.app.Fragment;
89
import androidx.fragment.app.FragmentTransaction;
910
import androidx.preference.ListPreference;
1011
import androidx.preference.Preference;
1112
import androidx.preference.PreferenceFragmentCompat;
13+
import androidx.preference.SwitchPreference;
14+
import androidx.preference.SwitchPreferenceCompat;
1215

1316
import com.fox2code.mmm.AppUpdateManager;
1417
import com.fox2code.mmm.BuildConfig;
@@ -158,32 +161,47 @@ public static class RepoFragment extends PreferenceFragmentCompat {
158161
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
159162
getPreferenceManager().setSharedPreferencesName("mmm");
160163
setPreferencesFromResource(R.xml.repo_preferences, rootKey);
161-
setRepoData("pref_repo_main", RepoManager.MAGISK_REPO,
164+
setRepoData(RepoManager.MAGISK_REPO,
162165
"Magisk Modules Repo (Official)", RepoManager.MAGISK_REPO_HOMEPAGE,
163166
null, null,null);
164-
setRepoData("pref_repo_alt", RepoManager.MAGISK_ALT_REPO,
167+
setRepoData(RepoManager.MAGISK_ALT_REPO,
165168
"Magisk Modules Alt Repo", RepoManager.MAGISK_ALT_REPO_HOMEPAGE,
166169
null, null,
167170
"https://github.com/Magisk-Modules-Alt-Repo/submission/issues");
168171
// Androidacy backend not yet implemented!
169-
setRepoData("pref_repo_androidacy",
170-
RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT,
172+
setRepoData(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT,
171173
"Androidacy Modules Repo",
172174
RepoManager.ANDROIDACY_MAGISK_REPO_HOMEPAGE,
173175
"https://t.me/androidacy_discussions",
174176
"https://patreon.com/androidacy",
175177
"https://www.androidacy.com/module-repository-applications/");
176178
}
177179

178-
private void setRepoData(String preferenceName, String url,
180+
private void setRepoData(String url,
179181
String fallbackTitle, String homepage,
180182
String supportUrl, String donateUrl,
181183
String submissionUrl) {
184+
String preferenceName = "pref_" + RepoManager.internalIdOfUrl(url);
182185
Preference preference = findPreference(preferenceName);
183186
if (preference == null) return;
184-
RepoData repoData = RepoManager.getINSTANCE().get(url);
187+
final RepoData repoData = RepoManager.getINSTANCE().get(url);
185188
preference.setTitle(repoData == null ? fallbackTitle :
186189
repoData.getNameOrFallback(fallbackTitle));
190+
preference = findPreference(preferenceName + "_enabled");
191+
if (preference != null) {
192+
if (repoData == null) {
193+
preference.setTitle(R.string.repo_disabled);
194+
preference.setEnabled(false);
195+
} else {
196+
preference.setTitle(repoData.isEnabled() ?
197+
R.string.repo_enabled : R.string.repo_disabled);
198+
preference.setOnPreferenceChangeListener((p, newValue) -> {
199+
p.setTitle(((Boolean) newValue) ?
200+
R.string.repo_enabled : R.string.repo_disabled);
201+
return true;
202+
});
203+
}
204+
}
187205
preference = findPreference(preferenceName + "_website");
188206
if (preference != null && homepage != null) {
189207
preference.setOnPreferenceClickListener(p -> {

0 commit comments

Comments
 (0)