From e2872d9af86686ca5daf187b8032769e0a788a08 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 5 Jan 2021 09:16:59 -0400 Subject: [PATCH] Add emdash instead of 0 if no callers are present and we haven't connected / loaded the group state. --- .../webrtc/CallParticipantsState.java | 16 ++++++++++---- .../components/webrtc/WebRtcCallView.java | 9 ++++---- .../webrtc/WebRtcCallViewModel.java | 8 +++---- .../CallParticipantsListDialog.java | 21 +++++++++++-------- .../securesms/events/WebRtcViewModel.java | 5 +++-- .../service/webrtc/state/CallInfoState.java | 10 +++++---- .../state/WebRtcServiceStateBuilder.java | 4 +++- 7 files changed, 45 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java index f3b68e8342..5003a5f8aa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsState.java @@ -6,6 +6,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.annimon.stream.ComparatorCompat; +import com.annimon.stream.OptionalLong; import com.annimon.stream.Stream; import org.thoughtcrime.securesms.R; @@ -35,7 +36,7 @@ public final class CallParticipantsState { false, false, false, - 0); + OptionalLong.empty()); private final WebRtcViewModel.State callState; private final WebRtcViewModel.GroupCallState groupCallState; @@ -46,7 +47,7 @@ public final class CallParticipantsState { private final boolean isInPipMode; private final boolean showVideoForOutgoing; private final boolean isViewingFocusedParticipant; - private final long remoteDevicesCount; + private final OptionalLong remoteDevicesCount; public CallParticipantsState(@NonNull WebRtcViewModel.State callState, @NonNull WebRtcViewModel.GroupCallState groupCallState, @@ -57,7 +58,7 @@ public final class CallParticipantsState { boolean isInPipMode, boolean showVideoForOutgoing, boolean isViewingFocusedParticipant, - long remoteDevicesCount) + OptionalLong remoteDevicesCount) { this.callState = callState; this.groupCallState = groupCallState; @@ -158,10 +159,17 @@ public final class CallParticipantsState { return Stream.of(getAllRemoteParticipants()).anyMatch(p -> p.getVideoSink().needsNewRequestingSize()); } - public long getRemoteDevicesCount() { + public @NonNull OptionalLong getRemoteDevicesCount() { return remoteDevicesCount; } + public @NonNull OptionalLong getParticipantCount() { + boolean includeSelf = groupCallState == WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED; + + return remoteDevicesCount.map(l -> l + (includeSelf ? 1L : 0L)) + .or(() -> includeSelf ? OptionalLong.of(1L) : OptionalLong.empty()); + } + public static @NonNull CallParticipantsState update(@NonNull CallParticipantsState oldState, @NonNull WebRtcViewModel webRtcViewModel, boolean enableVideo) 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 bec63b3bb3..f5fc5c520d 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 @@ -28,6 +28,7 @@ import androidx.transition.TransitionSet; import androidx.viewpager2.widget.MarginPageTransformer; import androidx.viewpager2.widget.ViewPager2; +import com.annimon.stream.OptionalLong; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.CenterCrop; import com.google.android.material.button.MaterialButton; @@ -262,16 +263,16 @@ public class WebRtcCallView extends FrameLayout { pages.add(WebRtcCallParticipantsPage.forSingleParticipant(state.getFocusedParticipant(), state.isInPipMode())); } - if ((state.getGroupCallState().isNotIdle() && state.getRemoteDevicesCount() > 0) || state.getGroupCallState().isConnected()) { + if ((state.getGroupCallState().isNotIdle() && state.getRemoteDevicesCount().orElse(0) > 0) || state.getGroupCallState().isConnected()) { recipientName.setText(state.getRemoteParticipantsDescription(getContext())); } else if (state.getGroupCallState().isNotIdle()) { recipientName.setText(getContext().getString(R.string.WebRtcCallView__s_group_call, Recipient.resolved(recipientId).getDisplayName(getContext()))); } if (state.getGroupCallState().isNotIdle() && participantCount != null) { - boolean includeSelf = state.getGroupCallState() == WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED; - - participantCount.setText(String.valueOf(state.getRemoteDevicesCount() + (includeSelf ? 1 : 0))); + participantCount.setText(state.getParticipantCount() + .mapToObj(String::valueOf).orElse("\u2014")); + participantCount.setEnabled(state.getParticipantCount().isPresent()); } pagerAdapter.submitList(pages); 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 2362acde64..c46144be84 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 @@ -170,7 +170,7 @@ public class WebRtcCallViewModel extends ViewModel { webRtcViewModel.isBluetoothAvailable(), Util.hasItems(webRtcViewModel.getRemoteParticipants()), repository.getAudioOutput(), - webRtcViewModel.getRemoteDevicesCount(), + webRtcViewModel.getRemoteDevicesCount().orElse(0), webRtcViewModel.getParticipantLimit()); if (webRtcViewModel.getState() == WebRtcViewModel.State.CALL_CONNECTED && callConnectedTime == -1) { @@ -274,9 +274,9 @@ public class WebRtcCallViewModel extends ViewModel { } private boolean shouldShowSpeakerHint(@NonNull CallParticipantsState state) { - return !state.isInPipMode() && - state.getRemoteDevicesCount() > 1 && - state.getGroupCallState().isConnected() && + return !state.isInPipMode() && + state.getRemoteDevicesCount().orElse(0) > 1 && + state.getGroupCallState().isConnected() && !SignalStore.tooltips().hasSeenGroupCallSpeakerView(); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/participantslist/CallParticipantsListDialog.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/participantslist/CallParticipantsListDialog.java index 1bc0286728..05a19ef49d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/participantslist/CallParticipantsListDialog.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/participantslist/CallParticipantsListDialog.java @@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.annimon.stream.OptionalLong; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import org.thoughtcrime.securesms.R; @@ -88,19 +89,21 @@ public class CallParticipantsListDialog extends BottomSheetDialogFragment { private void updateList(@NonNull CallParticipantsState callParticipantsState) { List> items = new ArrayList<>(); - boolean includeSelf = callParticipantsState.getGroupCallState() == WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED; + boolean includeSelf = callParticipantsState.getGroupCallState() == WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED; + OptionalLong headerCount = callParticipantsState.getParticipantCount(); - items.add(new CallParticipantsListHeader((int) callParticipantsState.getRemoteDevicesCount() + (includeSelf ? 1 : 0))); + headerCount.executeIfPresent(count -> { + items.add(new CallParticipantsListHeader((int) count)); - if (includeSelf) { - items.add(new CallParticipantViewState(callParticipantsState.getLocalParticipant())); - } + if (includeSelf) { + items.add(new CallParticipantViewState(callParticipantsState.getLocalParticipant())); + } - for (CallParticipant callParticipant : callParticipantsState.getAllRemoteParticipants()) { - items.add(new CallParticipantViewState(callParticipant)); - } + for (CallParticipant callParticipant : callParticipantsState.getAllRemoteParticipants()) { + items.add(new CallParticipantViewState(callParticipant)); + } + }); adapter.submitList(items); } - } diff --git a/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.java index 7d8232aaa9..9792765875 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.java @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.events; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.annimon.stream.OptionalLong; import com.annimon.stream.Stream; import org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink; @@ -94,7 +95,7 @@ public class WebRtcViewModel { private final CallParticipant localParticipant; private final List remoteParticipants; private final Set identityChangedRecipients; - private final long remoteDevicesCount; + private final OptionalLong remoteDevicesCount; private final Long participantLimit; public WebRtcViewModel(@NonNull WebRtcServiceState state) { @@ -154,7 +155,7 @@ public class WebRtcViewModel { return identityChangedRecipients; } - public long getRemoteDevicesCount() { + public OptionalLong getRemoteDevicesCount() { return remoteDevicesCount; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.java index 8eaf5455b4..addf90db55 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.java @@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.service.webrtc.state; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.annimon.stream.OptionalLong; + import org.signal.ringrtc.GroupCall; import org.thoughtcrime.securesms.events.CallParticipant; import org.thoughtcrime.securesms.events.CallParticipantId; @@ -35,7 +37,7 @@ public class CallInfoState { GroupCall groupCall; WebRtcViewModel.GroupCallState groupState; Set identityChangedRecipients; - long remoteDevicesCount; + OptionalLong remoteDevicesCount; Long participantLimit; public CallInfoState() { @@ -48,7 +50,7 @@ public class CallInfoState { null, WebRtcViewModel.GroupCallState.IDLE, Collections.emptySet(), - 0L, + OptionalLong.empty(), null); } @@ -75,7 +77,7 @@ public class CallInfoState { @Nullable GroupCall groupCall, @NonNull WebRtcViewModel.GroupCallState groupState, @NonNull Set identityChangedRecipients, - long remoteDevicesCount, + @NonNull OptionalLong remoteDevicesCount, @Nullable Long participantLimit) { this.callState = callState; @@ -147,7 +149,7 @@ public class CallInfoState { return identityChangedRecipients; } - public long getRemoteDevicesCount() { + public OptionalLong getRemoteDevicesCount() { return remoteDevicesCount; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java index fa550c5021..af9d47d891 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java @@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.service.webrtc.state; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.annimon.stream.OptionalLong; + import org.signal.ringrtc.GroupCall; import org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink; import org.thoughtcrime.securesms.events.CallParticipant; @@ -258,7 +260,7 @@ public class WebRtcServiceStateBuilder { } public @NonNull CallInfoStateBuilder remoteDevicesCount(long remoteDevicesCount) { - toBuild.remoteDevicesCount = remoteDevicesCount; + toBuild.remoteDevicesCount = OptionalLong.of(remoteDevicesCount); return this; }