diff --git a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java index 0ad79e30b..566acb646 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -245,6 +245,7 @@ public class WebRtcCallActivity extends AppCompatActivity implements SafetyNumbe viewModel.getCallParticipantListUpdate().observe(this, participantUpdateWindow::addCallParticipantListUpdate); viewModel.getSafetyNumberChangeEvent().observe(this, this::handleSafetyNumberChangeEvent); viewModel.getGroupMembers().observe(this, unused -> updateGroupMembersForGroupCall()); + viewModel.shouldShowSpeakerHint().observe(this, this::updateSpeakerHint); callScreen.getViewTreeObserver().addOnGlobalLayoutListener(() -> { CallParticipantsState state = viewModel.getCallParticipantsState().getValue(); @@ -286,10 +287,6 @@ public class WebRtcCallActivity extends AppCompatActivity implements SafetyNumbe videoTooltip.dismiss(); videoTooltip = null; } - } else if (event instanceof WebRtcCallViewModel.Event.ShowSpeakerViewHint) { - callScreen.showSpeakerViewHint(); - } else if (event instanceof WebRtcCallViewModel.Event.HideSpeakerViewHint) { - callScreen.hideSpeakerViewHint(); } else { throw new IllegalArgumentException("Unknown event: " + event); } @@ -517,6 +514,14 @@ public class WebRtcCallActivity extends AppCompatActivity implements SafetyNumbe startService(new Intent(this, WebRtcCallService.class).setAction(WebRtcCallService.ACTION_GROUP_REQUEST_UPDATE_MEMBERS)); } + private void updateSpeakerHint(boolean showSpeakerHint) { + if (showSpeakerHint) { + callScreen.showSpeakerViewHint(); + } else { + callScreen.hideSpeakerViewHint(); + } + } + @Override public void onSendAnywayAfterSafetyNumberChange(@NonNull List changedRecipients) { CallParticipantsState state = viewModel.getCallParticipantsState().getValue(); 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 9e476b248..15c966174 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 @@ -517,7 +517,7 @@ public class WebRtcCallView extends FrameLayout { } public void showSpeakerViewHint() { - groupCallSpeakerHint.get(); + groupCallSpeakerHint.get().setVisibility(View.VISIBLE); } public void hideSpeakerViewHint() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallViewModel.java index dec7e5fa9..2362acde6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallViewModel.java @@ -47,6 +47,7 @@ public class WebRtcCallViewModel extends ViewModel { private final LiveData safetyNumberChangeEvent = LiveDataUtil.combineLatest(isInPipMode, identityChangedRecipients, SafetyNumberChangeEvent::new); private final LiveData groupRecipient = LiveDataUtil.filter(Transformations.switchMap(liveRecipient, LiveRecipient::getLiveData), Recipient::isActiveGroup); private final LiveData> groupMembers = LiveDataUtil.skip(Transformations.switchMap(groupRecipient, r -> Transformations.distinctUntilChanged(new LiveGroup(r.requireGroupId()).getFullMembers())), 1); + private final LiveData shouldShowSpeakerHint = Transformations.map(participantsState, this::shouldShowSpeakerHint); private boolean canDisplayTooltipIfNeeded = true; private boolean hasEnabledLocalVideo = false; @@ -100,6 +101,10 @@ public class WebRtcCallViewModel extends ViewModel { return groupMembers; } + public LiveData shouldShowSpeakerHint() { + return shouldShowSpeakerHint; + } + public boolean canEnterPipMode() { return canEnterPipMode; } @@ -122,12 +127,12 @@ public class WebRtcCallViewModel extends ViewModel { @MainThread public void setIsViewingFocusedParticipant(@NonNull CallParticipantsState.SelectedPage page) { - //noinspection ConstantConditions - participantsState.setValue(CallParticipantsState.update(participantsState.getValue(), page)); if (page == CallParticipantsState.SelectedPage.FOCUSED) { SignalStore.tooltips().markGroupCallSpeakerViewSeen(); - events.setValue(new Event.HideSpeakerViewHint()); } + + //noinspection ConstantConditions + participantsState.setValue(CallParticipantsState.update(participantsState.getValue(), page)); } public void onDismissedVideoTooltip() { @@ -187,14 +192,6 @@ public class WebRtcCallViewModel extends ViewModel { canDisplayTooltipIfNeeded = false; events.setValue(new Event.ShowVideoTooltip()); } - - //noinspection ConstantConditions - if (!isInPipMode.getValue() && - webRtcViewModel.getRemoteParticipants().size() > 1 && - webRtcViewModel.getGroupState().isConnected() && - !SignalStore.tooltips().hasSeenGroupCallSpeakerView()) { - events.setValue(new Event.ShowSpeakerViewHint()); - } } private boolean containsPlaceholders(@NonNull List callParticipants) { @@ -276,6 +273,13 @@ public class WebRtcCallViewModel extends ViewModel { return isInPipMode ? WebRtcControls.PIP : controls; } + private boolean shouldShowSpeakerHint(@NonNull CallParticipantsState state) { + return !state.isInPipMode() && + state.getRemoteDevicesCount() > 1 && + state.getGroupCallState().isConnected() && + !SignalStore.tooltips().hasSeenGroupCallSpeakerView(); + } + private void startTimer() { cancelTimer(); @@ -332,12 +336,6 @@ public class WebRtcCallViewModel extends ViewModel { public static class DismissVideoTooltip extends Event { } - public static class ShowSpeakerViewHint extends Event { - } - - public static class HideSpeakerViewHint extends Event { - } - public static class StartCall extends Event { private final boolean isVideoCall;