Generic Way to do the mvp with hilt
Closed this issue · 3 comments
Hi,
I read the code and have few questions.
As there is one main Contract in this code which is associated to a specific views/presenter and for that you did the bindings in the module class.
For the increasing number of activities, don't you think it is not a good idea to bind every time a new activity and presenter in modules.
I am just curious to know, is there any way to avoid the bindings for every activity/presenter again and again with hilt.
Hello @shehramjamil, this is because we are using MVP and we work with interfaces and Hilt is not smart enough, we have to tell how to bind these interfaces. Hilt is done to facilitate the ViewModel stuff, to avoid that boilerplate of factory, keys, etc.
What we could do is instead of binding the Activity to pass it as a presenter parameter, we could do like attachView
or dettachView
and avoid that binding.
When you say
don't you think it is not a good idea to bind every time a new activity and presenter in modules
What do you mean? Do you know any technique to avoid that? You propose to bind the new activities/presenter in other place?
I used to follow the same technique as you mentioned which is attaching and detaching views and I use abstract class to do so. In that way, we can just pass our interfaces to abstract classes and can bind them.
But what I think is , using this approach is very lengthy and takes a lot of code.
I recently studied the MVVM with hilt and Livedata and it is faster way to start a code from scratch and we can get rid of a lot of code.
You can see my repo "News-reader". I am still working on it.
I believe the MVVM with the repository pattern given by the developers guide is optimal approach.
I agree, but the purpose of this repository is to make it for MVP projects because there are plenty of repositories with MVVM - LiveData, and we wanted to create an MVP sample for those who want to use Hilt on an MVP pattern project.
I close this issue, if you know any way to avoid that boilerplate code of interfaces let us know or even create a Pull Request.
Thanks for the feedback though.