Lilly
04/25/2019, 10:39 AMEventHandler
. Im working with Kotlin + Dagger 2 (not dagger-android) with currently one simple Component
which is built in application class. EventHandler
needs the activity or at least some views and I will inject it into my activity so its a circular dependency. Is there a better way to do this or to avoid the circular dependency?rook
04/25/2019, 2:56 PMEventHandler
Lilly
04/25/2019, 8:44 PMactivity.fragment_navhost.findNavController().navigate(destinationId)
As you can see, I need either the activity or the view. I also handling other events here.rook
04/25/2019, 9:00 PMdestinationId
that wayLilly
04/25/2019, 10:07 PMLilly
04/25/2019, 10:08 PMEventHandler
class implements an NavigationEvent
interface and some other eventsLilly
04/26/2019, 11:43 AMrook
04/26/2019, 3:33 PMinterface NavigableView { fun navigate(navigationKey: String) }
interface MyView : NavigableView
class EventHandler() {
var currentView: NavigableView? = null
fun navigate(key: String) { currentView.navigate(key) }
}
class MyActivity() : Activity, MyView {
override fun navigate(navigationKey: String){
//navigate somewhere
}
}
Lilly
04/26/2019, 4:49 PMcurrentView
in my activity like:
mEventHandler.currentView = this
My Code looks currently like this:
class MainActivity : BaseActivity(), NavigationEvent {
override fun startFragment(destinationId: Int) {
this.fragment_navhost.findNavController().navigate(destinationId)
}
And I just want to move the NavigationEvent
implementation to the EventHandler
rook
04/26/2019, 6:18 PMLilly
04/26/2019, 8:19 PMrook
04/26/2019, 8:54 PMEventHandler
to every view, and at the entry point of every view, have it set the currentView
on the EventHandler
to itself
override fun onStart() {
eventHandler.currentView = this
}
Lilly
04/26/2019, 9:05 PMfragment_navhost
Lilly
04/26/2019, 9:24 PMrook
04/26/2019, 10:03 PMLilly
04/26/2019, 10:29 PM