use of forpdateam.ru.forpda.api.devdb.models.Brands in project ForPDA by RadiationX.
the class BrandsFragment method loadData.
@Override
public boolean loadData() {
if (!super.loadData()) {
return false;
}
setRefreshing(true);
subscribe(RxApi.DevDb().getBrands(mansCats[selected]), this::onLoad, new Brands());
return true;
}
use of forpdateam.ru.forpda.api.devdb.models.Brands in project ForPDA by RadiationX.
the class DevDb method getBrands.
public Brands getBrands(String catId) throws Exception {
Brands data = new Brands();
NetworkResponse response = Api.getWebClient().get("https://4pda.ru/devdb/" + catId + "/all");
Matcher matcher = Brands.LETTERS_PATTERN.matcher(response.getBody());
while (matcher.find()) {
String letter = matcher.group(1);
ArrayList<Brands.Item> items = new ArrayList<>();
Matcher itemsMatcher = Brands.ITEMS_IN_LETTER_PATTERN.matcher(matcher.group(2));
while (itemsMatcher.find()) {
Brands.Item item = new Brands.Item();
item.setId(itemsMatcher.group(1));
item.setTitle(ApiUtils.fromHtml(itemsMatcher.group(2)));
item.setCount(Integer.parseInt(itemsMatcher.group(3)));
items.add(item);
}
data.putItems(letter, items);
}
matcher = MAIN_PATTERN.matcher(response.getBody());
if (matcher.find()) {
Matcher bcMatcher = BREADCRUMB_PATTERN.matcher(matcher.group(1));
while (bcMatcher.find()) {
if (bcMatcher.group(2) == null) {
data.setCatId(bcMatcher.group(1));
data.setCatTitle(bcMatcher.group(3));
}
}
data.setActual(Integer.parseInt(matcher.group(5)));
data.setAll(Integer.parseInt(matcher.group(6)));
}
return data;
}
Aggregations