Search in sources :

Example 1 with ThemePage

use of forpdateam.ru.forpda.api.theme.models.ThemePage in project ForPDA by RadiationX.

the class ThemeFragment method onBackPressed.

@Override
public boolean onBackPressed() {
    super.onBackPressed();
    if (tooltip != null && tooltip.isShowing()) {
        tooltip.dismiss();
        return true;
    }
    if (messagePanel.onBackPressed())
        return true;
    if (getMenu().findItem(R.id.action_search) != null && getMenu().findItem(R.id.action_search).isActionViewExpanded()) {
        toolbar.collapseActionView();
        return true;
    }
    if (App.get().getPreferences().getBoolean("theme.anchor_history", true)) {
        if (currentPage != null && currentPage.getAnchors().size() > 1) {
            currentPage.removeAnchor();
            scrollToAnchor(currentPage.getAnchor());
            return true;
        }
    }
    if (history.size() > 1) {
        setAction(BACK_ACTION);
        ThemePage removed = history.get(history.size() - 1);
        history.remove(history.size() - 1);
        currentPage = history.get(history.size() - 1);
        Log.e(LOG_TAG, "BACK PRESS REMOVE " + removed + " :" + currentPage);
        tab_url = currentPage.getUrl();
        updateView();
        return true;
    }
    if ((messagePanel.getMessage() != null && !messagePanel.getMessage().isEmpty()) || !messagePanel.getAttachments().isEmpty()) {
        new AlertDialog.Builder(getContext()).setMessage(R.string.editpost_lose_changes).setPositiveButton(R.string.ok, (dialog, which) -> {
            history.clear();
            TabManager.get().remove(ThemeFragment.this);
        }).setNegativeButton(R.string.no, null).show();
        return true;
    }
    return false;
}
Also used : ThemePage(forpdateam.ru.forpda.api.theme.models.ThemePage)

Example 2 with ThemePage

use of forpdateam.ru.forpda.api.theme.models.ThemePage in project ForPDA by RadiationX.

the class ThemeFragmentWeb method updateHistoryLast.

@Override
protected void updateHistoryLast(ThemePage themePage) {
    Log.d(LOG_TAG, "updateHistoryLast " + themePage + " : " + currentPage);
    ThemePage lastHistory = history.get(history.size() - 1);
    themePage.getAnchors().addAll(lastHistory.getAnchors());
    themePage.setScrollY(lastHistory.getScrollY());
    history.set(history.size() - 1, themePage);
}
Also used : ThemePage(forpdateam.ru.forpda.api.theme.models.ThemePage)

Example 3 with ThemePage

use of forpdateam.ru.forpda.api.theme.models.ThemePage in project ForPDA by RadiationX.

the class Theme method parsePage.

public ThemePage parsePage(String url, NetworkResponse response, boolean hatOpen, boolean pollOpen) throws Exception {
    ThemePage page = new ThemePage();
    page.setHatOpen(hatOpen);
    page.setPollOpen(pollOpen);
    String redirectUrl = response.getRedirect();
    if (redirectUrl == null)
        redirectUrl = url;
    page.setUrl(redirectUrl);
    long time = System.currentTimeMillis();
    Matcher matcher = elemToScrollPattern.matcher(redirectUrl);
    while (matcher.find()) {
        page.addAnchor(matcher.group(1));
    }
    matcher = themeIdPattern.matcher(response.getBody());
    if (matcher.find()) {
        page.setForumId(Integer.parseInt(matcher.group(1)));
        page.setId(Integer.parseInt(matcher.group(2)));
    }
    page.setPagination(Pagination.parseForum(response.getBody()));
    matcher = titlePattern.matcher(response.getBody());
    if (matcher.find()) {
        page.setTitle(ApiUtils.fromHtml(matcher.group(1)));
        page.setDesc(ApiUtils.fromHtml(matcher.group(2)));
    }
    matcher = alreadyInFavPattern.matcher(response.getBody());
    if (matcher.find()) {
        page.setInFavorite(true);
        matcher = favIdPattern.matcher(response.getBody());
        if (matcher.find()) {
            page.setFavId(Integer.parseInt(matcher.group(1)));
        }
    }
    matcher = universalForumPosts.matcher(response.getBody());
    Matcher attachMatcher = null;
    while (matcher.find()) {
        ThemePost item = new ThemePost();
        item.setTopicId(page.getId());
        item.setForumId(page.getForumId());
        item.setId(Integer.parseInt(matcher.group(1)));
        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());
        page.setCanQuote(!matcher.group(20).isEmpty());
        item.setCanQuote(page.canQuote());
        item.setBody(matcher.group(21));
        if (attachMatcher == null) {
            attachMatcher = attachImagesPattern.matcher(item.getBody());
        } else {
            attachMatcher.reset(item.getBody());
        }
        while (attachMatcher.find()) {
            item.addAttachImage(attachMatcher.group(1), attachMatcher.group(2));
        }
        if (item.isCurator() && item.getUserId() == ClientHelper.getUserId())
            page.setCurator(true);
        page.addPost(item);
    }
    matcher = pollMainPattern.matcher(response.getBody());
    if (matcher.find()) {
        Poll poll = new Poll();
        final boolean isResult = matcher.group().contains("<img");
        poll.setIsResult(isResult);
        poll.setTitle(ApiUtils.fromHtml(matcher.group(1)));
        Matcher matcher1 = pollQuestions.matcher(matcher.group(2));
        while (matcher1.find()) {
            PollQuestion pollQuestion = new PollQuestion();
            pollQuestion.setTitle(ApiUtils.fromHtml(matcher1.group(1)));
            Matcher itemsMatcher = pollQuestionItems.matcher(matcher1.group(2));
            while (itemsMatcher.find()) {
                PollQuestionItem questionItem = new PollQuestionItem();
                if (!isResult) {
                    questionItem.setType(itemsMatcher.group(1));
                    questionItem.setName(ApiUtils.fromHtml(itemsMatcher.group(2)));
                    questionItem.setValue(Integer.parseInt(itemsMatcher.group(3)));
                    questionItem.setTitle(ApiUtils.fromHtml(itemsMatcher.group(4)));
                } else {
                    questionItem.setTitle(ApiUtils.fromHtml(itemsMatcher.group(5)));
                    questionItem.setVotes(Integer.parseInt(itemsMatcher.group(6)));
                    questionItem.setPercent(Float.parseFloat(itemsMatcher.group(7).replace(",", ".")));
                }
                pollQuestion.addItem(questionItem);
            }
            poll.addQuestion(pollQuestion);
        }
        matcher1 = pollButtons.matcher(matcher.group(4));
        while (matcher1.find()) {
            String value = matcher1.group(1);
            if (value.contains("Голосовать")) {
                poll.setVoteButton();
            } else if (value.contains("результаты")) {
                poll.setShowResultButton();
            } else if (value.contains("пункты опроса")) {
                poll.setShowPollButton();
            }
        }
        poll.setVotesCount(Integer.parseInt(matcher.group(3)));
        page.setPoll(poll);
    }
    return page;
}
Also used : ThemePost(forpdateam.ru.forpda.api.theme.models.ThemePost) ThemePage(forpdateam.ru.forpda.api.theme.models.ThemePage) PollQuestion(forpdateam.ru.forpda.api.theme.models.PollQuestion) Matcher(java.util.regex.Matcher) Poll(forpdateam.ru.forpda.api.theme.models.Poll) PollQuestionItem(forpdateam.ru.forpda.api.theme.models.PollQuestionItem)

Example 4 with ThemePage

use of forpdateam.ru.forpda.api.theme.models.ThemePage in project ForPDA by RadiationX.

the class ThemeFragment method loadData.

@Override
public boolean loadData() {
    if (!super.loadData()) {
        return false;
    }
    setRefreshing(true);
    refreshToolbarMenuItems(false);
    boolean hatOpen = false;
    boolean pollOpen = false;
    if (currentPage != null) {
        hatOpen = currentPage.isHatOpen();
        pollOpen = currentPage.isPollOpen();
    }
    subscribe(RxApi.Theme().getTheme(tab_url, true, hatOpen, pollOpen), this::onLoadData, new ThemePage(), v -> loadData());
    return true;
}
Also used : ThemePage(forpdateam.ru.forpda.api.theme.models.ThemePage)

Example 5 with ThemePage

use of forpdateam.ru.forpda.api.theme.models.ThemePage in project ForPDA by RadiationX.

the class ThemeFragmentWeb method callbackUpdateHistoryHtml.

@JavascriptInterface
public void callbackUpdateHistoryHtml(String value) {
    ThemePage themePage = history.get(history.size() - 1);
    Log.d(LOG_TAG, "updateHistoryLastHtml " + themePage + " : " + currentPage);
    themePage.setScrollY(webView.getScrollY());
    themePage.setHtml(value);
}
Also used : ThemePage(forpdateam.ru.forpda.api.theme.models.ThemePage) JavascriptInterface(android.webkit.JavascriptInterface)

Aggregations

ThemePage (forpdateam.ru.forpda.api.theme.models.ThemePage)6 JavascriptInterface (android.webkit.JavascriptInterface)1 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)1 Poll (forpdateam.ru.forpda.api.theme.models.Poll)1 PollQuestion (forpdateam.ru.forpda.api.theme.models.PollQuestion)1 PollQuestionItem (forpdateam.ru.forpda.api.theme.models.PollQuestionItem)1 ThemePost (forpdateam.ru.forpda.api.theme.models.ThemePost)1 TabFragment (forpdateam.ru.forpda.ui.fragments.TabFragment)1 ThemeFragment (forpdateam.ru.forpda.ui.fragments.theme.ThemeFragment)1 Matcher (java.util.regex.Matcher)1