(misc) repo_repo_

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 2 years ago
parent a268013b0d
commit 173422e9e1

@ -1,7 +1,5 @@
package com.fox2code.mmm.repo; package com.fox2code.mmm.repo;
import android.content.SharedPreferences;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.utils.io.Hashes; import com.fox2code.mmm.utils.io.Hashes;
import com.fox2code.mmm.utils.io.PropUtils; 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) { public CustomRepoData addRepo(String repo) {
if (RepoManager.isBuiltInRepo(repo)) if (RepoManager.isBuiltInRepo(repo))
throw new IllegalArgumentException("Can't add built-in repo to custom repos"); 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)); 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(); 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); Realm realm = Realm.getInstance(realmConfiguration);
int finalI = i;
String finalWebsite = website; String finalWebsite = website;
String finalSupport = support; String finalSupport = support;
String finalDonate = donate; String finalDonate = donate;
String finalSubmitModule = submitModule; String finalSubmitModule = submitModule;
realm.executeTransaction(realm1 -> { realm.executeTransaction(realm1 -> {
// find the matching entry for repo_0, repo_1, etc. // 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) { if (reposList == null) {
reposList = realm1.createObject(ReposList.class, "repo_" + finalI); reposList = realm1.createObject(ReposList.class, id);
} }
reposList.setUrl(repo); reposList.setUrl(repo);
reposList.setName(name); reposList.setName(name);
@ -161,10 +154,8 @@ public class CustomRepoManager {
return customRepoData; return customRepoData;
} }
public CustomRepoData getRepo(int index) { public CustomRepoData getRepo(String id) {
if (index >= MAX_CUSTOM_REPOS) return null; return (CustomRepoData) this.repoManager.get(id);
String repo = customRepos[index];
return repo == null ? null : (CustomRepoData) this.repoManager.get(repo);
} }
public void removeRepo(int index) { public void removeRepo(int index) {
@ -177,7 +168,6 @@ public class CustomRepoManager {
customRepoData.setEnabled(false); customRepoData.setEnabled(false);
customRepoData.override = null; customRepoData.override = null;
} }
this.getSharedPreferences().edit().remove("repo_" + index).apply();
this.dirty = true; this.dirty = true;
} }
} }

@ -110,6 +110,13 @@ public class RepoData extends XRepo {
ReposList reposList = realm.where(ReposList.class).equalTo("id", this.id).findFirst(); ReposList reposList = realm.where(ReposList.class).equalTo("id", this.id).findFirst();
if (reposList == null) { if (reposList == null) {
Timber.d("RepoData for %s not found in database", this.id); 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 { } else {
Timber.d("RepoData for %s found in database", this.id); 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.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -1157,15 +1158,19 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
Realm realm = Realm.getInstance(realmConfiguration); Realm realm = Realm.getInstance(realmConfiguration);
// get all repos that are not built-in // get all repos that are not built-in
int CUSTOM_REPO_ENTRIES = 0; int CUSTOM_REPO_ENTRIES = 0;
// array of custom repos
ArrayList<String> customRepos = new ArrayList<>();
RealmResults<ReposList> customRepoDataDB = realm.where(ReposList.class).findAll(); RealmResults<ReposList> customRepoDataDB = realm.where(ReposList.class).findAll();
for (ReposList repo : customRepoDataDB) { for (ReposList repo : customRepoDataDB) {
if (!repo.getId().equals("androidacy") && !repo.getId().equals("magisk_alt_repo")) { if (!repo.getId().equals("androidacy") && !repo.getId().equals("magisk_alt_repo")) {
CUSTOM_REPO_ENTRIES++; CUSTOM_REPO_ENTRIES++;
customRepos.add(repo.getId());
} }
} }
final CustomRepoManager customRepoManager = RepoManager.getINSTANCE().getCustomRepoManager(); final CustomRepoManager customRepoManager = RepoManager.getINSTANCE().getCustomRepoManager();
for (int i = 0; i < CUSTOM_REPO_ENTRIES; i++) { 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); setRepoData(repoData, "pref_custom_repo_" + i);
if (initial) { if (initial) {
Preference preference = findPreference("pref_custom_repo_" + i + "_delete"); Preference preference = findPreference("pref_custom_repo_" + i + "_delete");
@ -1268,6 +1273,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
positiveButton.setEnabled(true); positiveButton.setEnabled(true);
} }
} }
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
} }

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