Search in sources :

Example 1 with ActionMode

use of androidx.appcompat.view.ActionMode in project Signal-Android by WhisperSystems.

the class ConversationListFragment method updateMultiSelectState.

private void updateMultiSelectState() {
    int count = viewModel.currentSelectedConversations().size();
    boolean hasUnread = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().isRead());
    boolean hasUnpinned = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().isPinned());
    boolean hasUnmuted = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().getRecipient().live().get().isMuted());
    boolean canPin = viewModel.getPinnedCount() < MAXIMUM_PINNED_CONVERSATIONS;
    if (actionMode != null) {
        actionMode.setTitle(requireContext().getResources().getQuantityString(R.plurals.ConversationListFragment_s_selected, count, count));
    }
    List<ActionItem> items = new ArrayList<>();
    Set<Long> selectionIds = viewModel.currentSelectedConversations().stream().map(conversation -> conversation.getThreadRecord().getThreadId()).collect(Collectors.toSet());
    if (hasUnread) {
        items.add(new ActionItem(R.drawable.ic_read_24, getResources().getQuantityString(R.plurals.ConversationListFragment_read_plural, count), () -> handleMarkAsRead(selectionIds)));
    } else {
        items.add(new ActionItem(R.drawable.ic_unread_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unread_plural, count), () -> handleMarkAsUnread(selectionIds)));
    }
    if (!isArchived() && hasUnpinned && canPin) {
        items.add(new ActionItem(R.drawable.ic_pin_24, getResources().getQuantityString(R.plurals.ConversationListFragment_pin_plural, count), () -> handlePin(viewModel.currentSelectedConversations())));
    } else if (!isArchived() && !hasUnpinned) {
        items.add(new ActionItem(R.drawable.ic_unpin_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unpin_plural, count), () -> handleUnpin(selectionIds)));
    }
    if (isArchived()) {
        items.add(new ActionItem(R.drawable.ic_unarchive_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unarchive_plural, count), () -> handleArchive(selectionIds, true)));
    } else {
        items.add(new ActionItem(R.drawable.ic_archive_24, getResources().getQuantityString(R.plurals.ConversationListFragment_archive_plural, count), () -> handleArchive(selectionIds, true)));
    }
    items.add(new ActionItem(R.drawable.ic_delete_24, getResources().getQuantityString(R.plurals.ConversationListFragment_delete_plural, count), () -> handleDelete(selectionIds)));
    if (hasUnmuted) {
        items.add(new ActionItem(R.drawable.ic_mute_24, getResources().getQuantityString(R.plurals.ConversationListFragment_mute_plural, count), () -> handleMute(viewModel.currentSelectedConversations())));
    } else {
        items.add(new ActionItem(R.drawable.ic_unmute_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unmute_plural, count), () -> handleUnmute(viewModel.currentSelectedConversations())));
    }
    items.add(new ActionItem(R.drawable.ic_select_24, getString(R.string.ConversationListFragment_select_all), viewModel::onSelectAllClick));
    bottomActionBar.setItems(items);
}
Also used : NewConversationActivity(org.thoughtcrime.securesms.NewConversationActivity) Bundle(android.os.Bundle) PulsingFloatingActionButton(org.thoughtcrime.securesms.components.registration.PulsingFloatingActionButton) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) NonNull(androidx.annotation.NonNull) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ColorInt(androidx.annotation.ColorInt) Manifest(android.Manifest) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) TooltipCompat(androidx.appcompat.widget.TooltipCompat) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) Fragment(androidx.fragment.app.Fragment) Badge(org.thoughtcrime.securesms.badges.models.Badge) Canvas(android.graphics.Canvas) SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Megaphone(org.thoughtcrime.securesms.megaphone.Megaphone) ContextCompat(androidx.core.content.ContextCompat) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) ViewCompat(androidx.core.view.ViewCompat) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) Megaphones(org.thoughtcrime.securesms.megaphone.Megaphones) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) DimensionUnit(org.signal.core.util.DimensionUnit) IdRes(androidx.annotation.IdRes) Nullable(androidx.annotation.Nullable) SignalContextMenu(org.thoughtcrime.securesms.components.menu.SignalContextMenu) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) InsightsLauncher(org.thoughtcrime.securesms.insights.InsightsLauncher) UnexpectedSubscriptionCancellation(org.thoughtcrime.securesms.components.settings.app.subscription.errors.UnexpectedSubscriptionCancellation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) UnreadPayments(org.thoughtcrime.securesms.conversationlist.model.UnreadPayments) StickyHeaderDecoration(org.thoughtcrime.securesms.util.StickyHeaderDecoration) DialogFragment(androidx.fragment.app.DialogFragment) ServiceOutageReminder(org.thoughtcrime.securesms.components.reminder.ServiceOutageReminder) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) CantProcessSubscriptionPaymentBottomSheetDialogFragment(org.thoughtcrime.securesms.badges.self.expired.CantProcessSubscriptionPaymentBottomSheetDialogFragment) WorkerThread(androidx.annotation.WorkerThread) PaymentDetailsParcelable(org.thoughtcrime.securesms.payments.preferences.details.PaymentDetailsParcelable) MainFragment(org.thoughtcrime.securesms.MainFragment) ArrayList(java.util.ArrayList) ActionMenuView(androidx.appcompat.widget.ActionMenuView) ReminderView(org.thoughtcrime.securesms.components.reminder.ReminderView) KeyCachingService(org.thoughtcrime.securesms.service.KeyCachingService) WebSocketConnectionState(org.whispersystems.signalservice.api.websocket.WebSocketConnectionState) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) SignalProxyUtil(org.thoughtcrime.securesms.util.SignalProxyUtil) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) RatingManager(org.thoughtcrime.securesms.components.RatingManager) AppStartup(org.thoughtcrime.securesms.util.AppStartup) LinkedHashSet(java.util.LinkedHashSet) MainNavigator(org.thoughtcrime.securesms.MainNavigator) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ProgressDialog(android.app.ProgressDialog) Permissions(org.thoughtcrime.securesms.permissions.Permissions) UnreadPaymentsView(org.thoughtcrime.securesms.components.UnreadPaymentsView) PushRegistrationReminder(org.thoughtcrime.securesms.components.reminder.PushRegistrationReminder) Optional(org.whispersystems.libsignal.util.guava.Optional) Reminder(org.thoughtcrime.securesms.components.reminder.Reminder) BottomSheetUtil(org.thoughtcrime.securesms.util.BottomSheetUtil) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) SnackbarAsyncTask(org.thoughtcrime.securesms.util.task.SnackbarAsyncTask) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalBottomActionBar(org.thoughtcrime.securesms.components.menu.SignalBottomActionBar) ArgbEvaluatorCompat(com.google.android.material.animation.ArgbEvaluatorCompat) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) NotificationProfileSelectionFragment(org.thoughtcrime.securesms.components.settings.app.notifications.manual.NotificationProfileSelectionFragment) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) PaymentDetailsFragmentArgs(org.thoughtcrime.securesms.payments.preferences.details.PaymentDetailsFragmentArgs) ConversationFragment(org.thoughtcrime.securesms.conversation.ConversationFragment) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) DrawableRes(androidx.annotation.DrawableRes) R(org.thoughtcrime.securesms.R) PlayStoreUtil(org.thoughtcrime.securesms.util.PlayStoreUtil) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) Locale(java.util.Locale) PluralsRes(androidx.annotation.PluralsRes) NotificationProfiles(org.thoughtcrime.securesms.notifications.profiles.NotificationProfiles) View(android.view.View) MegaphoneViewBuilder(org.thoughtcrime.securesms.megaphone.MegaphoneViewBuilder) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecyclerView(androidx.recyclerview.widget.RecyclerView) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) SearchToolbar(org.thoughtcrime.securesms.components.SearchToolbar) Conversation(org.thoughtcrime.securesms.conversationlist.model.Conversation) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) ExpiredBuildReminder(org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder) SearchResult(org.thoughtcrime.securesms.search.SearchResult) AsyncTask(android.os.AsyncTask) VoiceNotePlayerView(org.thoughtcrime.securesms.components.voice.VoiceNotePlayerView) Collection(java.util.Collection) UUID(java.util.UUID) ThreadMode(org.greenrobot.eventbus.ThreadMode) AvatarUtil(org.thoughtcrime.securesms.util.AvatarUtil) ExpiredBadgeBottomSheetDialogFragment(org.thoughtcrime.securesms.badges.self.expired.ExpiredBadgeBottomSheetDialogFragment) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) CreateKbsPinActivity(org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity) VoiceNoteMediaControllerOwner(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) MarkReadReceiver(org.thoughtcrime.securesms.notifications.MarkReadReceiver) MessageResult(org.thoughtcrime.securesms.search.MessageResult) Toolbar(androidx.appcompat.widget.Toolbar) Snackbar(com.google.android.material.snackbar.Snackbar) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) DozeReminder(org.thoughtcrime.securesms.components.reminder.DozeReminder) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) Context(android.content.Context) TopToastPopup(org.thoughtcrime.securesms.util.TopToastPopup) RESULT_OK(android.app.Activity.RESULT_OK) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) AppForegroundObserver(org.thoughtcrime.securesms.util.AppForegroundObserver) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) TooltipPopup(org.thoughtcrime.securesms.components.TooltipPopup) SuppressLint(android.annotation.SuppressLint) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) OutdatedBuildReminder(org.thoughtcrime.securesms.components.reminder.OutdatedBuildReminder) POSITION_BELOW(org.thoughtcrime.securesms.components.TooltipPopup.POSITION_BELOW) EventBus(org.greenrobot.eventbus.EventBus) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) MegaphoneActionController(org.thoughtcrime.securesms.megaphone.MegaphoneActionController) Stub(org.thoughtcrime.securesms.util.views.Stub) LayoutInflater(android.view.LayoutInflater) MediaSelectionActivity(org.thoughtcrime.securesms.mediasend.v2.MediaSelectionActivity) PaymentsActivity(org.thoughtcrime.securesms.payments.preferences.PaymentsActivity) ActionMode(androidx.appcompat.view.ActionMode) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) ServiceOutageDetectionJob(org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob) Subscribe(org.greenrobot.eventbus.Subscribe) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent) MuteDialog(org.thoughtcrime.securesms.MuteDialog) Activity(android.app.Activity) Collections(java.util.Collections) Resources(android.content.res.Resources) UnauthorizedReminder(org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint)

Example 2 with ActionMode

use of androidx.appcompat.view.ActionMode in project Signal-Android by WhisperSystems.

the class ConversationFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    final View view = inflater.inflate(R.layout.conversation_fragment, container, false);
    videoContainer = view.findViewById(R.id.video_container);
    list = view.findViewById(android.R.id.list);
    composeDivider = view.findViewById(R.id.compose_divider);
    layoutTransition = new LayoutTransition();
    transitionListener = new TransitionListener(list);
    scrollToBottomButton = view.findViewById(R.id.scroll_to_bottom);
    scrollToMentionButton = view.findViewById(R.id.scroll_to_mention);
    scrollDateHeader = view.findViewById(R.id.scroll_date_header);
    toolbarShadow = requireActivity().findViewById(R.id.conversation_toolbar_shadow);
    reactionsShade = view.findViewById(R.id.reactions_shade);
    bottomActionBar = view.findViewById(R.id.conversation_bottom_action_bar);
    final LinearLayoutManager layoutManager = new SmoothScrollingLinearLayoutManager(getActivity(), true);
    final ConversationItemAnimator conversationItemAnimator = new ConversationItemAnimator(() -> {
        ConversationAdapter adapter = getListAdapter();
        if (adapter == null) {
            return false;
        } else {
            return Util.hasItems(adapter.getSelectedItems());
        }
    }, () -> conversationViewModel.shouldPlayMessageAnimations() && list.getScrollState() == RecyclerView.SCROLL_STATE_IDLE, () -> list.canScrollVertically(1) || list.canScrollVertically(-1));
    multiselectItemDecoration = new MultiselectItemDecoration(requireContext(), () -> conversationViewModel.getWallpaper().getValue());
    list.setHasFixedSize(false);
    list.setLayoutManager(layoutManager);
    RecyclerViewColorizer recyclerViewColorizer = new RecyclerViewColorizer(list);
    list.addItemDecoration(multiselectItemDecoration);
    list.setItemAnimator(conversationItemAnimator);
    getViewLifecycleOwner().getLifecycle().addObserver(multiselectItemDecoration);
    snapToTopDataObserver = new ConversationSnapToTopDataObserver(list, new ConversationScrollRequestValidator());
    conversationBanner = (ConversationBannerView) inflater.inflate(R.layout.conversation_item_banner, container, false);
    topLoadMoreView = (ViewSwitcher) inflater.inflate(R.layout.load_more_header, container, false);
    bottomLoadMoreView = (ViewSwitcher) inflater.inflate(R.layout.load_more_header, container, false);
    initializeLoadMoreView(topLoadMoreView);
    initializeLoadMoreView(bottomLoadMoreView);
    typingView = (ConversationTypingView) inflater.inflate(R.layout.conversation_typing_view, container, false);
    new ConversationItemSwipeCallback(conversationMessage -> actionMode == null && MenuState.canReplyToMessage(recipient.get(), MenuState.isActionMessage(conversationMessage.getMessageRecord()), conversationMessage.getMessageRecord(), messageRequestViewModel.shouldShowMessageRequest(), groupViewModel.isNonAdminInAnnouncementGroup()), this::handleReplyMessage).attachToRecyclerView(list);
    giphyMp4ProjectionRecycler = initializeGiphyMp4();
    this.groupViewModel = new ViewModelProvider(getParentFragment(), new ConversationGroupViewModel.Factory()).get(ConversationGroupViewModel.class);
    this.messageCountsViewModel = new ViewModelProvider(getParentFragment()).get(MessageCountsViewModel.class);
    this.conversationViewModel = new ViewModelProvider(getParentFragment(), new ConversationViewModel.Factory()).get(ConversationViewModel.class);
    conversationViewModel.getChatColors().observe(getViewLifecycleOwner(), recyclerViewColorizer::setChatColors);
    conversationViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> {
        ConversationAdapter adapter = getListAdapter();
        if (adapter != null) {
            getListAdapter().submitList(messages, () -> {
                list.post(() -> conversationViewModel.onMessagesCommitted(messages));
            });
        }
    });
    conversationViewModel.getConversationMetadata().observe(getViewLifecycleOwner(), this::presentConversationMetadata);
    conversationViewModel.getShowMentionsButton().observe(getViewLifecycleOwner(), shouldShow -> {
        if (shouldShow) {
            ViewUtil.animateIn(scrollToMentionButton, mentionButtonInAnimation);
        } else {
            ViewUtil.animateOut(scrollToMentionButton, mentionButtonOutAnimation, View.INVISIBLE);
        }
    });
    conversationViewModel.getShowScrollToBottom().observe(getViewLifecycleOwner(), shouldShow -> {
        if (shouldShow) {
            ViewUtil.animateIn(scrollToBottomButton, scrollButtonInAnimation);
        } else {
            ViewUtil.animateOut(scrollToBottomButton, scrollButtonOutAnimation, View.INVISIBLE);
        }
    });
    scrollToBottomButton.setOnClickListener(v -> scrollToBottom());
    scrollToMentionButton.setOnClickListener(v -> scrollToNextMention());
    updateToolbarDependentMargins();
    colorizer = new Colorizer();
    conversationViewModel.getNameColorsMap().observe(getViewLifecycleOwner(), nameColorsMap -> {
        colorizer.onNameColorsChanged(nameColorsMap);
        ConversationAdapter adapter = getListAdapter();
        if (adapter != null) {
            adapter.notifyItemRangeChanged(0, adapter.getItemCount(), ConversationAdapter.PAYLOAD_NAME_COLORS);
        }
    });
    conversationUpdateTick = new ConversationUpdateTick(this::updateConversationItemTimestamps);
    getViewLifecycleOwner().getLifecycle().addObserver(conversationUpdateTick);
    listener.getVoiceNoteMediaController().getVoiceNotePlayerViewState().observe(getViewLifecycleOwner(), state -> conversationViewModel.setInlinePlayerVisible(state.isPresent()));
    conversationViewModel.getConversationTopMargin().observe(getViewLifecycleOwner(), topMargin -> {
        lastSeenScrollOffset = topMargin;
        ViewUtil.setTopMargin(scrollDateHeader, topMargin + ViewUtil.dpToPx(8));
    });
    conversationViewModel.getActiveNotificationProfile().observe(getViewLifecycleOwner(), this::updateNotificationProfileStatus);
    initializeScrollButtonAnimations();
    initializeResources();
    initializeMessageRequestViewModel();
    initializeListAdapter();
    conversationViewModel.getSearchQuery().observe(getViewLifecycleOwner(), this::onSearchQueryUpdated);
    return view;
}
Also used : TypingStatusRepository(org.thoughtcrime.securesms.components.TypingStatusRepository) Bundle(android.os.Bundle) GroupMigrationMembershipChange(org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) GiphyMp4ItemDecoration(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ItemDecoration) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask) Manifest(android.Manifest) LayoutTransition(android.animation.LayoutTransition) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat) MultiselectForwardFragmentArgs(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragmentArgs) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) HtmlUtil(org.thoughtcrime.securesms.util.HtmlUtil) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) MultiDeviceViewOnceOpenJob(org.thoughtcrime.securesms.jobs.MultiDeviceViewOnceOpenJob) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) ViewCompat(androidx.core.view.ViewCompat) StickyHeaderViewHolder(org.thoughtcrime.securesms.conversation.ConversationAdapter.StickyHeaderViewHolder) MultiselectForwardFragment(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragment) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) DimensionUnit(org.signal.core.util.DimensionUnit) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) MessageRecordUtil(org.thoughtcrime.securesms.util.MessageRecordUtil) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StickyHeaderDecoration(org.thoughtcrime.securesms.util.StickyHeaderDecoration) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) ViewKt(androidx.core.view.ViewKt) Util(org.thoughtcrime.securesms.util.Util) ArrayList(java.util.ArrayList) MessageRequestState(org.thoughtcrime.securesms.messagerequests.MessageRequestState) SpannableStringBuilder(android.text.SpannableStringBuilder) SignalProxyUtil(org.thoughtcrime.securesms.util.SignalProxyUtil) Toast(android.widget.Toast) Menu(android.view.Menu) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) GiphyMp4ProjectionRecycler(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionRecycler) LiveData(androidx.lifecycle.LiveData) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) Collectors(com.annimon.stream.Collectors) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Contact(org.thoughtcrime.securesms.contactshare.Contact) RecipientBottomSheetDialogFragment(org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment) Permissions(org.thoughtcrime.securesms.permissions.Permissions) TextUtils(android.text.TextUtils) SafetyNumberChangeDialog(org.thoughtcrime.securesms.conversation.ui.error.SafetyNumberChangeDialog) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) ItemClickListener(org.thoughtcrime.securesms.conversation.ConversationAdapter.ItemClickListener) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) Configuration(android.content.res.Configuration) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) RecipientExporter(org.thoughtcrime.securesms.recipients.RecipientExporter) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) PhoneNumberFormatter(org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter) ValueAnimator(android.animation.ValueAnimator) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Rect(android.graphics.Rect) ConversationTypingView(org.thoughtcrime.securesms.components.ConversationTypingView) SignalBottomActionBar(org.thoughtcrime.securesms.components.menu.SignalBottomActionBar) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) GroupLinkInviteFriendsBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.invitesandrequests.invite.GroupLinkInviteFriendsBottomSheetDialogFragment) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Animator(android.animation.Animator) R(org.thoughtcrime.securesms.R) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) GiphyMp4ProjectionPlayerHolder(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionPlayerHolder) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Locale(java.util.Locale) View(android.view.View) ViewOnceUtil(org.thoughtcrime.securesms.revealable.ViewOnceUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Animation(android.view.animation.Animation) RecyclerView(androidx.recyclerview.widget.RecyclerView) VoiceNotePlaybackState(org.thoughtcrime.securesms.components.voice.VoiceNotePlaybackState) NavHostFragment(androidx.navigation.fragment.NavHostFragment) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) ViewSwitcher(android.widget.ViewSwitcher) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) AsyncTask(android.os.AsyncTask) ContactUtil(org.thoughtcrime.securesms.contactshare.ContactUtil) MessageRequestViewModel(org.thoughtcrime.securesms.messagerequests.MessageRequestViewModel) HtmlCompat(androidx.core.text.HtmlCompat) LongMessageFragment(org.thoughtcrime.securesms.longmessage.LongMessageFragment) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) ViewGroup(android.view.ViewGroup) VoiceNoteMediaControllerOwner(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) Slide(org.thoughtcrime.securesms.mms.Slide) ConversationItemAnimator(org.thoughtcrime.securesms.conversation.mutiselect.ConversationItemAnimator) GroupId(org.thoughtcrime.securesms.groups.GroupId) Toolbar(androidx.appcompat.widget.Toolbar) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) GiphyMp4PlaybackPolicy(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicy) OnScrollListener(androidx.recyclerview.widget.RecyclerView.OnScrollListener) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) Snackbar(com.google.android.material.snackbar.Snackbar) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) SharedContactDetailsActivity(org.thoughtcrime.securesms.contactshare.SharedContactDetailsActivity) TopToastPopup(org.thoughtcrime.securesms.util.TopToastPopup) MultiselectPart(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart) ReactionsBottomSheetDialogFragment(org.thoughtcrime.securesms.reactions.ReactionsBottomSheetDialogFragment) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) StickerPackPreviewActivity(org.thoughtcrime.securesms.stickers.StickerPackPreviewActivity) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) GroupsV1MigrationInfoBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationInfoBottomSheetDialogFragment) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) ConversationScrollToView(org.thoughtcrime.securesms.components.ConversationScrollToView) ViewOnceMessageActivity(org.thoughtcrime.securesms.revealable.ViewOnceMessageActivity) GiphyMp4PlaybackController(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackController) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) VerifyIdentityActivity(org.thoughtcrime.securesms.verify.VerifyIdentityActivity) MultiselectItemDecoration(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectItemDecoration) GroupDescriptionDialog(org.thoughtcrime.securesms.groups.ui.managegroup.dialogs.GroupDescriptionDialog) GroupDescriptionUtil(org.thoughtcrime.securesms.groups.v2.GroupDescriptionUtil) LayoutInflater(android.view.LayoutInflater) ActivityCompat(androidx.core.app.ActivityCompat) MessageDetailsFragment(org.thoughtcrime.securesms.messagedetails.MessageDetailsFragment) RemoteDeleteUtil(org.thoughtcrime.securesms.util.RemoteDeleteUtil) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) CachedInflater(org.thoughtcrime.securesms.util.CachedInflater) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) ActionMode(androidx.appcompat.view.ActionMode) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) Observer(androidx.lifecycle.Observer) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) Bitmap(android.graphics.Bitmap) EnableCallNotificationSettingsDialog(org.thoughtcrime.securesms.conversation.ui.error.EnableCallNotificationSettingsDialog) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) InputStream(java.io.InputStream) LayoutTransition(android.animation.LayoutTransition) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ConversationTypingView(org.thoughtcrime.securesms.components.ConversationTypingView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ConversationScrollToView(org.thoughtcrime.securesms.components.ConversationScrollToView) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) ConversationItemAnimator(org.thoughtcrime.securesms.conversation.mutiselect.ConversationItemAnimator) MultiselectItemDecoration(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectItemDecoration) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 3 with ActionMode

use of androidx.appcompat.view.ActionMode in project Signal-Android by signalapp.

the class ConversationListFragment method updateMultiSelectState.

private void updateMultiSelectState() {
    int count = viewModel.currentSelectedConversations().size();
    boolean hasUnread = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().isRead());
    boolean hasUnpinned = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().isPinned());
    boolean hasUnmuted = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().getRecipient().live().get().isMuted());
    boolean canPin = viewModel.getPinnedCount() < MAXIMUM_PINNED_CONVERSATIONS;
    if (actionMode != null) {
        actionMode.setTitle(requireContext().getResources().getQuantityString(R.plurals.ConversationListFragment_s_selected, count, count));
    }
    List<ActionItem> items = new ArrayList<>();
    Set<Long> selectionIds = viewModel.currentSelectedConversations().stream().map(conversation -> conversation.getThreadRecord().getThreadId()).collect(Collectors.toSet());
    if (hasUnread) {
        items.add(new ActionItem(R.drawable.ic_read_24, getResources().getQuantityString(R.plurals.ConversationListFragment_read_plural, count), () -> handleMarkAsRead(selectionIds)));
    } else {
        items.add(new ActionItem(R.drawable.ic_unread_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unread_plural, count), () -> handleMarkAsUnread(selectionIds)));
    }
    if (!isArchived() && hasUnpinned && canPin) {
        items.add(new ActionItem(R.drawable.ic_pin_24, getResources().getQuantityString(R.plurals.ConversationListFragment_pin_plural, count), () -> handlePin(viewModel.currentSelectedConversations())));
    } else if (!isArchived() && !hasUnpinned) {
        items.add(new ActionItem(R.drawable.ic_unpin_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unpin_plural, count), () -> handleUnpin(selectionIds)));
    }
    if (isArchived()) {
        items.add(new ActionItem(R.drawable.ic_unarchive_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unarchive_plural, count), () -> handleArchive(selectionIds, true)));
    } else {
        items.add(new ActionItem(R.drawable.ic_archive_24, getResources().getQuantityString(R.plurals.ConversationListFragment_archive_plural, count), () -> handleArchive(selectionIds, true)));
    }
    items.add(new ActionItem(R.drawable.ic_delete_24, getResources().getQuantityString(R.plurals.ConversationListFragment_delete_plural, count), () -> handleDelete(selectionIds)));
    if (hasUnmuted) {
        items.add(new ActionItem(R.drawable.ic_mute_24, getResources().getQuantityString(R.plurals.ConversationListFragment_mute_plural, count), () -> handleMute(viewModel.currentSelectedConversations())));
    } else {
        items.add(new ActionItem(R.drawable.ic_unmute_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unmute_plural, count), () -> handleUnmute(viewModel.currentSelectedConversations())));
    }
    items.add(new ActionItem(R.drawable.ic_select_24, getString(R.string.ConversationListFragment_select_all), viewModel::onSelectAllClick));
    bottomActionBar.setItems(items);
}
Also used : NewConversationActivity(org.thoughtcrime.securesms.NewConversationActivity) Bundle(android.os.Bundle) PulsingFloatingActionButton(org.thoughtcrime.securesms.components.registration.PulsingFloatingActionButton) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) NonNull(androidx.annotation.NonNull) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ColorInt(androidx.annotation.ColorInt) Manifest(android.Manifest) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) TooltipCompat(androidx.appcompat.widget.TooltipCompat) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) Fragment(androidx.fragment.app.Fragment) Badge(org.thoughtcrime.securesms.badges.models.Badge) Canvas(android.graphics.Canvas) SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Megaphone(org.thoughtcrime.securesms.megaphone.Megaphone) ContextCompat(androidx.core.content.ContextCompat) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) ViewCompat(androidx.core.view.ViewCompat) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) Megaphones(org.thoughtcrime.securesms.megaphone.Megaphones) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) DimensionUnit(org.signal.core.util.DimensionUnit) IdRes(androidx.annotation.IdRes) Nullable(androidx.annotation.Nullable) SignalContextMenu(org.thoughtcrime.securesms.components.menu.SignalContextMenu) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) InsightsLauncher(org.thoughtcrime.securesms.insights.InsightsLauncher) UnexpectedSubscriptionCancellation(org.thoughtcrime.securesms.components.settings.app.subscription.errors.UnexpectedSubscriptionCancellation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) UnreadPayments(org.thoughtcrime.securesms.conversationlist.model.UnreadPayments) StickyHeaderDecoration(org.thoughtcrime.securesms.util.StickyHeaderDecoration) DialogFragment(androidx.fragment.app.DialogFragment) ServiceOutageReminder(org.thoughtcrime.securesms.components.reminder.ServiceOutageReminder) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) CantProcessSubscriptionPaymentBottomSheetDialogFragment(org.thoughtcrime.securesms.badges.self.expired.CantProcessSubscriptionPaymentBottomSheetDialogFragment) WorkerThread(androidx.annotation.WorkerThread) PaymentDetailsParcelable(org.thoughtcrime.securesms.payments.preferences.details.PaymentDetailsParcelable) MainFragment(org.thoughtcrime.securesms.MainFragment) ArrayList(java.util.ArrayList) ActionMenuView(androidx.appcompat.widget.ActionMenuView) ReminderView(org.thoughtcrime.securesms.components.reminder.ReminderView) KeyCachingService(org.thoughtcrime.securesms.service.KeyCachingService) WebSocketConnectionState(org.whispersystems.signalservice.api.websocket.WebSocketConnectionState) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) SignalProxyUtil(org.thoughtcrime.securesms.util.SignalProxyUtil) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) RatingManager(org.thoughtcrime.securesms.components.RatingManager) AppStartup(org.thoughtcrime.securesms.util.AppStartup) LinkedHashSet(java.util.LinkedHashSet) MainNavigator(org.thoughtcrime.securesms.MainNavigator) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ProgressDialog(android.app.ProgressDialog) Permissions(org.thoughtcrime.securesms.permissions.Permissions) UnreadPaymentsView(org.thoughtcrime.securesms.components.UnreadPaymentsView) PushRegistrationReminder(org.thoughtcrime.securesms.components.reminder.PushRegistrationReminder) Optional(org.whispersystems.libsignal.util.guava.Optional) Reminder(org.thoughtcrime.securesms.components.reminder.Reminder) BottomSheetUtil(org.thoughtcrime.securesms.util.BottomSheetUtil) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) SnackbarAsyncTask(org.thoughtcrime.securesms.util.task.SnackbarAsyncTask) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalBottomActionBar(org.thoughtcrime.securesms.components.menu.SignalBottomActionBar) ArgbEvaluatorCompat(com.google.android.material.animation.ArgbEvaluatorCompat) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) NotificationProfileSelectionFragment(org.thoughtcrime.securesms.components.settings.app.notifications.manual.NotificationProfileSelectionFragment) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) PaymentDetailsFragmentArgs(org.thoughtcrime.securesms.payments.preferences.details.PaymentDetailsFragmentArgs) ConversationFragment(org.thoughtcrime.securesms.conversation.ConversationFragment) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) DrawableRes(androidx.annotation.DrawableRes) R(org.thoughtcrime.securesms.R) PlayStoreUtil(org.thoughtcrime.securesms.util.PlayStoreUtil) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) Locale(java.util.Locale) PluralsRes(androidx.annotation.PluralsRes) NotificationProfiles(org.thoughtcrime.securesms.notifications.profiles.NotificationProfiles) View(android.view.View) MegaphoneViewBuilder(org.thoughtcrime.securesms.megaphone.MegaphoneViewBuilder) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecyclerView(androidx.recyclerview.widget.RecyclerView) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) SearchToolbar(org.thoughtcrime.securesms.components.SearchToolbar) Conversation(org.thoughtcrime.securesms.conversationlist.model.Conversation) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) ExpiredBuildReminder(org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder) SearchResult(org.thoughtcrime.securesms.search.SearchResult) AsyncTask(android.os.AsyncTask) VoiceNotePlayerView(org.thoughtcrime.securesms.components.voice.VoiceNotePlayerView) Collection(java.util.Collection) UUID(java.util.UUID) ThreadMode(org.greenrobot.eventbus.ThreadMode) AvatarUtil(org.thoughtcrime.securesms.util.AvatarUtil) ExpiredBadgeBottomSheetDialogFragment(org.thoughtcrime.securesms.badges.self.expired.ExpiredBadgeBottomSheetDialogFragment) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) CreateKbsPinActivity(org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity) VoiceNoteMediaControllerOwner(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) MarkReadReceiver(org.thoughtcrime.securesms.notifications.MarkReadReceiver) MessageResult(org.thoughtcrime.securesms.search.MessageResult) Toolbar(androidx.appcompat.widget.Toolbar) Snackbar(com.google.android.material.snackbar.Snackbar) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) DozeReminder(org.thoughtcrime.securesms.components.reminder.DozeReminder) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) Context(android.content.Context) TopToastPopup(org.thoughtcrime.securesms.util.TopToastPopup) RESULT_OK(android.app.Activity.RESULT_OK) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) AppForegroundObserver(org.thoughtcrime.securesms.util.AppForegroundObserver) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) TooltipPopup(org.thoughtcrime.securesms.components.TooltipPopup) SuppressLint(android.annotation.SuppressLint) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) OutdatedBuildReminder(org.thoughtcrime.securesms.components.reminder.OutdatedBuildReminder) POSITION_BELOW(org.thoughtcrime.securesms.components.TooltipPopup.POSITION_BELOW) EventBus(org.greenrobot.eventbus.EventBus) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) MegaphoneActionController(org.thoughtcrime.securesms.megaphone.MegaphoneActionController) Stub(org.thoughtcrime.securesms.util.views.Stub) LayoutInflater(android.view.LayoutInflater) MediaSelectionActivity(org.thoughtcrime.securesms.mediasend.v2.MediaSelectionActivity) PaymentsActivity(org.thoughtcrime.securesms.payments.preferences.PaymentsActivity) ActionMode(androidx.appcompat.view.ActionMode) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) ServiceOutageDetectionJob(org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob) Subscribe(org.greenrobot.eventbus.Subscribe) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent) MuteDialog(org.thoughtcrime.securesms.MuteDialog) Activity(android.app.Activity) Collections(java.util.Collections) Resources(android.content.res.Resources) UnauthorizedReminder(org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint)

Example 4 with ActionMode

use of androidx.appcompat.view.ActionMode in project Signal-Android by signalapp.

the class ConversationFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    final View view = inflater.inflate(R.layout.conversation_fragment, container, false);
    videoContainer = view.findViewById(R.id.video_container);
    list = view.findViewById(android.R.id.list);
    composeDivider = view.findViewById(R.id.compose_divider);
    layoutTransition = new LayoutTransition();
    transitionListener = new TransitionListener(list);
    scrollToBottomButton = view.findViewById(R.id.scroll_to_bottom);
    scrollToMentionButton = view.findViewById(R.id.scroll_to_mention);
    scrollDateHeader = view.findViewById(R.id.scroll_date_header);
    toolbarShadow = requireActivity().findViewById(R.id.conversation_toolbar_shadow);
    reactionsShade = view.findViewById(R.id.reactions_shade);
    bottomActionBar = view.findViewById(R.id.conversation_bottom_action_bar);
    final LinearLayoutManager layoutManager = new SmoothScrollingLinearLayoutManager(getActivity(), true);
    final ConversationItemAnimator conversationItemAnimator = new ConversationItemAnimator(() -> {
        ConversationAdapter adapter = getListAdapter();
        if (adapter == null) {
            return false;
        } else {
            return Util.hasItems(adapter.getSelectedItems());
        }
    }, () -> conversationViewModel.shouldPlayMessageAnimations() && list.getScrollState() == RecyclerView.SCROLL_STATE_IDLE, () -> list.canScrollVertically(1) || list.canScrollVertically(-1));
    multiselectItemDecoration = new MultiselectItemDecoration(requireContext(), () -> conversationViewModel.getWallpaper().getValue());
    list.setHasFixedSize(false);
    list.setLayoutManager(layoutManager);
    RecyclerViewColorizer recyclerViewColorizer = new RecyclerViewColorizer(list);
    list.addItemDecoration(multiselectItemDecoration);
    list.setItemAnimator(conversationItemAnimator);
    getViewLifecycleOwner().getLifecycle().addObserver(multiselectItemDecoration);
    snapToTopDataObserver = new ConversationSnapToTopDataObserver(list, new ConversationScrollRequestValidator());
    conversationBanner = (ConversationBannerView) inflater.inflate(R.layout.conversation_item_banner, container, false);
    topLoadMoreView = (ViewSwitcher) inflater.inflate(R.layout.load_more_header, container, false);
    bottomLoadMoreView = (ViewSwitcher) inflater.inflate(R.layout.load_more_header, container, false);
    initializeLoadMoreView(topLoadMoreView);
    initializeLoadMoreView(bottomLoadMoreView);
    typingView = (ConversationTypingView) inflater.inflate(R.layout.conversation_typing_view, container, false);
    new ConversationItemSwipeCallback(conversationMessage -> actionMode == null && MenuState.canReplyToMessage(recipient.get(), MenuState.isActionMessage(conversationMessage.getMessageRecord()), conversationMessage.getMessageRecord(), messageRequestViewModel.shouldShowMessageRequest(), groupViewModel.isNonAdminInAnnouncementGroup()), this::handleReplyMessage).attachToRecyclerView(list);
    giphyMp4ProjectionRecycler = initializeGiphyMp4();
    this.groupViewModel = new ViewModelProvider(getParentFragment(), new ConversationGroupViewModel.Factory()).get(ConversationGroupViewModel.class);
    this.messageCountsViewModel = new ViewModelProvider(getParentFragment()).get(MessageCountsViewModel.class);
    this.conversationViewModel = new ViewModelProvider(getParentFragment(), new ConversationViewModel.Factory()).get(ConversationViewModel.class);
    conversationViewModel.getChatColors().observe(getViewLifecycleOwner(), recyclerViewColorizer::setChatColors);
    conversationViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> {
        ConversationAdapter adapter = getListAdapter();
        if (adapter != null) {
            getListAdapter().submitList(messages, () -> {
                list.post(() -> conversationViewModel.onMessagesCommitted(messages));
            });
        }
    });
    conversationViewModel.getConversationMetadata().observe(getViewLifecycleOwner(), this::presentConversationMetadata);
    conversationViewModel.getShowMentionsButton().observe(getViewLifecycleOwner(), shouldShow -> {
        if (shouldShow) {
            ViewUtil.animateIn(scrollToMentionButton, mentionButtonInAnimation);
        } else {
            ViewUtil.animateOut(scrollToMentionButton, mentionButtonOutAnimation, View.INVISIBLE);
        }
    });
    conversationViewModel.getShowScrollToBottom().observe(getViewLifecycleOwner(), shouldShow -> {
        if (shouldShow) {
            ViewUtil.animateIn(scrollToBottomButton, scrollButtonInAnimation);
        } else {
            ViewUtil.animateOut(scrollToBottomButton, scrollButtonOutAnimation, View.INVISIBLE);
        }
    });
    scrollToBottomButton.setOnClickListener(v -> scrollToBottom());
    scrollToMentionButton.setOnClickListener(v -> scrollToNextMention());
    updateToolbarDependentMargins();
    colorizer = new Colorizer();
    conversationViewModel.getNameColorsMap().observe(getViewLifecycleOwner(), nameColorsMap -> {
        colorizer.onNameColorsChanged(nameColorsMap);
        ConversationAdapter adapter = getListAdapter();
        if (adapter != null) {
            adapter.notifyItemRangeChanged(0, adapter.getItemCount(), ConversationAdapter.PAYLOAD_NAME_COLORS);
        }
    });
    conversationUpdateTick = new ConversationUpdateTick(this::updateConversationItemTimestamps);
    getViewLifecycleOwner().getLifecycle().addObserver(conversationUpdateTick);
    listener.getVoiceNoteMediaController().getVoiceNotePlayerViewState().observe(getViewLifecycleOwner(), state -> conversationViewModel.setInlinePlayerVisible(state.isPresent()));
    conversationViewModel.getConversationTopMargin().observe(getViewLifecycleOwner(), topMargin -> {
        lastSeenScrollOffset = topMargin;
        ViewUtil.setTopMargin(scrollDateHeader, topMargin + ViewUtil.dpToPx(8));
    });
    conversationViewModel.getActiveNotificationProfile().observe(getViewLifecycleOwner(), this::updateNotificationProfileStatus);
    initializeScrollButtonAnimations();
    initializeResources();
    initializeMessageRequestViewModel();
    initializeListAdapter();
    conversationViewModel.getSearchQuery().observe(getViewLifecycleOwner(), this::onSearchQueryUpdated);
    return view;
}
Also used : TypingStatusRepository(org.thoughtcrime.securesms.components.TypingStatusRepository) Bundle(android.os.Bundle) GroupMigrationMembershipChange(org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) GiphyMp4ItemDecoration(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ItemDecoration) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask) Manifest(android.Manifest) LayoutTransition(android.animation.LayoutTransition) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat) MultiselectForwardFragmentArgs(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragmentArgs) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) HtmlUtil(org.thoughtcrime.securesms.util.HtmlUtil) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) MultiDeviceViewOnceOpenJob(org.thoughtcrime.securesms.jobs.MultiDeviceViewOnceOpenJob) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) ViewCompat(androidx.core.view.ViewCompat) StickyHeaderViewHolder(org.thoughtcrime.securesms.conversation.ConversationAdapter.StickyHeaderViewHolder) MultiselectForwardFragment(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragment) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) DimensionUnit(org.signal.core.util.DimensionUnit) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) MessageRecordUtil(org.thoughtcrime.securesms.util.MessageRecordUtil) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StickyHeaderDecoration(org.thoughtcrime.securesms.util.StickyHeaderDecoration) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) ViewKt(androidx.core.view.ViewKt) Util(org.thoughtcrime.securesms.util.Util) ArrayList(java.util.ArrayList) MessageRequestState(org.thoughtcrime.securesms.messagerequests.MessageRequestState) SpannableStringBuilder(android.text.SpannableStringBuilder) SignalProxyUtil(org.thoughtcrime.securesms.util.SignalProxyUtil) Toast(android.widget.Toast) Menu(android.view.Menu) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) GiphyMp4ProjectionRecycler(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionRecycler) LiveData(androidx.lifecycle.LiveData) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) Collectors(com.annimon.stream.Collectors) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Contact(org.thoughtcrime.securesms.contactshare.Contact) RecipientBottomSheetDialogFragment(org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment) Permissions(org.thoughtcrime.securesms.permissions.Permissions) TextUtils(android.text.TextUtils) SafetyNumberChangeDialog(org.thoughtcrime.securesms.conversation.ui.error.SafetyNumberChangeDialog) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) ItemClickListener(org.thoughtcrime.securesms.conversation.ConversationAdapter.ItemClickListener) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) Configuration(android.content.res.Configuration) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) RecipientExporter(org.thoughtcrime.securesms.recipients.RecipientExporter) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) PhoneNumberFormatter(org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter) ValueAnimator(android.animation.ValueAnimator) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Rect(android.graphics.Rect) ConversationTypingView(org.thoughtcrime.securesms.components.ConversationTypingView) SignalBottomActionBar(org.thoughtcrime.securesms.components.menu.SignalBottomActionBar) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) GroupLinkInviteFriendsBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.invitesandrequests.invite.GroupLinkInviteFriendsBottomSheetDialogFragment) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Animator(android.animation.Animator) R(org.thoughtcrime.securesms.R) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) GiphyMp4ProjectionPlayerHolder(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionPlayerHolder) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Locale(java.util.Locale) View(android.view.View) ViewOnceUtil(org.thoughtcrime.securesms.revealable.ViewOnceUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Animation(android.view.animation.Animation) RecyclerView(androidx.recyclerview.widget.RecyclerView) VoiceNotePlaybackState(org.thoughtcrime.securesms.components.voice.VoiceNotePlaybackState) NavHostFragment(androidx.navigation.fragment.NavHostFragment) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) ViewSwitcher(android.widget.ViewSwitcher) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) AsyncTask(android.os.AsyncTask) ContactUtil(org.thoughtcrime.securesms.contactshare.ContactUtil) MessageRequestViewModel(org.thoughtcrime.securesms.messagerequests.MessageRequestViewModel) HtmlCompat(androidx.core.text.HtmlCompat) LongMessageFragment(org.thoughtcrime.securesms.longmessage.LongMessageFragment) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) ViewGroup(android.view.ViewGroup) VoiceNoteMediaControllerOwner(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) Slide(org.thoughtcrime.securesms.mms.Slide) ConversationItemAnimator(org.thoughtcrime.securesms.conversation.mutiselect.ConversationItemAnimator) GroupId(org.thoughtcrime.securesms.groups.GroupId) Toolbar(androidx.appcompat.widget.Toolbar) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) GiphyMp4PlaybackPolicy(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicy) OnScrollListener(androidx.recyclerview.widget.RecyclerView.OnScrollListener) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) Snackbar(com.google.android.material.snackbar.Snackbar) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) SharedContactDetailsActivity(org.thoughtcrime.securesms.contactshare.SharedContactDetailsActivity) TopToastPopup(org.thoughtcrime.securesms.util.TopToastPopup) MultiselectPart(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart) ReactionsBottomSheetDialogFragment(org.thoughtcrime.securesms.reactions.ReactionsBottomSheetDialogFragment) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) StickerPackPreviewActivity(org.thoughtcrime.securesms.stickers.StickerPackPreviewActivity) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) GroupsV1MigrationInfoBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationInfoBottomSheetDialogFragment) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) ConversationScrollToView(org.thoughtcrime.securesms.components.ConversationScrollToView) ViewOnceMessageActivity(org.thoughtcrime.securesms.revealable.ViewOnceMessageActivity) GiphyMp4PlaybackController(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackController) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) VerifyIdentityActivity(org.thoughtcrime.securesms.verify.VerifyIdentityActivity) MultiselectItemDecoration(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectItemDecoration) GroupDescriptionDialog(org.thoughtcrime.securesms.groups.ui.managegroup.dialogs.GroupDescriptionDialog) GroupDescriptionUtil(org.thoughtcrime.securesms.groups.v2.GroupDescriptionUtil) LayoutInflater(android.view.LayoutInflater) ActivityCompat(androidx.core.app.ActivityCompat) MessageDetailsFragment(org.thoughtcrime.securesms.messagedetails.MessageDetailsFragment) RemoteDeleteUtil(org.thoughtcrime.securesms.util.RemoteDeleteUtil) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) CachedInflater(org.thoughtcrime.securesms.util.CachedInflater) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) ActionMode(androidx.appcompat.view.ActionMode) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) Observer(androidx.lifecycle.Observer) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) Bitmap(android.graphics.Bitmap) EnableCallNotificationSettingsDialog(org.thoughtcrime.securesms.conversation.ui.error.EnableCallNotificationSettingsDialog) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) InputStream(java.io.InputStream) LayoutTransition(android.animation.LayoutTransition) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ConversationTypingView(org.thoughtcrime.securesms.components.ConversationTypingView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ConversationScrollToView(org.thoughtcrime.securesms.components.ConversationScrollToView) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) ConversationItemAnimator(org.thoughtcrime.securesms.conversation.mutiselect.ConversationItemAnimator) MultiselectItemDecoration(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectItemDecoration) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

Manifest (android.Manifest)4 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 Intent (android.content.Intent)4 Color (android.graphics.Color)4 Uri (android.net.Uri)4 AsyncTask (android.os.AsyncTask)4 Bundle (android.os.Bundle)4 LayoutInflater (android.view.LayoutInflater)4 Menu (android.view.Menu)4 MenuItem (android.view.MenuItem)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 FrameLayout (android.widget.FrameLayout)4 TextView (android.widget.TextView)4 Toast (android.widget.Toast)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)4 ActionMode (androidx.appcompat.view.ActionMode)4