Search in sources :

Example 41 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttWorker method doWork.

@NonNull
@Override
public Result doWork() {
    Data data = getInputData();
    boolean useEncryptedTopic = data.getBoolean(USE_ENCRYPTED_TOPIC, false);
    boolean subscribe = data.getBoolean(SUBSCRIBE, false);
    Contact contact = null;
    Channel channel = null;
    try {
        contact = (Contact) GsonUtils.getObjectFromJson(data.getString(CONTACT), Contact.class);
        channel = (Channel) GsonUtils.getObjectFromJson(data.getString(CHANNEL), Channel.class);
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    boolean subscribeToTyping = data.getBoolean(SUBSCRIBE_TO_TYPING, false);
    boolean unSubscribeToTyping = data.getBoolean(UN_SUBSCRIBE_TO_TYPING, false);
    boolean subscribeToSupportGroupTopic = data.getBoolean(CONNECT_TO_SUPPORT_GROUP_TOPIC, false);
    boolean unSubscribeToSupportGroupTopic = data.getBoolean(DISCONNECT_FROM_SUPPORT_GROUP_TOPIC, false);
    String userKeyString = data.getString(USER_KEY_STRING);
    String deviceKeyString = data.getString(DEVICE_KEY_STRING);
    boolean connectedStatus = data.getBoolean(CONNECTED_PUBLISH, false);
    boolean stop = data.getBoolean(STOP_TYPING, false);
    boolean typing = data.getBoolean(TYPING, false);
    if (subscribe) {
        if (isAppInBackground()) {
            Log.d(TAG, "App is in background, MQTT method call not required...");
            return Result.success();
        }
        ApplozicMqttService applozicMqttService = ApplozicMqttService.getInstance(getApplicationContext());
        applozicMqttService.connectClient(true);
        applozicMqttService.subscribe(useEncryptedTopic);
        applozicMqttService.publishClientStatus(MobiComUserPreference.getInstance(getApplicationContext()).getSuUserKeyString(), MobiComUserPreference.getInstance(getApplicationContext()).getDeviceKeyString(), "1");
    }
    if (subscribeToTyping) {
        ApplozicMqttService.getInstance(getApplicationContext()).subscribeToTypingTopic(channel);
        if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
            ApplozicMqttService.getInstance(getApplicationContext()).subscribeToOpenGroupTopic(channel);
        }
        return Result.success();
    }
    if (unSubscribeToTyping) {
        ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToTypingTopic(channel);
        if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
            ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToOpenGroupTopic(channel);
        }
        return Result.success();
    }
    if (subscribeToSupportGroupTopic) {
        ApplozicMqttService.getInstance(getApplicationContext()).subscribeToSupportGroup(useEncryptedTopic);
        return Result.success();
    }
    if (unSubscribeToSupportGroupTopic) {
        ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToSupportGroup(useEncryptedTopic);
        return Result.success();
    }
    if (!TextUtils.isEmpty(userKeyString) && !TextUtils.isEmpty(deviceKeyString)) {
        ApplozicMqttService.getInstance(getApplicationContext()).publishOfflineStatusUnsubscribeAndDisconnect(userKeyString, deviceKeyString, useEncryptedTopic);
    }
    if (connectedStatus) {
        ApplozicMqttService applozicMqttService = ApplozicMqttService.getInstance(getApplicationContext());
        applozicMqttService.connectClient(true);
        applozicMqttService.publishClientStatus(MobiComUserPreference.getInstance(getApplicationContext()).getSuUserKeyString(), MobiComUserPreference.getInstance(getApplicationContext()).getDeviceKeyString(), "1");
    }
    if (contact != null && stop) {
        ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, null);
    }
    if (contact != null && (contact.isBlocked() || contact.isBlockedBy())) {
        return Result.success();
    }
    if (contact != null || channel != null) {
        if (typing) {
            ApplozicMqttService.getInstance(getApplicationContext()).typingStarted(contact, channel);
        } else {
            ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, channel);
        }
    }
    return Result.success();
}
Also used : ApplozicMqttService(com.applozic.mobicomkit.api.ApplozicMqttService) Channel(com.applozic.mobicommons.people.channel.Channel) Data(androidx.work.Data) Contact(com.applozic.mobicommons.people.contact.Contact) NonNull(androidx.annotation.NonNull)

Example 42 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method updateChannelSubTitle.

public void updateChannelSubTitle(final Channel channel) {
    if (channel.isOpenGroup()) {
        if (getActivity() != null) {
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    setToolbarSubtitle("");
                    setToolbarImage(null, channel);
                }
            });
            return;
        }
    }
    channelUserMapperList = ChannelService.getInstance(getActivity()).getListOfUsersFromChannelUserMapper(channel.getKey());
    if (channelUserMapperList != null && channelUserMapperList.size() > 0) {
        if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
            String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
            if (!TextUtils.isEmpty(userId)) {
                final Contact withUserContact = appContactService.getContactById(userId);
                if (withUserContact != null) {
                    if (getActivity() == null) {
                        return;
                    }
                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            if (withUserContact.isBlocked()) {
                                if (getActivity() != null) {
                                    setToolbarSubtitle("");
                                }
                            } else {
                                if (withUserContact.isConnected() && getActivity() != null) {
                                    setToolbarSubtitle(ApplozicService.getContext(getContext()).getString(R.string.user_online));
                                    setToolbarImage(null, channel);
                                } else if (withUserContact.getLastSeenAt() != 0 && getActivity() != null) {
                                    setToolbarSubtitle(ApplozicService.getContext(getContext()).getString(R.string.subtitle_last_seen_at_time) + " " + DateUtils.getDateAndTimeForLastSeen(getContext(), withUserContact.getLastSeenAt(), alCustomizationSettings.getDateFormatCustomization().getTimeAndDateTemplate(), R.string.JUST_NOW, R.plurals.MINUTES_AGO, R.plurals.HOURS_AGO, R.string.YESTERDAY));
                                    setToolbarImage(null, channel);
                                } else if (getActivity() != null) {
                                    setToolbarSubtitle("");
                                    setToolbarImage(null, channel);
                                }
                            }
                        }
                    });
                }
            }
        } else {
            final StringBuffer stringBuffer = new StringBuffer();
            Contact contactDisplayName;
            String youString = "";
            int i = 0;
            for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
                i++;
                if (i > 20)
                    break;
                contactDisplayName = appContactService.getContactById(channelUserMapper.getUserKey());
                if (!TextUtils.isEmpty(channelUserMapper.getUserKey())) {
                    if (loggedInUserId.equals(channelUserMapper.getUserKey())) {
                        youString = ApplozicService.getContext(getContext()).getString(R.string.you_string);
                    } else {
                        stringBuffer.append(contactDisplayName.getDisplayName()).append(",");
                    }
                }
            }
            final String finalYouString = youString;
            if (getActivity() == null) {
                return;
            }
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (!TextUtils.isEmpty(stringBuffer)) {
                        if (channelUserMapperList.size() <= 20) {
                            if (!TextUtils.isEmpty(finalYouString)) {
                                stringBuffer.append(finalYouString).append(",");
                            }
                            int lastIndex = stringBuffer.lastIndexOf(",");
                            String userIds = stringBuffer.replace(lastIndex, lastIndex + 1, "").toString();
                            if (getActivity() != null) {
                                setToolbarSubtitle(userIds);
                                setToolbarImage(null, channel);
                            }
                        } else {
                            if (getActivity() != null) {
                                setToolbarSubtitle(stringBuffer.toString());
                                setToolbarImage(null, channel);
                            }
                        }
                    } else {
                        if (getActivity() != null) {
                            setToolbarSubtitle(finalYouString);
                            setToolbarImage(null, channel);
                        }
                    }
                }
            });
        }
    }
}
Also used : ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) Collections.disjoint(java.util.Collections.disjoint) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 43 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method onCreateView.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View list = inflater.inflate(R.layout.mobicom_message_list, container, false);
    recyclerView = (RecyclerView) list.findViewById(R.id.messageList);
    linearLayoutManager = new AlLinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerViewPositionHelper = new RecyclerViewPositionHelper(recyclerView, linearLayoutManager);
    ((ConversationActivity) getActivity()).setChildFragmentLayoutBGToTransparent();
    messageList = new ArrayList<Message>();
    multimediaPopupGrid = (GridView) list.findViewById(R.id.mobicom_multimedia_options1);
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    loggedInUserId = MobiComUserPreference.getInstance(getContext()).getUserId();
    toolbar = (Toolbar) getActivity().findViewById(R.id.my_toolbar);
    toolbar.setClickable(true);
    mainEditTextLinearLayout = (LinearLayout) list.findViewById(R.id.main_edit_text_linear_layout);
    individualMessageSendLayout = (LinearLayout) list.findViewById(R.id.individual_message_send_layout);
    slideImageView = (ImageView) list.findViewById(R.id.slide_image_view);
    sendButton = (ImageButton) individualMessageSendLayout.findViewById(R.id.conversation_send);
    recordButton = (ImageButton) individualMessageSendLayout.findViewById(R.id.record_button);
    mainEditTextLinearLayout = (LinearLayout) list.findViewById(R.id.main_edit_text_linear_layout);
    audioRecordFrameLayout = (FrameLayout) list.findViewById(R.id.audio_record_frame_layout);
    messageTemplateView = (RecyclerView) list.findViewById(R.id.mobicomMessageTemplateView);
    applozicLabel = list.findViewById(R.id.applozicLabel);
    Configuration config = getResources().getConfiguration();
    recordButtonWeakReference = new WeakReference<ImageButton>(recordButton);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
            sendButton.setScaleX(-1);
            mainEditTextLinearLayout.setBackgroundResource(R.drawable.applozic_chat_left_icon);
            audioRecordFrameLayout.setBackgroundResource(R.drawable.applozic_chat_left_icon);
            slideImageView.setImageResource(R.drawable.slide_arrow_right);
        }
    }
    if (MobiComUserPreference.getInstance(getContext()).getPricingPackage() == 1) {
        applozicLabel.setVisibility(VISIBLE);
    }
    if (alCustomizationSettings.isPoweredByApplozic()) {
        list.findViewById(R.id.txtPoweredByApplozic).setVisibility(VISIBLE);
    }
    extendedSendingOptionLayout = (LinearLayout) list.findViewById(R.id.extended_sending_option_layout);
    attachmentLayout = (RelativeLayout) list.findViewById(R.id.attachment_layout);
    isTyping = (TextView) list.findViewById(R.id.isTyping);
    contextFrameLayout = (FrameLayout) list.findViewById(R.id.contextFrameLayout);
    contextSpinner = (Spinner) list.findViewById(R.id.spinner_show);
    slideTextLinearlayout = (LinearLayout) list.findViewById(R.id.slide_LinearLayout);
    errorEditTextView = (EditText) list.findViewById(R.id.error_edit_text_view);
    audioRecordIconImageView = (ImageView) list.findViewById(R.id.audio_record_icon_image_view);
    recordTimeTextView = (TextView) list.findViewById(R.id.recording_time_text_view);
    mDetector = new GestureDetectorCompat(getContext(), this);
    adapterView = new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) {
            if (conversations != null && conversations.size() > 0) {
                Conversation conversation = conversations.get(pos);
                BroadcastService.currentConversationId = conversation.getId();
                if (onSelected) {
                    currentConversationId = conversation.getId();
                    if (messageList != null) {
                        messageList.clear();
                    }
                    downloadConversation = new DownloadConversation(recyclerView, true, 1, 0, 0, contact, channel, conversation.getId());
                    AlTask.execute(downloadConversation);
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    };
    mediaUploadProgressBar = (ProgressBar) attachmentLayout.findViewById(R.id.media_upload_progress_bar);
    emoticonsFrameLayout = (FrameLayout) list.findViewById(R.id.emojicons_frame_layout);
    emoticonsBtn = (ImageButton) list.findViewById(R.id.emoticons_btn);
    if (emojiIconHandler == null && emoticonsBtn != null) {
        emoticonsBtn.setVisibility(View.GONE);
    }
    replayRelativeLayout = (RelativeLayout) list.findViewById(R.id.reply_message_layout);
    messageTextView = (TextView) list.findViewById(R.id.messageTextView);
    galleryImageView = (ImageView) list.findViewById(R.id.imageViewForPhoto);
    nameTextView = (TextView) list.findViewById(R.id.replyNameTextView);
    attachReplyCancelLayout = (ImageButton) list.findViewById(R.id.imageCancel);
    messageDropDownActionButton = (FloatingActionButton) list.findViewById(R.id.message_drop_down);
    messageUnreadCountTextView = (TextView) list.findViewById(R.id.message_unread_count_textView);
    imageViewRLayout = (RelativeLayout) list.findViewById(R.id.imageViewRLayout);
    imageViewForAttachmentType = (ImageView) list.findViewById(R.id.imageViewForAttachmentType);
    spinnerLayout = inflater.inflate(R.layout.mobicom_message_list_header_footer, null);
    infoBroadcast = (TextView) spinnerLayout.findViewById(R.id.info_broadcast);
    spinnerLayout.setVisibility(View.GONE);
    emptyTextView = (TextView) list.findViewById(R.id.noConversations);
    emptyTextView.setTextColor(Color.parseColor(alCustomizationSettings.getNoConversationLabelTextColor().trim()));
    emoticonsBtn.setOnClickListener(this);
    sentIcon = getResources().getDrawable(R.drawable.applozic_ic_action_message_sent);
    deliveredIcon = getResources().getDrawable(R.drawable.applozic_ic_action_message_delivered);
    recordButton.setVisibility(alCustomizationSettings.isRecordButton() && (contact != null || channel != null) ? View.VISIBLE : View.GONE);
    sendButton.setVisibility(alCustomizationSettings.isRecordButton() && (contact != null || channel != null) ? View.GONE : View.VISIBLE);
    GradientDrawable bgShape = (GradientDrawable) sendButton.getBackground();
    bgShape.setColor(Color.parseColor(alCustomizationSettings.getSendButtonBackgroundColor().trim()));
    GradientDrawable bgShapeRecordButton = (GradientDrawable) recordButton.getBackground();
    bgShapeRecordButton.setColor(Color.parseColor(alCustomizationSettings.getSendButtonBackgroundColor().trim()));
    attachButton = (ImageButton) individualMessageSendLayout.findViewById(R.id.attach_button);
    sendType = (Spinner) extendedSendingOptionLayout.findViewById(R.id.sendTypeSpinner);
    messageEditText = (MentionAutoCompleteTextView) individualMessageSendLayout.findViewById(R.id.conversation_message);
    if (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
        MentionAdapter mentionAdapter = new MentionAdapter(requireContext());
        mentionAdapter.addAll(MentionHelper.getMentionsListForChannel(requireContext(), channel.getKey()));
        messageEditText.initMentions(mentionAdapter);
    }
    messageEditText.setTextColor(Color.parseColor(alCustomizationSettings.getMessageEditTextTextColor()));
    messageEditText.setHintTextColor(Color.parseColor(alCustomizationSettings.getMessageEditTextHintTextColor()));
    linearLayoutMessageSendDisabledInfo = (LinearLayout) list.findViewById(R.id.user_not_able_to_chat_layout);
    textViewMessageSendDisabledInfo = (TextView) linearLayoutMessageSendDisabledInfo.findViewById(R.id.user_not_able_to_chat_textView);
    textViewMessageSendDisabledInfo.setTextColor(Color.parseColor(alCustomizationSettings.getUserNotAbleToChatTextColor()));
    if (channel != null && channel.isDeleted()) {
        hideMessageSendLayoutAndShowGroupDeletedInfo();
    }
    if (!TextUtils.isEmpty(defaultText)) {
        messageEditText.setText(defaultText);
        defaultText = "";
    }
    scheduleOption = (Button) extendedSendingOptionLayout.findViewById(R.id.scheduleOption);
    mediaContainer = (ImageView) attachmentLayout.findViewById(R.id.media_container);
    attachedFile = (TextView) attachmentLayout.findViewById(R.id.attached_file);
    ImageView closeAttachmentLayout = (ImageView) attachmentLayout.findViewById(R.id.close_attachment_layout);
    swipeLayout = (SwipeRefreshLayout) list.findViewById(R.id.swipe_container);
    swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
    ArrayAdapter<CharSequence> sendTypeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.send_type_options, R.layout.mobiframework_custom_spinner);
    sendTypeAdapter.setDropDownViewResource(R.layout.mobiframework_custom_spinner);
    sendType.setAdapter(sendTypeAdapter);
    t = new CountDownTimer(Long.MAX_VALUE, 1000) {

        @Override
        public void onTick(long millisUntilFinished) {
            count++;
            seconds = count;
            if (seconds == 60) {
                minutes++;
                count = 0;
                seconds = 0;
            }
            if (minutes == 60) {
                minutes = 0;
                count = 0;
            }
            if (count % 2 == 0) {
                audioRecordIconImageView.setVisibility(VISIBLE);
                audioRecordIconImageView.setImageResource(R.drawable.applozic_audio_record);
            } else {
                audioRecordIconImageView.setVisibility(View.INVISIBLE);
            }
            recordTimeTextView.setText(String.format("%02d:%02d", minutes, seconds));
        }

        @Override
        public void onFinish() {
            count = 0;
        }
    };
    recordButton.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mDetector.onTouchEvent(motionEvent);
            if (motionEvent.getAction() == MotionEvent.ACTION_UP && longPress) {
                isToastVisible = true;
                errorEditTextView.setVisibility(View.GONE);
                errorEditTextView.requestFocus();
                errorEditTextView.setError(null);
                startedDraggingX = -1;
                audioRecordFrameLayout.setVisibility(View.GONE);
                mainEditTextLinearLayout.setVisibility(View.VISIBLE);
                applozicAudioRecordManager.sendAudio();
                t.cancel();
                longPress = false;
                messageEditText.requestFocus();
                seconds = 0;
                minutes = 0;
                count = 0;
            } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                float x = motionEvent.getX();
                if (x < -distCanMove) {
                    count = 0;
                    t.cancel();
                    audioRecordIconImageView.setImageResource(R.drawable.applozic_audio_delete);
                    recordTimeTextView.setVisibility(View.GONE);
                    applozicAudioRecordManager.cancelAudio();
                    messageEditText.requestFocus();
                }
                x = x + ApplozicAudioRecordAnimation.getX(recordButton);
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideTextLinearlayout.getLayoutParams();
                if (startedDraggingX != -1) {
                    float dist = (x - startedDraggingX);
                    params.leftMargin = dp(30) + (int) dist;
                    slideTextLinearlayout.setLayoutParams(params);
                    float alpha = 1.0f + dist / distCanMove;
                    if (alpha > 1) {
                        alpha = 1;
                    } else if (alpha < 0) {
                        alpha = 0;
                    }
                    ApplozicAudioRecordAnimation.setAlpha(slideTextLinearlayout, alpha);
                }
                if (x <= ApplozicAudioRecordAnimation.getX(slideTextLinearlayout) + slideTextLinearlayout.getWidth() + dp(30)) {
                    if (startedDraggingX == -1) {
                        startedDraggingX = x;
                        distCanMove = (audioRecordFrameLayout.getMeasuredWidth() - slideTextLinearlayout.getMeasuredWidth() - dp(48)) / 2.0f;
                        if (distCanMove <= 0) {
                            distCanMove = dp(80);
                        } else if (distCanMove > dp(80)) {
                            distCanMove = dp(80);
                        }
                    }
                }
                if (params.leftMargin > dp(30)) {
                    params.leftMargin = dp(30);
                    slideTextLinearlayout.setLayoutParams(params);
                    ApplozicAudioRecordAnimation.setAlpha(slideTextLinearlayout, 1);
                    startedDraggingX = -1;
                }
            }
            view.onTouchEvent(motionEvent);
            return true;
        }
    });
    messageEditText.addTextChangedListener(new TextWatcher() {

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        public void afterTextChanged(Editable s) {
            try {
                if (!TextUtils.isEmpty(s.toString()) && s.toString().trim().length() > 0 && !typingStarted) {
                    typingStarted = true;
                    handleSendAndRecordButtonView(true);
                } else if (s.toString().trim().length() == 0 && typingStarted) {
                    typingStarted = false;
                    handleSendAndRecordButtonView(!TextUtils.isEmpty(filePath));
                }
                if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) {
                    Applozic.publishTypingStatus(getContext(), channel, contact, typingStarted);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    messageEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (alCustomizationSettings.isMessageFastScrollEnabled()) {
                if (getActivity() == null) {
                    return;
                }
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        linearLayoutManager.setStackFromEnd(true);
                        linearLayoutManager.setReverseLayout(true);
                    }
                });
            }
            emoticonsFrameLayout.setVisibility(View.GONE);
        }
    });
    attachReplyCancelLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            messageMetaData = null;
            replayRelativeLayout.setVisibility(View.GONE);
        }
    });
    messageEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                if (typingStarted) {
                    if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) {
                        Applozic.publishTypingStatus(getActivity(), channel, contact, typingStarted);
                    }
                }
                emoticonsFrameLayout.setVisibility(View.GONE);
                multimediaPopupGrid.setVisibility(View.GONE);
            }
        }
    });
    recordButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!isToastVisible && !typingStarted) {
                vibrate();
                errorEditTextView.requestFocus();
                errorEditTextView.setError(ApplozicService.getContext(getContext()).getString(R.string.hold_to_record_release_to_send));
                isToastVisible = true;
                new CountDownTimer(3000, 1000) {

                    @Override
                    public void onTick(long millisUntilFinished) {
                    }

                    @Override
                    public void onFinish() {
                        errorEditTextView.setError(null);
                        messageEditText.requestFocus();
                        isToastVisible = false;
                    }
                }.start();
            } else {
                errorEditTextView.setError(null);
                isToastVisible = false;
            }
            emoticonsFrameLayout.setVisibility(View.GONE);
            sendMessage();
            handleSendAndRecordButtonView(false);
            errorEditTextView.setVisibility(View.VISIBLE);
        }
    });
    sendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (alCustomizationSettings.isMessageFastScrollEnabled()) {
                if (getActivity() == null) {
                    return;
                }
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        recyclerView.smoothScrollToPosition(messageList.size());
                        recyclerView.getLayoutManager().scrollToPosition(messageList.size());
                    }
                });
            }
            emoticonsFrameLayout.setVisibility(View.GONE);
            sendMessage();
        }
    });
    closeAttachmentLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            filePath = null;
            filePaths.clear();
            attachmentLayout.setVisibility(View.GONE);
            if (messageEditText != null && TextUtils.isEmpty(messageEditText.getText().toString().trim()) && recordButton != null && sendButton != null) {
                handleSendAndRecordButtonView(false);
            }
        }
    });
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (recyclerDetailConversationAdapter != null) {
                recyclerDetailConversationAdapter.contactImageLoader.setPauseWork(newState == RecyclerView.SCROLL_STATE_DRAGGING);
            }
        }

        @Override
        public void onScrolled(final RecyclerView recyclerView, int dx, int dy) {
            if (alCustomizationSettings.isMessageFastScrollEnabled()) {
                int totalItemCount = linearLayoutManager.getItemCount();
                int lastVisible = linearLayoutManager.findLastVisibleItemPosition();
                if (totalItemCount - lastVisible != 1) {
                    messageDropDownActionButton.setVisibility(VISIBLE);
                } else {
                    messageUnreadCountTextView.setVisibility(View.INVISIBLE);
                    messageDropDownActionButton.setVisibility(View.INVISIBLE);
                    messageUnreadCount = 0;
                }
            }
            if (loadMore) {
                int topRowVerticalPosition = (recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
                swipeLayout.setEnabled(topRowVerticalPosition >= 0);
            }
        }
    });
    messageDropDownActionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getActivity() == null) {
                return;
            }
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    recyclerView.smoothScrollToPosition(messageList.size());
                    recyclerView.getLayoutManager().scrollToPosition(messageList.size());
                }
            });
        }
    });
    toolbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getContext() != null && getContext().getApplicationContext() instanceof ALProfileClickListener) {
                ((ALProfileClickListener) getContext().getApplicationContext()).onClick(getActivity(), (contact != null ? contact.getUserId() : null), channel, true);
            }
            if (channel != null) {
                if (Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType()) && User.RoleType.USER_ROLE.getValue().equals(MobiComUserPreference.getInstance(getContext()).getUserRoleType())) {
                    return;
                }
                if (channel.isDeleted()) {
                    return;
                }
                if (alCustomizationSettings.isGroupInfoScreenVisible() && !Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) && !Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
                    Intent channelInfo = new Intent(getActivity(), ChannelInfoActivity.class);
                    channelInfo.putExtra(ChannelInfoActivity.CHANNEL_KEY, channel.getKey());
                    channelInfo.putExtra(ChannelInfoActivity.CHANNEL_UPDATE_RECEIVER, channelUpdateReceiver);
                    startActivity(channelInfo);
                } else if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) && alCustomizationSettings.isUserProfileFragment()) {
                    UserProfileFragment userProfileFragment = (UserProfileFragment) UIService.getFragmentByTag(getActivity(), ConversationUIService.USER_PROFILE_FRAMENT);
                    String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
                    if (!TextUtils.isEmpty(userId)) {
                        BroadcastService.sendContactProfileClickBroadcast(ApplozicService.getContext(MobiComConversationFragment.this.getContext()), userId);
                        if (userProfileFragment == null) {
                            Contact newContact = appContactService.getContactById(userId);
                            userProfileFragment = new UserProfileFragment();
                            Bundle bundle = new Bundle();
                            bundle.putSerializable(ConversationUIService.CONTACT, newContact);
                            userProfileFragment.setArguments(bundle);
                            ConversationActivity.addFragment(getActivity(), userProfileFragment, ConversationUIService.USER_PROFILE_FRAMENT);
                        }
                    }
                }
            } else {
                if (contact != null) {
                    BroadcastService.sendContactProfileClickBroadcast(ApplozicService.getContext(MobiComConversationFragment.this.getContext()), contact.getUserId());
                }
                if (alCustomizationSettings.isUserProfileFragment()) {
                    UserProfileFragment userProfileFragment = (UserProfileFragment) UIService.getFragmentByTag(getActivity(), ConversationUIService.USER_PROFILE_FRAMENT);
                    if (userProfileFragment == null) {
                        userProfileFragment = new UserProfileFragment();
                        Bundle bundle = new Bundle();
                        bundle.putSerializable(ConversationUIService.CONTACT, contact);
                        userProfileFragment.setArguments(bundle);
                        ConversationActivity.addFragment(getActivity(), userProfileFragment, ConversationUIService.USER_PROFILE_FRAMENT);
                    }
                }
            }
        }
    });
    recyclerView.setLongClickable(true);
    messageTemplate = alCustomizationSettings.getMessageTemplate();
    if (messageTemplate != null && messageTemplate.isEnabled()) {
        templateAdapter = new MobicomMessageTemplateAdapter(getContext(), messageTemplate);
        MobicomMessageTemplateAdapter.MessageTemplateDataListener listener = new MobicomMessageTemplateAdapter.MessageTemplateDataListener() {

            @Override
            public void onItemSelected(String message) {
                final Message lastMessage = !messageList.isEmpty() ? messageList.get(messageList.size() - 1) : null;
                String messageType = null;
                if (lastMessage != null) {
                    messageType = lastMessage.getMessageType();
                }
                if ((messageTemplate.getTextMessageList() != null && !messageTemplate.getTextMessageList().getMessageList().isEmpty() && messageTemplate.getTextMessageList().isSendMessageOnClick() && "text".equals(messageType)) || (messageTemplate.getImageMessageList() != null && !messageTemplate.getImageMessageList().getMessageList().isEmpty() && messageTemplate.getImageMessageList().isSendMessageOnClick() && "image".equals(messageType)) || (messageTemplate.getVideoMessageList() != null && !messageTemplate.getVideoMessageList().getMessageList().isEmpty() && messageTemplate.getVideoMessageList().isSendMessageOnClick() && "video".equals(messageType)) || (messageTemplate.getLocationMessageList() != null && !messageTemplate.getLocationMessageList().getMessageList().isEmpty() && messageTemplate.getLocationMessageList().isSendMessageOnClick() && "location".equals(messageType)) || (messageTemplate.getContactMessageList() != null && !messageTemplate.getContactMessageList().getMessageList().isEmpty() && messageTemplate.getContactMessageList().isSendMessageOnClick() && "contact".equals(messageType)) || (messageTemplate.getAudioMessageList() != null && !messageTemplate.getAudioMessageList().getMessageList().isEmpty() && messageTemplate.getAudioMessageList().isSendMessageOnClick() && "audio".equals(messageType)) || messageTemplate.getSendMessageOnClick()) {
                    sendMessage(message);
                }
                if (messageTemplate.getHideOnSend()) {
                    AlMessageMetadataUpdateTask.MessageMetadataListener listener1 = new AlMessageMetadataUpdateTask.MessageMetadataListener() {

                        @Override
                        public void onSuccess(Context context, String message) {
                            templateAdapter.removeTemplates();
                        }

                        @Override
                        public void onFailure(Context context, String error) {
                        }
                    };
                    if (lastMessage != null) {
                        Map<String, String> metadata = lastMessage.getMetadata();
                        metadata.put("isDoneWithClicking", "true");
                        lastMessage.setMetadata(metadata);
                        AlTask.execute(new AlMessageMetadataUpdateTask(getContext(), lastMessage.getKeyString(), lastMessage.getMetadata(), listener1));
                    }
                }
                final Intent intent = new Intent();
                intent.setAction("com.applozic.mobicomkit.TemplateMessage");
                intent.putExtra("templateMessage", message);
                intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
                getActivity().sendBroadcast(intent);
            }
        };
        templateAdapter.setOnItemSelected(listener);
        LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
        messageTemplateView.setLayoutManager(horizontalLayoutManagaer);
        messageTemplateView.setAdapter(templateAdapter);
    }
    createTemplateMessages();
    messageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (EditorInfo.IME_ACTION_DONE == actionId && getActivity() != null) {
                Utils.toggleSoftKeyBoard(getActivity(), true);
                return true;
            }
            return false;
        }
    });
    channelUpdateReceiver = new ResultReceiver(null) {

        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode == 1) {
                if (channel != null) {
                    Channel newChannel = ChannelDatabaseService.getInstance(getContext()).getChannelByChannelKey(channel.getKey());
                    setChannel(newChannel);
                    updateChannelTitle(newChannel);
                }
            }
        }
    };
    return list;
}
Also used : Configuration(android.content.res.Configuration) ViewConfiguration(android.view.ViewConfiguration) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AlLinearLayoutManager(com.applozic.mobicomkit.uiwidgets.conversation.AlLinearLayoutManager) AlMessageMetadataUpdateTask(com.applozic.mobicomkit.uiwidgets.async.AlMessageMetadataUpdateTask) ChannelInfoActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ChannelInfoActivity) MentionAutoCompleteTextView(com.applozic.mobicomkit.uiwidgets.conversation.mention.MentionAutoCompleteTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) Channel(com.applozic.mobicommons.people.channel.Channel) MentionAdapter(com.applozic.mobicomkit.uiwidgets.conversation.mention.MentionAdapter) GradientDrawable(android.graphics.drawable.GradientDrawable) ALProfileClickListener(com.applozic.mobicomkit.uiwidgets.uilistener.ALProfileClickListener) AdapterView(android.widget.AdapterView) AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) Message(com.applozic.mobicomkit.api.conversation.Message) Conversation(com.applozic.mobicommons.people.channel.Conversation) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) RecyclerViewPositionHelper(com.applozic.mobicomkit.uiwidgets.conversation.activity.RecyclerViewPositionHelper) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AlLinearLayoutManager(com.applozic.mobicomkit.uiwidgets.conversation.AlLinearLayoutManager) Context(android.content.Context) Bundle(android.os.Bundle) CountDownTimer(android.os.CountDownTimer) UserProfileFragment(com.applozic.mobicomkit.uiwidgets.people.fragment.UserProfileFragment) Intent(android.content.Intent) ImageView(android.widget.ImageView) MentionAutoCompleteTextView(com.applozic.mobicomkit.uiwidgets.conversation.mention.MentionAutoCompleteTextView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AttachmentView(com.applozic.mobicomkit.api.attachment.AttachmentView) GestureDetectorCompat(androidx.core.view.GestureDetectorCompat) Collections.disjoint(java.util.Collections.disjoint) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException) MotionEvent(android.view.MotionEvent) Contact(com.applozic.mobicommons.people.contact.Contact) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) MobicomMessageTemplateAdapter(com.applozic.mobicomkit.uiwidgets.conversation.adapter.MobicomMessageTemplateAdapter) ResultReceiver(android.os.ResultReceiver)

Example 44 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method sendMessage.

public void sendMessage(String message, Map<String, String> messageMetaData, FileMeta fileMetas, String fileMetaKeyStrings, short messageContentType, String filePath) {
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
    Message messageToSend = new Message();
    if (channel != null) {
        messageToSend.setGroupId(channel.getKey());
        if (!TextUtils.isEmpty(channel.getClientGroupId())) {
            messageToSend.setClientGroupId(channel.getClientGroupId());
        }
    } else {
        messageToSend.setTo(contact.getContactIds());
        messageToSend.setContactIds(contact.getContactIds());
    }
    messageToSend.setRead(Boolean.TRUE);
    messageToSend.setStoreOnDevice(Boolean.TRUE);
    if (messageToSend.getCreatedAtTime() == null) {
        messageToSend.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
    }
    if (currentConversationId != null && currentConversationId != 0) {
        messageToSend.setConversationId(currentConversationId);
    }
    messageToSend.setSendToDevice(Boolean.FALSE);
    messageToSend.setType(sendType.getSelectedItemId() == 1 ? Message.MessageType.MT_OUTBOX.getValue() : Message.MessageType.OUTBOX.getValue());
    messageToSend.setTimeToLive(getTimeToLive());
    messageToSend.setMessage(message);
    messageToSend.setDeviceKeyString(userPreferences.getDeviceKeyString());
    messageToSend.setSource(Message.Source.MT_MOBILE_APP.getValue());
    String originalFilePath = this.filePath != null ? this.filePath : filePath;
    if (!TextUtils.isEmpty(originalFilePath)) {
        List<String> filePaths = new ArrayList<String>();
        filePaths.add(originalFilePath);
        messageToSend.setFilePaths(filePaths);
        if (messageContentType == Message.ContentType.AUDIO_MSG.getValue() || messageContentType == Message.ContentType.CONTACT_MSG.getValue() || messageContentType == Message.ContentType.VIDEO_MSG.getValue()) {
            messageToSend.setContentType(messageContentType);
        } else {
            messageToSend.setContentType(Message.ContentType.ATTACHMENT.getValue());
        }
    } else {
        messageToSend.setContentType(messageContentType);
    }
    if (messageMetaData == null) {
        messageMetaData = new HashMap<>();
    }
    if (channel != null && channel.getType() != null && Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
        String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
        if (!TextUtils.isEmpty(userId)) {
            Contact newContact = appContactService.getContactById(userId);
            if (newContact.isBlockedBy()) {
                messageMetaData.put(Channel.AL_BLOCK, "true");
            }
        }
    }
    messageToSend.setFileMetaKeyStrings(fileMetaKeyStrings);
    messageToSend.setFileMetas(fileMetas);
    if (!TextUtils.isEmpty(ApplozicClient.getInstance(getActivity()).getMessageMetaData())) {
        Type mapType = new TypeToken<Map<String, String>>() {
        }.getType();
        Map<String, String> messageMetaDataMap = null;
        try {
            messageMetaDataMap = new Gson().fromJson(ApplozicClient.getInstance(getActivity()).getMessageMetaData(), mapType);
            if (messageMetaDataMap != null && !messageMetaDataMap.isEmpty()) {
                messageMetaData.putAll(messageMetaDataMap);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (this.messageMetaData != null && !this.messageMetaData.isEmpty()) {
        messageMetaData.putAll(this.messageMetaData);
    }
    messageToSend.setMetadata(messageMetaData);
    conversationService.sendMessage(messageToSend, userDisplayName);
    if (replayRelativeLayout != null) {
        replayRelativeLayout.setVisibility(View.GONE);
    }
    if (selfDestructMessageSpinner != null) {
        selfDestructMessageSpinner.setSelection(0);
    }
    attachmentLayout.setVisibility(View.GONE);
    if (channel != null && channel.getType() != null && Channel.GroupType.BROADCAST_ONE_BY_ONE.getValue().equals(channel.getType())) {
        sendBroadcastMessage(message, originalFilePath);
    }
    this.messageMetaData = null;
    this.filePath = null;
}
Also used : AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) Message(com.applozic.mobicomkit.api.conversation.Message) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException) Contact(com.applozic.mobicommons.people.contact.Contact) Type(java.lang.reflect.Type) Map(java.util.Map) HashMap(java.util.HashMap)

Example 45 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class MessageInfoFragment method init.

private void init() {
    if (contactImageLoader == null) {
        contactImageLoader = new ImageLoader(getContext(), getListPreferredItemHeight()) {

            @Override
            protected Bitmap processBitmap(Object data) {
                if (getContext() != null) {
                    return contactService.downloadContactImage(getContext(), (Contact) data);
                }
                return null;
            }
        };
        contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
        contactImageLoader.addImageCache(getActivity().getSupportFragmentManager(), 0.1f);
    }
    if (locationImageLoader == null) {
        locationImageLoader = new ImageLoader(getContext(), ImageUtils.getLargestScreenDimension((Activity) getContext())) {

            @Override
            protected Bitmap processBitmap(Object data) {
                if (getContext() != null) {
                    return fileClientService.loadMessageImage(getContext(), (String) data);
                }
                return null;
            }
        };
        locationImageLoader.setImageFadeIn(false);
        locationImageLoader.addImageCache(((FragmentActivity) getContext()).getSupportFragmentManager(), 0.1f);
    }
    Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.my_toolbar);
    toolbar.setClickable(false);
    toolbar.setTitle(getString(R.string.applozic_message_info));
    toolbar.setSubtitle("");
}
Also used : Bitmap(android.graphics.Bitmap) ImageLoader(com.applozic.mobicommons.commons.image.ImageLoader) Contact(com.applozic.mobicommons.people.contact.Contact) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

Contact (com.applozic.mobicommons.people.contact.Contact)107 Channel (com.applozic.mobicommons.people.channel.Channel)26 Message (com.applozic.mobicomkit.api.conversation.Message)18 Intent (android.content.Intent)17 AppContactService (com.applozic.mobicomkit.contact.AppContactService)17 ArrayList (java.util.ArrayList)15 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)14 UserDetail (com.applozic.mobicomkit.api.account.user.UserDetail)12 Test (org.junit.Test)12 Bitmap (android.graphics.Bitmap)11 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)10 Context (android.content.Context)9 SpannableString (android.text.SpannableString)8 NonNull (androidx.annotation.NonNull)8 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)8 ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)8 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)8 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)7 ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)7 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)7