Set pip auto-enter based off live view-model value.

This commit is contained in:
Alex Hart
2024-09-27 10:27:08 -03:00
parent 588f107300
commit 5394aaa44c
2 changed files with 22 additions and 11 deletions

View File

@@ -370,7 +370,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
private boolean enterPipModeIfPossible() {
if (isSystemPipEnabledAndAvailable()) {
if (viewModel.canEnterPipMode()) {
if (Boolean.TRUE.equals(viewModel.canEnterPipMode().getValue())) {
try {
enterPictureInPictureMode(pipBuilderParams.build());
} catch (Exception e) {
@@ -380,6 +380,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
return true;
}
if (Build.VERSION.SDK_INT >= 31) {
pipBuilderParams.setAutoEnterEnabled(false);
}
@@ -573,15 +574,24 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
pipBuilderParams = new PictureInPictureParams.Builder();
pipBuilderParams.setAspectRatio(aspectRatio);
if (Build.VERSION.SDK_INT >= 31) {
pipBuilderParams.setAutoEnterEnabled(true);
viewModel.canEnterPipMode().observe(this, canEnterPipMode -> {
pipBuilderParams.setAutoEnterEnabled(canEnterPipMode);
tryToSetPictureInPictureParams();
});
} else {
tryToSetPictureInPictureParams();
}
if (Build.VERSION.SDK_INT >= 26) {
try {
setPictureInPictureParams(pipBuilderParams.build());
} catch (Exception e) {
Log.w(TAG, "System lied about having PiP available.", e);
}
}
}
private void tryToSetPictureInPictureParams() {
if (Build.VERSION.SDK_INT >= 26) {
try {
setPictureInPictureParams(pipBuilderParams.build());
} catch (Exception e) {
Log.w(TAG, "System lied about having PiP available.", e);
}
}
}

View File

@@ -17,6 +17,7 @@ import androidx.lifecycle.ViewModel;
import com.annimon.stream.Stream;
import org.signal.core.util.ThreadUtil;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.components.webrtc.v2.CallControlsState;
import org.thoughtcrime.securesms.components.webrtc.v2.CallEvent;
import org.thoughtcrime.securesms.database.GroupTable;
@@ -74,6 +75,7 @@ public class WebRtcCallViewModel extends ViewModel {
private final LiveData<Integer> groupMemberCount = Transformations.map(groupMembers, List::size);
private final Observable<Boolean> shouldShowSpeakerHint = participantsState.map(this::shouldShowSpeakerHint);
private final MutableLiveData<Boolean> isLandscapeEnabled = new MutableLiveData<>();
private final MutableLiveData<Boolean> canEnterPipMode = new MutableLiveData<>(false);
private final Observer<List<GroupMemberEntry.FullMember>> groupMemberStateUpdater = m -> participantsState.onNext(CallParticipantsState.update(participantsState.getValue(), m));
private final MutableLiveData<WebRtcEphemeralState> ephemeralState = new MutableLiveData<>();
private final BehaviorProcessor<RecipientId> recipientId = BehaviorProcessor.createDefault(RecipientId.UNKNOWN);
@@ -91,7 +93,6 @@ public class WebRtcCallViewModel extends ViewModel {
private boolean wasInOutgoingRingingMode = false;
private long callConnectedTime = -1;
private boolean answerWithVideoAvailable = false;
private boolean canEnterPipMode = false;
private List<CallParticipant> previousParticipantsList = Collections.emptyList();
private boolean callStarting = false;
private boolean switchOnFirstScreenShare = true;
@@ -209,7 +210,7 @@ public class WebRtcCallViewModel extends ViewModel {
return ephemeralState;
}
public boolean canEnterPipMode() {
public LiveData<Boolean> canEnterPipMode() {
return canEnterPipMode;
}
@@ -280,7 +281,7 @@ public class WebRtcCallViewModel extends ViewModel {
@MainThread
public void updateFromWebRtcViewModel(@NonNull WebRtcViewModel webRtcViewModel, boolean enableVideo) {
canEnterPipMode = !webRtcViewModel.getState().isPreJoinOrNetworkUnavailable();
canEnterPipMode.setValue(!webRtcViewModel.getState().isPreJoinOrNetworkUnavailable());
if (callStarting && webRtcViewModel.getState().isPassedPreJoin()) {
callStarting = false;
}