Search in sources :

Example 1 with AttachmentItem

use of forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem 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 AttachmentItem

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

the class AttachmentAdapter method updateChecked.

private void updateChecked(ViewHolder holder, int position) {
    AttachmentItem item = items.get(position);
    if (item.isSelected()) {
        if (!selected.contains(item)) {
            selected.add(item);
        }
    } else {
        selected.remove(item);
    }
    holder.radioButton.setChecked(item.isSelected());
    if (item.getLoadState() == AttachmentItem.STATE_NOT_LOADED) {
        holder.overlay.setVisibility(View.VISIBLE);
        holder.overlay.setBackgroundColor(Color.argb(item.isSelected() ? 96 : 48, 255, 0, 0));
    } else {
        holder.overlay.setBackgroundColor(Color.argb(48, 0, 0, 0));
        holder.overlay.setVisibility(item.isSelected() ? View.VISIBLE : View.GONE);
    }
    if (onSelectedListener != null)
        onSelectedListener.onSelected(item, position, selected.size());
}
Also used : AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 3 with AttachmentItem

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

the class AttachmentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final AttachmentAdapter.ViewHolder holder, final int position) {
    AttachmentItem item = items.get(position);
    switch(item.getLoadState()) {
        case AttachmentItem.STATE_LOADING:
            holder.description.setVisibility(View.GONE);
            holder.progressBar.setVisibility(View.VISIBLE);
            holder.reload.setVisibility(View.GONE);
            holder.imageView.setVisibility(View.GONE);
            item.setProgressListener(holder.progressListener);
            break;
        case AttachmentItem.STATE_NOT_LOADED:
            holder.description.setVisibility(View.GONE);
            holder.progressBar.setVisibility(View.GONE);
            holder.reload.setVisibility(View.VISIBLE);
            holder.imageView.setVisibility(View.GONE);
            break;
        case AttachmentItem.STATE_LOADED:
            holder.description.setVisibility(View.VISIBLE);
            holder.name.setText(item.getName());
            holder.attributes.setText(item.getExtension().concat(", ").concat(item.getWeight()));
            holder.progressBar.setVisibility(View.GONE);
            holder.reload.setVisibility(View.GONE);
            holder.imageView.setVisibility(View.VISIBLE);
            if (item.getTypeFile() == AttachmentItem.TYPE_IMAGE) {
                ImageLoader.getInstance().displayImage(item.getImageUrl(), holder.imageView);
            } else {
                holder.imageView.setImageDrawable(App.getVecDrawable(holder.itemView.getContext(), R.drawable.ic_insert_drive_file_gray_24dp));
            }
            break;
    }
    updateChecked(holder, position);
}
Also used : AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 4 with AttachmentItem

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

the class AttachmentsPopup method preUploadFiles.

public List<AttachmentItem> preUploadFiles(List<RequestFile> files) {
    Log.d(LOG_TAG, "preUploadFiles " + files);
    List<AttachmentItem> loadingItems = new ArrayList<>();
    for (RequestFile file : files) {
        AttachmentItem item = new AttachmentItem(file.getFileName());
        item.setProgressListener(percent -> {
        });
        Log.d(LOG_TAG, "Add loading item " + item);
        adapter.add(item);
        loadingItems.add(item);
    }
    return loadingItems;
}
Also used : ArrayList(java.util.ArrayList) RequestFile(forpdateam.ru.forpda.api.RequestFile) AttachmentItem(forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem)

Example 5 with AttachmentItem

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

the class Qms method uploadFiles.

public List<AttachmentItem> uploadFiles(List<RequestFile> files, List<AttachmentItem> pending) throws Exception {
    String baseUrl = "https://ru.imgbb.com/";
    String uploadUrl = "https://ru.imgbb.com/json";
    String authToken = "null";
    NetworkResponse baseResponse = Api.getWebClient().get(baseUrl);
    Matcher baseMatcher = imgBbPattern.matcher(baseResponse.getBody());
    if (baseMatcher.find()) {
        uploadUrl = baseMatcher.group(1);
        authToken = baseMatcher.group(2);
    }
    HashMap<String, String> headers = new HashMap<>();
    headers.put("type", "file");
    headers.put("action", "upload");
    headers.put("privacy", "undefined");
    headers.put("timestamp", Long.toString(System.currentTimeMillis()));
    headers.put("auth_token", authToken);
    headers.put("nsfw", "0");
    // Matcher matcher = null;
    for (int i = 0; i < files.size(); i++) {
        RequestFile file = files.get(i);
        AttachmentItem item = pending.get(i);
        file.setRequestName("source");
        NetworkRequest.Builder builder = new NetworkRequest.Builder().url(uploadUrl).formHeaders(headers).file(file);
        NetworkResponse response = Api.getWebClient().request(builder.build(), item.getItemProgressListener());
        JSONObject responseJson = new JSONObject(response.getBody());
        forpdateam.ru.forpda.common.Utils.longLog(responseJson.toString(4));
        if (responseJson.getInt("status_code") == 200) {
            JSONObject imageJson = responseJson.getJSONObject("image");
            item.setName(imageJson.getString("filename"));
            item.setId(0);
            item.setExtension(imageJson.getString("extension"));
            item.setWeight(imageJson.getString("size_formatted"));
            item.setTypeFile(AttachmentItem.TYPE_IMAGE);
            item.setLoadState(AttachmentItem.STATE_LOADED);
            item.setImageUrl(imageJson.getJSONObject("medium").getString("url"));
            item.setUrl(imageJson.getJSONObject("image").getString("url"));
        }
    }
    return pending;
}
Also used : JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) 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)

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