Search in sources :

Example 11 with RealmStoryProto

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

the class MessageDataStorage method isStorySeen.

public boolean isStorySeen(long storyId) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    boolean[] result = new boolean[1];
    storageQueue.postRunnable(() -> {
        try {
            database.executeTransaction(realm -> {
                RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
                if (realmStoryProto != null) {
                    result[0] = realmStoryProto.isSeen();
                }
            });
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return result[0];
}
Also used : RealmStoryProto(net.iGap.realm.RealmStoryProto) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with RealmStoryProto

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

the class MessageDataStorage method getStoryWithFileToken.

public StoryObject getStoryWithFileToken(String fileToken) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    StoryObject[] storyObjects = new StoryObject[1];
    storageQueue.postRunnable(() -> {
        try {
            RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("fileToken", fileToken).findFirst();
            if (realmStoryProto != null) {
                storyObjects[0] = StoryObject.create(realmStoryProto);
            }
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return storyObjects[0];
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) RealmStoryProto(net.iGap.realm.RealmStoryProto) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with RealmStoryProto

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

the class MessageDataStorage method getStoryWithUploadId.

public StoryObject getStoryWithUploadId(long uploadId) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    StoryObject[] storyObjects = new StoryObject[1];
    storageQueue.postRunnable(() -> {
        try {
            RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("id", uploadId).findFirst();
            if (realmStoryProto != null) {
                storyObjects[0] = StoryObject.create(realmStoryProto);
            }
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return storyObjects[0];
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) RealmStoryProto(net.iGap.realm.RealmStoryProto) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 14 with RealmStoryProto

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

the class StoryCell method setData.

public void setData(StoryObject storyObject, boolean isRoom, String displayName, String color, Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked) {
    initView(context, needDivider, status, imageLoadingStatus, iconClicked, storyObject.createdAt);
    this.userId = storyObject.userId;
    this.roomId = storyObject.roomId;
    this.isFromMyStatus = true;
    String name = HelperImageBackColor.getFirstAlphabetName(storyObject.displayName != null ? storyObject.displayName : "");
    if (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED) {
        if (isRoom && mode == 0) {
            deleteIcon.setTextColor(Color.RED);
            topText.setText(storyObject.displayName);
            bottomText.setText(context.getString(R.string.story_could_not_sent));
            bottomText.setTextColor(Color.RED);
        } else {
            uploadIcon.setVisibility(VISIBLE);
            deleteIcon.setVisibility(VISIBLE);
            deleteIcon.setText(R.string.icon_delete);
            topText.setVisibility(GONE);
            bottomText.setVisibility(GONE);
            middleText.setVisibility(VISIBLE);
            middleText.setText(context.getString(R.string.story_could_not_sent));
            middleText.setTextColor(Color.RED);
        }
    } else if (circleImageLoading.getStatus() == ImageLoadingView.Status.LOADING) {
        if (isRoom && mode == 0) {
            topText.setText(storyObject.displayName);
            bottomText.setText(context.getString(R.string.story_sending));
        } else {
            uploadIcon.setVisibility(GONE);
            deleteIcon.setVisibility(GONE);
            topText.setVisibility(GONE);
            middleText.setVisibility(VISIBLE);
            middleText.setText(context.getString(R.string.story_sending));
            middleText.setTextColor(Theme.getInstance().getTitleTextColor(context));
        }
    } else {
        topText.setVisibility(VISIBLE);
        bottomText.setVisibility(VISIBLE);
        middleText.setVisibility(GONE);
        uploadIcon.setVisibility(GONE);
        deleteIcon.setVisibility(VISIBLE);
        if (isRoom && mode == 0) {
            topText.setText(storyObject.displayName);
        } else {
            if (G.selectedLanguage.equals("fa")) {
                topText.setText(HelperCalander.convertToUnicodeFarsiNumber(String.valueOf(storyObject.viewCount)) + " " + context.getString(R.string.story_views));
            } else {
                topText.setText(storyObject.viewCount + " " + context.getString(R.string.story_views));
            }
        }
        bottomText.setText(LastSeenTimeUtil.computeTime(context, storyObject.userId, storyObject.createdAt / 1000L, false, false));
    }
    AttachmentObject attachment = storyObject.attachmentObject;
    if (attachment != null && (attachment.thumbnailPath != null || attachment.filePath != null)) {
        try {
            Glide.with(G.context).load(attachment.filePath != null ? attachment.filePath : attachment.thumbnailPath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
        } catch (Exception e) {
            Glide.with(G.context).load(HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color)).into(circleImageLoading);
        }
    } else if (attachment != null) {
        Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
        DownloadObject object = DownloadObject.createForStory(attachment, storyObject.storyId, true);
        Log.e("skfjskjfsd", "setData2: " + storyId + "/" + object.downloadId);
        if (object != null) {
            Downloader.getInstance(AccountManager.selectedAccount).download(object, arg -> {
                if (arg.status == Status.SUCCESS && arg.data != null) {
                    String filepath = arg.data.getFilePath();
                    String downloadedFileToken = arg.data.getToken();
                    if (!(new File(filepath).exists())) {
                        HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
                    }
                    if (arg.data.getDownloadObject().downloadId == storyId) {
                        DbManager.getInstance().doRealmTransaction(realm1 -> {
                            RealmStoryProto realmStoryProto = realm1.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
                            if (realmStoryProto != null) {
                                realmStoryProto.getFile().setLocalFilePath(filepath);
                            }
                        });
                        G.runOnUiThread(() -> Glide.with(G.context).load(filepath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading));
                    }
                }
            });
        }
    } else {
        Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
    }
}
Also used : LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull) UploadObject(net.iGap.module.upload.UploadObject) FrameLayout(android.widget.FrameLayout) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Theme(net.iGap.module.Theme) G(net.iGap.G) HttpUploader(net.iGap.helper.upload.ApiBased.HttpUploader) RealmStoryProto(net.iGap.realm.RealmStoryProto) View(android.view.View) Canvas(android.graphics.Canvas) Log(android.util.Log) HelperImageBackColor(net.iGap.helper.HelperImageBackColor) MainStoryObject(net.iGap.story.MainStoryObject) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperCalander(net.iGap.helper.HelperCalander) MessageController(net.iGap.controllers.MessageController) Status(net.iGap.module.downloader.Status) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Downloader(net.iGap.module.downloader.Downloader) RealmStory(net.iGap.realm.RealmStory) Uploader(net.iGap.module.upload.Uploader) HelperLog(net.iGap.helper.HelperLog) FontIconTextView(net.iGap.module.FontIconTextView) List(java.util.List) TextView(android.widget.TextView) ProtoStoryUserAddNew(net.iGap.proto.ProtoStoryUserAddNew) ViewMaker.i_Dp(net.iGap.adapter.items.chat.ViewMaker.i_Dp) Paint(android.graphics.Paint) EventManager(net.iGap.observers.eventbus.EventManager) DownloadObject(net.iGap.module.downloader.DownloadObject) Context(android.content.Context) AttachmentObject(net.iGap.structs.AttachmentObject) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ViewMaker.setTextSize(net.iGap.adapter.items.chat.ViewMaker.setTextSize) AccountManager(net.iGap.module.accountManager.AccountManager) StoryObject(net.iGap.story.StoryObject) ArrayList(java.util.ArrayList) LayoutCreator(net.iGap.helper.LayoutCreator) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) MessageObject(net.iGap.structs.MessageObject) TextUtils(android.text.TextUtils) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IconView(net.iGap.messenger.ui.components.IconView) CircleImageView(net.iGap.module.CircleImageView) File(java.io.File) Color(android.graphics.Color) Gravity(android.view.Gravity) Glide(com.bumptech.glide.Glide) TypedValue(android.util.TypedValue) ViewMaker(net.iGap.adapter.items.chat.ViewMaker) ProtoGlobal(net.iGap.proto.ProtoGlobal) MessageDataStorage(net.iGap.controllers.MessageDataStorage) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) RealmStoryProto(net.iGap.realm.RealmStoryProto) AttachmentObject(net.iGap.structs.AttachmentObject) DownloadObject(net.iGap.module.downloader.DownloadObject) BitmapDrawable(android.graphics.drawable.BitmapDrawable) File(java.io.File)

Example 15 with RealmStoryProto

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

the class MessageDataStorage method getSortedRoomStoryObjectsInMainStoryObject.

public List<MainStoryObject> getSortedRoomStoryObjectsInMainStoryObject(long userId, boolean isOtherRoomStory, long roomId, String[] sortBy, Sort[] orderBy) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    List<MainStoryObject> stories = new ArrayList<>();
    storageQueue.postRunnable(() -> {
        try {
            RealmResults<RealmStoryProto> realmStoryProtos;
            RealmResults<RealmStory> realmStory;
            RealmStory myRealmStory = null;
            if (isOtherRoomStory) {
                myRealmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("roomId", roomId).findFirst();
                realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).sort("lastCreatedAt", Sort.DESCENDING).findAll();
            } else {
                realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("roomId", roomId).findAll();
                if (realmStory == null || realmStory.size() == 0) {
                    realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).findAll();
                }
            }
            if (realmStory != null && realmStory.size() > 0) {
                for (int i = 0; i < realmStory.size(); i++) {
                    List<StoryObject> storyObjects = new ArrayList<>();
                    realmStoryProtos = realmStory.get(i).getRealmStoryProtos().sort(sortBy, orderBy);
                    stories.add(MainStoryObject.create(realmStory.get(i)));
                    for (int j = 0; j < realmStoryProtos.size(); j++) {
                        if (realmStoryProtos.get(j).isForRoom() && realmStoryProtos.get(j).getRoomId() == roomId) {
                            storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
                        }
                    }
                    stories.get(i).storyObjects = storyObjects;
                }
                if (isOtherRoomStory && myRealmStory != null) {
                    List<StoryObject> storyObjects = new ArrayList<>();
                    realmStoryProtos = myRealmStory.getRealmStoryProtos().sort(sortBy, orderBy);
                    stories.add(0, MainStoryObject.create(myRealmStory));
                    for (int j = 0; j < realmStoryProtos.size(); j++) {
                        if (realmStoryProtos.get(j).isForRoom() && realmStoryProtos.get(j).getRoomId() == roomId) {
                            storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
                        }
                    }
                    stories.get(0).storyObjects = storyObjects;
                }
            } else {
                if (isOtherRoomStory && myRealmStory != null) {
                    List<StoryObject> storyObjects = new ArrayList<>();
                    realmStoryProtos = myRealmStory.getRealmStoryProtos().sort(sortBy, orderBy);
                    stories.add(0, MainStoryObject.create(myRealmStory));
                    for (int j = 0; j < realmStoryProtos.size(); j++) {
                        storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
                    }
                    stories.get(0).storyObjects = storyObjects;
                }
            }
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return stories;
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) RealmStory(net.iGap.realm.RealmStory) ArrayList(java.util.ArrayList) MainStoryObject(net.iGap.story.MainStoryObject) CountDownLatch(java.util.concurrent.CountDownLatch) RealmStoryProto(net.iGap.realm.RealmStoryProto)

Aggregations

RealmStoryProto (net.iGap.realm.RealmStoryProto)26 CountDownLatch (java.util.concurrent.CountDownLatch)19 MainStoryObject (net.iGap.story.MainStoryObject)16 StoryObject (net.iGap.story.StoryObject)16 ArrayList (java.util.ArrayList)13 RealmStory (net.iGap.realm.RealmStory)12 File (java.io.File)6 Sort (io.realm.Sort)4 List (java.util.List)3 Context (android.content.Context)2 Canvas (android.graphics.Canvas)2 Color (android.graphics.Color)2 Paint (android.graphics.Paint)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 TextUtils (android.text.TextUtils)2 Log (android.util.Log)2 TypedValue (android.util.TypedValue)2 Gravity (android.view.Gravity)2 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)2