0

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

  • MainActivity - The activity class, holds a listview.
  • MainPresenter - interface, holding a setup container method, and a refresh one
  • MainPresenterImpl - the implementation of the presenter
  • MainView - interface for the MainActivity (for mvp)
  • Note_Container - Contains the NoteHandler to load-save notes, creates/stores the adapter and can make changes
  • Ignore noteactivity its empty
  • di folder is for dependency injection
  • models has only a note class that holds two strings
  • NoteHandler - Contains the NoteRepository and handles exceptions whenever they're thrown.
  • NoteRepository - Saves and loads the notes from a file using gson library.

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?

Punit
  • 324
  • 1
  • 4
  • 17
  • Nice setup. A good approach is to let your presenter delegate most tasks. onXXClicked in the presenter calls something on either a view, a controller or some other class. In this case, a view that navigates your app somewhere else. I would evade having a reference to the context in your presenter (appart from the attached view). – Frank Sep 26 '17 at 15:23

1 Answers1

0

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

Leandro Borges Ferreira
  • 12,422
  • 10
  • 53
  • 73