From 164703b37a9bf876818112caf6a6edbf276bd8ec Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 31 Mar 2018 22:24:53 +0200 Subject: simplified reInit logic --- .../pixart/messenger/ui/ConversationActivity.java | 2 +- .../pixart/messenger/ui/ConversationFragment.java | 30 +++++----------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 36b5de0c0..52b993582 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -429,7 +429,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation } else { mainNeedsRefresh = true; } - conversationFragment.reInit(conversation, extras); + conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras); if (mainNeedsRefresh) { refreshFragment(R.id.main_fragment); } else { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 054aef715..30058dd1e 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1905,8 +1905,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void onStart() { super.onStart(); if (this.reInitRequiredOnStart) { - reInit(conversation); final Bundle extras = pendingExtras.pop(); + reInit(conversation, extras != null); if (extras != null) { processExtras(extras); } @@ -1957,7 +1957,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void reInit(Conversation conversation, Bundle extras) { this.saveMessageDraftStopAudioPlayer(); - if (this.reInit(conversation, false, extras != null)) { + if (this.reInit(conversation, extras != null)) { if (extras != null) { processExtras(extras); this.reInitRequiredOnStart = false; @@ -1969,14 +1969,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } private void reInit(Conversation conversation) { - reInit(conversation, false, false); - } - - private void reInitRestore(Conversation conversation) { - reInit(conversation, true, false); + reInit(conversation, false); } - private boolean reInit(Conversation conversation, boolean restore, boolean hasExtras) { + private boolean reInit(final Conversation conversation, final boolean hasExtras) { if (conversation == null) { return false; } @@ -1985,14 +1981,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (this.activity == null || this.binding == null) { return false; } - Log.d(Config.LOGTAG, "reInit(restore=" + Boolean.toString(restore) + ", hasExtras=" + Boolean.toString(hasExtras) + ")"); - - final boolean fullReset = !restore && !hasExtras; - + Log.d(Config.LOGTAG, "reInit(hasExtras=" + Boolean.toString(hasExtras) + ")"); setupIme(); - if (fullReset) { - this.conversation.trim(); - } this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName())); this.binding.textinput.setKeyboardListener(null); @@ -2000,16 +1990,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.textinput.append(this.conversation.getNextMessage()); this.binding.textinput.setKeyboardListener(this); messageListAdapter.updatePreferences(); - if (fullReset) { - this.binding.messagesView.setAdapter(messageListAdapter); - } refresh(false); this.conversation.messagesLoaded.set(true); - //usually on a restore we don’t want to jump unless there is no scroll state to restore anyway - //on a view intent (indicated by hasExtras) we always want to jump - final boolean jump = (!restore || pendingScrollState.peek() == null) || hasExtras; - if (jump) { + if (hasExtras) { synchronized (this.messageList) { Log.d(Config.LOGTAG, "jump to first unread message"); final Message first = conversation.getFirstUnreadMessage(); @@ -2762,7 +2746,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke clearPending(); return; } - reInitRestore(conversation); + reInit(conversation); ScrollState scrollState = pendingScrollState.pop(); if (scrollState != null) { setScrollPosition(scrollState); -- cgit v1.2.3