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;
});
});
}
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;
});
});
}
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);
}
}
}
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);
}
Aggregations