From 1500299607cec27119773fe3a94124ce8c84b194 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 1 Apr 2018 19:14:53 +0200 Subject: [PATCH] in case fragment starts after activity is bound to service; fetch conversation from uuid --- .../ui/ConversationFragment.java | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 624445028..143e93e2d 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -92,6 +92,7 @@ import eu.siacs.conversations.ui.util.ScrollState; import eu.siacs.conversations.ui.util.SendButtonAction; import eu.siacs.conversations.ui.util.SendButtonTool; import eu.siacs.conversations.ui.widget.EditMessage; +import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.MessageUtils; import eu.siacs.conversations.utils.NickValidityChecker; import eu.siacs.conversations.utils.StylingHelper; @@ -1804,14 +1805,18 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @Override public void onStart() { super.onStart(); - if (this.reInitRequiredOnStart) { + if (this.reInitRequiredOnStart && this.conversation != null) { final Bundle extras = pendingExtras.pop(); - reInit(conversation, extras != null); + reInit(this.conversation, extras != null); if (extras != null) { processExtras(extras); } - } else { - Log.d(Config.LOGTAG, "skipped reinit on start"); + } else if (conversation == null && activity != null && activity.xmppConnectionService != null) { + final String uuid = pendingConversationsUuid.pop(); + Log.d(Config.LOGTAG,"ConversationFragment.onStart() - activity was bound but no conversation loaded. uuid="+uuid); + if (uuid != null) { + findAndReInitByUuidOrArchive(uuid); + } } } @@ -2567,18 +2572,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke Log.d(Config.LOGTAG, "ConversationFragment.onBackendConnected()"); String uuid = pendingConversationsUuid.pop(); if (uuid != null) { - Conversation conversation = activity.xmppConnectionService.findConversationByUuid(uuid); - if (conversation == null) { - clearPending(); - activity.onConversationArchived(null); + if (!findAndReInitByUuidOrArchive(uuid)) { return; } - reInit(conversation); - ScrollState scrollState = pendingScrollState.pop(); - String lastMessageUuid = pendingLastMessageUuid.pop(); - if (scrollState != null) { - setScrollPosition(scrollState, lastMessageUuid); - } } else { if (!activity.xmppConnectionService.isConversationStillOpen(conversation)) { clearPending(); @@ -2593,6 +2589,22 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke clearPending(); } + 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(); + if (scrollState != null) { + setScrollPosition(scrollState, lastMessageUuid); + } + return true; + } + private void clearPending() { if (postponedActivityResult.pop() != null) { Log.e(Config.LOGTAG, "cleared pending intent with unhandled result left");