Search in sources :

Example 6 with RealmStoryProto

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

the class MessageDataStorage method getCurrentUserRoomStories.

public List<StoryObject> getCurrentUserRoomStories(long roomId, int listMode) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    List<StoryObject> stories = new ArrayList<>();
    storageQueue.postRunnable(() -> {
        try {
            RealmResults<RealmStoryProto> realmStoryProto;
            boolean isAbleToAdd = true;
            if (roomId == 0) {
                realmStoryProto = database.where(RealmStoryProto.class).equalTo("isForRoom", true).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).findAll().sort(new String[] { "createdAt", "index" }, new Sort[] { Sort.DESCENDING, Sort.DESCENDING });
            } else {
                realmStoryProto = database.where(RealmStoryProto.class).equalTo("isForRoom", true).equalTo("roomId", roomId).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).findAll().sort(new String[] { "createdAt", "index" }, new Sort[] { Sort.DESCENDING, Sort.DESCENDING });
            }
            for (int i = 0; i < realmStoryProto.size(); i++) {
                if (listMode == 0) {
                    for (int j = 0; j < stories.size(); j++) {
                        if (realmStoryProto.get(i).getRoomId() == stories.get(j).roomId) {
                            isAbleToAdd = false;
                            break;
                        } else {
                            isAbleToAdd = true;
                        }
                    }
                    if (isAbleToAdd) {
                        stories.add(StoryObject.create(realmStoryProto.get(i)));
                    }
                } else {
                    stories.add(StoryObject.create(realmStoryProto.get(i)));
                }
            }
            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) RealmStoryProto(net.iGap.realm.RealmStoryProto) ArrayList(java.util.ArrayList) Sort(io.realm.Sort) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with RealmStoryProto

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

the class StoryCell method setData.

public void setData(MainStoryObject mainStoryObject, String color, Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked) {
    this.userId = mainStoryObject.userId;
    this.roomId = mainStoryObject.roomId;
    this.isVerified = mainStoryObject.isVerified;
    initView(context, needDivider, status, imageLoadingStatus, iconClicked, mainStoryObject.storyObjects.get(0).createdAt);
    circleImageLoading.setStatus(imageLoadingStatus);
    if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
        topText.setText(context.getString(R.string.my_status));
    } else {
        if (roomId != 0) {
            channelIconTv.setVisibility(VISIBLE);
        }
        if (isVerified) {
            verifyIconTv.setVisibility(VISIBLE);
        }
        topText.setText(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
    }
    String name = HelperImageBackColor.getFirstAlphabetName(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
    if (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED) {
        bottomText.setText(context.getString(R.string.story_could_not_sent));
        bottomText.setTextColor(Color.RED);
        deleteIcon.setTextColor(Color.RED);
        addIcon.setTextColor(Color.RED);
        addIcon.setText(R.string.icon_error);
    } else if (circleImageLoading.getStatus() == ImageLoadingView.Status.LOADING) {
        bottomText.setText(context.getString(R.string.story_sending));
        deleteIcon.setTextColor(Theme.getInstance().getTitleTextColor(context));
    } else {
        bottomText.setText(LastSeenTimeUtil.computeTime(context, mainStoryObject.userId, mainStoryObject.storyObjects.get(0).createdAt / 1000L, false, false));
    }
    AttachmentObject attachment = mainStoryObject.storyObjects.get(0).attachmentObject;
    if (status == CircleStatus.LOADING_CIRCLE_IMAGE) {
        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(new BitmapDrawable(context.getResources(), 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, storyId, true);
            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 8 with RealmStoryProto

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

the class StoryViewFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (isSingle) {
        if (isForReply) {
            DbManager.getInstance().doRealmTransaction(realm -> {
                RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
                if (realmStoryProto != null) {
                    MainStoryObject mainStoryObject = new MainStoryObject();
                    List<StoryObject> storyObjects = new ArrayList<>();
                    mainStoryObject.userId = realmStoryProto.getUserId();
                    storyObjects.add(StoryObject.create(realmStoryProto));
                    mainStoryObject.displayName = realmStoryProto.getDisplayName();
                    mainStoryObject.profileColor = realmStoryProto.getProfileColor();
                    mainStoryObject.storyObjects = storyObjects;
                    storyResults.add(mainStoryObject);
                }
            });
        } else {
            storyResults.addAll(getMessageDataStorage().getSortedStoryObjectsInMainStoryObject(userId, new String[] { "createdAt" }, new Sort[] { Sort.ASCENDING }));
        }
    } else {
        if (isForRoom && !isForOtherRoom) {
            storyResults.addAll(getMessageDataStorage().getSortedRoomStoryObjectsInMainStoryObject(0, isForOtherRoom, roomId, new String[] { "createdAt" }, new Sort[] { Sort.ASCENDING }));
        } else {
            storyResults.addAll(getMessageDataStorage().getSortedStoryObjectsInMainStoryObject(0, new String[] { "createdAt" }, new Sort[] { Sort.ASCENDING }));
        }
    }
    setUpPager();
}
Also used : StoryObject(net.iGap.story.StoryObject) MainStoryObject(net.iGap.story.MainStoryObject) RealmStoryProto(net.iGap.realm.RealmStoryProto) ArrayList(java.util.ArrayList) Sort(io.realm.Sort) MainStoryObject(net.iGap.story.MainStoryObject)

Example 9 with RealmStoryProto

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

the class MessageDataStorage method updateStoryStatus.

public void updateStoryStatus(long id, int status) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    storageQueue.postRunnable(() -> {
        try {
            database.executeTransaction(realm -> {
                RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("id", id).findFirst();
                if (realmStoryProto != null) {
                    realmStoryProto.setStatus(status);
                }
            });
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : RealmStoryProto(net.iGap.realm.RealmStoryProto) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with RealmStoryProto

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

the class MessageDataStorage method getNotNullTokenStories.

public List<StoryObject> getNotNullTokenStories(long userId, int status) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    List<RealmStoryProto> stories = new ArrayList<>();
    List<StoryObject> storyObjects = new ArrayList<>();
    storageQueue.postRunnable(() -> {
        try {
            if (status == 0) {
                stories.addAll(database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("userId", userId).isNotNull("fileToken").findAll());
            } else {
                stories.addAll(database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("userId", userId).equalTo("status", status).isNotNull("fileToken").findAll());
            }
            for (int i = 0; i < stories.size(); i++) {
                storyObjects.add(StoryObject.create(database.copyFromRealm(stories.get(i))));
            }
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return storyObjects;
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) RealmStoryProto(net.iGap.realm.RealmStoryProto) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch)

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