Notify when calls start to be routed over cellular data.

Only when the device thinks that it's also connected to a WiFi network.
This commit is contained in:
Rashad Sookram
2022-07-18 18:24:38 -04:00
committed by Cody Henthorne
parent e024541b8a
commit 88b895f5ea
14 changed files with 141 additions and 9 deletions

View File

@@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcEphemeralState;
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
import org.thoughtcrime.securesms.util.NetworkUtil;
import org.thoughtcrime.securesms.util.SingleLiveEvent;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
@@ -74,6 +75,7 @@ public class WebRtcCallViewModel extends ViewModel {
private final Runnable stopOutgoingRingingMode = this::stopOutgoingRingingMode;
private boolean canDisplayTooltipIfNeeded = true;
private boolean canDisplayPopupIfNeeded = true;
private boolean hasEnabledLocalVideo = false;
private boolean wasInOutgoingRingingMode = false;
private long callConnectedTime = -1;
@@ -292,6 +294,13 @@ public class WebRtcCallViewModel extends ViewModel {
canDisplayTooltipIfNeeded = false;
events.setValue(new Event.ShowVideoTooltip());
}
if (canDisplayPopupIfNeeded && webRtcViewModel.isCellularConnection() && NetworkUtil.isConnectedWifi(ApplicationDependencies.getApplication())) {
canDisplayPopupIfNeeded = false;
events.setValue(new Event.ShowWifiToCellularPopup());
} else if (!webRtcViewModel.isCellularConnection()) {
canDisplayPopupIfNeeded = true;
}
}
@MainThread
@@ -481,6 +490,9 @@ public class WebRtcCallViewModel extends ViewModel {
public static class DismissVideoTooltip extends Event {
}
public static class ShowWifiToCellularPopup extends Event {
}
public static class StartCall extends Event {
private final boolean isVideoCall;

View File

@@ -0,0 +1,39 @@
package org.thoughtcrime.securesms.components.webrtc
import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.PopupWindow
import androidx.core.view.postDelayed
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.util.VibrateUtil
import java.util.concurrent.TimeUnit
/**
* Popup shown when the device is connected to a WiFi and cellular network, and WiFi is unusable for
* RingRTC.
*/
class WifiToCellularPopupWindow(private val parent: ViewGroup) : PopupWindow(
LayoutInflater.from(parent.context).inflate(R.layout.wifi_to_cellular_popup, parent, false),
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT
) {
init {
animationStyle = R.style.PopupAnimation
}
fun show() {
showAtLocation(parent, Gravity.TOP or Gravity.START, 0, 0)
VibrateUtil.vibrate(parent.context, VIBRATE_DURATION_MS)
contentView.postDelayed(DISPLAY_DURATION_MS) {
dismiss()
}
}
companion object {
private val DISPLAY_DURATION_MS = TimeUnit.SECONDS.toMillis(4)
private const val VIBRATE_DURATION_MS = 50
}
}