in case fragment starts after activity is bound to service; fetch conversation from uuid

This commit is contained in:
Daniel Gultsch 2018-04-01 19:14:53 +02:00
parent 962ecbedfa
commit 1500299607
1 changed files with 26 additions and 14 deletions

View File

@ -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");