Search in sources :

Example 1 with RealmStickerItem

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

the class StickerRepository method getStickerByEmoji.

public Flowable<List<StructIGSticker>> getStickerByEmoji(String unicode) {
    return DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmStickerItem.class).equalTo("name", unicode).sort("recentTime", Sort.DESCENDING).findAll().asFlowable().filter(RealmResults::isLoaded).map(realmStickers -> {
            List<StructIGSticker> stickers = new ArrayList<>();
            for (int i = 0; i < realmStickers.size(); i++) {
                RealmStickerItem stickerItem = realmStickers.get(i);
                if (stickerItem != null) {
                    StructIGSticker sticker = new StructIGSticker(stickerItem);
                    stickers.add(sticker);
                }
            }
            return stickers;
        });
    });
}
Also used : StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) ArrayList(java.util.ArrayList) RealmStickerItem(net.iGap.realm.RealmStickerItem)

Example 2 with RealmStickerItem

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

the class StickerRepository method getStickerGroupWithRecentTabForEmojiView.

public Flowable<List<StructIGStickerGroup>> getStickerGroupWithRecentTabForEmojiView() {
    return DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmStickerGroup.class).findAllAsync().asFlowable().filter(RealmResults::isLoaded).map(realmStickers -> {
            List<StructIGStickerGroup> structIGStickerGroups = new ArrayList<>();
            for (int i = 0; i < realmStickers.size(); i++) {
                StructIGStickerGroup stickerGroup = new StructIGStickerGroup(realmStickers.get(i));
                structIGStickerGroups.add(stickerGroup);
            }
            return structIGStickerGroups;
        }).map(structIGStickerGroups -> {
            StructIGStickerGroup stickerGroup = new StructIGStickerGroup(StructIGStickerGroup.RECENT_GROUP);
            stickerGroup.setName(G.context.getResources().getString(R.string.recently));
            RealmResults<RealmStickerItem> realmStickersDetails = realm.where(RealmStickerItem.class).limit(RECENT_STICKER_LIMIT).notEqualTo("recentTime", 0).sort("recentTime", Sort.DESCENDING).findAll();
            List<StructIGSticker> stickers = new ArrayList<>();
            for (int i = 0; i < realmStickersDetails.size(); i++) {
                RealmStickerItem stickerItem = realmStickersDetails.get(i);
                if (stickerItem != null) {
                    stickers.add(new StructIGSticker(stickerItem));
                }
            }
            stickerGroup.setStickers(stickers);
            if (stickers.size() > 0) {
                structIGStickerGroups.add(0, stickerGroup);
            }
            return structIGStickerGroups;
        }).map(structIGStickerGroups -> {
            StructIGStickerGroup favoriteStickerGroup = new StructIGStickerGroup(StructIGStickerGroup.FAVORITE_GROUP);
            favoriteStickerGroup.setName(G.context.getResources().getString(R.string.beeptunesÙ€favorite_song));
            RealmResults<RealmStickerItem> stickerItems = realm.where(RealmStickerItem.class).limit(FAVORITE_STICKER_LIMIT).equalTo("isFavorite", true).sort("recentTime", Sort.DESCENDING).findAll();
            if (stickerItems != null) {
                List<StructIGSticker> stickers = new ArrayList<>();
                for (int i = 0; i < stickerItems.size(); i++) {
                    RealmStickerItem stickerItem = stickerItems.get(i);
                    if (stickerItem != null) {
                        stickers.add(new StructIGSticker(stickerItem));
                    }
                }
                favoriteStickerGroup.setStickers(stickers);
            // boolean hasRecent = structIGStickerGroups.get(0).getGroupId().equals(StructIGStickerGroup.RECENT_GROUP);
            // if (stickers.size() > 0) {
            // structIGStickerGroups.add(hasRecent ? 1 : 0, favoriteStickerGroup);
            // }
            }
            return structIGStickerGroups;
        });
    });
}
Also used : JsonObject(com.google.gson.JsonObject) SingleSource(io.reactivex.SingleSource) StickerCategoryGroupDataModel(net.iGap.fragments.emoji.apiModels.StickerCategoryGroupDataModel) FileLog(net.iGap.helper.FileLog) Completable(io.reactivex.Completable) AESCrypt(net.iGap.module.AESCrypt) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) StructIGStickerCategory(net.iGap.fragments.emoji.struct.StructIGStickerCategory) RealmStickerItem(net.iGap.realm.RealmStickerItem) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SliderDataModel(net.iGap.fragments.emoji.apiModels.SliderDataModel) Flowable(io.reactivex.Flowable) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) RsaDataModel(net.iGap.fragments.emoji.apiModels.RsaDataModel) IGSingleObserver(net.iGap.observers.rx.IGSingleObserver) CardStatusDataModel(net.iGap.fragments.emoji.apiModels.CardStatusDataModel) HelperNumerical(net.iGap.helper.HelperNumerical) Ids(net.iGap.fragments.emoji.apiModels.Ids) CompletableObserver(io.reactivex.CompletableObserver) RealmResults(io.realm.RealmResults) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) StickerApi(net.iGap.api.StickerApi) UserGiftStickersDataModel(net.iGap.fragments.emoji.apiModels.UserGiftStickersDataModel) File(java.io.File) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) Sort(io.realm.Sort) Base64(android.util.Base64) CardDetailDataModel(net.iGap.fragments.emoji.apiModels.CardDetailDataModel) IssueDataModel(net.iGap.fragments.emoji.apiModels.IssueDataModel) R(net.iGap.R) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) ResponseCallback(net.iGap.observers.interfaces.ResponseCallback) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) RealmResults(io.realm.RealmResults) RealmStickerItem(net.iGap.realm.RealmStickerItem)

Example 3 with RealmStickerItem

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

the class FragmentChat method sendStickerAsMessage.

private void sendStickerAsMessage(StructIGSticker structIGSticker) {
    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.STICKER);
    roomMessage.setRoomId(mRoomId);
    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();
    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());
    if (isReply()) {
        RealmRoomMessage copyReplyMessage = DbManager.getInstance().doRealmTask(realm -> {
            RealmRoomMessage copyReplyMessage1 = realm.where(RealmRoomMessage.class).equalTo("messageId", getReplyMessageId()).findFirst();
            if (copyReplyMessage1 != null) {
                return realm.copyFromRealm(copyReplyMessage1);
            }
            return null;
        });
        if (copyReplyMessage != null) {
            roomMessage.setReplyTo(copyReplyMessage);
        }
    }
    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);
    scrollToEnd();
    if (isReply()) {
        mReplayLayout.setTag(null);
        mReplayLayout.setVisibility(View.GONE);
    }
    if (FragmentChat.structIGSticker != null) {
        FragmentChat.structIGSticker = null;
        if (getActivity() instanceof ActivityMain) {
            ((ActivityMain) getActivity()).checkHasSharedData(false);
        }
    }
}
Also used : RealmAdditional(net.iGap.realm.RealmAdditional) ActivityMain(net.iGap.activities.ActivityMain) Gson(com.google.gson.Gson) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmAttachment(net.iGap.realm.RealmAttachment) HelperSaveFile(net.iGap.helper.HelperSaveFile) File(java.io.File) AttachFile(net.iGap.module.AttachFile) MessageObject(net.iGap.structs.MessageObject) RealmStickerItem(net.iGap.realm.RealmStickerItem)

Example 4 with RealmStickerItem

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

Aggregations

RealmStickerItem (net.iGap.realm.RealmStickerItem)4 Gson (com.google.gson.Gson)3 File (java.io.File)3 ArrayList (java.util.ArrayList)2 StructIGSticker (net.iGap.fragments.emoji.struct.StructIGSticker)2 Base64 (android.util.Base64)1 JsonObject (com.google.gson.JsonObject)1 Completable (io.reactivex.Completable)1 CompletableObserver (io.reactivex.CompletableObserver)1 Flowable (io.reactivex.Flowable)1 Single (io.reactivex.Single)1 SingleSource (io.reactivex.SingleSource)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Schedulers (io.reactivex.schedulers.Schedulers)1 RealmResults (io.realm.RealmResults)1 Sort (io.realm.Sort)1 HashSet (java.util.HashSet)1 List (java.util.List)1