aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-05-22 17:52:27 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-05-22 17:52:27 +0200
commite5b8302fd9a09552f0b33a956703751bf9da80a7 (patch)
tree8e9493c326b39f62d8c73b99443c106e71508303 /src/main/java/eu/siacs/conversations
parent33218ec32a47292a46d574e5107164b8e8a72e40 (diff)
show first unread message on top after reinit
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java15
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java55
2 files changed, 46 insertions, 24 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index 10b42b460..23420d69a 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -96,6 +96,21 @@ public class Conversation extends AbstractEntity implements Blockable {
this.messagesLeftOnServer = value;
}
+
+ public Message getFirstUnreadMessage() {
+ Message first = null;
+ synchronized (this.messages) {
+ for (int i = messages.size() - 1; i >= 0; --i) {
+ if (messages.get(i).isRead()) {
+ return first;
+ } else {
+ first = messages.get(i);
+ }
+ }
+ }
+ return first;
+ }
+
public Message findUnsentMessageWithUuid(String uuid) {
synchronized(this.messages) {
for (final Message message : this.messages) {
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index f1352780a..60514d205 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -123,27 +123,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
- private int getIndexOf(String uuid, List<Message> messages) {
- if (uuid == null) {
- return messages.size() - 1;
- }
- for(int i = 0; i < messages.size(); ++i) {
- if (uuid.equals(messages.get(i).getUuid())) {
- return i;
- } else {
- Message next = messages.get(i);
- while(next != null && next.wasMergedIntoPrevious()) {
- if (uuid.equals(next.getUuid())) {
- return i;
- }
- next = next.next();
- }
-
- }
- }
- return 0;
- }
-
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
@@ -212,6 +191,28 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
};
+
+ private int getIndexOf(String uuid, List<Message> messages) {
+ if (uuid == null) {
+ return messages.size() - 1;
+ }
+ for(int i = 0; i < messages.size(); ++i) {
+ if (uuid.equals(messages.get(i).getUuid())) {
+ return i;
+ } else {
+ Message next = messages.get(i);
+ while(next != null && next.wasMergedIntoPrevious()) {
+ if (uuid.equals(next.getUuid())) {
+ return i;
+ }
+ next = next.next();
+ }
+
+ }
+ }
+ return 0;
+ }
+
private final int KEYCHAIN_UNLOCK_NOT_REQUIRED = 0;
private final int KEYCHAIN_UNLOCK_REQUIRED = 1;
private final int KEYCHAIN_UNLOCK_PENDING = 2;
@@ -796,9 +797,15 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
this.messagesView.setAdapter(messageListAdapter);
updateMessages();
this.messagesLoaded = true;
- int size = this.messageList.size();
- if (size > 0) {
- messagesView.setSelection(size - 1);
+ synchronized (this.messageList) {
+ final Message first = conversation.getFirstUnreadMessage();
+ final int pos;
+ if (first == null) {
+ pos = Math.max(0,this.messageList.size() - 1);
+ } else {
+ pos = getIndexOf(first.getUuid(), this.messageList);
+ }
+ messagesView.setSelection(pos);
}
}