Search in sources :

Example 16 with StoryObject

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

the class MyStatusStoryListFragment method sendRoomStory.

private void sendRoomStory() {
    if (isFromRoom && !isForRoomImage) {
        long storyId = SUID.id().get();
        long lastUploadedStoryId = storyId + 1L;
        int[] imageDimens = { 0, 0 };
        long attachementId = SUID.id().get();
        imageDimens = AndroidUtils.getImageDimens(roomImagePath);
        RealmAttachment realmAttachment = getMessageDataStorage().createRealmObject(roomImagePath, imageDimens, attachementId);
        StoryObject storyObject = new StoryObject();
        storyObject.isSeen = false;
        storyObject.realmAttachment = realmAttachment;
        storyObject.isForRoom = isFromRoom;
        storyObject.userId = AccountManager.getInstance().getCurrentUser().getId();
        storyObject.roomId = this.roomId;
        storyObject.sessionId = AccountManager.getInstance().getCurrentUser().getId();
        storyObject.displayName = this.roomTitle;
        storyObject.createdAt = System.currentTimeMillis();
        storyObject.caption = "";
        storyObject.status = MessageObject.STATUS_SENDING;
        storyObject.id = lastUploadedStoryId;
        List<StoryObject> realmStories = getMessageDataStorage().getStoryWithIndexSort(storyObject.userId);
        if (realmStories != null && realmStories.size() > 0) {
            storyObject.index = realmStories.get(0).index + 1;
        } else {
            storyObject.index = 0;
        }
        storyInLocal.add(storyObject);
        getMessageDataStorage().putStoriesToDatabaseOffline(false, storyObject.userId, storyObject.roomId, storyInLocal, storyObject.displayName, isFromRoom);
        storyInLocal.remove(0);
        HttpUploader.isStoryUploading = true;
        Uploader.getInstance().upload(UploadObject.createForStory(lastUploadedStoryId, roomImagePath, null, "", ProtoGlobal.RoomMessageType.STORY));
        storyInLocal = new ArrayList<>();
    } else if (isForRoomImage) {
        sendRoomStory(paths, itemGalleryList, roomId, listMode, roomTitle);
    }
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) RealmAttachment(net.iGap.realm.RealmAttachment)

Example 17 with StoryObject

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

the class StoryFragment method receivedEvent.

@Override
public void receivedEvent(int id, int account, Object... args) {
    swipeRefreshLayout.setRefreshing(false);
    if (id == EventManager.STORY_LIST_FETCHED || id == EventManager.STORY_DELETED || id == EventManager.STORY_ALL_SEEN || id == EventManager.STORY_USER_ADD_NEW || id == EventManager.STORY_ROOM_IMAGE_UPLOAD || id == EventManager.STORY_ROOM_UPLOAD) {
        G.runOnUiThread(() -> loadStories());
    } else if (id == EventManager.STORY_UPLOAD) {
        G.runOnUiThread(() -> {
            actionButtonsRootView.setVisibility(View.GONE);
            progressBar.setVisibility(View.VISIBLE);
        });
        objectsCounter = 0;
        List<String> paths = (List<String>) args[0];
        ArrayList<StructBottomSheet> itemGalleryList = (ArrayList<StructBottomSheet>) args[1];
        boolean isForRoom = (boolean) args[2];
        long roomId = (long) args[3];
        int listMode = (int) args[4];
        String roomTitle = (String) args[5];
        if (paths.size() > 1) {
            if (isForRoom) {
                HttpUploader.isRoomMultiUpload = true;
                HttpUploader.storyRoomIdForUpload = roomId;
            } else {
                HttpUploader.isMultiUpload = true;
            }
        }
        for (int i = 0; i < paths.size(); i++) {
            long storyId = SUID.id().get();
            long lastUploadedStoryId = storyId + 1L;
            int[] imageDimens = { 0, 0 };
            long attachementId = SUID.id().get();
            imageDimens = AndroidUtils.getImageDimens(paths.get(i));
            RealmAttachment realmAttachment = getMessageDataStorage().createRealmObject(paths.get(i), imageDimens, attachementId);
            StoryObject storyObject = new StoryObject();
            storyObject.isSeen = false;
            storyObject.realmAttachment = realmAttachment;
            storyObject.userId = AccountManager.getInstance().getCurrentUser().getId();
            storyObject.sessionId = AccountManager.getInstance().getCurrentUser().getId();
            storyObject.displayName = AccountManager.getInstance().getCurrentUser().getName();
            storyObject.createdAt = System.currentTimeMillis();
            storyObject.caption = itemGalleryList.get(objectsCounter).getText();
            storyObject.status = MessageObject.STATUS_SENDING;
            storyObject.id = lastUploadedStoryId;
            List<StoryObject> realmStories = getMessageDataStorage().getStoryWithIndexSort(storyObject.userId);
            if (realmStories != null && realmStories.size() > 0) {
                storyObject.index = realmStories.get(0).index + 1;
            } else {
                storyObject.index = i;
            }
            storyInLocal.add(storyObject);
            getMessageDataStorage().putStoriesToDatabaseOffline(false, storyObject.userId, 0, storyInLocal, storyObject.displayName, false);
            storyInLocal.remove(0);
            HttpUploader.isStoryUploading = true;
            Uploader.getInstance().upload(UploadObject.createForStory(lastUploadedStoryId, paths.get(i), null, itemGalleryList.get(objectsCounter).getText(), ProtoGlobal.RoomMessageType.STORY));
            objectsCounter++;
            if (objectsCounter == itemGalleryList.size()) {
                G.runOnUiThread(() -> loadStories());
                storyInLocal = new ArrayList<>();
            }
        }
    } else if (id == EventManager.STORY_STATUS_UPLOAD) {
        String path = (String) args[0];
        long storyId = SUID.id().get();
        long lastUploadedStoryId = storyId + 1L;
        int[] imageDimens = { 0, 0 };
        long attachementId = SUID.id().get();
        imageDimens = AndroidUtils.getImageDimens(path);
        RealmAttachment realmAttachment = getMessageDataStorage().createRealmObject(path, imageDimens, attachementId);
        StoryObject storyObject = new StoryObject();
        storyObject.isSeen = false;
        storyObject.realmAttachment = realmAttachment;
        storyObject.userId = AccountManager.getInstance().getCurrentUser().getId();
        storyObject.sessionId = AccountManager.getInstance().getCurrentUser().getId();
        storyObject.displayName = AccountManager.getInstance().getCurrentUser().getName();
        storyObject.createdAt = System.currentTimeMillis();
        storyObject.caption = "";
        storyObject.status = MessageObject.STATUS_SENDING;
        storyObject.id = lastUploadedStoryId;
        List<StoryObject> realmStories = getMessageDataStorage().getStoryWithIndexSort(storyObject.userId);
        if (realmStories != null && realmStories.size() > 0) {
            storyObject.index = realmStories.get(0).index + 1;
        } else {
            storyObject.index = 0;
        }
        storyInLocal.add(storyObject);
        getMessageDataStorage().putStoriesToDatabaseOffline(false, storyObject.userId, 0, storyInLocal, storyObject.displayName, false);
        storyInLocal.remove(0);
        HttpUploader.isStoryUploading = true;
        Uploader.getInstance().upload(UploadObject.createForStory(lastUploadedStoryId, path, null, "", ProtoGlobal.RoomMessageType.STORY));
        objectsCounter++;
        G.runOnUiThread(() -> loadStories());
        storyInLocal = new ArrayList<>();
    } else if (id == EventManager.STORY_SENDING) {
        if (isAdded() && isVisible()) {
            progressBar.setVisibility(View.GONE);
            actionButtonsRootView.setVisibility(View.GONE);
            G.runOnUiThread(() -> loadStories());
        }
    } else if (id == EventManager.STORY_UPLOADED_FAILED) {
        if (isAdded()) {
            progressBar.setVisibility(View.GONE);
            actionButtonsRootView.setVisibility(View.VISIBLE);
        }
        G.runOnUiThread(() -> loadStories());
    } else if (id == EventManager.STORY_USER_INFO) {
        long userId = (long) args[0];
        Integer position = adapter.getFailedMessages(userId, 0);
        if (position != null) {
            adapter.addRow();
        }
    } else if (id == EventManager.STORY_ROOM_INFO) {
        long roomId = (long) args[0];
        Integer position = adapter.getFailedMessages(0, roomId);
        if (position != null) {
            adapter.addRow();
        }
    }
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) ArrayList(java.util.ArrayList) StructBottomSheet(net.iGap.module.structs.StructBottomSheet) List(java.util.List) ArrayList(java.util.ArrayList) RealmAttachment(net.iGap.realm.RealmAttachment)

Example 18 with StoryObject

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

Example 19 with StoryObject

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

the class MessageDataStorage method getStoryByStatus.

public List<StoryObject> getStoryByStatus(long userId, long roomId, int status, boolean isNotNullToken, boolean isForRoom, String[] fieldSort) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    List<RealmStoryProto> stories = new ArrayList<>();
    List<StoryObject> storyObjects = new ArrayList<>();
    storageQueue.postRunnable(() -> {
        try {
            if (isNotNullToken) {
                if (fieldSort == null) {
                    if (isForRoom) {
                        stories.addAll(database.where(RealmStoryProto.class).equalTo("isForRoom", true).equalTo("roomId", roomId).equalTo("userId", userId).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("status", status).isNotNull("fileToken").findAll());
                    } else {
                        stories.addAll(database.where(RealmStoryProto.class).equalTo("userId", userId).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("status", status).isNotNull("fileToken").findAll());
                    }
                } else {
                    if (isForRoom) {
                        stories.addAll(database.where(RealmStoryProto.class).equalTo("isForRoom", true).equalTo("roomId", roomId).equalTo("userId", userId).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("status", status).isNotNull("fileToken").findAll().sort(fieldSort, new Sort[] { Sort.ASCENDING }));
                    } else {
                        stories.addAll(database.where(RealmStoryProto.class).equalTo("userId", userId).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("status", status).isNotNull("fileToken").findAll().sort(fieldSort, new Sort[] { Sort.ASCENDING }));
                    }
                }
                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 });
            } else {
                if (isForRoom && roomId != 0) {
                    stories.addAll(database.where(RealmStoryProto.class).equalTo("isForRoom", true).equalTo("roomId", roomId).equalTo("userId", userId).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("status", status).findAll());
                } else {
                    stories.addAll(database.where(RealmStoryProto.class).equalTo("userId", userId).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("status", status).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) Sort(io.realm.Sort) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 20 with StoryObject

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

the class MessageDataStorage method getStoryWithIndexSort.

public List<StoryObject> getStoryWithIndexSort(long userId) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    List<StoryObject> storyObjects = new ArrayList<>();
    storageQueue.postRunnable(() -> {
        try {
            database.beginTransaction();
            List<RealmStoryProto> realmStories = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("userId", userId).findAll().sort("index", Sort.DESCENDING);
            if (realmStories != null && realmStories.size() > 0) {
                for (int i = 0; i < realmStories.size(); i++) {
                    storyObjects.add(StoryObject.create(realmStories.get(i)));
                }
            }
            database.commitTransaction();
            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

StoryObject (net.iGap.story.StoryObject)24 MainStoryObject (net.iGap.story.MainStoryObject)22 ArrayList (java.util.ArrayList)18 RealmStoryProto (net.iGap.realm.RealmStoryProto)15 CountDownLatch (java.util.concurrent.CountDownLatch)12 RealmStory (net.iGap.realm.RealmStory)8 Sort (io.realm.Sort)4 List (java.util.List)4 RealmAttachment (net.iGap.realm.RealmAttachment)3 View (android.view.View)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 File (java.io.File)2 IconView (net.iGap.messenger.ui.components.IconView)2 CircleImageView (net.iGap.module.CircleImageView)2 FontIconTextView (net.iGap.module.FontIconTextView)2 MaterialDesignTextView (net.iGap.module.MaterialDesignTextView)2 ProtoStoryUserAddNew (net.iGap.proto.ProtoStoryUserAddNew)2 RealmRegisteredInfo (net.iGap.realm.RealmRegisteredInfo)2 ImageLoadingView (net.iGap.story.liststories.ImageLoadingView)2