use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class FilesAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final FileViewHolder holder, final int position) {
Attachment attachment = items.get(position);
holder.attachmentId = attachment.getUniqueId();
// set file icon
holder.tvFileName.setText(attachment.getTitle());
Long size = attachment.getFileSize();
holder.tvFileSize.setText(FileUtils.byteCountToDisplaySize(size != null ? size : 0));
holder.ivFileIcon.setImageResource(attachment.getFilePath() != null ? getFileIconByCategory(FileCategory.determineFileCategory(attachment.getMimeType())) : R.drawable.ic_download);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onFileClick(position);
}
});
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (items.size() > position)
listener.onFileLongClick(items.get(position), v);
return true;
}
});
holder.ivCancelDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onDownloadCancel();
}
});
holder.itemView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View view) {
holder.subscribeForDownloadProgress();
}
@Override
public void onViewDetachedFromWindow(View v) {
holder.unsubscribeAll();
}
});
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class FileMessageVH method setUpFile.
private void setUpFile(RealmList<Attachment> attachments, Context context) {
RealmList<Attachment> fileAttachments = new RealmList<>();
for (Attachment attachment : attachments) {
if (!attachment.isImage())
fileAttachments.add(attachment);
}
if (fileAttachments.size() > 0) {
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
rvFileList.setLayoutManager(layoutManager);
FilesAdapter adapter = new FilesAdapter(fileAttachments, this);
rvFileList.setAdapter(adapter);
fileLayout.setVisibility(View.VISIBLE);
}
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class ImageGridBuilder method bindView.
public void bindView(View view, RealmList<Attachment> attachments, View.OnClickListener clickListener) {
if (attachments.size() == 1) {
ImageView imageView = getImageView(view, 0);
bindOneImage(attachments.get(0), view, imageView);
imageView.setOnClickListener(clickListener);
} else {
TextView tvCounter = view.findViewById(R.id.tvCounter);
int index = 0;
loop: for (Attachment attachment : attachments) {
if (index > 5)
break loop;
ImageView imageView = getImageView(view, index);
if (imageView != null) {
bindImage(attachment, view, imageView);
imageView.setOnClickListener(clickListener);
}
index++;
}
if (tvCounter != null) {
if (attachments.size() > MAX_IMAGE_IN_GRID) {
tvCounter.setText(new StringBuilder("+").append(attachments.size() - MAX_IMAGE_IN_GRID));
tvCounter.setVisibility(View.VISIBLE);
} else
tvCounter.setVisibility(View.GONE);
}
}
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class HttpFileUploadManager method retrySendFileMessage.
public void retrySendFileMessage(final MessageItem messageItem, Context context) {
List<String> notUploadedFilesPaths = new ArrayList<>();
for (Attachment attachment : messageItem.getAttachments()) {
if (attachment.getFileUrl() == null || attachment.getFileUrl().isEmpty())
notUploadedFilesPaths.add(attachment.getFilePath());
}
// if all attachments have url that they was uploaded. just resend existing message
if (notUploadedFilesPaths.size() == 0) {
final AccountJid accountJid = messageItem.getAccount();
final UserJid userJid = messageItem.getUser();
final String messageId = messageItem.getUniqueId();
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
MessageManager.getInstance().removeErrorAndResendMessage(accountJid, userJid, messageId);
}
});
} else
// else, upload files that haven't urls. Then write they in existing message and send
uploadFile(messageItem.getAccount(), messageItem.getUser(), notUploadedFilesPaths, null, messageItem.getUniqueId(), context);
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class HttpFileUploadManager method mediaToAttachment.
private static Attachment mediaToAttachment(ExtendedFormField.Media media, String title) {
Attachment attachment = new Attachment();
attachment.setTitle(title);
try {
if (media.getWidth() != null && !media.getWidth().isEmpty())
attachment.setImageWidth(Integer.valueOf(media.getWidth()));
if (media.getHeight() != null && !media.getHeight().isEmpty())
attachment.setImageHeight(Integer.valueOf(media.getHeight()));
} catch (NumberFormatException e) {
LogManager.exception(LOG_TAG, e);
}
ExtendedFormField.Uri uri = media.getUri();
if (uri != null) {
attachment.setMimeType(uri.getType());
attachment.setFileSize(uri.getSize());
attachment.setDuration(uri.getDuration());
attachment.setFileUrl(uri.getUri());
attachment.setIsImage(FileManager.isImageUrl(uri.getUri()));
}
return attachment;
}
Aggregations