Search in sources :

Example 16 with RealmAttachment

use of net.iGap.realm.RealmAttachment in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method putAttachmentToken.

public void putAttachmentToken(final long messageId, final String token) {
    storageQueue.postRunnable(() -> {
        try {
            database.beginTransaction();
            RealmAttachment attachment = database.where(RealmAttachment.class).equalTo("id", messageId).findFirst();
            if (attachment != null) {
                attachment.token = token;
            }
            database.commitTransaction();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : RealmAttachment(net.iGap.realm.RealmAttachment)

Example 17 with RealmAttachment

use of net.iGap.realm.RealmAttachment in project iGap-Android by KianIranian-STDG.

the class AdapterChatBackground method startDownload.

private void startDownload(final int position, final MessageProgress messageProgress) {
    if (mList.get(position).getProtoWallpaper() != null) {
        messageProgress.withDrawable(R.drawable.ic_cancel, true);
        RealmAttachment pf = mList.get(position).getProtoWallpaper().getFile();
        messageProgress.withOnProgress(new OnProgress() {

            @Override
            public void onProgressFinished() {
                messageProgress.post(new Runnable() {

                    @Override
                    public void run() {
                        messageProgress.withProgress(0);
                        messageProgress.setVisibility(View.GONE);
                        notifyItemChanged(position);
                    }
                });
            }
        });
        DownloadObject downloadObject = DownloadObject.createForRoomMessage(AttachmentObject.create(pf), ProtoGlobal.RoomMessageType.IMAGE.getNumber());
        Downloader.getInstance(AccountManager.selectedAccount).download(downloadObject, arg -> {
            if (arg.status == Status.SUCCESS && arg.data != null) {
                String filepath = arg.data.getFilePath();
                String fileToken = arg.data.getToken();
                if (!(new File(filepath).exists())) {
                    HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
                }
                DbManager.getInstance().doRealmTransaction(realm -> {
                    for (RealmAvatar realmAvatar1 : realm.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
                        realmAvatar1.getFile().setLocalFilePath(filepath);
                    }
                });
            } else if (arg.status == Status.LOADING && arg.data != null) {
                messageProgress.post(new Runnable() {

                    @Override
                    public void run() {
                        messageProgress.withProgress(arg.data.getProgress());
                    }
                });
            } else if (arg.status == Status.ERROR) {
                messageProgress.post(new Runnable() {

                    @Override
                    public void run() {
                        messageProgress.withProgress(0);
                        messageProgress.withDrawable(R.drawable.ic_download, true);
                    }
                });
            }
        });
    }
}
Also used : DownloadObject(net.iGap.module.downloader.DownloadObject) RealmAttachment(net.iGap.realm.RealmAttachment) OnProgress(net.iGap.messageprogress.OnProgress) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) File(java.io.File) RealmAvatar(net.iGap.realm.RealmAvatar)

Aggregations

RealmAttachment (net.iGap.realm.RealmAttachment)17 File (java.io.File)7 HelperString (net.iGap.helper.HelperString)5 DownloadObject (net.iGap.module.downloader.DownloadObject)4 Gson (com.google.gson.Gson)3 List (java.util.List)3 HelperDownloadFile (net.iGap.helper.HelperDownloadFile)3 RealmAdditional (net.iGap.realm.RealmAdditional)3 RealmAvatar (net.iGap.realm.RealmAvatar)3 Intent (android.content.Intent)2 ArrayList (java.util.ArrayList)2 StructBottomSheet (net.iGap.module.structs.StructBottomSheet)2 RealmRoom (net.iGap.realm.RealmRoom)2 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)2 RealmStickerItem (net.iGap.realm.RealmStickerItem)2 RealmString (net.iGap.realm.RealmString)2 RealmWallpaper (net.iGap.realm.RealmWallpaper)2 MainStoryObject (net.iGap.story.MainStoryObject)2 StoryObject (net.iGap.story.StoryObject)2 MessageObject (net.iGap.structs.MessageObject)2