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