use of forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem in project ForPDA by RadiationX.
the class EditPost method uploadFilesV2.
public List<AttachmentItem> uploadFilesV2(int postId, List<RequestFile> files, List<AttachmentItem> pending) throws Exception {
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("forum-attach-files", "").formHeader("code", "check");
NetworkResponse response;
Matcher matcher = null;
for (int i = 0; i < files.size(); i++) {
RequestFile file = files.get(i);
AttachmentItem item = pending.get(i);
file.setRequestName("FILE_UPLOAD[]");
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] targetArray = new byte[file.getFileStream().available()];
file.getFileStream().read(targetArray);
InputStream is1 = new ByteArrayInputStream(targetArray);
file.getFileStream().close();
file.setFileStream(is1);
messageDigest.update(targetArray);
byte[] hash = messageDigest.digest();
String md5 = ByteArraytoHexString(hash);
builder.formHeader("md5", md5).formHeader("size", "" + file.getFileStream().available()).formHeader("name", file.getFileName());
response = Api.getWebClient().request(builder.build());
if (response.getBody().equals("0")) {
NetworkRequest.Builder uploadRequest = 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("forum-attach-files", "").formHeader("code", "upload").file(file);
response = Api.getWebClient().request(uploadRequest.build(), item.getProgressListener());
}
if (matcher == null) {
matcher = attachmentsPattern.matcher(response.getBody());
} else {
matcher = matcher.reset(response.getBody());
}
if (matcher.find()) {
fillAttachmentV2(item, matcher);
}
item.setStatus(AttachmentItem.STATUS_UPLOADED);
}
return pending;
}
use of forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem 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;
}
use of forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem in project ForPDA by RadiationX.
the class EditPostFragment method sendMessage.
private void sendMessage() {
messagePanel.setProgressState(true);
postForm.setMessage(messagePanel.getMessage());
List<AttachmentItem> attachments = messagePanel.getAttachments();
postForm.getAttachments().clear();
for (AttachmentItem item : attachments) {
postForm.addAttachment(item);
}
subscribe(RxApi.EditPost().sendPost(postForm), s -> {
messagePanel.setProgressState(false);
if (s.getId() != 0) {
TabFragment fragment = TabManager.get().get(getParentTag());
if (fragment != null) {
if (fragment instanceof ThemeFragment) {
ThemeFragment themeFragment = (ThemeFragment) fragment;
if (postForm.getType() == TYPE_EDIT_POST) {
themeFragment.onEditPostCompleted(s);
} else {
themeFragment.onSendPostCompleted(s);
}
}
}
TabManager.get().remove(EditPostFragment.this);
}
}, new ThemePage(), v -> loadData());
}
use of forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem in project ForPDA by RadiationX.
the class AttachmentAdapter method deleteSelected.
public void deleteSelected() {
for (AttachmentItem item : selected) {
if (item.getStatus() == AttachmentItem.STATUS_REMOVED) {
int index = items.indexOf(item);
items.remove(index);
notifyItemRemoved(index);
}
}
unSelectItems();
if (onDataChangeListener != null) {
onDataChangeListener.onChange(items.size());
}
}
use of forpdateam.ru.forpda.api.theme.editpost.models.AttachmentItem in project ForPDA by RadiationX.
the class AttachmentsPopup method insertAttachment.
public void insertAttachment(List<AttachmentItem> items, boolean toSpoiler) {
StringBuilder text = new StringBuilder();
if (toSpoiler)
text.append("[spoiler]");
for (AttachmentItem item : items) {
if (insertAttachmentListener != null) {
text.append(insertAttachmentListener.onInsert(item));
} else {
text.append("[attachment=").append(item.getId()).append(":").append(item.getName()).append("]");
}
}
if (toSpoiler)
text.append("[/spoiler]");
messagePanel.insertText(text.toString());
adapter.unSelectItems();
dialog.cancel();
}
Aggregations