(misc) repo_repo_

Signed-off-by: androidacy-user <opensource@androidacy.com>
master
androidacy-user 1 year ago
parent a268013b0d
commit 173422e9e1

@ -1,7 +1,5 @@
package com.fox2code.mmm.repo;
import android.content.SharedPreferences;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.utils.io.Hashes;
import com.fox2code.mmm.utils.io.PropUtils;
@ -55,10 +53,6 @@ public class CustomRepoManager {
});
}
private SharedPreferences getSharedPreferences() {
return MainApplication.getPreferences("mmm_custom_repos");
}
public CustomRepoData addRepo(String repo) {
if (RepoManager.isBuiltInRepo(repo))
throw new IllegalArgumentException("Can't add built-in repo to custom repos");
@ -124,16 +118,15 @@ public class CustomRepoManager {
String id = "repo_" + Hashes.hashSha256(repo.getBytes(StandardCharsets.UTF_8));
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("ReposList.realm").encryptionKey(MainApplication.getINSTANCE().getKey()).allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build();
Realm realm = Realm.getInstance(realmConfiguration);
int finalI = i;
String finalWebsite = website;
String finalSupport = support;
String finalDonate = donate;
String finalSubmitModule = submitModule;
realm.executeTransaction(realm1 -> {
// find the matching entry for repo_0, repo_1, etc.
ReposList reposList = realm1.where(ReposList.class).equalTo("id", "repo_" + id).findFirst();
ReposList reposList = realm1.where(ReposList.class).equalTo("id", id).findFirst();
if (reposList == null) {
reposList = realm1.createObject(ReposList.class, "repo_" + finalI);
reposList = realm1.createObject(ReposList.class, id);
}
reposList.setUrl(repo);
reposList.setName(name);
@ -161,10 +154,8 @@ public class CustomRepoManager {
return customRepoData;
}
public CustomRepoData getRepo(int index) {
if (index >= MAX_CUSTOM_REPOS) return null;
String repo = customRepos[index];
return repo == null ? null : (CustomRepoData) this.repoManager.get(repo);
public CustomRepoData getRepo(String id) {
return (CustomRepoData) this.repoManager.get(id);
}
public void removeRepo(int index) {
@ -177,7 +168,6 @@ public class CustomRepoManager {
customRepoData.setEnabled(false);
customRepoData.override = null;
}
this.getSharedPreferences().edit().remove("repo_" + index).apply();
this.dirty = true;
}
}

@ -110,6 +110,13 @@ public class RepoData extends XRepo {
ReposList reposList = realm.where(ReposList.class).equalTo("id", this.id).findFirst();
if (reposList == null) {
Timber.d("RepoData for %s not found in database", this.id);
// log every repo in db
Object[] fullList = realm.where(ReposList.class).findAll().toArray();
Timber.d("RepoData: " + this.id + ". repos in database: " + fullList.length);
for (Object repo : fullList) {
ReposList r = (ReposList) repo;
Timber.d("RepoData: " + this.id + ". repo: " + r.getId() + " " + r.getName() + " " + r.getWebsite() + " " + r.getSupport() + " " + r.getDonate() + " " + r.getSubmitModule() + " " + r.isEnabled());
}
} else {
Timber.d("RepoData for %s found in database", this.id);
}

@ -88,6 +88,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -1157,15 +1158,19 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
Realm realm = Realm.getInstance(realmConfiguration);
// get all repos that are not built-in
int CUSTOM_REPO_ENTRIES = 0;
// array of custom repos
ArrayList<String> customRepos = new ArrayList<>();
RealmResults<ReposList> customRepoDataDB = realm.where(ReposList.class).findAll();
for (ReposList repo : customRepoDataDB) {
if (!repo.getId().equals("androidacy") && !repo.getId().equals("magisk_alt_repo")) {
CUSTOM_REPO_ENTRIES++;
customRepos.add(repo.getId());
}
}
final CustomRepoManager customRepoManager = RepoManager.getINSTANCE().getCustomRepoManager();
for (int i = 0; i < CUSTOM_REPO_ENTRIES; i++) {
CustomRepoData repoData = customRepoManager.getRepo(i);
// get the id of the repo at current index in customRepos
CustomRepoData repoData = customRepoManager.getRepo(customRepos.get(i));
setRepoData(repoData, "pref_custom_repo_" + i);
if (initial) {
Preference preference = findPreference("pref_custom_repo_" + i + "_delete");
@ -1268,6 +1273,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
positiveButton.setEnabled(true);
}
}
@Override
public void afterTextChanged(Editable s) {
}

@ -9,10 +9,5 @@ dependencyResolutionManagement {
maven { setUrl("https://jitpack.io") }
}
}
buildCache {
local {
isEnabled = true
}
}
rootProject.name = "MagiskModuleManager"
include(":app")
Loading…
Cancel
Save