1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

Avoid IndexOutOfRangeException.

If there is no next message, it should return to a MessageList.
This commit is contained in:
Koji Arai 2013-02-19 02:06:30 +09:00
parent 9287d97626
commit 7da4c7cc1b
2 changed files with 17 additions and 11 deletions

View File

@ -1356,14 +1356,12 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
@Override
public void showNextMessageOrReturn() {
if (K9.messageViewReturnToList()) {
if (K9.messageViewReturnToList() || !showNextMessage()) {
if (mDisplayMode == DisplayMode.SPLIT_VIEW) {
showMessageViewPlaceHolder();
} else {
showMessageList();
}
} else {
showNextMessage();
}
}
@ -1377,18 +1375,24 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
mActionBarSubject.setMessageHeader(header);
}
private void showNextMessage() {
private boolean showNextMessage() {
MessageReference ref = mMessageViewFragment.getMessageReference();
if (ref != null) {
mMessageListFragment.openNext(ref);
if (mMessageListFragment.openNext(ref)) {
return true;
}
}
return false;
}
private void showPreviousMessage() {
private boolean showPreviousMessage() {
MessageReference ref = mMessageViewFragment.getMessageReference();
if (ref != null) {
mMessageListFragment.openPrevious(ref);
if (mMessageListFragment.openPrevious(ref)) {
return true;
}
}
return false;
}
private void showMessageList() {

View File

@ -2854,22 +2854,24 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
}
}
public void openPrevious(MessageReference messageReference) {
public boolean openPrevious(MessageReference messageReference) {
int position = getPosition(messageReference);
if (position <= 0) {
return;
return false;
}
openMessageAtPosition(position - 1);
return true;
}
public void openNext(MessageReference messageReference) {
public boolean openNext(MessageReference messageReference) {
int position = getPosition(messageReference);
if (position < 0 || position == mAdapter.getCount() - 1) {
return;
return false;
}
openMessageAtPosition(position + 1);
return true;
}
public boolean isFirst(MessageReference messageReference) {