RtpSessionActivity code clean up
This commit is contained in:
parent
622b569bbc
commit
5728cf13ea
|
@ -1,8 +1,9 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
|
||||||
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -40,16 +41,6 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
|
||||||
import org.webrtc.RendererCommon;
|
|
||||||
import org.webrtc.SurfaceViewRenderer;
|
|
||||||
import org.webrtc.VideoTrack;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.databinding.ActivityRtpSessionBinding;
|
import eu.siacs.conversations.databinding.ActivityRtpSessionBinding;
|
||||||
|
@ -63,7 +54,6 @@ import eu.siacs.conversations.ui.util.MainThreadExecutor;
|
||||||
import eu.siacs.conversations.ui.util.Rationals;
|
import eu.siacs.conversations.ui.util.Rationals;
|
||||||
import eu.siacs.conversations.utils.PermissionUtils;
|
import eu.siacs.conversations.utils.PermissionUtils;
|
||||||
import eu.siacs.conversations.utils.TimeFrameUtils;
|
import eu.siacs.conversations.utils.TimeFrameUtils;
|
||||||
import eu.siacs.conversations.xml.Namespace;
|
|
||||||
import eu.siacs.conversations.xmpp.Jid;
|
import eu.siacs.conversations.xmpp.Jid;
|
||||||
import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
|
import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
|
||||||
import eu.siacs.conversations.xmpp.jingle.ContentAddition;
|
import eu.siacs.conversations.xmpp.jingle.ContentAddition;
|
||||||
|
@ -73,6 +63,16 @@ import eu.siacs.conversations.xmpp.jingle.Media;
|
||||||
import eu.siacs.conversations.xmpp.jingle.RtpCapability;
|
import eu.siacs.conversations.xmpp.jingle.RtpCapability;
|
||||||
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
|
||||||
|
|
||||||
|
import org.webrtc.RendererCommon;
|
||||||
|
import org.webrtc.SurfaceViewRenderer;
|
||||||
|
import org.webrtc.VideoTrack;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class RtpSessionActivity extends XmppActivity
|
public class RtpSessionActivity extends XmppActivity
|
||||||
implements XmppConnectionService.OnJingleRtpConnectionUpdate,
|
implements XmppConnectionService.OnJingleRtpConnectionUpdate,
|
||||||
eu.siacs.conversations.ui.widget.SurfaceViewRenderer.OnAspectRatioChanged {
|
eu.siacs.conversations.ui.widget.SurfaceViewRenderer.OnAspectRatioChanged {
|
||||||
|
@ -107,9 +107,7 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
RtpEndUserState.RECONNECTING,
|
RtpEndUserState.RECONNECTING,
|
||||||
RtpEndUserState.INCOMING_CONTENT_ADD);
|
RtpEndUserState.INCOMING_CONTENT_ADD);
|
||||||
private static final List<RtpEndUserState> STATES_CONSIDERED_CONNECTED =
|
private static final List<RtpEndUserState> STATES_CONSIDERED_CONNECTED =
|
||||||
Arrays.asList(
|
Arrays.asList(RtpEndUserState.CONNECTED, RtpEndUserState.RECONNECTING);
|
||||||
RtpEndUserState.CONNECTED,
|
|
||||||
RtpEndUserState.RECONNECTING);
|
|
||||||
private static final List<RtpEndUserState> STATES_SHOWING_PIP_PLACEHOLDER =
|
private static final List<RtpEndUserState> STATES_SHOWING_PIP_PLACEHOLDER =
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
RtpEndUserState.ACCEPTING_CALL,
|
RtpEndUserState.ACCEPTING_CALL,
|
||||||
|
@ -231,18 +229,19 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
final var itemItem = item.getItemId();
|
||||||
case R.id.action_help:
|
if (itemItem == R.id.action_help) {
|
||||||
launchHelpInBrowser();
|
launchHelpInBrowser();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_goto_chat:
|
} else if (itemItem == R.id.action_goto_chat) {
|
||||||
switchToConversation();
|
switchToConversation();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_switch_to_video:
|
} else if (itemItem == R.id.action_switch_to_video) {
|
||||||
requestPermissionAndSwitchToVideo();
|
requestPermissionAndSwitchToVideo();
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchHelpInBrowser() {
|
private void launchHelpInBrowser() {
|
||||||
|
@ -319,8 +318,9 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void acceptContentAdd(final ContentAddition contentAddition) {
|
private void acceptContentAdd(final ContentAddition contentAddition) {
|
||||||
if (contentAddition == null || contentAddition.direction != ContentAddition.Direction.INCOMING) {
|
if (contentAddition == null
|
||||||
Log.d(Config.LOGTAG,"ignore press on content-accept button");
|
|| contentAddition.direction != ContentAddition.Direction.INCOMING) {
|
||||||
|
Log.d(Config.LOGTAG, "ignore press on content-accept button");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
requestPermissionAndAcceptContentAdd(contentAddition);
|
requestPermissionAndAcceptContentAdd(contentAddition);
|
||||||
|
@ -329,7 +329,11 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
private void requestPermissionAndAcceptContentAdd(final ContentAddition contentAddition) {
|
private void requestPermissionAndAcceptContentAdd(final ContentAddition contentAddition) {
|
||||||
final List<String> permissions = permissions(contentAddition.media());
|
final List<String> permissions = permissions(contentAddition.media());
|
||||||
if (PermissionUtils.hasPermission(this, permissions, REQUEST_ACCEPT_CONTENT)) {
|
if (PermissionUtils.hasPermission(this, permissions, REQUEST_ACCEPT_CONTENT)) {
|
||||||
requireRtpConnection().acceptContentAdd(contentAddition.summary);
|
try {
|
||||||
|
requireRtpConnection().acceptContentAdd(contentAddition.summary);
|
||||||
|
} catch (final IllegalStateException e) {
|
||||||
|
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,8 +685,10 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
private boolean isConnected() {
|
private boolean isConnected() {
|
||||||
final JingleRtpConnection connection =
|
final JingleRtpConnection connection =
|
||||||
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
|
||||||
final RtpEndUserState endUserState = connection == null ? null : connection.getEndUserState();
|
final RtpEndUserState endUserState =
|
||||||
return STATES_CONSIDERED_CONNECTED.contains(endUserState) || endUserState == RtpEndUserState.INCOMING_CONTENT_ADD;
|
connection == null ? null : connection.getEndUserState();
|
||||||
|
return STATES_CONSIDERED_CONNECTED.contains(endUserState)
|
||||||
|
|| endUserState == RtpEndUserState.INCOMING_CONTENT_ADD;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean switchToPictureInPicture() {
|
private boolean switchToPictureInPicture() {
|
||||||
|
@ -840,68 +846,43 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
updateStateDisplay(state, Collections.emptySet(), null);
|
updateStateDisplay(state, Collections.emptySet(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStateDisplay(final RtpEndUserState state, final Set<Media> media, final ContentAddition contentAddition) {
|
private void updateStateDisplay(
|
||||||
|
final RtpEndUserState state,
|
||||||
|
final Set<Media> media,
|
||||||
|
final ContentAddition contentAddition) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INCOMING_CALL:
|
case INCOMING_CALL -> {
|
||||||
Preconditions.checkArgument(media.size() > 0, "Media must not be empty");
|
Preconditions.checkArgument(media.size() > 0, "Media must not be empty");
|
||||||
if (media.contains(Media.VIDEO)) {
|
if (media.contains(Media.VIDEO)) {
|
||||||
setTitle(R.string.rtp_state_incoming_video_call);
|
setTitle(R.string.rtp_state_incoming_video_call);
|
||||||
} else {
|
} else {
|
||||||
setTitle(R.string.rtp_state_incoming_call);
|
setTitle(R.string.rtp_state_incoming_call);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case INCOMING_CONTENT_ADD:
|
case INCOMING_CONTENT_ADD -> {
|
||||||
if (contentAddition != null && contentAddition.media().contains(Media.VIDEO)) {
|
if (contentAddition != null && contentAddition.media().contains(Media.VIDEO)) {
|
||||||
setTitle(R.string.rtp_state_content_add_video);
|
setTitle(R.string.rtp_state_content_add_video);
|
||||||
} else {
|
} else {
|
||||||
setTitle(R.string.rtp_state_content_add);
|
setTitle(R.string.rtp_state_content_add);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case CONNECTING:
|
case CONNECTING -> setTitle(R.string.rtp_state_connecting);
|
||||||
setTitle(R.string.rtp_state_connecting);
|
case CONNECTED -> setTitle(R.string.rtp_state_connected);
|
||||||
break;
|
case RECONNECTING -> setTitle(R.string.rtp_state_reconnecting);
|
||||||
case CONNECTED:
|
case ACCEPTING_CALL -> setTitle(R.string.rtp_state_accepting_call);
|
||||||
setTitle(R.string.rtp_state_connected);
|
case ENDING_CALL -> setTitle(R.string.rtp_state_ending_call);
|
||||||
break;
|
case FINDING_DEVICE -> setTitle(R.string.rtp_state_finding_device);
|
||||||
case RECONNECTING:
|
case RINGING -> setTitle(R.string.rtp_state_ringing);
|
||||||
setTitle(R.string.rtp_state_reconnecting);
|
case DECLINED_OR_BUSY -> setTitle(R.string.rtp_state_declined_or_busy);
|
||||||
break;
|
case CONNECTIVITY_ERROR -> setTitle(R.string.rtp_state_connectivity_error);
|
||||||
case ACCEPTING_CALL:
|
case CONNECTIVITY_LOST_ERROR -> setTitle(R.string.rtp_state_connectivity_lost_error);
|
||||||
setTitle(R.string.rtp_state_accepting_call);
|
case RETRACTED -> setTitle(R.string.rtp_state_retracted);
|
||||||
break;
|
case APPLICATION_ERROR -> setTitle(R.string.rtp_state_application_failure);
|
||||||
case ENDING_CALL:
|
case SECURITY_ERROR -> setTitle(R.string.rtp_state_security_error);
|
||||||
setTitle(R.string.rtp_state_ending_call);
|
case ENDED -> throw new IllegalStateException(
|
||||||
break;
|
"Activity should have called finishAndReleaseWakeLock();");
|
||||||
case FINDING_DEVICE:
|
default -> throw new IllegalStateException(
|
||||||
setTitle(R.string.rtp_state_finding_device);
|
String.format("State %s has not been handled in UI", state));
|
||||||
break;
|
|
||||||
case RINGING:
|
|
||||||
setTitle(R.string.rtp_state_ringing);
|
|
||||||
break;
|
|
||||||
case DECLINED_OR_BUSY:
|
|
||||||
setTitle(R.string.rtp_state_declined_or_busy);
|
|
||||||
break;
|
|
||||||
case CONNECTIVITY_ERROR:
|
|
||||||
setTitle(R.string.rtp_state_connectivity_error);
|
|
||||||
break;
|
|
||||||
case CONNECTIVITY_LOST_ERROR:
|
|
||||||
setTitle(R.string.rtp_state_connectivity_lost_error);
|
|
||||||
break;
|
|
||||||
case RETRACTED:
|
|
||||||
setTitle(R.string.rtp_state_retracted);
|
|
||||||
break;
|
|
||||||
case APPLICATION_ERROR:
|
|
||||||
setTitle(R.string.rtp_state_application_failure);
|
|
||||||
break;
|
|
||||||
case SECURITY_ERROR:
|
|
||||||
setTitle(R.string.rtp_state_security_error);
|
|
||||||
break;
|
|
||||||
case ENDED:
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Activity should have called finishAndReleaseWakeLock();");
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException(
|
|
||||||
String.format("State %s has not been handled in UI", state));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -957,7 +938,10 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
private void updateButtonConfiguration(final RtpEndUserState state, final Set<Media> media, final ContentAddition contentAddition) {
|
private void updateButtonConfiguration(
|
||||||
|
final RtpEndUserState state,
|
||||||
|
final Set<Media> media,
|
||||||
|
final ContentAddition contentAddition) {
|
||||||
if (state == RtpEndUserState.ENDING_CALL || isPictureInPicture()) {
|
if (state == RtpEndUserState.ENDING_CALL || isPictureInPicture()) {
|
||||||
this.binding.rejectCall.setVisibility(View.INVISIBLE);
|
this.binding.rejectCall.setVisibility(View.INVISIBLE);
|
||||||
this.binding.endCall.setVisibility(View.INVISIBLE);
|
this.binding.endCall.setVisibility(View.INVISIBLE);
|
||||||
|
@ -973,7 +957,8 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
this.binding.acceptCall.setImageResource(R.drawable.ic_call_white_48dp);
|
this.binding.acceptCall.setImageResource(R.drawable.ic_call_white_48dp);
|
||||||
this.binding.acceptCall.setVisibility(View.VISIBLE);
|
this.binding.acceptCall.setVisibility(View.VISIBLE);
|
||||||
} else if (state == RtpEndUserState.INCOMING_CONTENT_ADD) {
|
} else if (state == RtpEndUserState.INCOMING_CONTENT_ADD) {
|
||||||
this.binding.rejectCall.setContentDescription(getString(R.string.reject_switch_to_video));
|
this.binding.rejectCall.setContentDescription(
|
||||||
|
getString(R.string.reject_switch_to_video));
|
||||||
this.binding.rejectCall.setOnClickListener(this::rejectContentAdd);
|
this.binding.rejectCall.setOnClickListener(this::rejectContentAdd);
|
||||||
this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp);
|
this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp);
|
||||||
this.binding.rejectCall.setVisibility(View.VISIBLE);
|
this.binding.rejectCall.setVisibility(View.VISIBLE);
|
||||||
|
@ -1065,7 +1050,7 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
private void updateInCallButtonConfigurationSpeaker(
|
private void updateInCallButtonConfigurationSpeaker(
|
||||||
final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices) {
|
final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices) {
|
||||||
switch (selectedAudioDevice) {
|
switch (selectedAudioDevice) {
|
||||||
case EARPIECE:
|
case EARPIECE -> {
|
||||||
this.binding.inCallActionRight.setImageResource(
|
this.binding.inCallActionRight.setImageResource(
|
||||||
R.drawable.ic_volume_off_black_24dp);
|
R.drawable.ic_volume_off_black_24dp);
|
||||||
if (numberOfChoices >= 2) {
|
if (numberOfChoices >= 2) {
|
||||||
|
@ -1074,13 +1059,13 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
this.binding.inCallActionRight.setOnClickListener(null);
|
this.binding.inCallActionRight.setOnClickListener(null);
|
||||||
this.binding.inCallActionRight.setClickable(false);
|
this.binding.inCallActionRight.setClickable(false);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case WIRED_HEADSET:
|
case WIRED_HEADSET -> {
|
||||||
this.binding.inCallActionRight.setImageResource(R.drawable.ic_headset_black_24dp);
|
this.binding.inCallActionRight.setImageResource(R.drawable.ic_headset_black_24dp);
|
||||||
this.binding.inCallActionRight.setOnClickListener(null);
|
this.binding.inCallActionRight.setOnClickListener(null);
|
||||||
this.binding.inCallActionRight.setClickable(false);
|
this.binding.inCallActionRight.setClickable(false);
|
||||||
break;
|
}
|
||||||
case SPEAKER_PHONE:
|
case SPEAKER_PHONE -> {
|
||||||
this.binding.inCallActionRight.setImageResource(R.drawable.ic_volume_up_black_24dp);
|
this.binding.inCallActionRight.setImageResource(R.drawable.ic_volume_up_black_24dp);
|
||||||
if (numberOfChoices >= 2) {
|
if (numberOfChoices >= 2) {
|
||||||
this.binding.inCallActionRight.setOnClickListener(this::switchToEarpiece);
|
this.binding.inCallActionRight.setOnClickListener(this::switchToEarpiece);
|
||||||
|
@ -1088,13 +1073,13 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
this.binding.inCallActionRight.setOnClickListener(null);
|
this.binding.inCallActionRight.setOnClickListener(null);
|
||||||
this.binding.inCallActionRight.setClickable(false);
|
this.binding.inCallActionRight.setClickable(false);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case BLUETOOTH:
|
case BLUETOOTH -> {
|
||||||
this.binding.inCallActionRight.setImageResource(
|
this.binding.inCallActionRight.setImageResource(
|
||||||
R.drawable.ic_bluetooth_audio_black_24dp);
|
R.drawable.ic_bluetooth_audio_black_24dp);
|
||||||
this.binding.inCallActionRight.setOnClickListener(null);
|
this.binding.inCallActionRight.setOnClickListener(null);
|
||||||
this.binding.inCallActionRight.setClickable(false);
|
this.binding.inCallActionRight.setClickable(false);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
this.binding.inCallActionRight.setVisibility(View.VISIBLE);
|
this.binding.inCallActionRight.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
@ -1123,10 +1108,10 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
private void switchCamera(final View view) {
|
private void switchCamera(final View view) {
|
||||||
Futures.addCallback(
|
Futures.addCallback(
|
||||||
requireRtpConnection().switchCamera(),
|
requireRtpConnection().switchCamera(),
|
||||||
new FutureCallback<Boolean>() {
|
new FutureCallback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(@Nullable Boolean isFrontCamera) {
|
public void onSuccess(@Nullable Boolean isFrontCamera) {
|
||||||
binding.localVideo.setMirror(isFrontCamera);
|
binding.localVideo.setMirror(Boolean.TRUE.equals(isFrontCamera));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1485,8 +1470,7 @@ public class RtpSessionActivity extends XmppActivity
|
||||||
final Account account, Jid with, final RtpEndUserState state, final Set<Media> media) {
|
final Account account, Jid with, final RtpEndUserState state, final Set<Media> media) {
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
|
intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
|
||||||
if (RtpCapability.jmiSupport(account.getRoster()
|
if (RtpCapability.jmiSupport(account.getRoster().getContact(with))) {
|
||||||
.getContact(with))) {
|
|
||||||
intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString());
|
intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString());
|
||||||
} else {
|
} else {
|
||||||
intent.putExtra(EXTRA_WITH, with.toEscapedString());
|
intent.putExtra(EXTRA_WITH, with.toEscapedString());
|
||||||
|
|
Loading…
Reference in a new issue