Fix network receiver

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-01-03 09:06:00 +01:00
parent 8c46f2c9b0
commit 0bb2968424

View File

@ -200,6 +200,8 @@ public class CallActivity extends AppCompatActivity {
private boolean cameraInitialized = false;
private boolean microphoneInitialized = false;
private BroadcastReceiver networkBroadcastReceier;
private static int getSystemUiVisibility() {
int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
@ -226,6 +228,17 @@ public class CallActivity extends AppCompatActivity {
callSession = "0";
credentials = ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken());
networkBroadcastReceier = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && !leavingCall) {
startPullingSignalingMessages(true);
} else if (Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && leavingCall) {
hangup(true);
}
}
};
callControls.setZ(100.0f);
basicInitialization();
@ -1098,6 +1111,7 @@ public class CallActivity extends AppCompatActivity {
@Override
public void onDestroy() {
hangup(false);
this.unregisterReceiver(networkBroadcastReceier);
super.onDestroy();
}
@ -1301,18 +1315,7 @@ public class CallActivity extends AppCompatActivity {
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
intentFilter.addAction("android.net.wifi.STATE_CHANGE");
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && leavingCall) {
startPullingSignalingMessages(true);
} else if (Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && !leavingCall) {
hangup(true);
}
}
};
this.registerReceiver(broadcastReceiver, intentFilter);
this.registerReceiver(networkBroadcastReceier, intentFilter);
}
private void animateCallControls(boolean show, long startDelay) {