Skip to content

Commit

Permalink
Renamed presenter's methods to attachView() and detachView()
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Apr 1, 2015
1 parent 77a54f0 commit a9182d4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public abstract class MvpActivity<P extends MvpPresenter> extends MosbyActivity
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
presenter = createPresenter();
presenter.setView(this);
presenter.attachView(this);
}

@Override protected void onDestroy() {
super.onDestroy();
presenter.onDestroy(false);
presenter.detachView(false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MvpBasePresenter<V extends MvpView> implements MvpPresenter<V> {

private WeakReference<V> viewRef;

@Override public void setView(V view) {
@Override public void attachView(V view) {
viewRef = new WeakReference<V>(view);
}

Expand All @@ -54,7 +54,7 @@ protected boolean isViewAttached() {
return viewRef != null && viewRef.get() != null;
}

@Override public void onDestroy(boolean retainInstance) {
@Override public void detachView(boolean retainInstance) {
if (viewRef != null) {
viewRef.clear();
viewRef = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public abstract class MvpFragment<P extends MvpPresenter> extends MosbyFragment
throw new NullPointerException("Presenter is null! Do you return null in createPresenter()?");
}
}
presenter.setView(this);
presenter.attachView(this);
}

@Override public void onDestroyView() {
super.onDestroyView();
presenter.onDestroy(getRetainInstance());
presenter.detachView(getRetainInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public interface MvpPresenter<V extends MvpView> {
/**
* Set or attach the view to this presenter
*/
public void setView(V view);
public void attachView(V view);

/**
* Will be called if the view has been destroyed. Typically this method will be invoked from
* <code>Activity.onDestroy()</code> or <code>Fragment.onDestroyView()</code>
* <code>Activity.detachView()</code> or <code>Fragment.onDestroyView()</code>
*/
public void onDestroy(boolean retainInstance);
public void detachView(boolean retainInstance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public void testOnDestroy(){
noViewAttached();
setView(view);
attachView(view);
Assert.assertTrue(isViewAttached());
Assert.assertNotNull(getView());
Assert.assertEquals(getView(), view);
onDestroy(true);
detachView(true);
noViewAttached();
setView(view);
onDestroy(false);
attachView(view);
detachView(false);
noViewAttached();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class MvpBaseRxPresenter<V extends MvpView, M> extends Subscribe

private WeakReference<V> viewRef;

@Override public void setView(V view) {
@Override public void attachView(V view) {
viewRef = new WeakReference<V>(view);
}

Expand All @@ -60,7 +60,7 @@ protected boolean isViewAttached() {
return viewRef != null && viewRef.get() != null;
}

@Override public void onDestroy(boolean retainInstance) {
@Override public void detachView(boolean retainInstance) {
if (viewRef != null) {
viewRef.clear();
viewRef = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public void loadCountries(final boolean pullToRefresh) {
countriesLoader.execute();
}

@Override public void onDestroy(boolean retainInstance) {
super.onDestroy(retainInstance);
@Override public void detachView(boolean retainInstance) {
super.detachView(retainInstance);

if (!retainInstance && countriesLoader != null) {
countriesLoader.cancel(true);
Log.d(TAG, "onDestroy() --> cancel Loader");
Log.d(TAG, "detachView() --> cancel Loader");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void startMvpTests(boolean pullToRefreshSupported) {
//
beforeTestNotFailing();
V view = createViewMock();
presenter.setView(view);
presenter.attachView(view);
loadData(presenter, false);
verify(view, never()).showError(any(Exception.class), anyBoolean());
verify(view, times(1)).showLoading(false);
Expand All @@ -86,7 +86,7 @@ protected void startMvpTests(boolean pullToRefreshSupported) {
// Load successfully, pull to refresh
//
view = createViewMock();
presenter.setView(view);
presenter.attachView(view);
loadData(presenter, true);
verify(view, never()).showError(any(Exception.class), anyBoolean());
verify(view, times(1)).showLoading(true);
Expand All @@ -101,7 +101,7 @@ protected void startMvpTests(boolean pullToRefreshSupported) {
beforeTestFailing();
view = createViewMock();
presenter = freshPresenter();
presenter.setView(view);
presenter.attachView(view);
loadData(presenter, false);
verify(view, times(1)).showLoading(false);
verify(view, times(1)).showError(any(Exception.class), Matchers.eq(false));
Expand All @@ -111,7 +111,7 @@ protected void startMvpTests(boolean pullToRefreshSupported) {

if (pullToRefreshSupported) {
view = createViewMock();
presenter.setView(view);
presenter.attachView(view);
loadData(presenter, true);
verify(view, times(1)).showLoading(true);
verify(view, times(1)).showError(any(Exception.class), Matchers.eq(true));
Expand Down

0 comments on commit a9182d4

Please sign in to comment.