Support vendor dumps repo

This commit is contained in:
YTKAB0BP
2024-11-21 21:37:43 +03:00
parent c138b0b259
commit 4a6a290f6d
2 changed files with 68 additions and 39 deletions
@@ -100,7 +100,13 @@ public class SetupActivity extends AppCompatActivity {
private final static String TAG = "SetupActivity";
private final static String PRUSA_REPOS_URL = "https://preset-repo-api.prusa3d.com/v1/repos";
private final static List<String> REPOS_URLS = Arrays.asList(
"https://preset-repo-api.prusa3d.com/v1/repos",
// QIDI's manifest should be adapted, they haven't put their idx file
// "https://raw.githubusercontent.com/QIDITECH/QIDISlicer/refs/heads/master/resources/profiles/ArchiveRepositoryManifest.json",
"https://raw.githubusercontent.com/utkabobr/SliceBeam/refs/heads/master/.profiledumpsrepo/manifest.json"
);
private final static int REPOS_INDEX = 1;
private final static int PROFILES_INDEX = 2;
private static int BOOSTY_INDEX = 3;
@@ -488,10 +494,22 @@ public class SetupActivity extends AppCompatActivity {
private void loadRepos(boolean fromPage) {
isLoading = true;
client.get(PRUSA_REPOS_URL, new AsyncHttpResponseHandler() {
repos.clear();
List<String> finishedIndexes = new ArrayList<>();
Map<String, List<ProfilesRepo>> reposMap = new HashMap<String, List<ProfilesRepo>>() {
@Nullable
@Override
public List<ProfilesRepo> get(@Nullable Object key) {
List<ProfilesRepo> list = super.get(key);
if (list == null) put((String) key, list = new ArrayList<>());
return list;
}
};
for (String repo : REPOS_URLS) {
client.get(repo, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
isLoading = false;
finishedIndexes.add(repo);
try {
JSONArray arr = new JSONArray(new String(responseBody));
for (int i = 0; i < arr.length(); i++) {
@@ -502,17 +520,25 @@ public class SetupActivity extends AppCompatActivity {
r.name = obj.getString("name");
r.description = obj.getString("description");
r.indexUrl = obj.getString("index_url");
repos.add(r);
reposMap.get(repo).add(r);
}
}
if (finishedIndexes.size() == REPOS_URLS.size()) {
// Filter in the right way
for (String repo : REPOS_URLS) {
repos.addAll(reposMap.get(repo));
}
ViewUtils.postOnMainThread(() -> {
isLoading = false;
if (fromPage) {
reposItem.onReposLoaded();
}
pager.setUserInputEnabled(true);
isReposLoaded = true;
});
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
@@ -532,6 +558,7 @@ public class SetupActivity extends AppCompatActivity {
}
});
}
}
@Override
protected void onPause() {
@@ -100,7 +100,9 @@ public class IOUtils {
vendor = "BBL";
} else if (type.equals("process")) {
int i = inherit.indexOf('@') + 1;
vendor = inherit.substring(i, inherit.indexOf(' ', i));
int j = inherit.indexOf(' ', i);
if (j == -1) j = inherit.length();
vendor = inherit.substring(i, j);
} else {
vendor = inherit.substring(0, inherit.indexOf(' '));
}