Search in sources :

Example 6 with Attachment

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

the class HttpFileUploadManager method parseFileMessage.

public static RealmList<Attachment> parseFileMessage(Stanza packet) {
    RealmList<Attachment> attachments = new RealmList<>();
    // parsing data references
    List<RefMedia> refMediaList = ReferencesManager.getMediaFromReferences(packet);
    if (!refMediaList.isEmpty()) {
        for (RefMedia media : refMediaList) {
            attachments.add(refMediaToAttachment(media));
        }
    }
    // parsing data forms
    DataForm dataForm = DataForm.from(packet);
    if (dataForm != null) {
        List<FormField> fields = dataForm.getFields();
        for (FormField field : fields) {
            if (field instanceof ExtendedFormField) {
                ExtendedFormField.Media media = ((ExtendedFormField) field).getMedia();
                attachments.add(mediaToAttachment(media, field.getLabel()));
            }
        }
    }
    return attachments;
}
Also used : RefMedia(com.xabber.android.data.extension.references.RefMedia) RealmList(io.realm.RealmList) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Attachment(com.xabber.android.data.database.messagerealm.Attachment) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 7 with Attachment

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

the class ImageViewerActivity method onCopyLinkClick.

private void onCopyLinkClick() {
    int position = viewPager.getCurrentItem();
    Attachment attachment = imageAttachments.get(position);
    String url = attachment.getFileUrl();
    ClipboardManager clipboardManager = ((ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE));
    if (clipboardManager != null)
        clipboardManager.setPrimaryClip(ClipData.newPlainText(url, url));
    Toast.makeText(this, R.string.toast_link_copied, Toast.LENGTH_SHORT).show();
}
Also used : ClipboardManager(android.content.ClipboardManager) Attachment(com.xabber.android.data.database.messagerealm.Attachment)

Example 8 with Attachment

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

the class ImageViewerActivity method setUpMenuOptions.

private void setUpMenuOptions(Menu menu) {
    int position = viewPager.getCurrentItem();
    Attachment attachment = imageAttachments.get(position);
    String filePath = attachment.getFilePath();
    Long size = attachment.getFileSize();
    menu.findItem(R.id.action_download_image).setVisible(filePath == null && size != null);
    menu.findItem(R.id.action_download_image).setEnabled(!isDownloading);
    menu.findItem(R.id.action_done).setVisible(filePath != null);
    menu.findItem(R.id.action_share).setVisible(size != null);
}
Also used : Attachment(com.xabber.android.data.database.messagerealm.Attachment)

Example 9 with Attachment

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

the class ImageViewerActivity method subscribeForAttachment.

private void subscribeForAttachment(Attachment attachment) {
    if (attachment == null)
        return;
    Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
    Attachment attachmentForSubscribe = realm.where(Attachment.class).equalTo(Attachment.Fields.UNIQUE_ID, attachment.getUniqueId()).findFirst();
    if (attachmentForSubscribe == null)
        return;
    Observable<Attachment> observable = attachmentForSubscribe.asObservable();
    attachmentStateSubscription.add(observable.doOnNext(new Action1<Attachment>() {

        @Override
        public void call(Attachment attachment) {
            updateToolbar();
            if (waitForSharing) {
                waitForSharing = false;
                onShareClick();
            }
        }
    }).subscribe());
}
Also used : Attachment(com.xabber.android.data.database.messagerealm.Attachment) Realm(io.realm.Realm)

Example 10 with Attachment

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

the class ImageViewerActivity method downloadImage.

private void downloadImage() {
    int position = viewPager.getCurrentItem();
    Attachment attachment = imageAttachments.get(position);
    DownloadManager.getInstance().downloadFile(attachment, accountJid, this);
}
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