From f44e12b077384c1f0fb14234f518e41fa73710a5 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 22 Apr 2018 19:31:56 +0200 Subject: in case fragment starts after activity is bound to service; fetch conversation from uuid --- .../pixart/messenger/ui/ConversationFragment.java | 39 ++++++++++++++-------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'src/main/java/de/pixart/messenger/ui/ConversationFragment.java') diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 1feb40b1f..8519c30cf 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -2085,14 +2085,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); + } } } @@ -3012,18 +3016,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(); @@ -3038,6 +3033,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"); -- cgit v1.2.3