Search in sources :

Example 1 with OnSwipeTouchListener

use of de.pixart.messenger.ui.interfaces.OnSwipeTouchListener in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method reInit.

private boolean reInit(final Conversation conversation, final boolean hasExtras) {
    if (conversation == null) {
        return false;
    }
    this.conversation = conversation;
    // once we set the conversation all is good and it will automatically do the right thing in onStart()
    if (this.activity == null || this.binding == null) {
        return false;
    }
    Log.d(Config.LOGTAG, "reInit(hasExtras=" + Boolean.toString(hasExtras) + ")");
    if (this.conversation.isRead() && hasExtras) {
        Log.d(Config.LOGTAG, "trimming conversation");
        this.conversation.trim();
    }
    setupIme();
    final boolean scrolledToBottomAndNoPending = this.scrolledToBottom() && pendingScrollState.peek() == null;
    this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName()));
    this.binding.textinput.setKeyboardListener(null);
    this.binding.textinput.setText("");
    this.binding.textinput.append(this.conversation.getNextMessage());
    this.binding.textinput.setKeyboardListener(this);
    messageListAdapter.updatePreferences();
    refresh(false);
    this.conversation.messagesLoaded.set(true);
    Log.d(Config.LOGTAG, "scrolledToBottomAndNoPending=" + Boolean.toString(scrolledToBottomAndNoPending));
    if (hasExtras || scrolledToBottomAndNoPending) {
        synchronized (this.messageList) {
            Log.d(Config.LOGTAG, "jump to first unread message");
            final Message first = conversation.getFirstUnreadMessage();
            final int bottom = Math.max(0, this.messageList.size() - 1);
            final int pos;
            if (first == null) {
                Log.d(Config.LOGTAG, "first unread message was null");
                pos = bottom;
            } else {
                int i = getIndexOf(first.getUuid(), this.messageList);
                pos = i < 0 ? bottom : i;
            }
            this.binding.messagesView.setSelection(pos);
        }
    }
    this.binding.messagesView.setOnTouchListener(new OnSwipeTouchListener(getContext()) {

        @Override
        public void onSwipeRight() {
            Log.d(Config.LOGTAG, "Swipe right detected");
            activity.onBackPressed();
        }
    });
    activity.onConversationRead(this.conversation);
    // TODO if we only do this when this fragment is running on main it won't *bing* in tablet layout which might be unnecessary since we can *see* it
    activity.xmppConnectionService.getNotificationService().setOpenConversation(this.conversation);
    return true;
}
Also used : EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) OnSwipeTouchListener(de.pixart.messenger.ui.interfaces.OnSwipeTouchListener) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Message (de.pixart.messenger.entities.Message)1 OnSwipeTouchListener (de.pixart.messenger.ui.interfaces.OnSwipeTouchListener)1 EditMessage (de.pixart.messenger.ui.widget.EditMessage)1