You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't so much of an issue but more of a design question. How would you go about reusing common views in u2020-mvp?
For example, I'd like to create a common LoginView which can be shown in different activities/fragments. The associated LoginComponent, LoginPresenter, and LoginModule all use @LoginScope. The idea here is to have all the functionality of logging-in encapsulated in LoginView which I can use at anytime.
I tried to accomplish this in few ways and ran into issues. For the examples below, let's assume we want to put LoginView into our MainActivity.
Include LoginModule in MainComponent as follows. I ran into issues with Dagger complaining about @LoginScope being used in @MainScope.
Defining LoginComponent as the "parent" component and MainComponent as a subcomponent. This solution is not desirable either because the common component acts as the "parent" component. Also you run into the issue of not being able to use multiple common components.
Is there no proper way to use common views in u2020-mvp?
The other option is to include the common view as part of a Fragment however there isn't an example here of mvp with Dagger injection of Fragments, views and its presenters.
The text was updated successfully, but these errors were encountered:
@charleschenster The u2020-mvp just a sample. As you can notice it doesn't have a right mpv implementation. For example Mosby has more clearly one. But u2020-mvp still can cover your goals.
I might offer you the next way:
Create different presenters for each place where you will use this view.
Create PresenterImpl interface . The our view will work with it.
Create ViewImpl interface. Our view will implement it.
Move the main code to ParentPresenter that implements PresenterImpl interface. ParentPresenter will work with ViewImpl.
For each using of View we must create a new Presenter class that is extended from ParentPresenter, new Scope and Module, of course.
And now each presenter creates through DI. For with way you should invoke presenter constructor clearly and provide it through appropriate module.
Such way is requires a more code, but it works.
For Fragments you can use our new realization of ComponentFinder class that supports of them:
public class ComponentFinder {
private ComponentFinder(){}
@SuppressWarnings("unchecked")
public static <C> C findActivityComponent(Context context) {
return ((HasComponent<C>) context).getComponent();
}
@SuppressWarnings({"unchecked", "ResourceType"})
public static <C> C findFragmentComponent(Context context) {
final HasPanel hasPanel = (HasPanel) context;
PanelScreenService panelScreenService = (PanelScreenService) context.getSystemService(PanelScreenService.NAME);
final String fragmentName = panelScreenService.getScreenName();
final Fragment fragment = hasPanel.getSupportFragmentManager().findFragmentByTag(fragmentName);
if (fragment == null) {
throw new IllegalStateException("No fragments added");
}
return ((HasComponent<C>) fragment).getComponent();
}
}
This isn't so much of an issue but more of a design question. How would you go about reusing common views in u2020-mvp?
For example, I'd like to create a common LoginView which can be shown in different activities/fragments. The associated LoginComponent, LoginPresenter, and LoginModule all use @LoginScope. The idea here is to have all the functionality of logging-in encapsulated in LoginView which I can use at anytime.
I tried to accomplish this in few ways and ran into issues. For the examples below, let's assume we want to put LoginView into our MainActivity.
Is there no proper way to use common views in u2020-mvp?
The other option is to include the common view as part of a Fragment however there isn't an example here of mvp with Dagger injection of Fragments, views and its presenters.
The text was updated successfully, but these errors were encountered: