Search in sources :

Example 1 with Attachment

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();
        }
    });
}
Also used : Attachment(com.xabber.android.data.database.messagerealm.Attachment) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with Attachment

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);
    }
}
Also used : FilesAdapter(com.xabber.android.ui.adapter.FilesAdapter) RealmList(io.realm.RealmList) Attachment(com.xabber.android.data.database.messagerealm.Attachment) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 3 with Attachment

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);
        }
    }
}
Also used : TextView(android.widget.TextView) Attachment(com.xabber.android.data.database.messagerealm.Attachment) ImageView(android.widget.ImageView)

Example 4 with Attachment

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);
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) Attachment(com.xabber.android.data.database.messagerealm.Attachment)

Example 5 with Attachment

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;
}
Also used : Attachment(com.xabber.android.data.database.messagerealm.Attachment)

Aggregations

Attachment (com.xabber.android.data.database.messagerealm.Attachment)31 RealmList (io.realm.RealmList)8 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)7 Realm (io.realm.Realm)6 File (java.io.File)5 ImageView (android.widget.ImageView)4 ForwardId (com.xabber.android.data.database.messagerealm.ForwardId)4 UserJid (com.xabber.android.data.entity.UserJid)4 View (android.view.View)3 TextView (android.widget.TextView)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 RefUser (com.xabber.android.data.extension.references.RefUser)3 Date (java.util.Date)3 Message (org.jivesoftware.smack.packet.Message)3 Resourcepart (org.jxmpp.jid.parts.Resourcepart)3 Intent (android.content.Intent)2 Drawable (android.graphics.drawable.Drawable)2 AccountJid (com.xabber.android.data.entity.AccountJid)2 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1