Redgram / redgram-for-reddit

An Open-Sourced Android Reddit Client
GNU General Public License v3.0
102 stars 19 forks source link

Organizing Views and Presenters #38

Closed mhdatie closed 7 years ago

mhdatie commented 8 years ago

ContentView is extended by both the views of Activities and Fragments that are part of a component. The interface method getContentContext() returns a BaseContextView which calls either getBaseActivity() or getBaseFragment(), which are implemented by the base activity/fragment, depending on the implementing view class.

ContentSubView is implemented by custom views that are used as part of activity or fragment layouts and are part of a sub-component. It extends ContentView. The method setBaseContextView(BaseContextView baseContextView) helps identify whether the custom view is part of an Activity or a Fragment for the RxLifeCycle, since Android's getContext() can never be a Fragment.

BaseContextView is only implemented by BaseActivity and BaseFragment, as well as 'SettingsActivity' which isn't part of a component.

BaseView is extended by all views.


Adding BasePresenter interface to make registerForEvents() and unregisterForEvents available in all sub presenters.


WARNING: Initial commit is not tested yet

mhdatie commented 8 years ago

Right now custom views do a simple check to use the appropriate RxLifecycle...would be nice to move this a generic helper

https://github.com/Redgram/redgram-for-reddit/blob/e2b6099fb8e8c380543bc578c2863e7daba1631f/Redgram/app/src/main/java/com/matie/redgram/data/managers/presenters/UserListPresenterImpl.java#L70

mhdatie commented 8 years ago

This answer on stack overflow explains how to access a Fragment from a custom view: http://stackoverflow.com/a/20304367/2898754

The logic in e2b6099 should provide a cleaner approach because we are referencing interfaces and dealing directly with views and presenters.