Search in sources :

Example 1 with Brand

use of forpdateam.ru.forpda.api.devdb.models.Brand in project ForPDA by RadiationX.

the class BrandFragment method loadData.

@Override
public boolean loadData() {
    if (!super.loadData()) {
        return false;
    }
    setRefreshing(true);
    subscribe(RxApi.DevDb().getBrand(catId, brandId), this::onLoad, new Brand());
    return true;
}
Also used : Brand(forpdateam.ru.forpda.api.devdb.models.Brand)

Example 2 with Brand

use of forpdateam.ru.forpda.api.devdb.models.Brand in project ForPDA by RadiationX.

the class SearchFragment method loadData.

@Override
public boolean loadData() {
    if (currentQuery != null && currentQuery.isEmpty()) {
        return false;
    }
    if (!super.loadData()) {
        return false;
    }
    setRefreshing(true);
    subscribe(RxApi.DevDb().search(currentQuery), this::onLoad, new Brand());
    return true;
}
Also used : Brand(forpdateam.ru.forpda.api.devdb.models.Brand)

Example 3 with Brand

use of forpdateam.ru.forpda.api.devdb.models.Brand in project ForPDA by RadiationX.

the class DevDb method getBrand.

public Brand getBrand(String catId, String brandId) throws Exception {
    Brand data = new Brand();
    NetworkResponse response = Api.getWebClient().get("https://4pda.ru/devdb/" + catId + "/" + brandId + "/all");
    Matcher matcher = Brand.DEVICES_PATTERN.matcher(response.getBody());
    while (matcher.find()) {
        Brand.DeviceItem item = new Brand.DeviceItem();
        item.setImageSrc(matcher.group(1));
        item.setId(matcher.group(2));
        item.setTitle(ApiUtils.fromHtml(matcher.group(3)));
        Matcher specsMatcher = SPECS_PATTERN.matcher(matcher.group(4));
        if (specsMatcher.find()) {
            item.addSpec(specsMatcher.group(1), specsMatcher.group(2));
        }
        if (matcher.group(5) != null)
            item.setPrice(matcher.group(5));
        if (matcher.group(7) != null) {
            item.setRating(Integer.parseInt(matcher.group(7)));
        }
        data.addDevice(item);
    }
    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));
            } else {
                data.setId(bcMatcher.group(2));
                data.setTitle(bcMatcher.group(3));
            }
        }
        data.setTitle(matcher.group(4));
        data.setActual(Integer.parseInt(matcher.group(5)));
        data.setAll(Integer.parseInt(matcher.group(6)));
    }
    return data;
}
Also used : Brand(forpdateam.ru.forpda.api.devdb.models.Brand) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse)

Aggregations

Brand (forpdateam.ru.forpda.api.devdb.models.Brand)3 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 Matcher (java.util.regex.Matcher)1