aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-03-31 22:18:00 +0200
committerChristian Schneppe <christian@pix-art.de>2018-03-31 22:18:00 +0200
commitb748514f09595cf0661efc55aa9b6596cd5f94f0 (patch)
tree0085ecec771b9c9861a460d3f03339547701d05f /src/main/java/de/pixart/messenger
parenta7af64cbeb43214351bbf9557e7e78f2dd295f51 (diff)
always scroll if viewing intent
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java33
2 files changed, 27 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index 2783a4b1f..b119d62ea 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -401,6 +401,9 @@ public class ConversationActivity extends XmppActivity implements OnConversation
@Override
public void onConversationSelected(Conversation conversation) {
+ if (ConversationFragment.getConversation(this) == conversation) {
+ Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
+ }
openConversation(conversation, null);
}
@@ -496,6 +499,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation
endConversation(conversation);
}
}
+ setIntent(createLauncherIntent(this));
}
public void endConversation(Conversation conversation) {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 338e899f4..054aef715 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -1930,6 +1930,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
updateChatState(this.conversation, msg);
this.activity.xmppConnectionService.getNotificationService().setOpenConversation(null);
}
+ this.reInitRequiredOnStart = true;
}
private void updateChatState(final Conversation conversation, final String msg) {
@@ -1956,7 +1957,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void reInit(Conversation conversation, Bundle extras) {
this.saveMessageDraftStopAudioPlayer();
- if (this.reInit(conversation)) {
+ if (this.reInit(conversation, false, extras != null)) {
if (extras != null) {
processExtras(extras);
this.reInitRequiredOnStart = false;
@@ -1967,23 +1968,29 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
- private boolean reInit(Conversation conversation) {
- return reInit(conversation, false);
+ private void reInit(Conversation conversation) {
+ reInit(conversation, false, false);
}
- private boolean reInit(Conversation conversation, boolean restore) {
+ private void reInitRestore(Conversation conversation) {
+ reInit(conversation, true, false);
+ }
+
+ private boolean reInit(Conversation conversation, boolean restore, boolean hasExtras) {
if (conversation == null) {
return false;
}
- final boolean hasChanged = this.conversation != null && this.conversation != conversation;
this.conversation = conversation;
//once we set the conversation all is good and it will automatically do the right thing in onStart()
if (this.activity == null || this.binding == null) {
return false;
}
- Log.d(Config.LOGTAG, "reInit(restore=" + Boolean.toString(restore) + ", hasChanged=" + Boolean.toString(hasChanged) + ")");
+ Log.d(Config.LOGTAG, "reInit(restore=" + Boolean.toString(restore) + ", hasExtras=" + Boolean.toString(hasExtras) + ")");
+
+ final boolean fullReset = !restore && !hasExtras;
+
setupIme();
- if (!restore && hasChanged) {
+ if (fullReset) {
this.conversation.trim();
}
@@ -1993,17 +2000,23 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
this.binding.textinput.append(this.conversation.getNextMessage());
this.binding.textinput.setKeyboardListener(this);
messageListAdapter.updatePreferences();
- if (!restore && hasChanged) {
+ if (fullReset) {
this.binding.messagesView.setAdapter(messageListAdapter);
}
refresh(false);
this.conversation.messagesLoaded.set(true);
- if (!restore && hasChanged) {
+
+ //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) {
synchronized (this.messageList) {
+ Log.d(Config.LOGTAG, "jump to first unread message");
final Message first = conversation.getFirstUnreadMessage();
final int bottom = Math.max(0, this.messageList.size() - 1);
final int pos;
if (first == null) {
+ Log.d(Config.LOGTAG, "first unread message was null");
pos = bottom;
} else {
int i = getIndexOf(first.getUuid(), this.messageList);
@@ -2749,7 +2762,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
clearPending();
return;
}
- reInit(conversation, true);
+ reInitRestore(conversation);
ScrollState scrollState = pendingScrollState.pop();
if (scrollState != null) {
setScrollPosition(scrollState);