Search in sources :

Example 1 with GroupActiveState

use of org.thoughtcrime.securesms.conversation.ConversationGroupViewModel.GroupActiveState in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    GroupActiveState groupActiveState = groupViewModel.getGroupActiveState().getValue();
    boolean isActiveGroup = groupActiveState != null && groupActiveState.isActiveGroup();
    boolean isActiveV2Group = groupActiveState != null && groupActiveState.isActiveV2Group();
    boolean isInActiveGroup = groupActiveState != null && !groupActiveState.isActiveGroup();
    if (isInMessageRequest() && recipient != null && !recipient.get().isBlocked()) {
        if (isActiveGroup) {
            inflater.inflate(R.menu.conversation_message_requests_group, menu);
        }
        super.onCreateOptionsMenu(menu, inflater);
    }
    if (isSecureText) {
        if (recipient.get().getExpiresInSeconds() > 0) {
            if (!isInActiveGroup) {
                inflater.inflate(R.menu.conversation_expiring_on, menu);
            }
            titleView.showExpiring(recipient);
        } else {
            if (!isInActiveGroup) {
                inflater.inflate(R.menu.conversation_expiring_off, menu);
            }
            titleView.clearExpiring();
        }
    }
    if (isSingleConversation()) {
        if (isSecureText)
            inflater.inflate(R.menu.conversation_callable_secure, menu);
        else if (!recipient.get().isReleaseNotes())
            inflater.inflate(R.menu.conversation_callable_insecure, menu);
    } else if (isGroupConversation()) {
        if (isActiveV2Group && Build.VERSION.SDK_INT > 19) {
            inflater.inflate(R.menu.conversation_callable_groupv2, menu);
            if (groupCallViewModel != null && Boolean.TRUE.equals(groupCallViewModel.hasActiveGroupCall().getValue())) {
                hideMenuItem(menu, R.id.menu_video_secure);
            }
            showGroupCallingTooltip();
        }
        inflater.inflate(R.menu.conversation_group_options, menu);
        if (!isPushGroupConversation()) {
            inflater.inflate(R.menu.conversation_mms_group_options, menu);
            if (distributionType == ThreadDatabase.DistributionTypes.BROADCAST) {
                menu.findItem(R.id.menu_distribution_broadcast).setChecked(true);
            } else {
                menu.findItem(R.id.menu_distribution_conversation).setChecked(true);
            }
        }
        inflater.inflate(R.menu.conversation_active_group_options, menu);
    }
    inflater.inflate(R.menu.conversation, menu);
    if (isSingleConversation() && !isSecureText && !recipient.get().isReleaseNotes()) {
        inflater.inflate(R.menu.conversation_insecure, menu);
    }
    if (recipient != null && recipient.get().isMuted())
        inflater.inflate(R.menu.conversation_muted, menu);
    else
        inflater.inflate(R.menu.conversation_unmuted, menu);
    if (isSingleConversation() && getRecipient().getContactUri() == null && !recipient.get().isReleaseNotes()) {
        inflater.inflate(R.menu.conversation_add_to_contacts, menu);
    }
    if (recipient != null && recipient.get().isSelf()) {
        if (isSecureText) {
            hideMenuItem(menu, R.id.menu_call_secure);
            hideMenuItem(menu, R.id.menu_video_secure);
        } else {
            hideMenuItem(menu, R.id.menu_call_insecure);
        }
        hideMenuItem(menu, R.id.menu_mute_notifications);
    }
    if (recipient != null && recipient.get().isBlocked()) {
        if (isSecureText) {
            hideMenuItem(menu, R.id.menu_call_secure);
            hideMenuItem(menu, R.id.menu_video_secure);
            hideMenuItem(menu, R.id.menu_expiring_messages);
            hideMenuItem(menu, R.id.menu_expiring_messages_off);
        } else {
            hideMenuItem(menu, R.id.menu_call_insecure);
        }
        hideMenuItem(menu, R.id.menu_mute_notifications);
    }
    if (recipient != null && recipient.get().isReleaseNotes()) {
        hideMenuItem(menu, R.id.menu_add_shortcut);
    }
    hideMenuItem(menu, R.id.menu_group_recipients);
    if (isActiveV2Group) {
        hideMenuItem(menu, R.id.menu_mute_notifications);
        hideMenuItem(menu, R.id.menu_conversation_settings);
    } else if (isGroupConversation()) {
        hideMenuItem(menu, R.id.menu_conversation_settings);
    }
    hideMenuItem(menu, R.id.menu_create_bubble);
    viewModel.canShowAsBubble().observe(getViewLifecycleOwner(), canShowAsBubble -> {
        MenuItem item = menu.findItem(R.id.menu_create_bubble);
        if (item != null) {
            item.setVisible(canShowAsBubble && !isInBubble());
        }
    });
    if (threadId == -1L) {
        hideMenuItem(menu, R.id.menu_view_media);
    }
    searchViewItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchViewItem.getActionView();
    SearchView.OnQueryTextListener queryListener = new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            searchViewModel.onQueryUpdated(query, threadId, true);
            searchNav.showLoading();
            viewModel.setSearchQuery(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            searchViewModel.onQueryUpdated(query, threadId, false);
            searchNav.showLoading();
            viewModel.setSearchQuery(query);
            return true;
        }
    };
    searchViewItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            searchView.setOnQueryTextListener(queryListener);
            searchViewModel.onSearchOpened();
            searchNav.setVisibility(View.VISIBLE);
            searchNav.setData(0, 0);
            inputPanel.setHideForSearch(true);
            for (int i = 0; i < menu.size(); i++) {
                if (!menu.getItem(i).equals(searchViewItem)) {
                    menu.getItem(i).setVisible(false);
                }
            }
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            searchView.setOnQueryTextListener(null);
            isSearchRequested = false;
            searchViewModel.onSearchClosed();
            searchNav.setVisibility(View.GONE);
            inputPanel.setHideForSearch(false);
            viewModel.setSearchQuery(null);
            setBlockedUserState(recipient.get(), isSecureText, isDefaultSms);
            invalidateOptionsMenu();
            return true;
        }
    });
    if (isSearchRequested) {
        if (searchViewItem.expandActionView()) {
            searchViewModel.onSearchOpened();
        }
    }
    super.onCreateOptionsMenu(menu, inflater);
}
Also used : SearchView(androidx.appcompat.widget.SearchView) GroupActiveState(org.thoughtcrime.securesms.conversation.ConversationGroupViewModel.GroupActiveState) MenuItem(android.view.MenuItem) SpannableString(android.text.SpannableString)

Aggregations

SpannableString (android.text.SpannableString)1 MenuItem (android.view.MenuItem)1 SearchView (androidx.appcompat.widget.SearchView)1 GroupActiveState (org.thoughtcrime.securesms.conversation.ConversationGroupViewModel.GroupActiveState)1