Search in sources :

Example 1 with MainStoryObject

use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method getSortedStoryObjectsInMainStoryObject.

public List<MainStoryObject> getSortedStoryObjectsInMainStoryObject(long userId, 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;
            RealmStory igapRealmStory = null;
            boolean isExistIgapRoomStory = false;
            igapRealmStory = database.where(RealmStory.class).equalTo("roomId", 2901).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findFirst();
            if (igapRealmStory != null && igapRealmStory.getRealmStoryProtos().size() > 0) {
                isExistIgapRoomStory = true;
            }
            if (userId == 0) {
                myRealmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).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("userId", userId).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);
                    if (isExistIgapRoomStory && realmStory.get(i).getRoomId() == 2901) {
                        stories.add(0, MainStoryObject.create(realmStory.get(i)));
                    } else {
                        stories.add(MainStoryObject.create(realmStory.get(i)));
                    }
                    for (int j = 0; j < realmStoryProtos.size(); j++) {
                        storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
                    }
                    stories.get(isExistIgapRoomStory && realmStory.get(i).getRoomId() == 2901 ? 0 : i).storyObjects = storyObjects;
                }
                if (userId == 0 && 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;
                }
            } else {
                if (userId == 0 && 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)

Example 2 with MainStoryObject

use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method getOtherUsersStories.

public List<MainStoryObject> getOtherUsersStories() {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    List<RealmStory> stories = new ArrayList<>();
    List<MainStoryObject> mainStoryObjects = new ArrayList<>();
    storageQueue.postRunnable(() -> {
        try {
            boolean isExistIgapRoomStory = false;
            RealmStory igapRealmStory = database.where(RealmStory.class).equalTo("roomId", 2901).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findFirst();
            stories.addAll(database.where(RealmStory.class).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).sort("lastCreatedAt", Sort.DESCENDING).findAll());
            if (igapRealmStory != null && igapRealmStory.getRealmStoryProtos().size() > 0) {
                isExistIgapRoomStory = true;
            }
            for (int i = 0; i < stories.size(); i++) {
                List<StoryObject> storyObjects = new ArrayList<>();
                RealmResults<RealmStoryProto> realmStoryProtos = stories.get(i).getRealmStoryProtos().sort(new String[] { "createdAt", "index" }, new Sort[] { Sort.DESCENDING, Sort.DESCENDING });
                if (realmStoryProtos != null && realmStoryProtos.size() > 0) {
                    for (int j = 0; j < realmStoryProtos.size(); j++) {
                        storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
                    }
                    MainStoryObject mainStoryObject = MainStoryObject.create(database.copyFromRealm(stories.get(i)));
                    mainStoryObject.storyObjects = storyObjects;
                    if (isExistIgapRoomStory && stories.get(i).getRoomId() == 2901) {
                        mainStoryObjects.add(0, mainStoryObject);
                    } else {
                        mainStoryObjects.add(mainStoryObject);
                    }
                }
            }
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return mainStoryObjects;
}
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)

Example 3 with MainStoryObject

use of net.iGap.story.MainStoryObject 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 4 with MainStoryObject

use of net.iGap.story.MainStoryObject 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 5 with MainStoryObject

use of net.iGap.story.MainStoryObject 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

ArrayList (java.util.ArrayList)7 MainStoryObject (net.iGap.story.MainStoryObject)7 RealmStory (net.iGap.realm.RealmStory)6 RealmStoryProto (net.iGap.realm.RealmStoryProto)6 StoryObject (net.iGap.story.StoryObject)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Context (android.content.Context)1 Canvas (android.graphics.Canvas)1 Color (android.graphics.Color)1 Paint (android.graphics.Paint)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 TypedValue (android.util.TypedValue)1 Gravity (android.view.Gravity)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1