diff --git a/rainbowmvp/build.gradle b/rainbowmvp/build.gradle index c027639..17c486f 100644 --- a/rainbowmvp/build.gradle +++ b/rainbowmvp/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 24 - versionCode 3 - versionName "1.2" + versionCode 4 + versionName "1.2.1" } buildTypes { release { diff --git a/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/ViewState.java b/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/ViewState.java index 06ffe6a..4029682 100644 --- a/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/ViewState.java +++ b/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/ViewState.java @@ -24,8 +24,8 @@ * FINISH - use in end of work any operation * SUCCESS - use for show result of any operation * ERROR - use for show error of any operation - * EMPTY - use for default state if not necessary show any information + * NOTHING - use for default state if not necessary show any information */ public enum ViewState { - START, IN_PROGRESS, FINISH, SUCCESS, ERROR, EMPTY + START, IN_PROGRESS, FINISH, SUCCESS, ERROR, NOTHING } diff --git a/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/base/BasePresenter.java b/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/base/BasePresenter.java index 916d396..23a84f3 100644 --- a/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/base/BasePresenter.java +++ b/rainbowmvp/src/main/java/com/ne1c/rainbowmvp/base/BasePresenter.java @@ -16,16 +16,19 @@ package com.ne1c.rainbowmvp.base; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + import com.ne1c.rainbowmvp.ViewState; import com.ne1c.rainbowmvp.ViewStateListener; public abstract class BasePresenter { private V mView; - private ViewState mLastState = ViewState.EMPTY; + private ViewState mLastState = ViewState.NOTHING; private ViewStateListener mViewStateListener; - public void bindView(V view) { + public void bindView(@NonNull V view) { mView = view; if (mViewStateListener != null) { @@ -41,6 +44,7 @@ public void onDestroy() { removeViewStateListener(); } + @Nullable public V getView() { return mView; } @@ -48,15 +52,7 @@ public V getView() { public void setViewState(ViewState state) { mLastState = state; - if (mViewStateListener != null) { - mViewStateListener.stateChanged(state); - } - } - - public void setViewState(ViewState state, boolean callListener) { - mLastState = state; - - if (callListener && mViewStateListener != null) { + if (mViewStateListener != null && mView != null) { mViewStateListener.stateChanged(state); } } diff --git a/sample/src/main/java/com/ne1c/rainbowmvpexample/presenter/MainPresenter.java b/sample/src/main/java/com/ne1c/rainbowmvpexample/presenter/MainPresenter.java index 12287af..8f203df 100644 --- a/sample/src/main/java/com/ne1c/rainbowmvpexample/presenter/MainPresenter.java +++ b/sample/src/main/java/com/ne1c/rainbowmvpexample/presenter/MainPresenter.java @@ -68,7 +68,7 @@ public void call(ArrayList repoModels) { if (getView() != null) { getView().showRepos(repoModels); getView().hideProgress(); - setViewState(ViewState.EMPTY); + setViewState(ViewState.NOTHING); } } }, new Action1() { @@ -80,7 +80,7 @@ public void call(Throwable throwable) { getView().showError(R.string.something_happened); getView().hideProgress(); - setViewState(ViewState.EMPTY); + setViewState(ViewState.NOTHING); } } });