diff --git a/app/src/main/java/org/thoughtcrime/securesms/MainNavigator.java b/app/src/main/java/org/thoughtcrime/securesms/MainNavigator.java index 8742d30e6..08a5affbd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MainNavigator.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MainNavigator.java @@ -56,8 +56,8 @@ public class MainNavigator { return false; } - public void goToConversation(@NonNull RecipientId recipientId, long threadId, int distributionType, int startingPosition) { - Intent intent = ConversationActivity.buildIntent(activity, recipientId, threadId, distributionType, startingPosition); + public void goToConversation(@NonNull RecipientId recipientId, long threadId, int distributionType, int startingPosition, boolean highlightStartPosition) { + Intent intent = ConversationActivity.buildIntent(activity, recipientId, threadId, distributionType, startingPosition, highlightStartPosition); activity.startActivity(intent); activity.overridePendingTransition(R.anim.slide_from_end, R.anim.fade_scale_out); diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 9dbb76057..ab909a36d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -281,13 +281,14 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private static final String TAG = ConversationActivity.class.getSimpleName(); - public static final String RECIPIENT_EXTRA = "recipient_id"; - public static final String THREAD_ID_EXTRA = "thread_id"; - public static final String TEXT_EXTRA = "draft_text"; - public static final String MEDIA_EXTRA = "media_list"; - public static final String STICKER_EXTRA = "sticker_extra"; - public static final String DISTRIBUTION_TYPE_EXTRA = "distribution_type"; - public static final String STARTING_POSITION_EXTRA = "starting_position"; + public static final String RECIPIENT_EXTRA = "recipient_id"; + public static final String THREAD_ID_EXTRA = "thread_id"; + public static final String TEXT_EXTRA = "draft_text"; + public static final String MEDIA_EXTRA = "media_list"; + public static final String STICKER_EXTRA = "sticker_extra"; + public static final String DISTRIBUTION_TYPE_EXTRA = "distribution_type"; + public static final String STARTING_POSITION_EXTRA = "starting_position"; + public static final String HIGHLIGHT_STARTING_POSITION_EXTRA = "highlight_starting_position"; private static final int PICK_GALLERY = 1; private static final int PICK_DOCUMENT = 2; @@ -355,13 +356,15 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @NonNull RecipientId recipientId, long threadId, int distributionType, - int startingPosition) + int startingPosition, + boolean highlightStartingPosition) { Intent intent = new Intent(context, ConversationActivity.class); intent.putExtra(ConversationActivity.RECIPIENT_EXTRA, recipientId); intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId); intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType); intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, startingPosition); + intent.putExtra(ConversationActivity.HIGHLIGHT_STARTING_POSITION_EXTRA, highlightStartingPosition); return intent; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java index e21c3c6c0..ef5b954a3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -217,6 +217,7 @@ public class ConversationFragment extends Fragment { this.conversationViewModel = ViewModelProviders.of(requireActivity(), new ConversationViewModel.Factory()).get(ConversationViewModel.class); conversationViewModel.getMessages().observe(this, list -> { if (getListAdapter() != null) { + Log.i(TAG, "submitList"); getListAdapter().submitList(list); } }); @@ -283,6 +284,7 @@ public class ConversationFragment extends Fragment { super.onResume(); if (list.getAdapter() != null) { + Log.i(TAG, "onResume notifyDataSetChanged"); list.getAdapter().notifyDataSetChanged(); } } @@ -905,10 +907,17 @@ public class ConversationFragment extends Fragment { private void scrollToStartingPosition(int startingPosition) { list.post(() -> { list.getLayoutManager().scrollToPosition(startingPosition); - getListAdapter().pulseHighlightItem(startingPosition); + + if (shouldHighlightStartingPosition()) { + getListAdapter().pulseHighlightItem(startingPosition); + } }); } + private boolean shouldHighlightStartingPosition() { + return requireActivity().getIntent().getBooleanExtra(ConversationActivity.HIGHLIGHT_STARTING_POSITION_EXTRA, false); + } + private void scrollToLastSeenPosition(int lastSeenPosition) { if (lastSeenPosition > 0) { list.post(() -> getListLayoutManager().scrollToPositionWithOffset(lastSeenPosition, list.getHeight())); diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java index cada0aabd..7e73f3168 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversationlist/ConversationListFragment.java @@ -126,6 +126,7 @@ import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; import org.thoughtcrime.securesms.util.concurrent.SimpleTask; import org.thoughtcrime.securesms.util.task.SnackbarAsyncTask; +import org.whispersystems.libsignal.util.Pair; import org.whispersystems.libsignal.util.guava.Optional; import java.util.Collections; @@ -352,19 +353,24 @@ public class ConversationListFragment extends MainFragment implements LoaderMana getNavigator().goToConversation(threadRecord.getRecipient().getId(), threadRecord.getThreadId(), threadRecord.getDistributionType(), - -1); + threadRecord.getUnreadCount(), + false); } @Override public void onContactClicked(@NonNull Recipient contact) { SimpleTask.run(getViewLifecycleOwner().getLifecycle(), () -> { - return DatabaseFactory.getThreadDatabase(getContext()).getThreadIdIfExistsFor(contact); - }, threadId -> { + long threadId = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdIfExistsFor(contact); + int unreadCount = DatabaseFactory.getMmsSmsDatabase(getContext()).getUnreadCount(threadId); + + return new Pair<>(threadId, unreadCount); + }, pair -> { hideKeyboard(); getNavigator().goToConversation(contact.getId(), - threadId, + pair.first(), ThreadDatabase.DistributionTypes.DEFAULT, - -1); + pair.second(), + false); }); } @@ -378,7 +384,8 @@ public class ConversationListFragment extends MainFragment implements LoaderMana getNavigator().goToConversation(message.conversationRecipient.getId(), message.threadId, ThreadDatabase.DistributionTypes.DEFAULT, - startingPosition); + startingPosition, + true); }); } @@ -728,8 +735,8 @@ public class ConversationListFragment extends MainFragment implements LoaderMana actionMode.setTitle(String.valueOf(defaultAdapter.getBatchSelectionIds().size())); } - private void handleCreateConversation(long threadId, Recipient recipient, int distributionType) { - getNavigator().goToConversation(recipient.getId(), threadId, distributionType, -1); + private void handleCreateConversation(long threadId, Recipient recipient, int distributionType, int unreadCount) { + getNavigator().goToConversation(recipient.getId(), threadId, distributionType, unreadCount, false); } @Override @@ -763,7 +770,7 @@ public class ConversationListFragment extends MainFragment implements LoaderMana @Override public void onItemClick(ConversationListItem item) { if (actionMode == null) { - handleCreateConversation(item.getThreadId(), item.getRecipient(), item.getDistributionType()); + handleCreateConversation(item.getThreadId(), item.getRecipient(), item.getDistributionType(), item.getUnreadCount()); } else { ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter(); adapter.toggleThreadInBatchSet(item.getThread()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/details/AddGroupDetailsActivity.java b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/details/AddGroupDetailsActivity.java index dddb8f62c..863d902df 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/details/AddGroupDetailsActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/details/AddGroupDetailsActivity.java @@ -63,7 +63,8 @@ public class AddGroupDetailsActivity extends PassphraseRequiredActionBarActivity recipientId, threadId, ThreadDatabase.DistributionTypes.DEFAULT, - -1); + -1, + false); startActivity(intent); setResult(RESULT_OK); diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java index 49fd09880..02126680e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java @@ -80,7 +80,13 @@ public class NotificationItem { public PendingIntent getPendingIntent(Context context) { Recipient recipient = threadRecipient != null ? threadRecipient : conversationRecipient; int startingPosition = jumpToMessage ? getStartingPosition(context, threadId, messageReceivedTimestamp) : -1; - Intent intent = ConversationActivity.buildIntent(context, recipient.getId(), threadId, 0, startingPosition); + + if (!jumpToMessage) { + int unreadCount = DatabaseFactory.getMmsSmsDatabase(context).getUnreadCount(threadId); + startingPosition = unreadCount > 0 ? unreadCount : -1; + } + + Intent intent = ConversationActivity.buildIntent(context, recipient.getId(), threadId, 0, startingPosition, jumpToMessage); makeIntentUniqueToPreventMerging(intent);