Listener interfaces have mixed responsibilities
The UI makes heavy use of listener interfaces that inherit from either DestroyableContext or BaseFragmentListener. These are used for various purposes:
- Callbacks from a controller to the UI (e.g.
TransportStateListener#stateUpdate()
) - Injecting dependencies into fragments (
BaseFragmentListener#getActivityComponent()
) - Manipulating other parts of the UI (e.g.
CreateGroupListener#showSoftKeyboard()
) - Running tasks (
DestroyableContext#runOnUiThreadUnlessDestroyed()
,BaseFragmentListener#runOnDbThread()
(deprecated))
These different purposes would ideally be separated into different interfaces. Maybe it would clarify things if communication from controllers back to the UI used the "listener" name and communication between fragments and their activities used some other name.
Listeners are usually provided by casting an Activity or Context (passed to ActivityLifecycleController#onActivityCreate()
or Fragment#onAttach()
) to an arbitrary listener interface. This is a bit of a hack - it would be nice if we could provide listeners in a type-safe way, for example by injection.
Related to #752 (closed).