Search in sources :

Example 1 with ScrollState

use of eu.siacs.conversations.ui.util.ScrollState in project Conversations by siacs.

the class ConversationsOverviewFragment method refresh.

@Override
void refresh() {
    if (this.binding == null || this.activity == null) {
        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.refresh() skipped updated because view binding or activity was null");
        return;
    }
    this.activity.xmppConnectionService.populateWithOrderedConversations(this.conversations);
    Conversation removed = this.swipedConversation.peek();
    if (removed != null) {
        if (removed.isRead()) {
            this.conversations.remove(removed);
        } else {
            pendingActionHelper.execute();
        }
    }
    this.conversationsAdapter.notifyDataSetChanged();
    ScrollState scrollState = pendingScrollState.pop();
    if (scrollState != null) {
        setScrollPosition(scrollState);
    }
}
Also used : ScrollState(eu.siacs.conversations.ui.util.ScrollState) Conversation(eu.siacs.conversations.entities.Conversation)

Example 2 with ScrollState

use of eu.siacs.conversations.ui.util.ScrollState in project Conversations by siacs.

the class ConversationsOverviewFragment method onSaveInstanceState.

@Override
public void onSaveInstanceState(Bundle bundle) {
    super.onSaveInstanceState(bundle);
    ScrollState scrollState = getScrollState();
    if (scrollState != null) {
        bundle.putParcelable(STATE_SCROLL_POSITION, scrollState);
    }
}
Also used : ScrollState(eu.siacs.conversations.ui.util.ScrollState)

Example 3 with ScrollState

use of eu.siacs.conversations.ui.util.ScrollState in project Conversations by siacs.

the class ConversationFragment method onSaveInstanceState.

@Override
public void onSaveInstanceState(@NotNull Bundle outState) {
    super.onSaveInstanceState(outState);
    if (conversation != null) {
        outState.putString(STATE_CONVERSATION_UUID, conversation.getUuid());
        outState.putString(STATE_LAST_MESSAGE_UUID, lastMessageUuid);
        final Uri uri = pendingTakePhotoUri.peek();
        if (uri != null) {
            outState.putString(STATE_PHOTO_URI, uri.toString());
        }
        final ScrollState scrollState = getScrollPosition();
        if (scrollState != null) {
            outState.putParcelable(STATE_SCROLL_POSITION, scrollState);
        }
        final ArrayList<Attachment> attachments = mediaPreviewAdapter == null ? new ArrayList<>() : mediaPreviewAdapter.getAttachments();
        if (attachments.size() > 0) {
            outState.putParcelableArrayList(STATE_MEDIA_PREVIEWS, attachments);
        }
    }
}
Also used : ScrollState(eu.siacs.conversations.ui.util.ScrollState) Attachment(eu.siacs.conversations.ui.util.Attachment) Uri(android.net.Uri)

Example 4 with ScrollState

use of eu.siacs.conversations.ui.util.ScrollState in project Conversations by siacs.

the class ConversationFragment method findAndReInitByUuidOrArchive.

private boolean findAndReInitByUuidOrArchive(@NonNull final String uuid) {
    Conversation conversation = activity.xmppConnectionService.findConversationByUuid(uuid);
    if (conversation == null) {
        clearPending();
        activity.onConversationArchived(null);
        return false;
    }
    reInit(conversation);
    ScrollState scrollState = pendingScrollState.pop();
    String lastMessageUuid = pendingLastMessageUuid.pop();
    List<Attachment> attachments = pendingMediaPreviews.pop();
    if (scrollState != null) {
        setScrollPosition(scrollState, lastMessageUuid);
    }
    if (attachments != null && attachments.size() > 0) {
        Log.d(Config.LOGTAG, "had attachments on restore");
        mediaPreviewAdapter.addMediaPreviews(attachments);
        toggleInputMethod();
    }
    return true;
}
Also used : ScrollState(eu.siacs.conversations.ui.util.ScrollState) Conversation(eu.siacs.conversations.entities.Conversation) Attachment(eu.siacs.conversations.ui.util.Attachment)

Example 5 with ScrollState

use of eu.siacs.conversations.ui.util.ScrollState in project Conversations by siacs.

the class ConversationFragment method getScrollPosition.

private ScrollState getScrollPosition() {
    final ListView listView = this.binding == null ? null : this.binding.messagesView;
    if (listView == null || listView.getCount() == 0 || listView.getLastVisiblePosition() == listView.getCount() - 1) {
        return null;
    } else {
        final int pos = listView.getFirstVisiblePosition();
        final View view = listView.getChildAt(0);
        if (view == null) {
            return null;
        } else {
            return new ScrollState(pos, view.getTop());
        }
    }
}
Also used : ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ScrollState(eu.siacs.conversations.ui.util.ScrollState) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint)

Aggregations

ScrollState (eu.siacs.conversations.ui.util.ScrollState)6 View (android.view.View)2 Conversation (eu.siacs.conversations.entities.Conversation)2 Attachment (eu.siacs.conversations.ui.util.Attachment)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1