Search in sources :

Example 6 with AttachmentItem

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

the class QmsChatFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    webView.setJsLifeCycleListener(this);
    webView.addJavascriptInterface(this, JS_INTERFACE);
    registerForContextMenu(webView);
    webView.setWebViewClient(new CustomWebViewClient());
    webView.setWebChromeClient(new CustomWebChromeClient());
    loadBaseWebContainer();
    viewsReady();
    attachmentsPopup.setAddOnClickListener(v -> tryPickFile());
    attachmentsPopup.setDeleteOnClickListener(v -> {
        attachmentsPopup.preDeleteFiles();
        List<AttachmentItem> selectedFiles = attachmentsPopup.getSelected();
        for (AttachmentItem item : selectedFiles) {
            item.setStatus(AttachmentItem.STATUS_REMOVED);
        }
        attachmentsPopup.onDeleteFiles(selectedFiles);
    });
    attachmentsPopup.setInsertAttachmentListener(item -> String.format(Locale.getDefault(), "\n[url=%s]Файл: %s, Размер: %s, Thumb: %s[/url]\n", item.getUrl(), item.getName(), item.getWeight(), item.getImageUrl()));
    messagePanel.addSendOnClickListener(v -> {
        if (currentChat.getThemeId() == QmsChatModel.NOT_CREATED) {
            themeCreator.sendNewTheme();
        } else {
            sendMessage();
        }
    });
    messagePanel.setHeightChangeListener(newHeight -> {
        webView.setPaddingBottom(newHeight);
    });
    App.get().addPreferenceChangeObserver(chatPreferenceObserver);
    tryShowAvatar();
    if (currentChat.getNick() != null) {
        setSubtitle(currentChat.getNick());
    }
    if (currentChat.getTitle() != null) {
        setTitle(currentChat.getTitle());
        setTabTitle(String.format(getString(R.string.fragment_tab_title_chat), currentChat.getTitle(), currentChat.getNick()));
    }
    if (currentChat.getThemeId() == QmsChatModel.NOT_CREATED) {
        themeCreator = new ChatThemeCreator(this);
    }
}
Also used : CustomWebViewClient(forpdateam.ru.forpda.common.webview.CustomWebViewClient) CustomWebChromeClient(forpdateam.ru.forpda.common.webview.CustomWebChromeClient) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 7 with AttachmentItem

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

the class QmsChatFragment method addUnusedAttachments.

private void addUnusedAttachments() {
    try {
        Matcher matcher = attachmentPattern.matcher(messagePanel.getMessage());
        ArrayList<String> attachmentsUrls = new ArrayList<>();
        while (matcher.find()) {
            attachmentsUrls.add(matcher.group(1));
        }
        ArrayList<AttachmentItem> notAttached = new ArrayList<>();
        for (AttachmentItem item : attachmentsPopup.getAttachments()) {
            if (!attachmentsUrls.contains(item.getUrl())) {
                notAttached.add(item);
            }
        }
        messagePanel.getMessageField().setSelection(messagePanel.getMessageField().getText().length());
        attachmentsPopup.insertAttachment(notAttached, false);
    } catch (Exception ignore) {
    }
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 8 with AttachmentItem

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

the class EditPost method uploadFiles.

public List<AttachmentItem> uploadFiles(int postId, List<RequestFile> files) throws Exception {
    String url = "https://4pda.ru/forum/index.php?&act=attach&code=attach_upload_process&attach_rel_id=".concat(postId == 0 ? "" : Integer.toString(postId));
    List<AttachmentItem> items = new ArrayList<>();
    AttachmentItem item;
    NetworkResponse response;
    Matcher matcher;
    for (RequestFile file : files) {
        file.setRequestName("FILE_UPLOAD[]");
        item = new AttachmentItem();
        NetworkRequest.Builder builder = new NetworkRequest.Builder().url(url).file(file);
        response = Api.getWebClient().request(builder.build());
        matcher = loadedAttachments.matcher(response.getBody());
        if (matcher.find())
            item = fillAttachment(item, matcher);
        matcher = statusInfo.matcher(response.getBody());
        if (matcher.find())
            fillAttachmentStatus(item, matcher);
        items.add(item);
    }
    return items;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) RequestFile(forpdateam.ru.forpda.api.RequestFile) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 9 with AttachmentItem

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

the class EditPost method deleteFilesV2.

public List<AttachmentItem> deleteFilesV2(int postId, List<AttachmentItem> items) throws Exception {
    NetworkResponse response;
    for (AttachmentItem item : items) {
        NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=attach").xhrHeader().formHeader("index", "1").formHeader("relId", Integer.toString(postId)).formHeader("maxSize", "134217728").formHeader("allowExt", "").formHeader("code", "remove").formHeader("id", Integer.toString(item.getId()));
        response = Api.getWebClient().request(builder.build());
        // todo проверка на ошибки, я хз че еще может быть кроме 0
        if (response.getBody().equals("0")) {
            item.setStatus(AttachmentItem.STATUS_REMOVED);
            item.setError(false);
        }
    }
    return items;
}
Also used : NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) NetworkRequest(forpdateam.ru.forpda.api.NetworkRequest) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 10 with AttachmentItem

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

the class EditPost method deleteFiles.

public List<AttachmentItem> deleteFiles(int postId, List<AttachmentItem> items) throws Exception {
    NetworkResponse response;
    Matcher matcher;
    for (AttachmentItem item : items) {
        response = Api.getWebClient().get("https://4pda.ru/forum/index.php?&act=attach&code=attach_upload_remove&attach_rel_id=".concat(postId == 0 ? "" : Integer.toString(postId)).concat("&attach_id=").concat(Integer.toString(item.getId())));
        matcher = statusInfo.matcher(response.getBody());
        if (matcher.find())
            fillAttachmentStatus(item, matcher);
    }
    return items;
}
Also used : Matcher(java.util.regex.Matcher) NetworkResponse(forpdateam.ru.forpda.api.NetworkResponse) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Aggregations

AttachmentItem (forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)16 NetworkResponse (forpdateam.ru.forpda.api.NetworkResponse)6 Matcher (java.util.regex.Matcher)6 NetworkRequest (forpdateam.ru.forpda.api.NetworkRequest)4 RequestFile (forpdateam.ru.forpda.api.RequestFile)4 ArrayList (java.util.ArrayList)3 EditPostForm (forpdateam.ru.forpda.api.theme.editpost.models.EditPostForm)2 EditPoll (forpdateam.ru.forpda.api.theme.editpost.models.EditPoll)1 ThemePage (forpdateam.ru.forpda.api.theme.models.ThemePage)1 CustomWebChromeClient (forpdateam.ru.forpda.common.webview.CustomWebChromeClient)1 CustomWebViewClient (forpdateam.ru.forpda.common.webview.CustomWebViewClient)1 TabFragment (forpdateam.ru.forpda.ui.fragments.TabFragment)1 ThemeFragment (forpdateam.ru.forpda.ui.fragments.theme.ThemeFragment)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MessageDigest (java.security.MessageDigest)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1