Skip to content

Commit

Permalink
Removing Data Source listeners manually is not really necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeblacio committed Oct 18, 2019
1 parent 6813197 commit d2fb332
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -364,7 +357,7 @@ class LinkingController(


override fun onStop() {
cleanup(true)
cleanup()
}

override fun onBackPressed(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class EmailSourceController(
}

override fun onResume(activityMessage: ActivityMessage?): Boolean {
if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener
return false
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class PinLockController(
}

override fun onResume(activityMessage: ActivityMessage?): Boolean {
if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener
websocketEvents.setListener(webSocketEventListener)
return false
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class PrivacyController(
}

override fun onResume(activityMessage: ActivityMessage?): Boolean {
if(generalDataSource.listener == null) generalDataSource.listener = generalDataSourceListener
websocketEvents.setListener(webSocketEventListener)
return false
}
Expand Down Expand Up @@ -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(){
Expand Down
Loading

0 comments on commit d2fb332

Please sign in to comment.