Allow to disable/enable built-in repos.

pull/55/head
Fox2Code 2 years ago
parent 08e0edbe6e
commit 5ee90a1b4e

@ -16,8 +16,6 @@
<!-- Supposed to fix bugs with old firmware, only requested on pre Marshmallow -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<application
android:name=".MainApplication"

@ -214,6 +214,7 @@ public class MainActivity extends CompatActivity implements SwipeRefreshLayout.O
moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
RepoManager.getINSTANCE().updateEnabledStates();
moduleViewListBuilder.appendRemoteModules();
Log.i(TAG, "Common Before applyTo");
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);

@ -143,9 +143,10 @@ public final class ModuleHolder implements Comparable<ModuleHolder> {
public boolean shouldRemove() {
return this.notificationType != null ? this.notificationType.shouldRemove() :
this.footerPx == 0 && this.moduleInfo == null && (this.repoModule == null ||
(PropUtils.isLowQualityModule(this.repoModule.moduleInfo) &&
!MainApplication.isDisableLowQualityModuleFilter()));
this.footerPx == 0 && this.moduleInfo == null &&
(this.repoModule == null || !this.repoModule.repoData.isEnabled() ||
(PropUtils.isLowQualityModule(this.repoModule.moduleInfo) &&
!MainApplication.isDisableLowQualityModuleFilter()));
}
public void getButtons(Context context, List<ActionButtonType> buttonTypeList, boolean showcaseMode) {

@ -73,6 +73,7 @@ public class ModuleViewListBuilder {
repoManager.runAfterUpdate(() -> {
Log.i(TAG, "A2: " + repoManager.getModules().size());
for (RepoModule repoModule : repoManager.getModules().values()) {
if (!repoModule.repoData.isEnabled()) continue;
ModuleInfo moduleInfo = repoModule.moduleInfo;
if (!showIncompatible && (moduleInfo.minApi > Build.VERSION.SDK_INT ||
(moduleInfo.maxApi != 0 && moduleInfo.maxApi < Build.VERSION.SDK_INT) ||

@ -111,7 +111,7 @@ public class AndroidacyRepoData extends RepoData {
lastLastUpdate = Math.max(lastLastUpdate, lastUpdate);
RepoModule repoModule = this.moduleHashMap.get(moduleId);
if (repoModule == null) {
repoModule = new RepoModule(moduleId);
repoModule = new RepoModule(this, moduleId);
repoModule.moduleInfo.flags = 0;
this.moduleHashMap.put(moduleId, repoModule);
newModules.add(repoModule);

@ -6,6 +6,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.R;
import com.fox2code.mmm.manager.ModuleInfo;
import com.fox2code.mmm.utils.Files;
@ -33,6 +34,7 @@ public class RepoData {
private static final String TAG = "RepoData";
private final Object populateLock = new Object();
public final String url;
public final String id;
public final File cacheRoot;
public final SharedPreferences cachedPreferences;
public final File metaDataCache;
@ -40,6 +42,7 @@ public class RepoData {
public final HashMap<String, RepoModule> moduleHashMap;
public long lastUpdate;
public String name;
private boolean enabled; // Cache for speed
private final Map<String, SpecialData> specialData;
private long specialLastUpdate;
@ -49,12 +52,15 @@ public class RepoData {
RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences,boolean special) {
this.url = url;
this.id = RepoManager.internalIdOfUrl(url);
this.cacheRoot = cacheRoot;
this.cachedPreferences = cachedPreferences;
this.metaDataCache = new File(cacheRoot, "modules.json");
this.special = special;
this.moduleHashMap = new HashMap<>();
this.name = this.url; // Set url as default name
this.enabled = MainApplication.getSharedPreferences()
.getBoolean("pref_" + this.id + "_enabled", true);
this.specialData = special ? new HashMap<>() : Collections.emptyMap();
if (!this.cacheRoot.isDirectory()) {
this.cacheRoot.mkdirs();
@ -141,7 +147,7 @@ public class RepoData {
}
RepoModule repoModule = this.moduleHashMap.get(moduleId);
if (repoModule == null) {
repoModule = new RepoModule(moduleId);
repoModule = new RepoModule(this, moduleId);
this.moduleHashMap.put(moduleId, repoModule);
newModules.add(repoModule);
} else {
@ -254,6 +260,21 @@ public class RepoData {
fallback : this.name;
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
MainApplication.getSharedPreferences().edit()
.putBoolean("pref_" + this.id + "_enabled", enabled).apply();
}
public void updateEnabledState() {
this.enabled = MainApplication.getSharedPreferences()
.getBoolean("pref_" + this.id + "_enabled", true);
}
private static class SpecialData {
SpecialData(long time, int stars) {
this.time = time; this.stars = stars;

@ -228,6 +228,11 @@ public final class RepoManager {
return hasInternet;
}
public void updateEnabledStates() {
for (RepoData repoData:this.repoData.values())
repoData.updateEnabledState();
}
public HashMap<String, RepoModule> getModules() {
this.afterUpdate();
return this.modules;

@ -5,6 +5,7 @@ import androidx.annotation.StringRes;
import com.fox2code.mmm.manager.ModuleInfo;
public class RepoModule {
public final RepoData repoData;
public final ModuleInfo moduleInfo;
public final String id;
public String repoName;
@ -18,7 +19,8 @@ public class RepoModule {
public int qualityText;
public int qualityValue;
public RepoModule(String id) {
public RepoModule(RepoData repoData, String id) {
this.repoData = repoData;
this.moduleInfo = new ModuleInfo(id);
this.id = id;
this.moduleInfo.flags |=

@ -26,6 +26,12 @@ public class RepoUpdater {
}
public int fetchIndex() {
if (!this.repoData.isEnabled()) {
this.indexRaw = null;
this.toUpdate = Collections.emptyList();
this.toApply = Collections.emptySet();
return 0;
}
try {
if (!this.repoData.prepare()) {
return 0;

@ -3,12 +3,15 @@ package com.fox2code.mmm.settings;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import androidx.preference.SwitchPreferenceCompat;
import com.fox2code.mmm.AppUpdateManager;
import com.fox2code.mmm.BuildConfig;
@ -158,16 +161,15 @@ public class SettingsActivity extends CompatActivity {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName("mmm");
setPreferencesFromResource(R.xml.repo_preferences, rootKey);
setRepoData("pref_repo_main", RepoManager.MAGISK_REPO,
setRepoData(RepoManager.MAGISK_REPO,
"Magisk Modules Repo (Official)", RepoManager.MAGISK_REPO_HOMEPAGE,
null, null,null);
setRepoData("pref_repo_alt", RepoManager.MAGISK_ALT_REPO,
setRepoData(RepoManager.MAGISK_ALT_REPO,
"Magisk Modules Alt Repo", RepoManager.MAGISK_ALT_REPO_HOMEPAGE,
null, null,
"https://github.com/Magisk-Modules-Alt-Repo/submission/issues");
// Androidacy backend not yet implemented!
setRepoData("pref_repo_androidacy",
RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT,
setRepoData(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT,
"Androidacy Modules Repo",
RepoManager.ANDROIDACY_MAGISK_REPO_HOMEPAGE,
"https://t.me/androidacy_discussions",
@ -175,15 +177,31 @@ public class SettingsActivity extends CompatActivity {
"https://www.androidacy.com/module-repository-applications/");
}
private void setRepoData(String preferenceName, String url,
private void setRepoData(String url,
String fallbackTitle, String homepage,
String supportUrl, String donateUrl,
String submissionUrl) {
String preferenceName = "pref_" + RepoManager.internalIdOfUrl(url);
Preference preference = findPreference(preferenceName);
if (preference == null) return;
RepoData repoData = RepoManager.getINSTANCE().get(url);
final RepoData repoData = RepoManager.getINSTANCE().get(url);
preference.setTitle(repoData == null ? fallbackTitle :
repoData.getNameOrFallback(fallbackTitle));
preference = findPreference(preferenceName + "_enabled");
if (preference != null) {
if (repoData == null) {
preference.setTitle(R.string.repo_disabled);
preference.setEnabled(false);
} else {
preference.setTitle(repoData.isEnabled() ?
R.string.repo_enabled : R.string.repo_disabled);
preference.setOnPreferenceChangeListener((p, newValue) -> {
p.setTitle(((Boolean) newValue) ?
R.string.repo_enabled : R.string.repo_disabled);
return true;
});
}
}
preference = findPreference(preferenceName + "_website");
if (preference != null && homepage != null) {
preference.setOnPreferenceClickListener(p -> {

@ -1,48 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
app:key="pref_repo_main"
app:key="pref_magisk_repo"
app:title="@string/loading">
<SwitchPreferenceCompat
app:defaultValue="true"
app:key="pref_magisk_repo_enabled"
app:icon="@drawable/ic_baseline_extension_24"
app:switchTextOn="@string/repo_enabled"
app:switchTextOff="@string/repo_enabled"
app:singleLineTitle="false" />
<Preference
app:key="pref_repo_main_website"
app:key="pref_magisk_repo_website"
app:icon="@drawable/ic_baseline_language_24"
app:title="@string/website"
app:singleLineTitle="false" />
</PreferenceCategory>
<PreferenceCategory
app:key="pref_repo_alt"
app:key="pref_magisk_alt_repo"
app:title="@string/loading">
<SwitchPreferenceCompat
app:defaultValue="true"
app:key="pref_magisk_alt_repo_enabled"
app:icon="@drawable/ic_baseline_extension_24"
app:switchTextOn="@string/repo_enabled"
app:switchTextOff="@string/repo_enabled"
app:singleLineTitle="false" />
<Preference
app:key="pref_repo_alt_website"
app:key="pref_magisk_alt_repo_website"
app:icon="@drawable/ic_baseline_language_24"
app:title="@string/website"
app:singleLineTitle="false" />
<Preference
app:key="pref_repo_alt_submit"
app:key="pref_magisk_alt_repo_submit"
app:icon="@drawable/ic_baseline_upload_file_24"
app:title="@string/submit_modules"
app:singleLineTitle="false" />
</PreferenceCategory>
<PreferenceCategory
app:key="pref_repo_androidacy"
app:key="pref_androidacy_repo"
app:title="@string/loading">
<SwitchPreferenceCompat
app:defaultValue="true"
app:key="pref_androidacy_repo_enabled"
app:icon="@drawable/ic_baseline_extension_24"
app:switchTextOn="@string/repo_enabled"
app:switchTextOff="@string/repo_enabled"
app:singleLineTitle="false" />
<Preference
app:key="pref_repo_androidacy_website"
app:key="pref_androidacy_repo_website"
app:icon="@drawable/ic_baseline_language_24"
app:title="@string/website"
app:singleLineTitle="false" />
<Preference
app:key="pref_repo_androidacy_support"
app:key="pref_androidacy_repo_support"
app:icon="@drawable/ic_baseline_telegram_24"
app:title="@string/support"
app:singleLineTitle="false" />
<Preference
app:key="pref_repo_androidacy_donate"
app:key="pref_androidacy_repo_donate"
app:icon="@drawable/ic_patreon"
app:title="@string/donate"
app:singleLineTitle="false" />
<Preference
app:key="pref_repo_androidacy_submit"
app:key="pref_androidacy_repo_submit"
app:icon="@drawable/ic_baseline_upload_file_24"
app:title="@string/submit_modules"
app:singleLineTitle="false" />

Loading…
Cancel
Save