diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-22 14:58:38 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-05-25 11:51:59 +0000 |
| commit | af941dcbd32684430b66ccb07b6df60b71770ad2 (patch) | |
| tree | 05c2d87d79c76dda26dc66985bc6485d863007bd /android/src | |
| parent | 84d21acf2312f51be09e23964113b652e7ea9b28 (diff) | |
| download | mullvadvpn-af941dcbd32684430b66ccb07b6df60b71770ad2.tar.xz mullvadvpn-af941dcbd32684430b66ccb07b6df60b71770ad2.zip | |
Use new API in `ForegroundNotificationManager`
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt index 449f62aa6c..fba3f02576 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt @@ -29,22 +29,14 @@ class ForegroundNotificationManager( private val notificationManager = service.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - private val listenerId = serviceNotifier.subscribe { newServiceInstance -> - connectionProxy = newServiceInstance?.connectionProxy - settingsListener = newServiceInstance?.settingsListener - } - private val badgeColor = service.resources.getColor(R.color.colorPrimary) - private var connectionListenerId: Int? = null private var connectionProxy: ConnectionProxy? = null set(value) { if (field != value) { - connectionListenerId?.let { listenerId -> - field?.onStateChange?.unsubscribe(listenerId) - } + field?.onStateChange?.unsubscribe(this) - connectionListenerId = value?.onStateChange?.subscribe { state -> + value?.onStateChange?.subscribe(this) { state -> tunnelState = state } @@ -56,11 +48,9 @@ class ForegroundNotificationManager( private var settingsListener: SettingsListener? = null set(value) { if (field != value) { - loginListenerId?.let { listenerId -> - field?.accountNumberNotifier?.unsubscribe(listenerId) - } + field?.accountNumberNotifier?.unsubscribe(this) - loginListenerId = value?.accountNumberNotifier?.subscribe { accountNumber -> + value?.accountNumberNotifier?.subscribe(this) { accountNumber -> loggedIn = accountNumber != null } @@ -197,6 +187,11 @@ class ForegroundNotificationManager( initChannel() } + serviceNotifier.subscribe(this) { newServiceInstance -> + connectionProxy = newServiceInstance?.connectionProxy + settingsListener = newServiceInstance?.settingsListener + } + service.apply { registerReceiver(connectReceiver, IntentFilter(KEY_CONNECT_ACTION)) registerReceiver(disconnectReceiver, IntentFilter(KEY_DISCONNECT_ACTION)) @@ -206,7 +201,7 @@ class ForegroundNotificationManager( } fun onDestroy() { - serviceNotifier.unsubscribe(listenerId) + serviceNotifier.unsubscribe(this) connectionProxy = null settingsListener = null |
