Search in sources :

Example 1 with SearchResult

use of forpdateam.ru.forpda.api.search.models.SearchResult in project ForPDA by RadiationX.

the class SearchFragment method loadData.

@Override
public boolean loadData() {
    if (!super.loadData()) {
        return false;
    }
    if (settings.getQuery().isEmpty() && settings.getNick().isEmpty()) {
        return true;
    }
    buildTitle();
    hidePopupWindows();
    /*if (searchSettingsView.getVisibility() == View.VISIBLE) {
            searchSettingsView.setVisibility(View.GONE);
        }*/
    setRefreshing(true);
    boolean withHtml = settings.getResult().equals(SearchSettings.RESULT_POSTS.first) && settings.getResourceType().equals(SearchSettings.RESOURCE_FORUM.first);
    subscribe(RxApi.Search().getSearch(settings, withHtml), this::onLoadData, new SearchResult(), v -> loadData());
    return true;
}
Also used : SearchResult(forpdateam.ru.forpda.api.search.models.SearchResult)

Example 2 with SearchResult

use of forpdateam.ru.forpda.api.search.models.SearchResult in project ForPDA by RadiationX.

the class Search method getSearch.

public SearchResult getSearch(SearchSettings settings) throws Exception {
    SearchResult result = new SearchResult();
    NetworkResponse response = Api.getWebClient().get(settings.toUrl());
    Matcher matcher = null;
    SearchItem item = null;
    boolean isNews = settings.getResourceType().equals(SearchSettings.RESOURCE_NEWS.first);
    boolean resultTopics = settings.getResult().equals(SearchSettings.RESULT_TOPICS.first);
    if (isNews) {
        matcher = newsListPattern.matcher(response.getBody());
        while (matcher.find()) {
            item = new SearchItem();
            item.setId(Integer.parseInt(matcher.group(1)));
            item.setImageUrl(matcher.group(2));
            item.setDate(matcher.group(3));
            item.setUserId(Integer.parseInt(matcher.group(4)));
            item.setNick(ApiUtils.fromHtml(matcher.group(5)));
            item.setTitle(ApiUtils.fromHtml(matcher.group(6)));
            item.setBody(matcher.group(7));
            result.addItem(item);
        }
    } else {
        if (resultTopics) {
            matcher = forumTopicsPattern.matcher(response.getBody());
            while (matcher.find()) {
                item = new SearchItem();
                item.setTopicId(Integer.parseInt(matcher.group(1)));
                // item.setId(Integer.parseInt(matcher.group(1)));
                item.setTitle(ApiUtils.fromHtml(matcher.group(4)));
                item.setDesc(ApiUtils.fromHtml(matcher.group(5)));
                item.setForumId(Integer.parseInt(matcher.group(6)));
                item.setUserId(Integer.parseInt(matcher.group(10)));
                item.setNick(ApiUtils.fromHtml(matcher.group(11)));
                item.setDate(matcher.group(12));
                result.addItem(item);
            }
        } else {
            matcher = universalForumPosts.matcher(response.getBody());
            while (matcher.find()) {
                item = new SearchItem();
                item.setTopicId(Integer.parseInt(matcher.group(2)));
                item.setId(Integer.parseInt(matcher.group(3)));
                item.setTitle(ApiUtils.fromHtml(matcher.group(4)));
                item.setDate(matcher.group(5));
                // item.setNumber(Integer.parseInt(matcher.group(6)));
                item.setOnline(matcher.group(7).contains("green"));
                String avatar = matcher.group(8);
                if (!avatar.isEmpty()) {
                    avatar = "https://s.4pda.to/forum/uploads/".concat(avatar);
                }
                item.setAvatar(avatar);
                item.setNick(ApiUtils.fromHtml(matcher.group(9)));
                item.setUserId(Integer.parseInt(matcher.group(10)));
                item.setCurator(matcher.group(11) != null);
                item.setGroupColor(matcher.group(12));
                item.setGroup(matcher.group(13));
                item.setCanMinus(!matcher.group(14).isEmpty());
                item.setReputation(matcher.group(15));
                item.setCanPlus(!matcher.group(16).isEmpty());
                item.setCanReport(!matcher.group(17).isEmpty());
                item.setCanEdit(!matcher.group(18).isEmpty());
                item.setCanDelete(!matcher.group(19).isEmpty());
                item.setCanQuote(!matcher.group(20).isEmpty());
                item.setBody(matcher.group(21));
                result.addItem(item);
            }
        }
    }
    if (isNews) {
        result.setPagination(Pagination.parseNews(response.getBody()));
    } else {
        result.setPagination(Pagination.parseForum(response.getBody()));
    }
    result.setSettings(settings);
    return result;
}
Also used : Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) SearchResult(forpdateam.ru.forpda.api.search.models.SearchResult) SearchItem(forpdateam.ru.forpda.api.search.models.SearchItem)

Aggregations

SearchResult (forpdateam.ru.forpda.api.search.models.SearchResult)2 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 SearchItem (forpdateam.ru.forpda.api.search.models.SearchItem)1 Matcher (java.util.regex.Matcher)1