From a0763be26bcc6bcb1db7b3e807768a4538856b89 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Fri, 12 Jan 2018 15:59:09 +0100 Subject: [PATCH] Try to fix cleanup Signed-off-by: Mario Danic --- .../nextcloud/talk/activities/CallActivity.java | 7 +------ .../talk/controllers/SettingsController.java | 14 +++++++------- .../talk/webrtc/MagicPeerConnectionWrapper.java | 11 ++++++----- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 8baa3da88..1ae965572 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -939,10 +939,7 @@ public class CallActivity extends AppCompatActivity { private void deleteMagicPeerConnection(MagicPeerConnectionWrapper magicPeerConnectionWrapper) { - if (magicPeerConnectionWrapper.getPeerConnection() != null) { - magicPeerConnectionWrapper.removeMediaStream(); - magicPeerConnectionWrapper.getPeerConnection().close(); - } + magicPeerConnectionWrapper.removePeerConnection(magicPeerConnectionWrapperList.size() == 1); magicPeerConnectionWrapperList.remove(magicPeerConnectionWrapper); } @@ -1209,8 +1206,6 @@ public class CallActivity extends AppCompatActivity { MagicPeerConnectionWrapper magicPeerConnectionWrapper; if ((magicPeerConnectionWrapper = getPeerConnectionWrapperForSessionId(sessionId)) != null) { runOnUiThread(() -> removeMediaStream(sessionId)); - magicPeerConnectionWrapper.removeMediaStream(); - magicPeerConnectionWrapper.removePeerConnection(); deleteMagicPeerConnection(magicPeerConnectionWrapper); } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java index cff596896..6f2412ab2 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java @@ -178,7 +178,7 @@ public class SettingsController extends BaseController { true); if (!TextUtils.isEmpty(getResources().getString(R.string.nc_gpl3_url))) { - licenceButton.setOnClickListener(view1 -> { + licenceButton.addPreferenceClickListener(view1 -> { sourceCodeButton.setEnabled(false); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources(). getString(R.string.nc_gpl3_url))); @@ -190,7 +190,7 @@ public class SettingsController extends BaseController { } if (!TextUtils.isEmpty(getResources().getString(R.string.nc_privacy_url))) { - privacyButton.setOnClickListener(view12 -> { + privacyButton.addPreferenceClickListener(view12 -> { sourceCodeButton.setEnabled(false); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources(). getString(R.string.nc_privacy_url))); @@ -202,7 +202,7 @@ public class SettingsController extends BaseController { } if (!TextUtils.isEmpty(getResources().getString(R.string.nc_source_code_url))) { - sourceCodeButton.setOnClickListener(view13 -> { + sourceCodeButton.addPreferenceClickListener(view13 -> { sourceCodeButton.setEnabled(false); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources(). getString(R.string.nc_source_code_url))); @@ -216,14 +216,14 @@ public class SettingsController extends BaseController { versionInfo.setSummary("v" + BuildConfig.VERSION_NAME); - addAccountButton.setOnClickListener(view15 -> { + addAccountButton.addPreferenceClickListener(view15 -> { addAccountButton.setEnabled(false); getParentController().getRouter().pushController(RouterTransaction.with(new ServerSelectionController()).pushChangeHandler(new VerticalChangeHandler()) .popChangeHandler(new VerticalChangeHandler())); }); - switchAccountButton.setOnClickListener(view16 -> { + switchAccountButton.addPreferenceClickListener(view16 -> { switchAccountButton.setEnabled(false); getParentController().getRouter().pushController(RouterTransaction.with(new SwitchAccountController()).pushChangeHandler(new VerticalChangeHandler()) @@ -255,7 +255,7 @@ public class SettingsController extends BaseController { baseUrlTextView.setText(userEntity.getBaseUrl()); - reauthorizeButton.setOnClickListener(view14 -> { + reauthorizeButton.addPreferenceClickListener(view14 -> { reauthorizeButton.setEnabled(false); getParentController().getRouter().pushController(RouterTransaction.with( new WebViewLoginController(userEntity.getBaseUrl(), true)) @@ -317,7 +317,7 @@ public class SettingsController extends BaseController { removeAccountButton.setEnabled(true); - removeAccountButton.setOnClickListener(view1 -> { + removeAccountButton.addPreferenceClickListener(view1 -> { removeAccountButton.setEnabled(false); cookieManager.getCookieStore().removeAll(); boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(userEntity.getId()); diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java index 5e5a759f5..0059b466b 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java @@ -92,13 +92,14 @@ public class MagicPeerConnectionWrapper { } } - public void removePeerConnection() { - peerConnection.close(); - peerConnection = null; - } - public void removeMediaStream() { + public void removePeerConnection(boolean isFinal) { if (peerConnection != null && localMediaStream != null) { + peerConnection.close(); peerConnection.removeStream(localMediaStream); + if (isFinal) { + peerConnection.dispose(); + } + peerConnection = null; } }