I've been trying to make a simple notepad app (my first app), using MVP
and dagger
.
I've understood most of the stuff but I'm a little bit lost if I have multiple behaviors. I'll explain.
My project hierarchy goes like this :
Click here
After explaining all of these you should (probably) have understood how the project works (feel free to criticize the hierarchy).
Now I want to add a button that creates a note. I'll just add the listener on the mainactivity
and redirect it to the Presenter...
But will the presenter handle the code to add a new note (Start a new intent, etc) or should I make a new class that will independently just handle this stuff?
If I want to add more buttons in the future, for example remove-all-notes or launch a help dialog, should I make for each button a class that will handle the code?
How can I organize something like that?
Navigation is not formally addressed in the MVP pattern. Well, I think there are two good ways:
1 - You can create a a Navigator/Router to handle the navigation for you. So the presenter address all this logic to the navigator or...
2 - You can handle screen changes in the Activity. I really believe that the screen change is a View's responsibility, so all you the is to pass the navigation command to the View. Like:
interface MainView{
void navigateToAddCardScreen()
void navigateToLoginScreen()
void navigateSomeScreen()
}
I prefer the second option. The navigator makes the code too much granular for me...
I hope I could help