use of net.iGap.realm.RealmAdditional 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.RealmAdditional 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);
}
use of net.iGap.realm.RealmAdditional in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method onBotBtnClick.
public void onBotBtnClick(View v, ButtonEntity buttonEntity) {
DbManager.getInstance().doRealmTask(realm -> {
try {
if (v.getId() == ButtonActionType.USERNAME_LINK) {
// TODO: fixed this and do not use G.currentActivity
HelperUrl.checkUsernameAndGoToRoomWithMessageId(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(1), HelperUrl.ChatEntry.chat, 0, 0);
} else if (v.getId() == ButtonActionType.BOT_ACTION) {
long messageId = System.currentTimeMillis();
RealmRoomMessage roomMessage = new RealmRoomMessage();
roomMessage.setMessageId(messageId);
roomMessage.setMessageType(ProtoGlobal.RoomMessageType.TEXT);
roomMessage.setRoomId(messageObject.roomId);
roomMessage.setMessage(((ArrayList<String>) v.getTag()).get(1));
roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
roomMessage.setUserId(AccountManager.getInstance().getCurrentUser().getId());
roomMessage.setCreateTime(TimeUtils.currentLocalTime());
if (((ArrayList<String>) v.getTag()).get(2) != null) {
RealmAdditional additional = new RealmAdditional();
additional.setId(AppUtils.makeRandomId());
additional.setAdditionalData(((ArrayList<String>) v.getTag()).get(2));
additional.setAdditionalType(3);
roomMessage.setRealmAdditional(additional);
}
new Thread(() -> {
DbManager.getInstance().doRealmTransaction(realm12 -> {
realm12.copyToRealmOrUpdate(roomMessage);
});
}).start();
MessageObject botMessage = MessageObject.create(roomMessage);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(type, messageObject.roomId, botMessage);
messageClickListener.sendFromBot(botMessage);
} else if (v.getId() == ButtonActionType.JOIN_LINK) {
// TODO: fixed this and do not use G.currentActivity
HelperUrl.checkAndJoinToRoom(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(14));
} else if (v.getId() == ButtonActionType.WEB_LINK) {
HelperUrl.openBrowser(((ArrayList<String>) v.getTag()).get(0));
} else if (v.getId() == ButtonActionType.WEBVIEW_LINK) {
messageClickListener.sendFromBot(((ArrayList<String>) v.getTag()).get(0));
} else if (v.getId() == ButtonActionType.REQUEST_PHONE) {
try {
new MaterialDialog.Builder(G.currentActivity).title(R.string.access_phone_number).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Long identity = System.currentTimeMillis();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmUserInfo realmUserInfo = RealmUserInfo.getRealmUserInfo(realm);
RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(messageObject.roomId, identity, realmUserInfo.getUserInfo().getPhoneNumber(), realmUserInfo.getUserInfo().getPhoneNumber(), 0, realm, ProtoGlobal.RoomMessageType.TEXT);
MessageObject botMessage = MessageObject.create(realmRoomMessage);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(type, messageObject.roomId, botMessage);
messageClickListener.sendFromBot(botMessage);
}
});
}
}).show();
} catch (Exception e) {
}
} else if (v.getId() == ButtonActionType.REQUEST_LOCATION) {
try {
new MaterialDialog.Builder(G.currentActivity).title(R.string.access_location).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (G.locationListener != null) {
isLocationFromBot = true;
G.locationListener.requestLocation();
}
}
}).show();
} catch (Exception e) {
}
} else if (v.getId() == ButtonActionType.PAY_DIRECT) {
JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
RealmRoom room = realm.where(RealmRoom.class).equalTo("id", messageObject.roomId).findFirst();
new HelperFragment(G.currentActivity.getSupportFragmentManager()).loadPayment(room.getTitle(), jsonObject.getString("token"), null);
} else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.CARD_TO_CARD.getNumber()) {
JSONObject rootJsonObject = new JSONObject(buttonEntity.getJsonObject());
JSONObject valueObject = rootJsonObject.getJSONObject("value");
String cardNumber = valueObject.getString("cardNumber");
int amount = valueObject.getInt("amount");
long userId = valueObject.getLong("userId");
CardToCardHelper.NewCallCardToCard(G.currentActivity, userId, amount, cardNumber);
} else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.BILL_MENU.getNumber()) {
try {
JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills, jsonObject)).setReplace(false).load();
} catch (JSONException e) {
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills)).setReplace(false).load();
}
} else if (v.getId() == ProtoGlobal.DiscoveryField.ButtonActionType.TRAFFIC_BILL_MENU.getNumber()) {
try {
JSONObject jsonObject = new JSONObject(((ArrayList<String>) v.getTag()).get(0));
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime, jsonObject)).setReplace(false).load();
} catch (JSONException e) {
new HelperFragment(G.currentActivity.getSupportFragmentManager(), FragmentPaymentBill.newInstance(R.string.pay_bills_crime)).setReplace(false).load();
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(G.context, "دستور با خطا مواجه شد", Toast.LENGTH_LONG).show();
}
});
/**
* The data was sent via the button via the view tag. Right now I only do this for the card due to lack of time with the new object
*/
}
Aggregations