From d2fb3321cae6a36080ea22b5f8c17c8fa80aa73a Mon Sep 17 00:00:00 2001 From: Jorge Blacio Date: Thu, 17 Oct 2019 17:36:33 -0500 Subject: [PATCH] Removing Data Source listeners manually is not really necessary --- .../mail/scenes/composer/ComposerController.kt | 9 ++------- .../emaildetail/EmailDetailSceneController.kt | 14 +++----------- .../mail/scenes/linking/LinkingController.kt | 13 +++---------- .../mail/scenes/mailbox/MailboxSceneController.kt | 8 ++------ .../mailbox/emailsource/EmailSourceController.kt | 10 +++------- .../restorebackup/RestoreBackupController.kt | 10 +++------- .../mail/scenes/settings/SettingsController.kt | 12 +++--------- .../changepassword/ChangePasswordController.kt | 12 +++--------- .../settings/cloudbackup/CloudBackupController.kt | 12 +++--------- .../scenes/settings/devices/DevicesController.kt | 13 +++---------- .../scenes/settings/labels/LabelsController.kt | 12 +++--------- .../scenes/settings/pinlock/PinLockController.kt | 10 +++------- .../scenes/settings/privacy/PrivacyController.kt | 10 +++------- .../scenes/settings/profile/ProfileController.kt | 12 +++--------- .../recovery_email/RecoveryEmailController.kt | 12 +++--------- .../scenes/settings/replyto/ReplyToController.kt | 12 +++--------- .../scenes/settings/syncing/SyncingController.kt | 10 +++------- .../mail/scenes/signin/SignInSceneController.kt | 4 ++-- 18 files changed, 51 insertions(+), 144 deletions(-) diff --git a/src/main/kotlin/com/criptext/mail/scenes/composer/ComposerController.kt b/src/main/kotlin/com/criptext/mail/scenes/composer/ComposerController.kt index 325794275..b5e4070c3 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/composer/ComposerController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/composer/ComposerController.kt @@ -663,8 +663,6 @@ class ComposerController(private val storage: KeyValueStorage, override fun onResume(activityMessage: ActivityMessage?): Boolean { if(scene.observer == null) scene.observer = this.observer - if(dataSource.listener == null) dataSource.listener = this.dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = this.generalDataSourceListener return false } @@ -676,14 +674,11 @@ class ComposerController(private val storage: KeyValueStorage, cleanup(true) } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(fullCleanup: Boolean){ val data = scene.getDataInputByUser() updateModelWithInputData(data) - - if(cleanDataSources) { + if(fullCleanup) { scene.observer = null - dataSource.listener = null - generalDataSource.listener = null } } diff --git a/src/main/kotlin/com/criptext/mail/scenes/emaildetail/EmailDetailSceneController.kt b/src/main/kotlin/com/criptext/mail/scenes/emaildetail/EmailDetailSceneController.kt index 4377078bb..f49b786c0 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/emaildetail/EmailDetailSceneController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/emaildetail/EmailDetailSceneController.kt @@ -884,27 +884,19 @@ class EmailDetailSceneController(private val storage: KeyValueStorage, } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) - dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) - generalDataSource.listener = remoteChangeDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } override fun onPause(){ - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ - if(cleanDataSources) { - dataSource.listener = null - generalDataSource.listener = null - } + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) } diff --git a/src/main/kotlin/com/criptext/mail/scenes/linking/LinkingController.kt b/src/main/kotlin/com/criptext/mail/scenes/linking/LinkingController.kt index fa055e6dc..7c594c235 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/linking/LinkingController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/linking/LinkingController.kt @@ -162,22 +162,15 @@ class LinkingController( override fun onResume(activityMessage: ActivityMessage?): Boolean { websocketEvents.setListener(webSocketEventListener) - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener return false } override fun onPause() { - cleanup(false) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - - if(cleanDataSources) { - dataSource.listener = null - generalDataSource.listener = null - } } private fun showSuspendedAccountDialog(){ @@ -364,7 +357,7 @@ class LinkingController( override fun onStop() { - cleanup(true) + cleanup() } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/mailbox/MailboxSceneController.kt b/src/main/kotlin/com/criptext/mail/scenes/mailbox/MailboxSceneController.kt index 87b66db9e..50ba204e9 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/mailbox/MailboxSceneController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/mailbox/MailboxSceneController.kt @@ -630,8 +630,6 @@ class MailboxSceneController(private val scene: MailboxScene, override fun onResume(activityMessage: ActivityMessage?): Boolean { websocketEvents.setListener(webSocketEventListener) - if(dataSource.listener == null) dataSourceController.setDataSourceListener() - if(generalDataSource.listener == null) generalDataSource.listener = removedDeviceDataSourceListener return handleActivityMessage(activityMessage) } @@ -697,12 +695,10 @@ class MailboxSceneController(private val scene: MailboxScene, cleanup(true) } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(fullCleanup: Boolean){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources) { - dataSource.listener = null - generalDataSource.listener = null + if(fullCleanup) { feedController.onStop() } } diff --git a/src/main/kotlin/com/criptext/mail/scenes/mailbox/emailsource/EmailSourceController.kt b/src/main/kotlin/com/criptext/mail/scenes/mailbox/emailsource/EmailSourceController.kt index e4e91cc43..f4adb73f8 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/mailbox/emailsource/EmailSourceController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/mailbox/emailsource/EmailSourceController.kt @@ -100,7 +100,6 @@ class EmailSourceController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener return false } @@ -159,18 +158,15 @@ class EmailSourceController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - generalDataSource.listener = null - } } private val webSocketEventListener = object : WebSocketEventListener { diff --git a/src/main/kotlin/com/criptext/mail/scenes/restorebackup/RestoreBackupController.kt b/src/main/kotlin/com/criptext/mail/scenes/restorebackup/RestoreBackupController.kt index 8b1c1c40a..a8759a9ac 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/restorebackup/RestoreBackupController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/restorebackup/RestoreBackupController.kt @@ -362,19 +362,15 @@ class RestoreBackupController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources) { - generalDataSource.listener = null - dataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/SettingsController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/SettingsController.kt index 935eb08bd..bc5968481 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/SettingsController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/SettingsController.kt @@ -242,8 +242,6 @@ class SettingsController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -256,19 +254,15 @@ class SettingsController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - generalDataSource.listener = null - dataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/changepassword/ChangePasswordController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/changepassword/ChangePasswordController.kt index 4d67dbce1..16f34fa62 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/changepassword/ChangePasswordController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/changepassword/ChangePasswordController.kt @@ -158,8 +158,6 @@ class ChangePasswordController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -290,19 +288,15 @@ class ChangePasswordController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - dataSource.listener = null - generalDataSource.listener = null - } } private fun showSuspendedAccountDialog(){ diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/cloudbackup/CloudBackupController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/cloudbackup/CloudBackupController.kt index c427dedb2..9c4c5b792 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/cloudbackup/CloudBackupController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/cloudbackup/CloudBackupController.kt @@ -273,8 +273,6 @@ class CloudBackupController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -583,19 +581,15 @@ class CloudBackupController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - dataSource.listener = null - generalDataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/devices/DevicesController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/devices/DevicesController.kt index 430409220..09a59396e 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/devices/DevicesController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/devices/DevicesController.kt @@ -162,8 +162,6 @@ class DevicesController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -381,20 +379,15 @@ class DevicesController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - - if(cleanDataSources) { - dataSource.listener = null - generalDataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/labels/LabelsController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/labels/LabelsController.kt index ae0cd174b..368d9558e 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/labels/LabelsController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/labels/LabelsController.kt @@ -146,8 +146,6 @@ class LabelsController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -367,19 +365,15 @@ class LabelsController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - dataSource.listener = null - generalDataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/pinlock/PinLockController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/pinlock/PinLockController.kt index 83f2ac3b6..9e8ba4c06 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/pinlock/PinLockController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/pinlock/PinLockController.kt @@ -142,7 +142,6 @@ class PinLockController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -219,18 +218,15 @@ class PinLockController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - generalDataSource.listener = null - } } private val webSocketEventListener = object : WebSocketEventListener { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/privacy/PrivacyController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/privacy/PrivacyController.kt index a52ed68b8..05894156c 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/privacy/PrivacyController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/privacy/PrivacyController.kt @@ -141,7 +141,6 @@ class PrivacyController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -275,18 +274,15 @@ class PrivacyController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - generalDataSource.listener = null - } } private fun showSuspendedAccountDialog(){ diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/profile/ProfileController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/profile/ProfileController.kt index 11dd3ca68..124a09ddb 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/profile/ProfileController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/profile/ProfileController.kt @@ -256,8 +256,6 @@ class ProfileController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -478,19 +476,15 @@ class ProfileController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - dataSource.listener = null - generalDataSource.listener = null - } } private fun setBitmapOnProfileImage(imagePath: String){ diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/recovery_email/RecoveryEmailController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/recovery_email/RecoveryEmailController.kt index 01d07985d..d2ed7b63b 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/recovery_email/RecoveryEmailController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/recovery_email/RecoveryEmailController.kt @@ -191,8 +191,6 @@ class RecoveryEmailController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -430,19 +428,15 @@ class RecoveryEmailController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - dataSource.listener = null - generalDataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/replyto/ReplyToController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/replyto/ReplyToController.kt index a0e9d104a..1082fa32c 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/replyto/ReplyToController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/replyto/ReplyToController.kt @@ -150,8 +150,6 @@ class ReplyToController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(dataSource.listener == null) dataSource.listener = dataSourceListener - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -244,19 +242,15 @@ class ReplyToController( } override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - dataSource.listener = null - generalDataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/settings/syncing/SyncingController.kt b/src/main/kotlin/com/criptext/mail/scenes/settings/syncing/SyncingController.kt index 91a1e12d1..944930ed1 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/settings/syncing/SyncingController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/settings/syncing/SyncingController.kt @@ -85,7 +85,6 @@ class SyncingController( } override fun onResume(activityMessage: ActivityMessage?): Boolean { - if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener websocketEvents.setListener(webSocketEventListener) return false } @@ -203,18 +202,15 @@ class SyncingController( override fun onPause() { - cleanup(false) + cleanup() } override fun onStop() { - cleanup(true) + cleanup() } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(){ websocketEvents.clearListener(webSocketEventListener) - if(cleanDataSources){ - generalDataSource.listener = null - } } override fun onBackPressed(): Boolean { diff --git a/src/main/kotlin/com/criptext/mail/scenes/signin/SignInSceneController.kt b/src/main/kotlin/com/criptext/mail/scenes/signin/SignInSceneController.kt index 20fda6e81..34ad8ad49 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/signin/SignInSceneController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/signin/SignInSceneController.kt @@ -844,9 +844,9 @@ class SignInSceneController( cleanup(true) } - private fun cleanup(cleanDataSources: Boolean){ + private fun cleanup(fullCleanup: Boolean){ stopWebSocket() - if(cleanDataSources){ + if(fullCleanup){ scene.signInUIObserver = null } }