From 5a1ef31b493a65e86cf2d1222aafce2aee350408 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 2 Aug 2018 11:57:10 -0400 Subject: [PATCH] Fix crash with moveToLastSeen() --- .../securesms/ConversationActivity.java | 3 +++ .../securesms/ConversationFragment.java | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 699a469be1..92337c0198 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -301,9 +301,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void onSuccess(Boolean result) { if (result != null && result) { + Log.i(TAG, "Finished loading draft"); Util.runOnMain(() -> { if (fragment != null && fragment.isResumed()) { fragment.moveToLastSeen(); + } else { + Log.w(TAG, "Wanted to move to the last seen position, but the fragment was in an invalid state"); } }); } diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index 20755c1eb3..912b61c2e2 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -191,10 +191,18 @@ public class ConversationFragment extends Fragment } public void moveToLastSeen() { - if (lastSeen > 0) { - int position = getListAdapter().findLastSeenPosition(lastSeen); - scrollToLastSeenPosition(position); + if (lastSeen <= 0) { + Log.i(TAG, "No need to move to last seen."); + return; } + + if (list == null || getListAdapter() == null) { + Log.w(TAG, "Tried to move to last seen position, but we hadn't initialized the view yet."); + return; + } + + int position = getListAdapter().findLastSeenPosition(lastSeen); + scrollToLastSeenPosition(position); } private void initializeResources() {