Search in sources :

Example 1 with Brands

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;
}
Also used : Brands(forpdateam.ru.forpda.api.devdb.models.Brands)

Example 2 with Brands

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;
}
Also used : Matcher(java.util.regex.Matcher) Brands(forpdateam.ru.forpda.api.devdb.models.Brands) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) ArrayList(java.util.ArrayList)

Aggregations

Brands (forpdateam.ru.forpda.api.devdb.models.Brands)2 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1