-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
71 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/org/xtimms/ridebus/ui/base/controller/controllerLeakWatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.xtimms.ridebus.ui.base.controller | ||
|
||
import android.view.View | ||
import com.bluelinelabs.conductor.Controller | ||
import com.bluelinelabs.conductor.ControllerChangeHandler | ||
import com.bluelinelabs.conductor.ControllerChangeType | ||
import leakcanary.AppWatcher | ||
|
||
private class RefWatchingControllerLifecycleListener : Controller.LifecycleListener() { | ||
|
||
private var hasExited = false | ||
|
||
override fun postDestroy(controller: Controller) { | ||
if (hasExited) { | ||
controller.expectWeaklyReachable() | ||
} | ||
} | ||
|
||
override fun preDestroyView(controller: Controller, view: View) { | ||
AppWatcher.objectWatcher.expectWeaklyReachable( | ||
view, | ||
"A destroyed controller view should have only weak references." | ||
) | ||
} | ||
|
||
override fun onChangeEnd( | ||
controller: Controller, | ||
changeHandler: ControllerChangeHandler, | ||
changeType: ControllerChangeType | ||
) { | ||
hasExited = !changeType.isEnter | ||
if (controller.isDestroyed) { | ||
controller.expectWeaklyReachable() | ||
} | ||
} | ||
|
||
private fun Controller.expectWeaklyReachable() { | ||
AppWatcher.objectWatcher.expectWeaklyReachable( | ||
this, | ||
"A destroyed controller should have only weak references." | ||
) | ||
} | ||
} | ||
|
||
fun Controller.watchForLeaks() { | ||
addLifecycleListener(RefWatchingControllerLifecycleListener()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters