don't scroll to pos 0 when uuid wasn't found

This commit is contained in:
Daniel Gultsch 2016-05-31 16:44:59 +02:00
parent b7c8ce1511
commit b3337c4ad7

View file

@ -13,6 +13,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.InputType; import android.text.InputType;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity; import android.view.Gravity;
@ -157,7 +158,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList); ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList);
updateStatusMessages(); updateStatusMessages();
messageListAdapter.notifyDataSetChanged(); messageListAdapter.notifyDataSetChanged();
int pos = getIndexOf(uuid,messageList); int pos = Math.max(getIndexOf(uuid,messageList),0);
messagesView.setSelectionFromTop(pos, pxOffset); messagesView.setSelectionFromTop(pos, pxOffset);
messagesLoaded = true; messagesLoaded = true;
if (messageLoaderToast != null) { if (messageLoaderToast != null) {
@ -210,7 +211,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
} }
} }
return 0; return -1;
} }
private final int KEYCHAIN_UNLOCK_NOT_REQUIRED = 0; private final int KEYCHAIN_UNLOCK_NOT_REQUIRED = 0;
@ -802,11 +803,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
this.messagesLoaded = true; this.messagesLoaded = true;
synchronized (this.messageList) { synchronized (this.messageList) {
final Message first = conversation.getFirstUnreadMessage(); final Message first = conversation.getFirstUnreadMessage();
final int bottom = Math.max(0, this.messageList.size() - 1);
final int pos; final int pos;
if (first == null) { if (first == null) {
pos = Math.max(0,this.messageList.size() - 1); pos = bottom;
} else { } else {
pos = getIndexOf(first.getUuid(), this.messageList); int i = getIndexOf(first.getUuid(), this.messageList);
pos = i < 0 ? bottom : i;
} }
messagesView.setSelection(pos); messagesView.setSelection(pos);
} }