Search in sources :

Example 11 with RealmAttachment

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

the class StructMessageAttachment method setLocalFilePath.

public void setLocalFilePath(final long messageId, @Nullable final String path) {
    this.localFilePath = path;
    DbManager.getInstance().doRealmTransaction(realm -> {
        final RealmAttachment realmAttachment = realm.where(RealmAttachment.class).equalTo("id", messageId).findFirst();
        if (realmAttachment == null) {
            RealmAttachment messageAttachment = realm.createObject(RealmAttachment.class, messageId);
            messageAttachment.setLocalFilePath(path);
        } else {
            if (realmAttachment.getLocalFilePath() == null) {
                realmAttachment.setLocalFilePath(path);
            }
        }
    });
}
Also used : RealmAttachment(net.iGap.realm.RealmAttachment)

Example 12 with RealmAttachment

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

the class UserProfileViewModel method getProfileWallpaper.

private void getProfileWallpaper(Realm realm) {
    try {
        RealmWallpaper realmWallpaper = realm.where(RealmWallpaper.class).equalTo("type", ProtoInfoWallpaper.InfoWallpaper.Type.PROFILE_WALLPAPER_VALUE).findFirst();
        if (realmWallpaper != null) {
            if (realmWallpaper.getWallPaperList() != null && realmWallpaper.getWallPaperList().size() > 0) {
                RealmAttachment pf = realmWallpaper.getWallPaperList().get(realmWallpaper.getWallPaperList().size() - 1).getFile();
                String bigImagePath = G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/" + pf.getCacheId() + "_" + DownloadObject.extractMime(pf.getName());
                if (!new File(bigImagePath).exists()) {
                    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(db -> {
                                for (RealmAvatar realmAvatar1 : db.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
                                    realmAvatar1.getFile().setLocalFilePath(filepath);
                                }
                            });
                            changeUserProfileWallpaperPath.postValue(bigImagePath);
                        }
                    });
                } else {
                    changeUserProfileWallpaperPath.postValue(bigImagePath);
                }
            } else {
                getProfileWallpaperFromServer();
            }
        } else {
            getProfileWallpaperFromServer();
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        e.printStackTrace();
    } catch (NullPointerException e2) {
        e2.printStackTrace();
    } catch (Exception e3) {
        e3.printStackTrace();
    }
}
Also used : RealmWallpaper(net.iGap.realm.RealmWallpaper) DownloadObject(net.iGap.module.downloader.DownloadObject) RealmAttachment(net.iGap.realm.RealmAttachment) HelperString(net.iGap.helper.HelperString) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) File(java.io.File) RealmAvatar(net.iGap.realm.RealmAvatar)

Example 13 with RealmAttachment

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

the class StoryDisplayFragment method sendStickerAsMessage.

private void sendStickerAsMessage(StructIGSticker structIGSticker) {
    RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", stories.get(counter).getUserId()).findFirst();
    });
    String additional = new Gson().toJson(structIGSticker);
    long identity = AppUtils.makeRandomId();
    int[] imageSize = AndroidUtils.getImageDimens(structIGSticker.getPath());
    RealmRoomMessage roomMessage = new RealmRoomMessage();
    roomMessage.setMessageId(identity);
    roomMessage.setMessageType(ProtoGlobal.RoomMessageType.STORY_REPLY);
    if (realmRoom != null) {
        roomMessage.setRoomId(realmRoom.getId());
    }
    roomMessage.setMessage(structIGSticker.getName());
    roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
    roomMessage.setUserId(AccountManager.getInstance().getCurrentUser().getId());
    roomMessage.setCreateTime(TimeUtils.currentLocalTime());
    RealmAdditional realmAdditional = new RealmAdditional();
    realmAdditional.setId(AppUtils.makeRandomId());
    realmAdditional.setAdditionalType(structIGSticker.isGiftSticker() ? AdditionalType.GIFT_STICKER : AdditionalType.STICKER);
    realmAdditional.setAdditionalData(additional);
    roomMessage.setRealmAdditional(realmAdditional);
    RealmAttachment realmAttachment = new RealmAttachment();
    if (structIGSticker.getToken() != null && !structIGSticker.getToken().isEmpty()) {
        realmAttachment.setToken(structIGSticker.getToken());
    }
    realmAttachment.setId(identity);
    realmAttachment.setLocalFilePath(structIGSticker.getPath());
    realmAttachment.setWidth(imageSize[0]);
    realmAttachment.setHeight(imageSize[1]);
    realmAttachment.setSize(new File(structIGSticker.getPath()).length());
    realmAttachment.setName(new File(structIGSticker.getPath()).getName());
    realmAttachment.setDuration(0);
    roomMessage.setAttachment(realmAttachment);
    roomMessage.getAttachment().setToken(structIGSticker.getToken());
    roomMessage.setAuthorHash(RealmUserInfo.getCurrentUserAuthorHash());
    roomMessage.setShowMessage(true);
    roomMessage.setCreateTime(TimeUtils.currentLocalTime());
    new Thread(() -> DbManager.getInstance().doRealmTransaction(realm -> {
        realm.copyToRealmOrUpdate(roomMessage);
        RealmStickerItem stickerItem = realm.where(RealmStickerItem.class).equalTo("id", structIGSticker.getId()).findFirst();
        if (stickerItem != null && stickerItem.isValid()) {
            stickerItem.setRecent();
        }
    })).start();
    MessageObject messageObject = MessageObject.create(roomMessage);
    ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).buildStoryReply(realmRoom.getType().getNumber(), realmRoom.getId(), stories.get(counter), messageObject, null);
}
Also used : RealmAdditional(net.iGap.realm.RealmAdditional) Gson(com.google.gson.Gson) RealmRoom(net.iGap.realm.RealmRoom) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmAttachment(net.iGap.realm.RealmAttachment) File(java.io.File) MessageObject(net.iGap.structs.MessageObject) RealmStickerItem(net.iGap.realm.RealmStickerItem)

Example 14 with RealmAttachment

use of net.iGap.realm.RealmAttachment 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 15 with RealmAttachment

use of net.iGap.realm.RealmAttachment 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)

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