Search in sources :

Example 16 with Attachment

use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.

the class MessageNotificationManager method getNotificationText.

private String getNotificationText(MessageItem message) {
    String text = message.getText().trim();
    if (message.haveAttachments() && message.getAttachments().size() > 0) {
        Attachment attachment = message.getAttachments().get(0);
        FileCategory category = FileCategory.determineFileCategory(attachment.getMimeType());
        text = FileCategory.getCategoryName(category, false) + attachment.getTitle();
    }
    if (message.haveForwardedMessages() && message.getForwardedIds().size() > 0 && text.isEmpty()) {
        String forwardText = message.getFirstForwardedMessageText();
        if (forwardText != null && !forwardText.isEmpty())
            text = forwardText;
        else
            text = context.getString(R.string.forwarded_messages_count, message.getForwardedIds().size());
    }
    return text;
}
Also used : FileCategory(com.xabber.android.data.filedownload.FileCategory) Attachment(com.xabber.android.data.database.messagerealm.Attachment)

Example 17 with Attachment

use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.

the class ClipManager method messageToText.

private static String messageToText(Realm realm, MessageItem message, long previousMessageTimestamp, int level) {
    String space = getSpace(level);
    StringBuilder stringBuilder = new StringBuilder();
    final String name = RosterManager.getDisplayAuthorName(message);
    final String date = StringUtils.getDateStringForClipboard(message.getTimestamp());
    if (!Utils.isSameDay(message.getTimestamp(), previousMessageTimestamp)) {
        stringBuilder.append("\n");
        stringBuilder.append(space);
        stringBuilder.append(date);
    }
    stringBuilder.append("\n");
    stringBuilder.append(space);
    stringBuilder.append('[');
    stringBuilder.append(StringUtils.getTimeTextWithSeconds(new Date(message.getTimestamp())));
    stringBuilder.append("] ");
    stringBuilder.append(name);
    stringBuilder.append(":\n");
    if (message.haveForwardedMessages()) {
        stringBuilder.append(messagesToText(realm, message.getForwardedIdsAsArray(), level + 1));
        stringBuilder.append("\n");
    }
    if (message.haveAttachments()) {
        for (Attachment attachment : message.getAttachments()) {
            stringBuilder.append(space);
            stringBuilder.append(attachment.getFileUrl());
            stringBuilder.append("\n");
        }
    }
    if (!message.getText().isEmpty()) {
        stringBuilder.append(space);
        stringBuilder.append(message.getText());
    }
    return stringBuilder.toString();
}
Also used : Attachment(com.xabber.android.data.database.messagerealm.Attachment) Date(java.util.Date)

Example 18 with Attachment

use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.

the class HttpFileUploadManager method refMediaToAttachment.

private static Attachment refMediaToAttachment(RefMedia media) {
    Attachment attachment = new Attachment();
    attachment.setFileUrl(media.getUri());
    attachment.setIsImage(FileManager.isImageUrl(media.getUri()));
    RefFile file = media.getFile();
    if (file != null) {
        attachment.setTitle(file.getName());
        attachment.setMimeType(file.getMediaType());
        attachment.setDuration(file.getDuration());
        attachment.setFileSize(file.getSize());
        if (file.getHeight() > 0)
            attachment.setImageHeight(file.getHeight());
        if (file.getWidth() > 0)
            attachment.setImageWidth(file.getWidth());
    }
    return attachment;
}
Also used : RefFile(com.xabber.android.data.extension.references.RefFile) Attachment(com.xabber.android.data.database.messagerealm.Attachment)

Example 19 with Attachment

use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.

the class FileInteractionFragment method openFileOrDownload.

private void openFileOrDownload(String messageUID, int attachmentPosition) {
    MessageItem messageItem = MessageDatabaseManager.getInstance().getRealmUiThread().where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageUID).findFirst();
    if (messageItem == null) {
        LogManager.w(LOG_TAG, "onMessageFileClick: null message item. UID: " + messageUID);
        return;
    }
    if (messageItem.haveAttachments()) {
        RealmList<Attachment> fileAttachments = new RealmList<>();
        for (Attachment attachment : messageItem.getAttachments()) {
            if (!attachment.isImage())
                fileAttachments.add(attachment);
        }
        Attachment attachment = fileAttachments.get(attachmentPosition);
        if (attachment == null)
            return;
        if (attachment.getFilePath() != null) {
            File file = new File(attachment.getFilePath());
            if (!file.exists()) {
                MessageManager.setAttachmentLocalPathToNull(attachment.getUniqueId());
                return;
            }
            Intent i = new Intent(Intent.ACTION_VIEW);
            String path = attachment.getFilePath();
            i.setDataAndType(FileProvider.getUriForFile(getActivity(), getActivity().getApplicationContext().getPackageName() + ".provider", new File(path)), attachment.getMimeType());
            i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            try {
                startActivity(i);
            } catch (ActivityNotFoundException e) {
                LogManager.exception(LOG_TAG, e);
                Toast.makeText(getActivity(), R.string.toast_could_not_open_file, Toast.LENGTH_SHORT).show();
            }
        } else
            DownloadManager.getInstance().downloadFile(attachment, account, getActivity());
    }
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RealmList(io.realm.RealmList) ActivityNotFoundException(android.content.ActivityNotFoundException) Attachment(com.xabber.android.data.database.messagerealm.Attachment) Intent(android.content.Intent) File(java.io.File)

Example 20 with Attachment

use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.

the class MessageManager method updateMessageWithNewAttachments.

public void updateMessageWithNewAttachments(final String messageId, final List<File> files) {
    Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
            if (messageItem != null) {
                RealmList<Attachment> attachments = messageItem.getAttachments();
                // remove temporary attachments created from uri
                // to replace it with attachments created from files
                attachments.deleteAllFromRealm();
                for (File file : files) {
                    Attachment attachment = new Attachment();
                    attachment.setFilePath(file.getPath());
                    attachment.setFileSize(file.length());
                    attachment.setTitle(file.getName());
                    attachment.setIsImage(FileManager.fileIsImage(file));
                    attachment.setMimeType(HttpFileUploadManager.getMimeType(file.getPath()));
                    attachment.setDuration((long) 0);
                    if (attachment.isImage()) {
                        HttpFileUploadManager.ImageSize imageSize = HttpFileUploadManager.getImageSizes(file.getPath());
                        attachment.setImageHeight(imageSize.getHeight());
                        attachment.setImageWidth(imageSize.getWidth());
                    }
                    attachments.add(attachment);
                }
            }
        }
    });
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RealmList(io.realm.RealmList) Attachment(com.xabber.android.data.database.messagerealm.Attachment) Realm(io.realm.Realm) File(java.io.File)

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