Search in sources :

Example 21 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class AppUtils method replyTextMessage.

/**
 * fetch type of message for show in reply view
 *
 * @param messageObject for detect message type
 * @return final message text
 */
public static String replyTextMessage(MessageObject messageObject, Resources resources) {
    MessageObject message = RealmRoomMessage.getFinalMessage(messageObject);
    String messageText = "";
    if (message != null) {
        switch(message.messageType) {
            case TEXT_VALUE:
            case STORY_REPLY_VALUE:
                if (message.message != null) {
                    messageText = message.message;
                }
                break;
            case AUDIO_TEXT_VALUE:
            case AUDIO_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.audio_message);
                break;
            case CONTACT_VALUE:
                messageText = message.contact.firstName + "\n" + message.contact.phones.get(message.contact.phones.size() - 1);
                break;
            case FILE_TEXT_VALUE:
            case FILE_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.file_message);
                break;
            case STICKER_VALUE:
                messageText = resources.getString(R.string.sticker);
                break;
            case GIF_TEXT_VALUE:
            case GIF_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.gif_message);
                break;
            case IMAGE_TEXT_VALUE:
            case IMAGE_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.image_message);
                break;
            case LOCATION_VALUE:
                messageText = resources.getString(R.string.location_message);
                break;
            case VIDEO_TEXT_VALUE:
            case VIDEO_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.video_message);
                break;
            case VOICE_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.voice_message);
                break;
            default:
                messageText = "";
                break;
        }
    }
    ArrayList<Tuple<Integer, Integer>> places = AbstractMessage.getBoldPlaces(messageText);
    messageText = AbstractMessage.removeBoldMark(messageText, places);
    return messageText;
}
Also used : MessageObject(net.iGap.structs.MessageObject) Tuple(net.iGap.libs.Tuple)

Example 22 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class MusicPlayer method fillMediaList.

public static ArrayList<MessageObject> fillMediaList(boolean setSelectedItem) {
    boolean isOnListMusic = false;
    mediaList = new ArrayList<>();
    List<RealmRoomMessage> roomMessages = DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmRoomMessage.class).equalTo("roomId", roomId).notEqualTo("createTime", 0).equalTo("deleted", false).equalTo("showMessage", true).findAll().sort("messageId", Sort.DESCENDING);
    });
    List<MessageObject> messageObjects = new ArrayList<>();
    for (RealmRoomMessage message : roomMessages) {
        messageObjects.add(MessageObject.create(message));
    }
    if (!messageObjects.isEmpty()) {
        for (MessageObject messageObject : messageObjects) {
            // TODO Saeed Mozaffari; write better code for detect voice and audio instead get all roomMessages
            MessageObject roomMessage = RealmRoomMessage.getFinalMessage(messageObject);
            if (isVoice) {
                if (ProtoGlobal.RoomMessageType.forNumber(roomMessage.messageType).toString().equals(ProtoGlobal.RoomMessageType.VOICE.toString())) {
                    try {
                        if (roomMessage.attachment.filePath != null) {
                            if (new File(roomMessage.attachment.filePath).exists()) {
                                mediaList.add(roomMessage);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else {
                if ((ProtoGlobal.RoomMessageType.forNumber(roomMessage.messageType).toString().equals(ProtoGlobal.RoomMessageType.AUDIO.toString()) || ProtoGlobal.RoomMessageType.forNumber(roomMessage.messageType).toString().equals(ProtoGlobal.RoomMessageType.AUDIO_TEXT.toString()))) {
                    if (mediaList.size() <= limitMediaList || !isOnListMusic) {
                        try {
                            if (roomMessage.id == Long.parseLong(messageId)) {
                                isOnListMusic = true;
                            }
                            if (roomMessage.attachment.isFileExistsOnLocal(roomMessage)) {
                                mediaList.add(roomMessage);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
    if (setSelectedItem) {
        for (int i = mediaList.size() - 1; i >= 0; i--) {
            try {
                MessageObject _rm = RealmRoomMessage.getFinalMessage(mediaList.get(i));
                if (_rm.attachment.filePath != null && _rm.attachment.filePath.equals(musicPath)) {
                    selectedMedia = i;
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return mediaList;
}
Also used : ArrayList(java.util.ArrayList) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) MessageObject(net.iGap.structs.MessageObject) File(java.io.File) SuppressLint(android.annotation.SuppressLint)

Example 23 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class MusicPlayer method nextMusic.

public static void nextMusic() {
    try {
        String beforeMessageId = MusicPlayer.messageId;
        selectedMedia--;
        if (selectedMedia < 0) {
            if (isVoice) {
                // avoid from return to first voice
                if (btnPlayMusic != null) {
                    btnPlayMusic.setText(context.getString(R.string.icon_play));
                }
                stopSound();
                closeLayoutMediaPlayer();
                return;
            }
            selectedMedia = mediaList.size() - 1;
        }
        MessageObject messageObject = RealmRoomMessage.getFinalMessage(mediaList.get(selectedMedia));
        boolean _continue = true;
        while (_continue) {
            if (!messageObject.attachment.isFileExistsOnLocal(messageObject)) {
                selectedMedia--;
                if (selectedMedia < 0) {
                    selectedMedia = mediaList.size() - 1;
                }
                messageObject = RealmRoomMessage.getFinalMessage(mediaList.get(selectedMedia));
            } else {
                _continue = false;
            }
        }
        startPlayer(messageObject.attachment.name, messageObject.attachment.filePath, roomName, roomId, false, String.valueOf(mediaList.get(selectedMedia).id));
        if (!messageObject.isSenderMe() && messageObject.status != MessageObject.STATUS_LISTENED) {
            if (roomType != CHANNEL_VALUE && isVoice) {
                EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.NEXT_VOICE, roomType, roomId, mediaList.get(selectedMedia).id, LISTENED_VALUE, mediaList.get(selectedMedia).documentId);
            }
        }
        if (FragmentChat.onMusicListener != null) {
            FragmentChat.onMusicListener.complete(true, MusicPlayer.messageId, beforeMessageId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageObject(net.iGap.structs.MessageObject)

Example 24 with MessageObject

use of net.iGap.structs.MessageObject 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 25 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class FragmentMediaPlayer method initComponent.

// *****************************************************************************************
private void initComponent(final View view) {
    final ImageView img_MusicImage = view.findViewById(R.id.ml_img_music_picture);
    onSetImage = new OnSetImage() {

        @Override
        public void setImage() {
            img_MusicImage.setImageBitmap(MusicPlayer.mediaThumpnail);
        }
    };
    musicSeekbar = view.findViewById(R.id.ml_seekBar1);
    musicSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser)
                MusicPlayer.setMusicProgress(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            MusicPlayer.pauseSound();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            MusicPlayer.playAndPause();
        }
    });
    onBackFragment = new OnBackFragment() {

        @Override
        public void onBack() {
            removeFromBaseFragment();
        }
    };
    rcvListMusicPlayer = view.findViewById(R.id.rcvListMusicPlayer);
    final SlidingUpPanelLayout slidingUpPanelLayout = view.findViewById(R.id.sliding_layout);
    footerAdapter = new ItemAdapter<>();
    fastItemAdapter = new FastItemAdapter();
    fastItemAdapter.addAdapter(1, footerAdapter);
    rcvListMusicPlayer.setAdapter(fastItemAdapter);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(_mActivity);
    rcvListMusicPlayer.setLayoutManager(linearLayoutManager);
    rcvListMusicPlayer.setHasFixedSize(true);
    rcvListMusicPlayer.addOnScrollListener(new EndlessRecyclerOnScrollListener(footerAdapter) {

        @Override
        public void onLoadMore(int currentPage) {
            footerAdapter.clear();
            footerAdapter.add(new ProgressItem().withEnabled(false));
            if (isThereAnyMoreItemToLoad) {
                getInfoRealm();
            }
        }
    });
    // getDataFromServer(ProtoClientSearchRoomHistory.ClientSearchRoomHistory.Filter.AUDIO);
    loadLocalData(ProtoClientSearchRoomHistory.ClientSearchRoomHistory.Filter.AUDIO, ProtoGlobal.RoomMessageType.AUDIO);
    for (MessageObject r : MusicPlayer.mediaList) {
        fastItemAdapter.add(new AdapterListMusicPlayer().setItem(r).withIdentifier(r.id));
    }
    rcvListMusicPlayer.scrollToPosition(fastItemAdapter.getPosition(Long.parseLong(MusicPlayer.messageId)));
}
Also used : SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) SeekBar(android.widget.SeekBar) EndlessRecyclerOnScrollListener(com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener) FastItemAdapter(com.mikepenz.fastadapter.commons.adapters.FastItemAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ProgressItem(com.mikepenz.fastadapter_extensions.items.ProgressItem) ImageView(android.widget.ImageView) MessageObject(net.iGap.structs.MessageObject)

Aggregations

MessageObject (net.iGap.structs.MessageObject)30 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)18 ArrayList (java.util.ArrayList)13 File (java.io.File)11 RealmRoom (net.iGap.realm.RealmRoom)11 SuppressLint (android.annotation.SuppressLint)10 ProtoGlobal (net.iGap.proto.ProtoGlobal)10 NonNull (androidx.annotation.NonNull)9 TextView (android.widget.TextView)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 List (java.util.List)8 G (net.iGap.G)8 HelperString (net.iGap.helper.HelperString)8 View (android.view.View)7 ImageView (android.widget.ImageView)7 Realm (io.realm.Realm)7 Intent (android.content.Intent)6 ViewGroup (android.view.ViewGroup)6 AppCompatTextView (androidx.appcompat.widget.AppCompatTextView)6 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)6