Skip to content

Commit

Permalink
add rxbus subcription manager
Browse files Browse the repository at this point in the history
  • Loading branch information
JsonChao committed Mar 16, 2018
1 parent 16f73ff commit ae3b254
Show file tree
Hide file tree
Showing 34 changed files with 389 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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所需的依赖
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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布局
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -82,6 +80,26 @@ public void showCancelCollectFail() {
}
}

@Override
public void showCollectSuccess() {

}

@Override
public void showCancelCollectSuccess() {

}

@Override
public void showLoginView() {

}

@Override
public void showLogoutView() {

}

/**
* 注入当前Fragment所需的依赖
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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所需的依赖
*/
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/json/chao/com/wanandroid/base/view/BaseView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public interface BaseView {
*/
void showLoading();

/**
* Show login view
*/
void showLoginView();

/**
* Show logout view
*/
void showLogoutView();

/**
* Show collect fail
*/
Expand All @@ -37,4 +47,14 @@ public interface BaseView {
*/
void showCancelCollectFail();

/**
* Show collect success
*/
void showCollectSuccess();

/**
* Show cancel collect success
*/
void showCancelCollectSuccess();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public interface KnowledgeHierarchyDetailContract {

interface View extends BaseView {


/**
* Show dismiss detail error view
*/
void showDismissDetailErrorView();
}

interface Presenter extends AbstractPresenter<View> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ interface View extends BaseView {
*/
void showKnowledgeHierarchyDetailDataFail();

/**
* Show jump the top
*/
void showJumpTheTop();

}

interface Presenter extends AbstractPresenter<View> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface View extends BaseView {
* Show collect list fail
*/
void showCollectListFail();

}

interface Presenter extends AbstractPresenter<View> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public interface MainContract {

interface View extends BaseView {


/**
* Show dismiss error view
*/
void showDismissErrorView();
}

interface Presenter extends AbstractPresenter<View> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ interface View extends BaseView {
*/
void showProjectListFail();

/**
* Show jump to the top
*/
void showJumpToTheTop();

}

interface Presenter extends AbstractPresenter<View> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +23,16 @@ public class KnowledgeHierarchyDetailPresenter extends BasePresenter<KnowledgeHi
this.mDataManager = dataManager;
}

@Override
public void attachView(KnowledgeHierarchyDetailContract.View view) {
super.attachView(view);
registerEvent();
}

private void registerEvent() {
addSubscribe(RxBus.getDefault().toFlowable(DismissDetailErrorView.class)
.subscribe(dismissDetailErrorView -> mView.showDismissDetailErrorView()));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,6 +29,25 @@ public class KnowledgeHierarchyListPresenter extends BasePresenter<KnowledgeHier
this.mDataManager = dataManager;
}

@Override
public void attachView(KnowledgeHierarchyListContract.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(KnowledgeJumpTopEvent.class)
.subscribe(knowledgeJumpTopEvent -> mView.showJumpTheTop()));
}

@Override
public void getKnowledgeHierarchyDetailData(int page, int cid) {
addSubscribe(mDataManager.getKnowledgeHierarchyDetailData(page, cid)
Expand Down
Loading

0 comments on commit ae3b254

Please sign in to comment.