Search in sources :

Example 1 with EditPostForm

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

the class ThemeFragment method createEditPostForm.

private EditPostForm createEditPostForm() {
    EditPostForm form = new EditPostForm();
    if (currentPage == null) {
        return null;
    }
    form.setForumId(currentPage.getForumId());
    form.setTopicId(currentPage.getId());
    form.setSt(currentPage.getPagination().getCurrent() * currentPage.getPagination().getPerPage());
    form.setMessage(messagePanel.getMessage());
    List<AttachmentItem> attachments = messagePanel.getAttachments();
    for (AttachmentItem item : attachments) {
        form.addAttachment(item);
    }
    return form;
}
Also used : EditPostForm(forpdateam.ru.forpda.api.theme.editpost.models.EditPostForm) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 2 with EditPostForm

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

the class ThemeFragment method sendMessage.

private void sendMessage() {
    hidePopupWindows();
    EditPostForm form = createEditPostForm();
    if (form != null) {
        messagePanel.setProgressState(true);
        subscribe(RxApi.EditPost().sendPost(form), s -> {
            messagePanel.setProgressState(false);
            if (s != currentPage) {
                onLoadData(s);
                messagePanel.clearAttachments();
                messagePanel.clearMessage();
                if (Preferences.Main.isEditorDefaultHidden(getContext())) {
                    hideMessagePanel();
                }
            }
        }, currentPage);
    }
}
Also used : EditPostForm(forpdateam.ru.forpda.api.theme.editpost.models.EditPostForm)

Example 3 with EditPostForm

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

the class ThemeFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    viewsReady();
    setFontSize(Preferences.Main.getWebViewSize(getContext()));
    notificationButton.setColorFilter(App.getColorFromAttr(getContext(), R.attr.contrast_text_color), PorterDuff.Mode.SRC_ATOP);
    notificationTitle.setText("Новое сообщение");
    notificationView.setVisibility(View.GONE);
    notificationButton.setOnClickListener(v -> {
        notificationView.setVisibility(View.GONE);
    });
    notificationView.findViewById(R.id.new_message_card).setOnClickListener(v -> {
        tab_url = "https://4pda.ru/forum/index.php?showtopic=" + currentPage.getId() + "&view=getnewpost";
        loadData(NORMAL_ACTION);
        notificationView.setVisibility(View.GONE);
    });
    messagePanel.enableBehavior();
    messagePanel.addSendOnClickListener(v -> sendMessage());
    messagePanel.getSendButton().setOnLongClickListener(v -> {
        EditPostForm form = createEditPostForm();
        if (form != null) {
            TabManager.get().add(EditPostFragment.newInstance(createEditPostForm(), currentPage.getTitle()));
        }
        return true;
    });
    messagePanel.getFullButton().setVisibility(View.VISIBLE);
    messagePanel.getFullButton().setOnClickListener(v -> {
        EditPostForm form = createEditPostForm();
        if (form != null) {
            TabManager.get().add(EditPostFragment.newInstance(createEditPostForm(), currentPage.getTitle()));
        }
    });
    messagePanel.getHideButton().setVisibility(View.VISIBLE);
    messagePanel.getHideButton().setOnClickListener(v -> {
        hideMessagePanel();
    });
    attachmentsPopup = messagePanel.getAttachmentsPopup();
    attachmentsPopup.setAddOnClickListener(v -> tryPickFile());
    attachmentsPopup.setDeleteOnClickListener(v -> removeFiles());
    paginationHelper.setListener(new PaginationHelper.PaginationListener() {

        @Override
        public boolean onTabSelected(TabLayout.Tab tab) {
            return refreshLayout.isRefreshing();
        }

        @Override
        public void onSelectedPage(int pageNumber) {
            String url = "https://4pda.ru/forum/index.php?showtopic=";
            url = url.concat(Uri.parse(tab_url).getQueryParameter("showtopic"));
            if (pageNumber != 0)
                url = url.concat("&st=").concat(Integer.toString(pageNumber));
            tab_url = url;
            loadData(NORMAL_ACTION);
        }
    });
    fab.setSize(FloatingActionButton.SIZE_MINI);
    if (Preferences.Main.isScrollButtonEnable(getContext())) {
        fab.setVisibility(View.VISIBLE);
    } else {
        fab.setVisibility(View.GONE);
    }
    fab.setScaleX(0.0f);
    fab.setScaleY(0.0f);
    fab.setAlpha(0.0f);
    App.get().addPreferenceChangeObserver(themePreferenceObserver);
    refreshLayoutStyle(refreshLayout);
    refreshLayout.setOnRefreshListener(() -> {
        loadData(REFRESH_ACTION);
    });
    if (App.get().getPreferences().getBoolean("theme.tooltip.long_click_send", true)) {
        tooltip = new SimpleTooltip.Builder(getContext()).anchorView(messagePanel.getSendButton()).text(R.string.tooltip_full_form).gravity(Gravity.TOP).animated(false).modal(true).transparentOverlay(false).backgroundColor(Color.BLACK).textColor(Color.WHITE).padding((float) App.px16).build();
        tooltip.show();
        App.get().getPreferences().edit().putBoolean("theme.tooltip.long_click_send", false).apply();
    }
    if (Preferences.Main.isEditorDefaultHidden(getContext())) {
        hideMessagePanel();
    } else {
        showMessagePanel(false);
    }
    App.get().subscribeFavorites(notification);
}
Also used : EditPostForm(forpdateam.ru.forpda.api.theme.editpost.models.EditPostForm) SimpleTooltip(io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip) TabLayout(android.support.design.widget.TabLayout) PaginationHelper(forpdateam.ru.forpda.ui.views.pagination.PaginationHelper) SuppressLint(android.annotation.SuppressLint)

Example 4 with EditPostForm

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

the class EditPost method loadForm.

public EditPostForm loadForm(int postId) throws Exception {
    EditPostForm form = new EditPostForm();
    String url = "https://4pda.ru/forum/index.php?act=post&do=edit_post&p=".concat(Integer.toString(postId));
    // url = url.concat("&t=").concat(Integer.toString(topicId)).concat("&f=").concat(Integer.toString(forumId));
    NetworkResponse response = Api.getWebClient().get(url);
    if (response.getBody().equals("nopermission")) {
        form.setErrorCode(EditPostForm.ERROR_NO_PERMISSION);
        return form;
    }
    Matcher matcher = postPattern.matcher(response.getBody());
    if (matcher.find()) {
        form.setMessage(ApiUtils.fromHtml(ApiUtils.escapeNewLine(matcher.group(1))));
        form.setEditReason(matcher.group(2));
    }
    matcher = pollInfoPattern.matcher(response.getBody());
    if (matcher.find()) {
        EditPoll poll = createPoll(matcher);
        form.setPoll(poll);
        EditPost.printPoll(poll);
    }
    response = Api.getWebClient().get("https://4pda.ru/forum/index.php?act=attach&index=1&relId=" + postId + "&maxSize=134217728&allowExt=&code=init&unlinked=");
    matcher = attachmentsPattern.matcher(response.getBody());
    while (matcher.find()) {
        form.addAttachment(fillAttachmentV2(new AttachmentItem(), matcher));
    }
    return form;
}
Also used : EditPostForm(forpdateam.ru.forpda.api.theme.editpost.models.EditPostForm) Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) EditPoll(forpdateam.ru.forpda.api.theme.editpost.models.EditPoll) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Aggregations

EditPostForm (forpdateam.ru.forpda.api.theme.editpost.models.EditPostForm)4 AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)2 SuppressLint (android.annotation.SuppressLint)1 TabLayout (android.support.design.widget.TabLayout)1 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)1 EditPoll (forpdateam.ru.forpda.api.theme.editpost.models.EditPoll)1 PaginationHelper (forpdateam.ru.forpda.ui.views.pagination.PaginationHelper)1 SimpleTooltip (io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip)1 Matcher (java.util.regex.Matcher)1