I like MVP concept, it helps me a lot to organize a code, but every time when i need to get a result from external app, from dialog, or request permission, I confront the same question - which component of architecture should care about this?
For example, we need to implement following behaviour:
So, we can do smth like this (also decide that Fragment implements View, contains link to Presenter and sends UI event to it):
interface View {
void showRecognizer();//2
void showChooseDialog(List<String> items);//4
}
interface Presenter {
void onButtonClick();//1
void onRecognizerResult(List<String> results);//3
void onResultChosen(String result);//5
}
Ok, it will work, but we have some problems:
So, I want to know your opinion about this, how it can be done better (or maybe you think this is ok)?
And generally speaking: starting dialogs and activities, requesting permissions, handling results, whose duty it is from the point of MVP and clean architecture?
Any thoughts or suggestions are encouraged. Please help me to clarify this, thanks.
My 5 cents about MVP:
Some things are just not avoidable in View part, like starting and listening to some services (example: google maps or places).
When doing something like that, I try to leave as little logic in View and notify Presenter of any interaction (even if not useful at that moment) and then returning the action that is needed to View.
My listeners usually trigger presenter and nothing else. Then presenter triggers the view to do some function. This may be an overkill but I don't want my presenters to feel left out.
In your case, View would start a dialog and/or permission request but presenter would order it to do so. Then when the results come back, give them to Presenter to decide what to do with it (as long as you don't pass Android stuff like views).
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With