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);
}
}
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) {
}
}
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;
}
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;
}
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;
}
Aggregations