implements Interactor
{
8 |
9 | private P subscribedPresenter;
10 |
11 | public BaseInteractor() {
12 |
13 | }
14 |
15 | @Override
16 | public P getPresenter() {
17 | return subscribedPresenter;
18 | }
19 |
20 | @Override
21 | public boolean isPresenterSubscribed() {
22 | return subscribedPresenter != null;
23 | }
24 |
25 | @Override
26 | public void subscribePresenter(P presenter) {
27 | this.subscribedPresenter = presenter;
28 | }
29 |
30 | @Override
31 | public void unsubscribePresenter() {
32 | this.subscribedPresenter = null;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lucasurbas/search/architecture/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.lucasurbas.search.architecture;
2 |
3 | import android.support.annotation.Nullable;
4 |
5 | import com.hannesdorfmann.mosby.mvp.MvpBasePresenter;
6 |
7 | import java.lang.ref.WeakReference;
8 |
9 | /**
10 | * Created by lucas.urbas on 29/08/15.
11 | */
12 | public abstract class BasePresenter extends MvpBasePresenter {
7 |
8 | P getPresenter();
9 |
10 | boolean isPresenterSubscribed();
11 |
12 | void subscribePresenter(P presenter);
13 |
14 | void unsubscribePresenter();
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lucasurbas/search/architecture/PresenterForInteractor.java:
--------------------------------------------------------------------------------
1 | package com.lucasurbas.search.architecture;
2 |
3 | /**
4 | * Created by lucas.urbas on 29/08/15.
5 | */
6 | public interface PresenterForInteractor {
7 |
8 | I getInteractor();
9 |
10 | I createInteractor();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lucasurbas/search/architecture/PresenterForView.java:
--------------------------------------------------------------------------------
1 | package com.lucasurbas.search.architecture;
2 |
3 | import com.hannesdorfmann.mosby.mvp.MvpPresenter;
4 |
5 | /**
6 | * Created by Lucas on 29/08/15.
7 | */
8 | public interface PresenterForViewnull
, if view is not attached, otherwise the concrete view instance
58 | */
59 | @Nullable
60 | protected V getView() {
61 | return viewRef == null ? null : viewRef.get();
62 | }
63 |
64 | /**
65 | * Checks if a view is attached to this presenter. You should always call this method before
66 | * calling {@link #getView()} to get the view instance.
67 | */
68 | protected boolean isViewAttached() {
69 | return viewRef != null && viewRef.get() != null;
70 | }
71 |
72 | @Override
73 | public void detachView(boolean retainInstance) {
74 | if (viewRef != null) {
75 | viewRef.clear();
76 | viewRef = null;
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lucasurbas/search/architecture/Interactor.java:
--------------------------------------------------------------------------------
1 | package com.lucasurbas.search.architecture;
2 |
3 | /**
4 | * Created by lucas.urbas on 29/08/15.
5 | */
6 | public interface Interactor