Search in sources :

Example 1 with OnContactPictureClicked

use of eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked in project Conversations by siacs.

the class ConversationFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_conversation, container, false);
    view.setOnClickListener(null);
    String[] allImagesMimeType = { "image/*" };
    mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
    mEditMessage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (activity != null) {
                activity.hideConversationsOverview();
            }
        }
    });
    mEditMessage.setOnEditorActionListener(mEditorActionListener);
    mEditMessage.setRichContentListener(allImagesMimeType, mEditorContentListener);
    mSendButton = (ImageButton) view.findViewById(R.id.textSendButton);
    mSendButton.setOnClickListener(this.mSendButtonListener);
    snackbar = (RelativeLayout) view.findViewById(R.id.snackbar);
    snackbarMessage = (TextView) view.findViewById(R.id.snackbar_message);
    snackbarAction = (TextView) view.findViewById(R.id.snackbar_action);
    messagesView = (ListView) view.findViewById(R.id.messages_view);
    messagesView.setOnScrollListener(mOnScrollListener);
    messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
    messageListAdapter = new MessageAdapter((ConversationActivity) getActivity(), this.messageList);
    messageListAdapter.setOnContactPictureClicked(new OnContactPictureClicked() {

        @Override
        public void onContactPictureClicked(Message message) {
            if (message.getStatus() <= Message.STATUS_RECEIVED) {
                if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
                    Jid user = message.getCounterpart();
                    if (user != null && !user.isBareJid()) {
                        if (!message.getConversation().getMucOptions().isUserInRoom(user)) {
                            Toast.makeText(activity, activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                        }
                        highlightInConference(user.getResourcepart());
                    }
                } else {
                    if (!message.getContact().isSelf()) {
                        String fingerprint;
                        if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
                            fingerprint = "pgp";
                        } else {
                            fingerprint = message.getFingerprint();
                        }
                        activity.switchToContactDetails(message.getContact(), fingerprint);
                    }
                }
            } else {
                Account account = message.getConversation().getAccount();
                Intent intent;
                if (activity.manuallyChangePresence()) {
                    intent = new Intent(activity, SetPresenceActivity.class);
                    intent.putExtra(SetPresenceActivity.EXTRA_ACCOUNT, account.getJid().toBareJid().toString());
                } else {
                    intent = new Intent(activity, EditAccountActivity.class);
                    intent.putExtra("jid", account.getJid().toBareJid().toString());
                    String fingerprint;
                    if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
                        fingerprint = "pgp";
                    } else {
                        fingerprint = message.getFingerprint();
                    }
                    intent.putExtra("fingerprint", fingerprint);
                }
                startActivity(intent);
            }
        }
    });
    messageListAdapter.setOnContactPictureLongClicked(new OnContactPictureLongClicked() {

        @Override
        public void onContactPictureLongClicked(Message message) {
            if (message.getStatus() <= Message.STATUS_RECEIVED) {
                if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
                    Jid user = message.getCounterpart();
                    if (user != null && !user.isBareJid()) {
                        if (message.getConversation().getMucOptions().isUserInRoom(user)) {
                            privateMessageWith(user);
                        } else {
                            Toast.makeText(activity, activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            } else {
                activity.showQrCode();
            }
        }
    });
    messageListAdapter.setOnQuoteListener(new MessageAdapter.OnQuoteListener() {

        @Override
        public void onQuote(String text) {
            if (mEditMessage.isEnabled()) {
                text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", "");
                Editable editable = mEditMessage.getEditableText();
                int position = mEditMessage.getSelectionEnd();
                if (position == -1)
                    position = editable.length();
                if (position > 0 && editable.charAt(position - 1) != '\n') {
                    editable.insert(position++, "\n");
                }
                editable.insert(position, text);
                position += text.length();
                editable.insert(position++, "\n");
                if (position < editable.length() && editable.charAt(position) != '\n') {
                    editable.insert(position, "\n");
                }
                mEditMessage.setSelection(position);
                mEditMessage.requestFocus();
                InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                if (inputMethodManager != null) {
                    inputMethodManager.showSoftInput(mEditMessage, InputMethodManager.SHOW_IMPLICIT);
                }
            }
        }
    });
    messagesView.setAdapter(messageListAdapter);
    registerForContextMenu(messagesView);
    return view;
}
Also used : MessageAdapter(eu.siacs.conversations.ui.adapter.MessageAdapter) Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) OnContactPictureLongClicked(eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked) OnContactPictureClicked(eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked) OnClickListener(android.view.View.OnClickListener) Editable(android.text.Editable)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Editable (android.text.Editable)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Account (eu.siacs.conversations.entities.Account)1 Message (eu.siacs.conversations.entities.Message)1 MessageAdapter (eu.siacs.conversations.ui.adapter.MessageAdapter)1 OnContactPictureClicked (eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked)1 OnContactPictureLongClicked (eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1