diff --git a/app/src/main/java/json/chao/com/wanandroid/app/GeeksApp.java b/app/src/main/java/json/chao/com/wanandroid/app/GeeksApp.java index 8a54e3d..aebb055 100644 --- a/app/src/main/java/json/chao/com/wanandroid/app/GeeksApp.java +++ b/app/src/main/java/json/chao/com/wanandroid/app/GeeksApp.java @@ -3,6 +3,7 @@ import android.app.Application; import android.content.Context; import android.database.sqlite.SQLiteDatabase; +import android.support.v4.BuildConfig; import android.support.v4.content.ContextCompat; import com.orhanobut.logger.AndroidLogAdapter; @@ -16,7 +17,6 @@ import com.squareup.leakcanary.RefWatcher; import com.tencent.bugly.crashreport.CrashReport; -import json.chao.com.wanandroid.BuildConfig; import json.chao.com.wanandroid.R; import json.chao.com.wanandroid.core.dao.DaoMaster; import json.chao.com.wanandroid.core.dao.DaoSession; diff --git a/app/src/main/java/json/chao/com/wanandroid/base/activity/AbstractSimpleActivity.java b/app/src/main/java/json/chao/com/wanandroid/base/activity/AbstractSimpleActivity.java index 21c0517..028397b 100644 --- a/app/src/main/java/json/chao/com/wanandroid/base/activity/AbstractSimpleActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/base/activity/AbstractSimpleActivity.java @@ -29,9 +29,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutId()); unBinder = ButterKnife.bind(this); - //LeakCanary -// RefWatcher refWatcher = GeeksApp.getRefWatcher(this); -// refWatcher.watch(this); mActivity = this; onViewCreated(); ActivityCollector.getInstance().addActivity(this); diff --git a/app/src/main/java/json/chao/com/wanandroid/base/activity/BaseActivity.java b/app/src/main/java/json/chao/com/wanandroid/base/activity/BaseActivity.java index b71d507..55719f3 100644 --- a/app/src/main/java/json/chao/com/wanandroid/base/activity/BaseActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/base/activity/BaseActivity.java @@ -72,6 +72,27 @@ public void showCancelCollectFail() { CommonUtils.showMessage(this, getString(R.string.cancel_collect_fail)); } + @Override + public void showCollectSuccess() { + + } + + @Override + public void showCancelCollectSuccess() { + + } + + @Override + public void showLoginView() { + + } + + @Override + public void showLogoutView() { + + } + + /** * 注入当前Activity所需的依赖 */ diff --git a/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleDialogFragment.java b/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleDialogFragment.java index 836012a..1a31324 100644 --- a/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleDialogFragment.java +++ b/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleDialogFragment.java @@ -34,9 +34,6 @@ public abstract class AbstractSimpleDialogFragment extends DialogFragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { mRootView = inflater.inflate(getLayout(), container, false); unBinder = ButterKnife.bind(this, mRootView); - //LeakCanary -// RefWatcher refWatcher = GeeksApp.getRefWatcher(getActivity()); -// refWatcher.watch(this); mCompositeDisposable = new CompositeDisposable(); initEventAndData(); @@ -52,6 +49,14 @@ public void onDestroyView() { unBinder.unbind(); } + @Override + public void onDestroy() { + super.onDestroy(); + //LeakCanary + RefWatcher refWatcher = GeeksApp.getRefWatcher(getActivity()); + refWatcher.watch(this); + } + /** * 获取当前Activity的UI布局 * diff --git a/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleFragment.java b/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleFragment.java index a33362a..64c5b64 100644 --- a/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleFragment.java +++ b/app/src/main/java/json/chao/com/wanandroid/base/fragment/AbstractSimpleFragment.java @@ -35,9 +35,6 @@ public abstract class AbstractSimpleFragment extends SupportFragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(getLayout(), container, false); unBinder = ButterKnife.bind(this, view); - //LeakCanary -// RefWatcher refWatcher = GeeksApp.getRefWatcher(_mActivity); -// refWatcher.watch(this); mCompositeDisposable = new CompositeDisposable(); return view; @@ -52,6 +49,14 @@ public void onDestroyView() { unBinder.unbind(); } + @Override + public void onDestroy() { + super.onDestroy(); + //LeakCanary + RefWatcher refWatcher = GeeksApp.getRefWatcher(_mActivity); + refWatcher.watch(this); + } + @Override public void onLazyInitView(@Nullable Bundle savedInstanceState) { super.onLazyInitView(savedInstanceState); diff --git a/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseDialogFragment.java b/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseDialogFragment.java index 13f99d2..4123175 100644 --- a/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseDialogFragment.java +++ b/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseDialogFragment.java @@ -1,8 +1,6 @@ package json.chao.com.wanandroid.base.fragment; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.view.View; import javax.inject.Inject; @@ -82,6 +80,26 @@ public void showCancelCollectFail() { } } + @Override + public void showCollectSuccess() { + + } + + @Override + public void showCancelCollectSuccess() { + + } + + @Override + public void showLoginView() { + + } + + @Override + public void showLogoutView() { + + } + /** * 注入当前Fragment所需的依赖 */ diff --git a/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseFragment.java b/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseFragment.java index 693468f..bf308fa 100644 --- a/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseFragment.java +++ b/app/src/main/java/json/chao/com/wanandroid/base/fragment/BaseFragment.java @@ -78,6 +78,26 @@ public void showCancelCollectFail() { CommonUtils.showMessage(_mActivity, getString(R.string.cancel_collect_fail)); } + @Override + public void showCollectSuccess() { + + } + + @Override + public void showCancelCollectSuccess() { + + } + + @Override + public void showLoginView() { + + } + + @Override + public void showLogoutView() { + + } + /** * 注入当前Fragment所需的依赖 */ diff --git a/app/src/main/java/json/chao/com/wanandroid/base/view/BaseView.java b/app/src/main/java/json/chao/com/wanandroid/base/view/BaseView.java index 28d7de6..f5bf091 100644 --- a/app/src/main/java/json/chao/com/wanandroid/base/view/BaseView.java +++ b/app/src/main/java/json/chao/com/wanandroid/base/view/BaseView.java @@ -27,6 +27,16 @@ public interface BaseView { */ void showLoading(); + /** + * Show login view + */ + void showLoginView(); + + /** + * Show logout view + */ + void showLogoutView(); + /** * Show collect fail */ @@ -37,4 +47,14 @@ public interface BaseView { */ void showCancelCollectFail(); + /** + * Show collect success + */ + void showCollectSuccess(); + + /** + * Show cancel collect success + */ + void showCancelCollectSuccess(); + } diff --git a/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyDetailContract.java b/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyDetailContract.java index 1e3c0a5..51f1c94 100644 --- a/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyDetailContract.java +++ b/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyDetailContract.java @@ -12,7 +12,10 @@ public interface KnowledgeHierarchyDetailContract { interface View extends BaseView { - + /** + * Show dismiss detail error view + */ + void showDismissDetailErrorView(); } interface Presenter extends AbstractPresenter { diff --git a/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyListContract.java b/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyListContract.java index 758da5f..ced7c51 100644 --- a/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyListContract.java +++ b/app/src/main/java/json/chao/com/wanandroid/contract/hierarchy/KnowledgeHierarchyListContract.java @@ -44,6 +44,11 @@ interface View extends BaseView { */ void showKnowledgeHierarchyDetailDataFail(); + /** + * Show jump the top + */ + void showJumpTheTop(); + } interface Presenter extends AbstractPresenter { diff --git a/app/src/main/java/json/chao/com/wanandroid/contract/main/CollectContract.java b/app/src/main/java/json/chao/com/wanandroid/contract/main/CollectContract.java index 037ec9e..fbc9468 100644 --- a/app/src/main/java/json/chao/com/wanandroid/contract/main/CollectContract.java +++ b/app/src/main/java/json/chao/com/wanandroid/contract/main/CollectContract.java @@ -34,6 +34,7 @@ interface View extends BaseView { * Show collect list fail */ void showCollectListFail(); + } interface Presenter extends AbstractPresenter { diff --git a/app/src/main/java/json/chao/com/wanandroid/contract/main/MainContract.java b/app/src/main/java/json/chao/com/wanandroid/contract/main/MainContract.java index fe02537..7800862 100644 --- a/app/src/main/java/json/chao/com/wanandroid/contract/main/MainContract.java +++ b/app/src/main/java/json/chao/com/wanandroid/contract/main/MainContract.java @@ -12,7 +12,10 @@ public interface MainContract { interface View extends BaseView { - + /** + * Show dismiss error view + */ + void showDismissErrorView(); } interface Presenter extends AbstractPresenter { diff --git a/app/src/main/java/json/chao/com/wanandroid/contract/project/ProjectListContract.java b/app/src/main/java/json/chao/com/wanandroid/contract/project/ProjectListContract.java index 7f155b2..35f3c4c 100644 --- a/app/src/main/java/json/chao/com/wanandroid/contract/project/ProjectListContract.java +++ b/app/src/main/java/json/chao/com/wanandroid/contract/project/ProjectListContract.java @@ -45,6 +45,11 @@ interface View extends BaseView { */ void showProjectListFail(); + /** + * Show jump to the top + */ + void showJumpToTheTop(); + } interface Presenter extends AbstractPresenter { diff --git a/app/src/main/java/json/chao/com/wanandroid/core/event/CancelCollectSuccessEvent.java b/app/src/main/java/json/chao/com/wanandroid/core/event/CancelCollectSuccessEvent.java deleted file mode 100644 index a2a58d7..0000000 --- a/app/src/main/java/json/chao/com/wanandroid/core/event/CancelCollectSuccessEvent.java +++ /dev/null @@ -1,9 +0,0 @@ -package json.chao.com.wanandroid.core.event; - -/** - * @author quchao - * @date 2018/3/1 - */ - -public class CancelCollectSuccessEvent { -} diff --git a/app/src/main/java/json/chao/com/wanandroid/core/event/CollectEvent.java b/app/src/main/java/json/chao/com/wanandroid/core/event/CollectEvent.java new file mode 100644 index 0000000..47a06d6 --- /dev/null +++ b/app/src/main/java/json/chao/com/wanandroid/core/event/CollectEvent.java @@ -0,0 +1,23 @@ +package json.chao.com.wanandroid.core.event; + +/** + * @author quchao + * @date 2018/3/16 + */ + +public class CollectEvent { + + private boolean isCancelCollectSuccess; + + public CollectEvent(boolean isCancelCollectSuccess) { + this.isCancelCollectSuccess = isCancelCollectSuccess; + } + + public boolean isCancelCollectSuccess() { + return isCancelCollectSuccess; + } + + public void setCancelCollectSuccess(boolean cancelCollectSuccess) { + isCancelCollectSuccess = cancelCollectSuccess; + } +} diff --git a/app/src/main/java/json/chao/com/wanandroid/core/event/CollectSuccessEvent.java b/app/src/main/java/json/chao/com/wanandroid/core/event/CollectSuccessEvent.java deleted file mode 100644 index a62a7c1..0000000 --- a/app/src/main/java/json/chao/com/wanandroid/core/event/CollectSuccessEvent.java +++ /dev/null @@ -1,9 +0,0 @@ -package json.chao.com.wanandroid.core.event; - -/** - * @author quchao - * @date 2018/3/1 - */ - -public class CollectSuccessEvent { -} diff --git a/app/src/main/java/json/chao/com/wanandroid/core/event/LoginEvent.java b/app/src/main/java/json/chao/com/wanandroid/core/event/LoginEvent.java index 1128d6a..b0642fd 100644 --- a/app/src/main/java/json/chao/com/wanandroid/core/event/LoginEvent.java +++ b/app/src/main/java/json/chao/com/wanandroid/core/event/LoginEvent.java @@ -6,4 +6,19 @@ */ public class LoginEvent { + + private boolean isLogin; + + public boolean isLogin() { + return isLogin; + } + + public void setLogin(boolean login) { + isLogin = login; + } + + public LoginEvent(boolean isLogin) { + + this.isLogin = isLogin; + } } diff --git a/app/src/main/java/json/chao/com/wanandroid/core/event/LogoutEvent.java b/app/src/main/java/json/chao/com/wanandroid/core/event/LogoutEvent.java deleted file mode 100644 index c560721..0000000 --- a/app/src/main/java/json/chao/com/wanandroid/core/event/LogoutEvent.java +++ /dev/null @@ -1,9 +0,0 @@ -package json.chao.com.wanandroid.core.event; - -/** - * @author quchao - * @date 2018/2/28 - */ - -public class LogoutEvent { -} diff --git a/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyDetailPresenter.java b/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyDetailPresenter.java index b5b4bec..0a615b1 100644 --- a/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyDetailPresenter.java +++ b/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyDetailPresenter.java @@ -2,9 +2,11 @@ import javax.inject.Inject; +import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.base.presenter.BasePresenter; import json.chao.com.wanandroid.contract.hierarchy.KnowledgeHierarchyDetailContract; +import json.chao.com.wanandroid.core.event.DismissDetailErrorView; /** * @author quchao @@ -21,7 +23,16 @@ public class KnowledgeHierarchyDetailPresenter extends BasePresenter mView.showDismissDetailErrorView())); + } } diff --git a/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyListPresenter.java b/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyListPresenter.java index 2bfc88d..aa3d657 100644 --- a/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyListPresenter.java +++ b/app/src/main/java/json/chao/com/wanandroid/presenter/hierarchy/KnowledgeHierarchyListPresenter.java @@ -2,12 +2,15 @@ import javax.inject.Inject; +import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.base.presenter.BasePresenter; import json.chao.com.wanandroid.contract.hierarchy.KnowledgeHierarchyListContract; import json.chao.com.wanandroid.core.bean.BaseResponse; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; +import json.chao.com.wanandroid.core.event.CollectEvent; +import json.chao.com.wanandroid.core.event.KnowledgeJumpTopEvent; import json.chao.com.wanandroid.utils.RxUtils; import json.chao.com.wanandroid.widget.BaseObserver; @@ -26,6 +29,25 @@ public class KnowledgeHierarchyListPresenter extends BasePresenter !collectEvent.isCancelCollectSuccess()) + .subscribe(collectEvent -> mView.showCollectSuccess())); + + addSubscribe(RxBus.getDefault().toFlowable(CollectEvent.class) + .filter(CollectEvent::isCancelCollectSuccess) + .subscribe(collectEvent -> mView.showCancelCollectSuccess())); + + addSubscribe( RxBus.getDefault().toFlowable(KnowledgeJumpTopEvent.class) + .subscribe(knowledgeJumpTopEvent -> mView.showJumpTheTop())); + } + @Override public void getKnowledgeHierarchyDetailData(int page, int cid) { addSubscribe(mDataManager.getKnowledgeHierarchyDetailData(page, cid) diff --git a/app/src/main/java/json/chao/com/wanandroid/presenter/main/CollectPresenter.java b/app/src/main/java/json/chao/com/wanandroid/presenter/main/CollectPresenter.java index 710672a..86337a3 100644 --- a/app/src/main/java/json/chao/com/wanandroid/presenter/main/CollectPresenter.java +++ b/app/src/main/java/json/chao/com/wanandroid/presenter/main/CollectPresenter.java @@ -3,11 +3,13 @@ import javax.inject.Inject; import json.chao.com.wanandroid.base.presenter.BasePresenter; +import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.contract.main.CollectContract; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.core.bean.BaseResponse; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; +import json.chao.com.wanandroid.core.event.CollectEvent; import json.chao.com.wanandroid.utils.RxUtils; import json.chao.com.wanandroid.widget.BaseObserver; @@ -25,6 +27,18 @@ public class CollectPresenter extends BasePresenter implem mDataManager = dataManager; } + @Override + public void attachView(CollectContract.View view) { + super.attachView(view); + registerEvent(); + } + + private void registerEvent() { + addSubscribe(RxBus.getDefault().toFlowable(CollectEvent.class) + .filter(CollectEvent::isCancelCollectSuccess) + .subscribe(collectEvent -> mView.showCancelCollectSuccess())); + } + @Override public void getCollectList(int page) { addSubscribe(mDataManager.getCollectList(page) diff --git a/app/src/main/java/json/chao/com/wanandroid/presenter/main/MainPresenter.java b/app/src/main/java/json/chao/com/wanandroid/presenter/main/MainPresenter.java index ac14198..6271cd9 100644 --- a/app/src/main/java/json/chao/com/wanandroid/presenter/main/MainPresenter.java +++ b/app/src/main/java/json/chao/com/wanandroid/presenter/main/MainPresenter.java @@ -1,12 +1,14 @@ package json.chao.com.wanandroid.presenter.main; - import javax.inject.Inject; +import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.base.presenter.BasePresenter; import json.chao.com.wanandroid.contract.main.MainContract; +import json.chao.com.wanandroid.core.event.DismissErrorView; +import json.chao.com.wanandroid.core.event.LoginEvent; /** * @author quchao @@ -22,5 +24,24 @@ public class MainPresenter extends BasePresenter implements M this.mDataManager = dataManager; } + @Override + public void attachView(MainContract.View view) { + super.attachView(view); + registerEvent(); + } + + private void registerEvent() { + addSubscribe(RxBus.getDefault().toFlowable(DismissErrorView.class) + .subscribe(dismissErrorView -> mView.showDismissErrorView())); + + addSubscribe( RxBus.getDefault().toFlowable(LoginEvent.class) + .filter(LoginEvent::isLogin) + .subscribe(loginEvent -> mView.showLoginView())); + + addSubscribe(RxBus.getDefault().toFlowable(LoginEvent.class) + .filter(loginEvent -> !loginEvent.isLogin()) + .subscribe(logoutEvent -> mView.showLogoutView())); + } + } diff --git a/app/src/main/java/json/chao/com/wanandroid/presenter/main/SearchListPresenter.java b/app/src/main/java/json/chao/com/wanandroid/presenter/main/SearchListPresenter.java index 5d359f0..01d7183 100644 --- a/app/src/main/java/json/chao/com/wanandroid/presenter/main/SearchListPresenter.java +++ b/app/src/main/java/json/chao/com/wanandroid/presenter/main/SearchListPresenter.java @@ -3,11 +3,13 @@ import javax.inject.Inject; import json.chao.com.wanandroid.base.presenter.BasePresenter; +import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.contract.main.SearchListContract; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.core.bean.BaseResponse; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; +import json.chao.com.wanandroid.core.event.CollectEvent; import json.chao.com.wanandroid.utils.RxUtils; import json.chao.com.wanandroid.widget.BaseObserver; @@ -29,6 +31,17 @@ public SearchListPresenter(DataManager dataManager) { @Override public void attachView(SearchListContract.View view) { super.attachView(view); + registerEvent(); + } + + private void registerEvent() { + addSubscribe(RxBus.getDefault().toFlowable(CollectEvent.class) + .filter(collectEvent -> !collectEvent.isCancelCollectSuccess()) + .subscribe(collectEvent -> mView.showCollectSuccess())); + + addSubscribe(RxBus.getDefault().toFlowable(CollectEvent.class) + .filter(CollectEvent::isCancelCollectSuccess) + .subscribe(collectEvent -> mView.showCancelCollectSuccess())); } @Override diff --git a/app/src/main/java/json/chao/com/wanandroid/presenter/mainpager/MainPagerPresenter.java b/app/src/main/java/json/chao/com/wanandroid/presenter/mainpager/MainPagerPresenter.java index 05cea0e..a78e1ce 100644 --- a/app/src/main/java/json/chao/com/wanandroid/presenter/mainpager/MainPagerPresenter.java +++ b/app/src/main/java/json/chao/com/wanandroid/presenter/mainpager/MainPagerPresenter.java @@ -6,6 +6,7 @@ import io.reactivex.Observable; import json.chao.com.wanandroid.app.Constants; +import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.base.presenter.BasePresenter; import json.chao.com.wanandroid.contract.mainpager.MainPagerContract; @@ -14,6 +15,8 @@ import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; import json.chao.com.wanandroid.core.bean.main.login.LoginResponse; +import json.chao.com.wanandroid.core.event.CollectEvent; +import json.chao.com.wanandroid.core.event.LoginEvent; import json.chao.com.wanandroid.utils.RxUtils; import json.chao.com.wanandroid.widget.BaseObserver; @@ -31,6 +34,27 @@ public class MainPagerPresenter extends BasePresenter im this.mDataManager = dataManager; } + @Override + public void attachView(MainPagerContract.View view) { + super.attachView(view); + registerEvent(); + } + + private void registerEvent() { + addSubscribe(RxBus.getDefault().toFlowable(CollectEvent.class) + .filter(collectEvent -> !collectEvent.isCancelCollectSuccess()) + .subscribe(collectEvent -> mView.showCollectSuccess())); + + addSubscribe(RxBus.getDefault().toFlowable(CollectEvent.class) + .filter(CollectEvent::isCancelCollectSuccess) + .subscribe(collectEvent -> mView.showCancelCollectSuccess())); + + addSubscribe( + RxBus.getDefault().toFlowable(LoginEvent.class) + .filter(LoginEvent::isLogin) + .subscribe(loginEvent -> mView.showLoginView())); + } + @Override public void loadMainPagerData() { String account = mDataManager.getLoginAccount(); diff --git a/app/src/main/java/json/chao/com/wanandroid/presenter/project/ProjectListPresenter.java b/app/src/main/java/json/chao/com/wanandroid/presenter/project/ProjectListPresenter.java index 31cbbf5..e86bf92 100644 --- a/app/src/main/java/json/chao/com/wanandroid/presenter/project/ProjectListPresenter.java +++ b/app/src/main/java/json/chao/com/wanandroid/presenter/project/ProjectListPresenter.java @@ -2,6 +2,7 @@ import javax.inject.Inject; +import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.base.presenter.BasePresenter; import json.chao.com.wanandroid.contract.project.ProjectListContract; @@ -9,6 +10,7 @@ import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; import json.chao.com.wanandroid.core.bean.project.ProjectListResponse; +import json.chao.com.wanandroid.core.event.JumpToTheTopEvent; import json.chao.com.wanandroid.utils.RxUtils; import json.chao.com.wanandroid.widget.BaseObserver; @@ -29,6 +31,12 @@ public class ProjectListPresenter extends BasePresenter mView.showJumpToTheTop())); } diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/activity/KnowledgeHierarchyDetailActivity.java b/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/activity/KnowledgeHierarchyDetailActivity.java index 512ba59..d25ac32 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/activity/KnowledgeHierarchyDetailActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/activity/KnowledgeHierarchyDetailActivity.java @@ -100,10 +100,6 @@ public CharSequence getPageTitle(int position) { RxBus.getDefault().toFlowable(ShowDetailErrorView.class) .filter(showDetailErrorView -> mErrorView != null) .subscribe(showDetailErrorView -> showError()); - - RxBus.getDefault().toFlowable(DismissDetailErrorView.class) - .filter(dismissDetailErrorView -> mErrorView != null) - .subscribe(dismissDetailErrorView -> mErrorView.setVisibility(View.GONE)); } @Override @@ -137,4 +133,12 @@ private void initToolbar() { } + @Override + public void showDismissDetailErrorView() { + if (mErrorView != null) { + mErrorView.setVisibility(View.GONE); + } + } + + } diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/fragment/KnowledgeHierarchyListFragment.java b/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/fragment/KnowledgeHierarchyListFragment.java index 5660903..089cf59 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/fragment/KnowledgeHierarchyListFragment.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/hierarchy/fragment/KnowledgeHierarchyListFragment.java @@ -23,10 +23,7 @@ import json.chao.com.wanandroid.app.Constants; import json.chao.com.wanandroid.base.fragment.BaseFragment; import json.chao.com.wanandroid.contract.hierarchy.KnowledgeHierarchyListContract; -import json.chao.com.wanandroid.core.event.CancelCollectSuccessEvent; -import json.chao.com.wanandroid.core.event.CollectSuccessEvent; import json.chao.com.wanandroid.core.event.DismissDetailErrorView; -import json.chao.com.wanandroid.core.event.KnowledgeJumpTopEvent; import json.chao.com.wanandroid.core.event.ReloadDetailEvent; import json.chao.com.wanandroid.core.event.ShowDetailErrorView; import json.chao.com.wanandroid.presenter.hierarchy.KnowledgeHierarchyListPresenter; @@ -57,7 +54,6 @@ public class KnowledgeHierarchyListFragment extends BaseFragment mAdapter != null && mAdapter.getData().size() > articlePosition) - .subscribe(collectSuccessEvent -> { - mAdapter.getData().get(articlePosition).setCollect(true); - mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); - }); - - RxBus.getDefault().toFlowable(CancelCollectSuccessEvent.class) - .filter(collectSuccessEvent -> mAdapter != null && mAdapter.getData().size() > articlePosition) - .subscribe(collectSuccessEvent -> { - mAdapter.getData().get(articlePosition).setCollect(false); - mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); - }); - - RxBus.getDefault().toFlowable(KnowledgeJumpTopEvent.class) - .filter(knowledgeJumpTopEvent -> mRecyclerView != null) - .subscribe(knowledgeJumpTopEvent -> mRecyclerView.smoothScrollToPosition(0)); - RxBus.getDefault().toFlowable(ReloadDetailEvent.class) .filter(reloadEvent -> mRefreshLayout != null) .subscribe(reloadEvent -> mRefreshLayout.autoRefresh()); @@ -171,6 +149,29 @@ public void showKnowledgeHierarchyDetailDataFail() { CommonUtils.showMessage(_mActivity, getString(R.string.failed_to_obtain_knowledge_data)); } + @Override + public void showJumpTheTop() { + if (mRecyclerView != null) { + mRecyclerView.smoothScrollToPosition(0); + } + } + + @Override + public void showCollectSuccess() { + if (mAdapter != null && mAdapter.getData().size() > articlePosition) { + mAdapter.getData().get(articlePosition).setCollect(true); + mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); + } + } + + @Override + public void showCancelCollectSuccess() { + if (mAdapter != null && mAdapter.getData().size() > articlePosition) { + mAdapter.getData().get(articlePosition).setCollect(false); + mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); + } + } + public static KnowledgeHierarchyListFragment getInstance(Serializable param1, String param2) { KnowledgeHierarchyListFragment fragment = new KnowledgeHierarchyListFragment(); Bundle args = new Bundle(); diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/ArticleDetailActivity.java b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/ArticleDetailActivity.java index 40b97fd..2ca8431 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/ArticleDetailActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/ArticleDetailActivity.java @@ -29,8 +29,7 @@ import json.chao.com.wanandroid.contract.main.ArticleDetailContract; import json.chao.com.wanandroid.core.DataManager; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; -import json.chao.com.wanandroid.core.event.CancelCollectSuccessEvent; -import json.chao.com.wanandroid.core.event.CollectSuccessEvent; +import json.chao.com.wanandroid.core.event.CollectEvent; import json.chao.com.wanandroid.presenter.main.ArticleDetailPresenter; import json.chao.com.wanandroid.utils.CommonUtils; import json.chao.com.wanandroid.utils.StatusBarUtil; @@ -231,9 +230,9 @@ private void initToolBar() { StatusBarUtil.setPaddingSmart(this, mToolbar); mToolbar.setNavigationOnClickListener(v -> { if (isCollect) { - RxBus.getDefault().post(new CollectSuccessEvent()); + RxBus.getDefault().post(new CollectEvent(false)); } else { - RxBus.getDefault().post(new CancelCollectSuccessEvent()); + RxBus.getDefault().post(new CollectEvent(true)); } onBackPressedSupport(); }); diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/CollectActivity.java b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/CollectActivity.java index 6542118..2d8fa88 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/CollectActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/CollectActivity.java @@ -16,13 +16,12 @@ import butterknife.BindView; import butterknife.OnClick; import json.chao.com.wanandroid.R; -import json.chao.com.wanandroid.app.Constants; import json.chao.com.wanandroid.base.activity.BaseActivity; import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.contract.main.CollectContract; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; -import json.chao.com.wanandroid.core.event.CancelCollectSuccessEvent; +import json.chao.com.wanandroid.core.event.CollectEvent; import json.chao.com.wanandroid.presenter.main.CollectPresenter; import json.chao.com.wanandroid.ui.mainpager.adapter.ArticleListAdapter; import json.chao.com.wanandroid.utils.CommonUtils; @@ -52,7 +51,6 @@ public class CollectActivity extends BaseActivity implements C private List mArticles; private ArticleListAdapter mAdapter; private int articlePosition; - private int themeCount; @Override protected void initInject() { @@ -69,10 +67,6 @@ protected void initEventAndData() { initToolbar(); initView(); setRefresh(); - - RxBus.getDefault().toFlowable(CancelCollectSuccessEvent.class) - .filter(cancelCollectSuccessEvent -> mAdapter.getData().size() > articlePosition) - .subscribe(cancelCollectSuccessEvent -> mAdapter.remove(articlePosition)); } @Override @@ -106,6 +100,13 @@ public void showCollectListFail() { CommonUtils.showMessage(this, getString(R.string.failed_to_obtain_collection_data)); } + @Override + public void showCancelCollectSuccess() { + if (mAdapter.getData().size() > articlePosition) { + mAdapter.remove(articlePosition); + } + } + @OnClick({R.id.collect_floating_action_btn}) void onClick(View view) { switch (view.getId()) { diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/LoginActivity.java b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/LoginActivity.java index d17f018..ffb9689 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/LoginActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/LoginActivity.java @@ -84,7 +84,7 @@ public void showLoginData(LoginResponse loginResponse) { mDataManager.setLoginAccount(loginData.getUsername()); mDataManager.setLoginPassword(loginData.getPassword()); mDataManager.setLoginStatus(true); - RxBus.getDefault().post(new LoginEvent()); + RxBus.getDefault().post(new LoginEvent(true)); CommonUtils.showMessage(this, getString(R.string.login_success)); onBackPressedSupport(); } diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/MainActivity.java b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/MainActivity.java index a2b9eb6..be3898a 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/MainActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/MainActivity.java @@ -31,9 +31,7 @@ import json.chao.com.wanandroid.component.RxBus; import json.chao.com.wanandroid.contract.main.MainContract; import json.chao.com.wanandroid.core.DataManager; -import json.chao.com.wanandroid.core.event.DismissErrorView; import json.chao.com.wanandroid.core.event.LoginEvent; -import json.chao.com.wanandroid.core.event.LogoutEvent; import json.chao.com.wanandroid.core.event.ShowErrorView; import json.chao.com.wanandroid.core.http.cookies.CookiesManager; import json.chao.com.wanandroid.presenter.main.MainPresenter; @@ -166,19 +164,9 @@ public void onDrawerSlide(View drawerView, float slideOffset) { toggle.syncState(); mDrawerLayout.addDrawerListener(toggle); - RxBus.getDefault().toFlowable(LoginEvent.class) - .subscribe(loginEvent -> setLoginView()); - - RxBus.getDefault().toFlowable(LogoutEvent.class) - .subscribe(logoutEvent -> setLogoutView()); - RxBus.getDefault().toFlowable(ShowErrorView.class) .filter(showErrorView -> mErrorView != null) .subscribe(showErrorView -> showError()); - - RxBus.getDefault().toFlowable(DismissErrorView.class) - .filter(dismissErrorView -> mErrorView != null) - .subscribe(dismissErrorView -> mErrorView.setVisibility(View.GONE)); } @Override @@ -302,9 +290,9 @@ private void switchFragment(int position) { private void initNavigationView() { mUsTv = ((TextView) mNavigationView.getHeaderView(0).findViewById(R.id.nav_header_login_tv)); if (mDataManager.getLoginStatus()) { - setLoginView(); + showLoginView(); } else { - setLogoutView(); + showLogoutView(); } mNavigationView.getMenu().findItem(R.id.nav_item_my_collect) @@ -330,7 +318,31 @@ private void initNavigationView() { }); } - private void setLoginView() { + private void logout() { + CommonAlertDialog.newInstance().showDialog( + this, getString(R.string.logout_tint), + getString(R.string.ok), + getString(R.string.no), + v -> { + CommonAlertDialog.newInstance().cancelDialog(); + mNavigationView.getMenu().findItem(R.id.nav_item_logout).setVisible(false); + mDataManager.setLoginStatus(false); + CookiesManager.clearAllCookies(); + RxBus.getDefault().post(new LoginEvent(false)); + startActivity(new Intent(this, LoginActivity.class)); + }, + v -> CommonAlertDialog.newInstance().cancelDialog()); + } + + @Override + public void showDismissErrorView() { + if (mErrorView != null) { + mErrorView.setVisibility(View.GONE); + } + } + + @Override + public void showLoginView() { if (mNavigationView == null) { return; } @@ -340,7 +352,8 @@ private void setLoginView() { mNavigationView.getMenu().findItem(R.id.nav_item_logout).setVisible(true); } - private void setLogoutView() { + @Override + public void showLogoutView() { mUsTv.setText(R.string.login_in); mUsTv.setOnClickListener(v -> startActivity(new Intent(this, LoginActivity.class))); if (mNavigationView == null) { @@ -348,21 +361,4 @@ private void setLogoutView() { } mNavigationView.getMenu().findItem(R.id.nav_item_logout).setVisible(false); } - - private void logout() { - CommonAlertDialog.newInstance().showDialog( - this, getString(R.string.logout_tint), - getString(R.string.ok), - getString(R.string.no), - v -> { - CommonAlertDialog.newInstance().cancelDialog(); - mNavigationView.getMenu().findItem(R.id.nav_item_logout).setVisible(false); - mDataManager.setLoginStatus(false); - CookiesManager.clearAllCookies(); - RxBus.getDefault().post(new LogoutEvent()); - startActivity(new Intent(this, LoginActivity.class)); - }, - v -> CommonAlertDialog.newInstance().cancelDialog()); - } - } diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/SearchListActivity.java b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/SearchListActivity.java index 61794e4..5f661e8 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/SearchListActivity.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/main/activity/SearchListActivity.java @@ -29,8 +29,7 @@ import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListData; import json.chao.com.wanandroid.core.bean.main.collect.FeedArticleListResponse; -import json.chao.com.wanandroid.core.event.CancelCollectSuccessEvent; -import json.chao.com.wanandroid.core.event.CollectSuccessEvent; +import json.chao.com.wanandroid.core.event.CollectEvent; import json.chao.com.wanandroid.presenter.main.SearchListPresenter; import json.chao.com.wanandroid.ui.mainpager.adapter.ArticleListAdapter; import json.chao.com.wanandroid.utils.CommonUtils; @@ -62,7 +61,6 @@ public class SearchListActivity extends BaseActivity implem private List mArticleList; private ArticleListAdapter mAdapter; private boolean isAddData; - private int themeCount; private String searchText; @Override @@ -103,20 +101,6 @@ protected void initEventAndData() { mRecyclerView.setAdapter(mAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); setRefresh(); - - RxBus.getDefault().toFlowable(CollectSuccessEvent.class) - .filter(collectSuccessEvent -> mAdapter.getData().size() > articlePosition) - .subscribe(collectSuccessEvent -> { - mAdapter.getData().get(articlePosition).setCollect(true); - mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); - }); - - RxBus.getDefault().toFlowable(CancelCollectSuccessEvent.class) - .filter(cancelCollectSuccessEvent -> mAdapter.getData().size() > articlePosition) - .subscribe(collectSuccessEvent -> { - mAdapter.getData().get(articlePosition).setCollect(false); - mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); - }); } @Override @@ -158,6 +142,22 @@ public void showSearchListFail() { CommonUtils.showMessage(this, getString(R.string.failed_to_obtain_search_data_list)); } + @Override + public void showCollectSuccess() { + if (mAdapter.getData().size() > articlePosition) { + mAdapter.getData().get(articlePosition).setCollect(true); + mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); + } + } + + @Override + public void showCancelCollectSuccess() { + if (mAdapter.getData().size() > articlePosition) { + mAdapter.getData().get(articlePosition).setCollect(false); + mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); + } + } + @OnClick({R.id.search_list_floating_action_btn}) void onClick(View view) { switch (view.getId()) { diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/mainpager/fragment/MainPagerFragment.java b/app/src/main/java/json/chao/com/wanandroid/ui/mainpager/fragment/MainPagerFragment.java index fb2603a..0f71e31 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/mainpager/fragment/MainPagerFragment.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/mainpager/fragment/MainPagerFragment.java @@ -29,11 +29,8 @@ import json.chao.com.wanandroid.app.Constants; import json.chao.com.wanandroid.base.fragment.BaseFragment; import json.chao.com.wanandroid.contract.mainpager.MainPagerContract; -import json.chao.com.wanandroid.core.event.CancelCollectSuccessEvent; -import json.chao.com.wanandroid.core.event.CollectSuccessEvent; import json.chao.com.wanandroid.core.event.DismissErrorView; import json.chao.com.wanandroid.core.event.LoginEvent; -import json.chao.com.wanandroid.core.event.LogoutEvent; import json.chao.com.wanandroid.core.event.ShowErrorView; import json.chao.com.wanandroid.core.http.cookies.CookiesManager; import json.chao.com.wanandroid.presenter.mainpager.MainPagerPresenter; @@ -146,32 +143,12 @@ protected void initEventAndData() { mPresenter.getFeedArticleList(mCurrentPage); } - //登录成功刷新数据 RxBus.getDefault().toFlowable(LoginEvent.class) + .filter(loginEvent -> !loginEvent.isLogin()) .subscribe(loginEvent -> { mCurrentPage = 0; mPresenter.getFeedArticleList(mCurrentPage); }); - - RxBus.getDefault().toFlowable(LogoutEvent.class) - .subscribe(loginEvent -> { - mCurrentPage = 0; - mPresenter.getFeedArticleList(mCurrentPage); - }); - - RxBus.getDefault().toFlowable(CollectSuccessEvent.class) - .filter(collectSuccessEvent -> mAdapter != null && mAdapter.getData().size() > articlePosition) - .subscribe(collectSuccessEvent -> { - mAdapter.getData().get(articlePosition).setCollect(true); - mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); - }); - - RxBus.getDefault().toFlowable(CancelCollectSuccessEvent.class) - .filter(cancelCollectSuccessEvent -> mAdapter != null && mAdapter.getData().size() > articlePosition) - .subscribe(cancelCollectSuccessEvent -> { - mAdapter.getData().get(articlePosition).setCollect(false); - mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); - }); } @Override @@ -185,7 +162,7 @@ public void showAutoLoginSuccess() { public void showAutoLoginFail() { mDataManager.setLoginStatus(false); CookiesManager.clearAllCookies(); - RxBus.getDefault().post(new LogoutEvent()); + RxBus.getDefault().post(new LoginEvent(false)); mPresenter.getBannerData(); } @@ -262,6 +239,12 @@ public void showBannerData(BannerResponse bannerResponse) { mBanner.start(); } + @Override + public void showLoginView() { + mCurrentPage = 0; + mPresenter.getFeedArticleList(mCurrentPage); + } + @Override public void showArticleListFail() { CommonUtils.showMessage(_mActivity, getString(R.string.failed_to_obtain_article_list)); @@ -272,6 +255,22 @@ public void showBannerDataFail() { CommonUtils.showMessage(_mActivity, getString(R.string.failed_to_obtain_banner_data)); } + @Override + public void showCollectSuccess() { + if (mAdapter != null && mAdapter.getData().size() > articlePosition) { + mAdapter.getData().get(articlePosition).setCollect(true); + mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); + } + } + + @Override + public void showCancelCollectSuccess() { + if (mAdapter != null && mAdapter.getData().size() > articlePosition) { + mAdapter.getData().get(articlePosition).setCollect(false); + mAdapter.setData(articlePosition, mAdapter.getData().get(articlePosition)); + } + } + @Override public void showError() { mRefreshLayout.setVisibility(View.INVISIBLE); diff --git a/app/src/main/java/json/chao/com/wanandroid/ui/project/fragment/ProjectListFragment.java b/app/src/main/java/json/chao/com/wanandroid/ui/project/fragment/ProjectListFragment.java index 798ac24..9c3e084 100644 --- a/app/src/main/java/json/chao/com/wanandroid/ui/project/fragment/ProjectListFragment.java +++ b/app/src/main/java/json/chao/com/wanandroid/ui/project/fragment/ProjectListFragment.java @@ -44,7 +44,6 @@ public class ProjectListFragment extends BaseFragment impl private boolean isRefresh = true; private int mCurrentPage; private int cid; - private int themeCount; @Override protected void initInject() { @@ -87,10 +86,6 @@ protected void initEventAndData() { mRecyclerView.setAdapter(mAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity)); mPresenter.getProjectListData(mCurrentPage, cid); - - RxBus.getDefault().toFlowable(JumpToTheTopEvent.class) - .filter(jumpToTheTopEvent -> mRecyclerView != null) - .subscribe(jumpToTheTopEvent -> mRecyclerView.smoothScrollToPosition(0)); } public static ProjectListFragment getInstance(int param1, String param2) { @@ -135,6 +130,13 @@ public void showProjectListFail() { CommonUtils.showMessage(_mActivity, getString(R.string.failed_to_obtain_project_list)); } + @Override + public void showJumpToTheTop() { + if (mRecyclerView != null) { + mRecyclerView.smoothScrollToPosition(0); + } + } + private void setRefresh() { mCurrentPage = 1; mRefreshLayout.setOnRefreshListener(refreshLayout -> {