public void createView(Contact contact, Channel channel, final AlMessageViewEvents listener) { removeAllViews(); this.listener = listener; LayoutInflater inflater = (LayoutInflater) getContext().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.al_message_sender_view, null); LinearLayout mainEditTextLayout = view.findViewById(R.id.main_edit_text_linear_layout); messageEditText = mainEditTextLayout.findViewById(R.id.conversation_message); attachmentButton = mainEditTextLayout.findViewById(R.id.attach_button); emoticonsButton = mainEditTextLayout.findViewById(R.id.emoticons_btn); emoticonsButton.setVisibility(GONE); messageEditText.setHint("Write a message..."); FrameLayout actionButtonLayout = view.findViewById(R.id.actionButtonLayout); sendMessageButton = actionButtonLayout.findViewById(R.id.conversation_send); audioRecordButton = actionButtonLayout.findViewById(R.id.record_button); audioRecordButton.setVisibility(GONE); sendMessageButton.setVisibility(VISIBLE); ((LinearLayout) view).removeAllViews(); publishTypingStatus(messageEditText, contact, channel); attachListeners(); addView(mainEditTextLayout); addView(actionButtonLayout); }
@Override public void afterTextChanged(Editable s) { try { if (!TextUtils.isEmpty(s.toString()) && s.toString().trim().length() > 0 && !typingStarted) { typingStarted = true; if (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()))) { Applozic.publishTypingStatus(getContext(), channel, contact, true); } } else if (s.toString().trim().length() == 0 && typingStarted) { typingStarted = false; if (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()))) { Applozic.publishTypingStatus(getContext(), channel, contact, false); } } if (listener != null) { listener.onTyping(editText, typingStarted); } } catch (Exception e) { } } });
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample); typingIndicator = findViewById(R.id.alTypingIndicator); messageSenderView = findViewById(R.id.alMessageSenderView); attachmentView = findViewById(R.id.alAttachmentView); snackBarLayout = findViewById(R.id.snackbarLayout); conversationFragment = (AlConversationFragment) getSupportFragmentManager().findFragmentById(R.id.conversationFragment); messageSenderView.createView(new AppContactService(this).getContactById("reytum6"), null, this); attachmentView.createView(); Applozic.getInstance(this).registerUIListener(this); }
@Override public void onFocusChange(View v, boolean hasFocus) { if (listener != null) { listener.onFocus(editText, hasFocus); } if (hasFocus && typingStarted && (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())))) { Applozic.publishTypingStatus(getContext(), channel, contact, typingStarted); } } });