From d3daaff6a4ef71212ac58395ea878295b8a2a04e Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 4 Apr 2023 14:39:11 -0300 Subject: [PATCH] Update collapsed toolbar state for group calling. --- .../securesms/WebRtcCallActivity.java | 15 +- .../components/webrtc/WebRtcCallView.java | 133 ++++++++++-------- app/src/main/res/layout/webrtc_call_view.xml | 54 +++---- .../layout/webrtc_call_view_header_small.xml | 72 ---------- app/src/main/res/menu/webrtc_toolbar_menu.xml | 9 ++ 5 files changed, 115 insertions(+), 168 deletions(-) delete mode 100644 app/src/main/res/layout/webrtc_call_view_header_small.xml create mode 100644 app/src/main/res/menu/webrtc_toolbar_menu.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java index b5456bf843..5ac777bed8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -851,11 +851,6 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan } } - @Override - public void onShowParticipantsList() { - CallParticipantsListDialog.show(getSupportFragmentManager()); - } - @Override public void onPageChanged(@NonNull CallParticipantsState.SelectedPage page) { viewModel.setIsViewingFocusedParticipant(page); @@ -877,6 +872,16 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan callStateUpdatePopupWindow.onCallStateUpdate(CallStateUpdatePopupWindow.CallStateUpdate.RINGING_DISABLED); } } + + @Override + public void onCallInfoClicked() { + CallParticipantsListDialog.show(getSupportFragmentManager()); + } + + @Override + public void onNavigateUpClicked() { + onBackPressed(); + } } private class WindowLayoutInfoConsumer implements Consumer { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java index 2b203f2f27..6ab156438b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java @@ -18,7 +18,9 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; +import androidx.annotation.StringRes; import androidx.appcompat.content.res.AppCompatResources; +import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; import androidx.constraintlayout.widget.Guideline; @@ -105,7 +107,7 @@ public class WebRtcCallView extends ConstraintLayout { private View startCallControls; private ViewPager2 callParticipantsPager; private RecyclerView callParticipantsRecycler; - private ConstraintLayout toolbar; + private ConstraintLayout largeHeader; private MaterialButton startCall; private Stub groupCallSpeakerHint; private Stub groupCallFullStub; @@ -115,15 +117,13 @@ public class WebRtcCallView extends ConstraintLayout { private Guideline showParticipantsGuideline; private Guideline topFoldGuideline; private Guideline callScreenTopFoldGuideline; - private View foldParticipantCountWrapper; - private TextView foldParticipantCount; private AvatarImageView largeHeaderAvatar; - private ConstraintSet largeHeaderConstraints; - private ConstraintSet smallHeaderConstraints; private Guideline statusBarGuideline; private Guideline navigationBarGuideline; private int navBarBottomInset; private View fullScreenShade; + private Toolbar collapsedToolbar; + private Toolbar headerToolbar; private WebRtcCallParticipantsPagerAdapter pagerAdapter; private WebRtcCallParticipantsRecyclerAdapter recyclerAdapter; @@ -185,21 +185,21 @@ public class WebRtcCallView extends ConstraintLayout { footerGradient = findViewById(R.id.call_screen_footer_gradient); startCallControls = findViewById(R.id.call_screen_start_call_controls); callParticipantsPager = findViewById(R.id.call_screen_participants_pager); - callParticipantsRecycler = findViewById(R.id.call_screen_participants_recycler); - toolbar = findViewById(R.id.call_screen_header); - startCall = findViewById(R.id.call_screen_start_call_start_call); + callParticipantsRecycler = findViewById(R.id.call_screen_participants_recycler); + largeHeader = findViewById(R.id.call_screen_header); + startCall = findViewById(R.id.call_screen_start_call_start_call); errorButton = findViewById(R.id.call_screen_error_cancel); groupCallSpeakerHint = new Stub<>(findViewById(R.id.call_screen_group_call_speaker_hint)); groupCallFullStub = new Stub<>(findViewById(R.id.group_call_call_full_view)); showParticipantsGuideline = findViewById(R.id.call_screen_show_participants_guideline); topFoldGuideline = findViewById(R.id.fold_top_guideline); callScreenTopFoldGuideline = findViewById(R.id.fold_top_call_screen_guideline); - foldParticipantCountWrapper = findViewById(R.id.fold_show_participants_menu_counter_wrapper); - foldParticipantCount = findViewById(R.id.fold_show_participants_menu_counter); largeHeaderAvatar = findViewById(R.id.call_screen_header_avatar); statusBarGuideline = findViewById(R.id.call_screen_status_bar_guideline); navigationBarGuideline = findViewById(R.id.call_screen_navigation_bar_guideline); fullScreenShade = findViewById(R.id.call_screen_full_shade); + collapsedToolbar = findViewById(R.id.webrtc_call_view_toolbar_text); + headerToolbar = findViewById(R.id.webrtc_call_view_toolbar_no_text); View decline = findViewById(R.id.call_screen_decline_call); View answerLabel = findViewById(R.id.call_screen_answer_call_label); @@ -224,7 +224,7 @@ public class WebRtcCallView extends ConstraintLayout { } }); - topViews.add(toolbar); + topViews.add(largeHeader); topViews.add(topGradient); incomingCallViews.add(answer); @@ -302,6 +302,36 @@ public class WebRtcCallView extends ConstraintLayout { } }); + collapsedToolbar.setNavigationOnClickListener(unused -> { + if (controlsListener != null) { + controlsListener.onNavigateUpClicked(); + } + }); + + collapsedToolbar.setOnMenuItemClickListener(item -> { + if (item.getItemId() == R.id.action_info && controlsListener != null) { + controlsListener.onCallInfoClicked(); + return true; + } + + return false; + }); + + headerToolbar.setNavigationOnClickListener(unused -> { + if (controlsListener != null) { + controlsListener.onNavigateUpClicked(); + } + }); + + headerToolbar.setOnMenuItemClickListener(item -> { + if (item.getItemId() == R.id.action_info && controlsListener != null) { + controlsListener.onCallInfoClicked(); + return true; + } + + return false; + }); + rotatableControls.add(hangup); rotatableControls.add(answer); rotatableControls.add(answerWithoutVideo); @@ -312,12 +342,6 @@ public class WebRtcCallView extends ConstraintLayout { rotatableControls.add(decline); rotatableControls.add(smallLocalAudioIndicator); rotatableControls.add(ringToggle); - - largeHeaderConstraints = new ConstraintSet(); - largeHeaderConstraints.clone(getContext(), R.layout.webrtc_call_view_header_large); - - smallHeaderConstraints = new ConstraintSet(); - smallHeaderConstraints.clone(getContext(), R.layout.webrtc_call_view_header_small); } @Override @@ -357,9 +381,9 @@ public class WebRtcCallView extends ConstraintLayout { if ((visible & SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { if (controls.adjustForFold()) { pictureInPictureGestureHelper.clearVerticalBoundaries(); - pictureInPictureGestureHelper.setTopVerticalBoundary(toolbar.getTop()); + pictureInPictureGestureHelper.setTopVerticalBoundary(largeHeader.getTop()); } else { - pictureInPictureGestureHelper.setTopVerticalBoundary(toolbar.getBottom()); + pictureInPictureGestureHelper.setTopVerticalBoundary(largeHeader.getBottom()); pictureInPictureGestureHelper.setBottomVerticalBoundary(videoToggle.getTop()); } } else { @@ -407,21 +431,21 @@ public class WebRtcCallView extends ConstraintLayout { if (state.getGroupCallState().isNotIdle()) { if (state.getCallState() == WebRtcViewModel.State.CALL_PRE_JOIN) { - status.setText(state.getPreJoinGroupDescription(getContext())); + setStatus(state.getPreJoinGroupDescription(getContext())); } else if (state.getCallState() == WebRtcViewModel.State.CALL_CONNECTED && state.isInOutgoingRingingMode()) { - status.setText(state.getOutgoingRingingGroupDescription(getContext())); + setStatus(state.getOutgoingRingingGroupDescription(getContext())); } else if (state.getGroupCallState().isRinging()) { - status.setText(state.getIncomingRingingGroupDescription(getContext())); + setStatus(state.getIncomingRingingGroupDescription(getContext())); } } if (state.getGroupCallState().isNotIdle()) { - String text = state.getParticipantCount() - .mapToObj(String::valueOf).orElse("\u2014"); boolean enabled = state.getParticipantCount().isPresent(); - - foldParticipantCount.setText(text); - foldParticipantCount.setEnabled(enabled); + collapsedToolbar.getMenu().getItem(0).setVisible(enabled); + headerToolbar.getMenu().getItem(0).setVisible(enabled); + } else { + collapsedToolbar.getMenu().getItem(0).setVisible(false); + headerToolbar.getMenu().getItem(0).setVisible(false); } pagerAdapter.submitList(pages); @@ -527,34 +551,34 @@ public class WebRtcCallView extends ConstraintLayout { } recipientId = recipient.getId(); - largeHeaderAvatar.setRecipient(recipient, false); - - if (recipient.isGroup()) { - foldParticipantCountWrapper.setOnClickListener(unused -> showParticipantsList()); - } - + collapsedToolbar.setTitle(recipient.getDisplayName(getContext())); recipientName.setText(recipient.getDisplayName(getContext())); } - public void setStatus(@NonNull String status) { + public void setStatus(@Nullable String status) { this.status.setText(status); + collapsedToolbar.setSubtitle(status); + } + + private void setStatus(@StringRes int statusRes) { + setStatus(getContext().getString(statusRes)); } public void setStatusFromHangupType(@NonNull HangupMessage.Type hangupType) { switch (hangupType) { case NORMAL: case NEED_PERMISSION: - status.setText(R.string.RedPhone_ending_call); + setStatus(R.string.RedPhone_ending_call); break; case ACCEPTED: - status.setText(R.string.WebRtcCallActivity__answered_on_a_linked_device); + setStatus(R.string.WebRtcCallActivity__answered_on_a_linked_device); break; case DECLINED: - status.setText(R.string.WebRtcCallActivity__declined_on_a_linked_device); + setStatus(R.string.WebRtcCallActivity__declined_on_a_linked_device); break; case BUSY: - status.setText(R.string.WebRtcCallActivity__busy_on_a_linked_device); + setStatus(R.string.WebRtcCallActivity__busy_on_a_linked_device); break; default: throw new IllegalStateException("Unknown hangup type: " + hangupType); @@ -564,18 +588,18 @@ public class WebRtcCallView extends ConstraintLayout { public void setStatusFromGroupCallState(@NonNull WebRtcViewModel.GroupCallState groupCallState) { switch (groupCallState) { case DISCONNECTED: - status.setText(R.string.WebRtcCallView__disconnected); + setStatus(R.string.WebRtcCallView__disconnected); break; case RECONNECTING: - status.setText(R.string.WebRtcCallView__reconnecting); + setStatus(R.string.WebRtcCallView__reconnecting); break; case CONNECTED_AND_JOINING: - status.setText(R.string.WebRtcCallView__joining); + setStatus(R.string.WebRtcCallView__joining); break; case CONNECTING: case CONNECTED_AND_JOINED: case CONNECTED: - status.setText(""); + setStatus(""); break; } } @@ -597,11 +621,6 @@ public class WebRtcCallView extends ConstraintLayout { callScreenTopFoldGuideline.setGuidelineEnd(0); } - if (webRtcControls.displayGroupMembersButton()) { - visibleViewSet.add(foldParticipantCountWrapper); - foldParticipantCount.setClickable(webRtcControls.adjustForFold()); - } - if (webRtcControls.displayStartCallControls()) { visibleViewSet.add(footerGradient); visibleViewSet.add(startCallControls); @@ -855,7 +874,7 @@ public class WebRtcCallView extends ConstraintLayout { } private void toggleControls() { - if (controls.isFadeOutEnabled() && toolbar.getVisibility() == VISIBLE) { + if (controls.isFadeOutEnabled() && largeHeader.getVisibility() == VISIBLE) { fadeOutControls(); } else { fadeInControls(); @@ -978,11 +997,13 @@ public class WebRtcCallView extends ConstraintLayout { constraintSet.applyTo(parent); if (showSmallHeader) { - smallHeaderConstraints.setVisibility(incomingRingStatus.getId(), visibleViewSet.contains(incomingRingStatus) ? View.VISIBLE : View.GONE); - smallHeaderConstraints.applyTo(toolbar); + collapsedToolbar.setVisibility(View.VISIBLE); + headerToolbar.setVisibility(View.GONE); + largeHeader.setVisibility(View.GONE); } else { - largeHeaderConstraints.setVisibility(incomingRingStatus.getId(), visibleViewSet.contains(incomingRingStatus) ? View.VISIBLE : View.GONE); - largeHeaderConstraints.applyTo(toolbar); + collapsedToolbar.setVisibility(View.GONE); + headerToolbar.setVisibility(View.VISIBLE); + largeHeader.setVisibility(View.VISIBLE); } } @@ -1032,11 +1053,6 @@ public class WebRtcCallView extends ConstraintLayout { ringToggle.setBackgroundResource(R.drawable.webrtc_call_screen_ring_toggle_small); } - private boolean showParticipantsList() { - controlsListener.onShowParticipantsList(); - return true; - } - public void switchToSpeakerView() { if (pagerAdapter.getItemCount() > 0) { callParticipantsPager.setCurrentItem(pagerAdapter.getItemCount() - 1, false); @@ -1067,9 +1083,10 @@ public class WebRtcCallView extends ConstraintLayout { void onDenyCallPressed(); void onAcceptCallWithVoiceOnlyPressed(); void onAcceptCallPressed(); - void onShowParticipantsList(); void onPageChanged(@NonNull CallParticipantsState.SelectedPage page); void onLocalPictureInPictureClicked(); void onRingGroupChanged(boolean ringGroup, boolean ringingAllowed); + void onCallInfoClicked(); + void onNavigateUpClicked(); } } diff --git a/app/src/main/res/layout/webrtc_call_view.xml b/app/src/main/res/layout/webrtc_call_view.xml index e5813b3d6e..a7ee0a9042 100644 --- a/app/src/main/res/layout/webrtc_call_view.xml +++ b/app/src/main/res/layout/webrtc_call_view.xml @@ -200,6 +200,27 @@ + + + + - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/webrtc_toolbar_menu.xml b/app/src/main/res/menu/webrtc_toolbar_menu.xml new file mode 100644 index 0000000000..68ccca8e33 --- /dev/null +++ b/app/src/main/res/menu/webrtc_toolbar_menu.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file