Search in sources :

Example 1 with RealmRoomMessageLocation

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

the class FragmentChat method sendPosition.

public void sendPosition(final Double latitude, final Double longitude, final String imagePath) {
    sendCancelAction();
    if (isShowLayoutUnreadMessage) {
        removeLayoutUnreadMessage();
    }
    final long messageId = AppUtils.makeRandomId();
    RealmRoomMessage roomMessage = new RealmRoomMessage();
    roomMessage.setMessageId(messageId);
    RealmRoomMessageLocation realmRoomMessageLocation = new RealmRoomMessageLocation();
    realmRoomMessageLocation.setId(AppUtils.makeRandomId());
    realmRoomMessageLocation.setLocationLat(latitude);
    realmRoomMessageLocation.setLocationLong(longitude);
    realmRoomMessageLocation.setImagePath(imagePath);
    roomMessage.setLocation(realmRoomMessageLocation);
    roomMessage.setCreateTime(TimeUtils.currentLocalTime());
    roomMessage.setMessageType(ProtoGlobal.RoomMessageType.LOCATION);
    roomMessage.setRoomId(mRoomId);
    roomMessage.setUserId(AccountManager.getInstance().getCurrentUser().getId());
    roomMessage.setAuthorHash(RealmUserInfo.getCurrentUserAuthorHash());
    roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
    if (replyMessageId() > 0) {
        RealmRoomMessage realmRoomMessageCopy = DbManager.getInstance().doRealmTask(realm -> {
            RealmRoomMessage realmRoomMessage = realm.where(RealmRoomMessage.class).equalTo("messageId", replyMessageId()).findFirst();
            if (realmRoomMessage != null) {
                return realm.copyFromRealm(realmRoomMessage);
            } else {
                return null;
            }
        });
        if (realmRoomMessageCopy != null) {
            roomMessage.setReplyTo(realmRoomMessageCopy);
        }
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            DbManager.getInstance().doRealmTransaction(realm -> {
                RealmRoomMessage managedMessage = realm.copyToRealmOrUpdate(roomMessage);
                RealmRoom.setLastMessageWithRoomMessage(realm, mRoomId, managedMessage);
            });
        }
    }).start();
    G.handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            switchAddItem(new ArrayList<>(Collections.singletonList(new StructMessageInfo(roomMessage))), false);
            MessageObject locationMessage = MessageObject.create(roomMessage);
            getSendMessageUtil().build(chatType, mRoomId, locationMessage);
            scrollToEnd();
        }
    }, 300);
    clearReplyView();
}
Also used : StructMessageInfo(net.iGap.module.structs.StructMessageInfo) RealmRoomMessageLocation(net.iGap.realm.RealmRoomMessageLocation) ArrayList(java.util.ArrayList) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) MessageObject(net.iGap.structs.MessageObject)

Aggregations

ArrayList (java.util.ArrayList)1 StructMessageInfo (net.iGap.module.structs.StructMessageInfo)1 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)1 RealmRoomMessageLocation (net.iGap.realm.RealmRoomMessageLocation)1 MessageObject (net.iGap.structs.MessageObject)1