Search in sources :

Example 6 with MessageRow

use of org.matrix.androidsdk.adapters.MessageRow in project matrix-android-sdk by matrix-org.

the class MatrixMessageListFragment method getReadMarkerMessageRow.

/**
 * Provides the read "marked row".
 * The closest row is provided if it is not displayed
 *
 * @return the currentReadMarkerRow
 */
private MessageRow getReadMarkerMessageRow(MessageRow newMessageRow) {
    final String currentReadMarkerEventId = mRoom.getReadMarkerEventId();
    MessageRow currentReadMarkerRow = mAdapter.getMessageRow(currentReadMarkerEventId);
    if (null == currentReadMarkerRow) {
        // crash reported by GA
        try {
            Event readMarkedEvent = mSession.getDataHandler().getStore().getEvent(currentReadMarkerEventId, mRoom.getRoomId());
            // the read marked event might be a non displayable event
            if ((null != readMarkedEvent) && !canAddEvent(readMarkedEvent)) {
                // retrieve the previous displayed event
                currentReadMarkerRow = mAdapter.getClosestRowFromTs(readMarkedEvent.eventId, readMarkedEvent.getOriginServerTs());
                // or it is the last known event
                if ((null != currentReadMarkerRow) && !canUpdateReadMarker(newMessageRow, currentReadMarkerRow)) {
                    currentReadMarkerRow = null;
                }
                // use the next one
                if (null == currentReadMarkerRow) {
                    currentReadMarkerRow = mAdapter.getClosestRowBeforeTs(readMarkedEvent.eventId, readMarkedEvent.getOriginServerTs());
                }
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "## getReadMarkerMessageRow() failed : " + e.getMessage());
        }
    }
    return currentReadMarkerRow;
}
Also used : MessageRow(org.matrix.androidsdk.adapters.MessageRow) MotionEvent(android.view.MotionEvent) Event(org.matrix.androidsdk.rest.model.Event)

Example 7 with MessageRow

use of org.matrix.androidsdk.adapters.MessageRow in project matrix-android-sdk by matrix-org.

the class MatrixMessageListFragment method addMessageRow.

// create a dummy message row for the message
// It is added to the Adapter
// return the created Message
private MessageRow addMessageRow(RoomMediaMessage roomMediaMessage) {
    // a message row can only be added if there is a defined room
    if (null != mRoom) {
        Event event = roomMediaMessage.getEvent();
        MessageRow newMessageRow = new MessageRow(event, mRoom.getState());
        mAdapter.add(newMessageRow);
        // Move read marker if necessary
        MessageRow currentReadMarkerRow = getReadMarkerMessageRow(newMessageRow);
        if (canUpdateReadMarker(newMessageRow, currentReadMarkerRow)) {
            View childView = mMessageListView.getChildAt(mMessageListView.getChildCount() - 1);
            // Previous message was the last read
            if ((null != childView) && (childView.getTop() >= 0)) {
                // New message is fully visible, keep reference to move the read marker once server echo is received
                mFutureReadMarkerEventId = event.eventId;
                mAdapter.resetReadMarker();
            }
        }
        scrollToBottom();
        getSession().getDataHandler().getStore().commit();
        return newMessageRow;
    } else {
        return null;
    }
}
Also used : MessageRow(org.matrix.androidsdk.adapters.MessageRow) MotionEvent(android.view.MotionEvent) Event(org.matrix.androidsdk.rest.model.Event) View(android.view.View) AbsListView(android.widget.AbsListView) AutoScrollDownListView(org.matrix.androidsdk.view.AutoScrollDownListView)

Aggregations

MessageRow (org.matrix.androidsdk.adapters.MessageRow)7 MotionEvent (android.view.MotionEvent)4 Event (org.matrix.androidsdk.rest.model.Event)4 View (android.view.View)2 AbsListView (android.widget.AbsListView)2 JsonObject (com.google.gson.JsonObject)2 ApiCallback (org.matrix.androidsdk.rest.callback.ApiCallback)2 SimpleApiCallback (org.matrix.androidsdk.rest.callback.SimpleApiCallback)2 MatrixError (org.matrix.androidsdk.rest.model.MatrixError)2 SearchResult (org.matrix.androidsdk.rest.model.search.SearchResult)2 AutoScrollDownListView (org.matrix.androidsdk.view.AutoScrollDownListView)2 Activity (android.app.Activity)1 ArrayList (java.util.ArrayList)1 MXCryptoError (org.matrix.androidsdk.crypto.MXCryptoError)1 Room (org.matrix.androidsdk.data.Room)1 RoomState (org.matrix.androidsdk.data.RoomState)1 RoomSummary (org.matrix.androidsdk.data.RoomSummary)1 SearchResponse (org.matrix.androidsdk.rest.model.search.SearchResponse)1 EventDisplay (org.matrix.androidsdk.util.EventDisplay)1 RetrofitError (retrofit.RetrofitError)1