Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtianqiu committed Nov 22, 2018
1 parent 7fcccc7 commit 1a6c4d5
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 102 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/code/mvvm/core/data/BaseRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ protected void sendData(Object eventKey, Object t) {
sendData(eventKey, null, t);
}

protected void sendData(Object eventKey, String tag, Object t) {
LiveBus.getDefault().postEvent(eventKey, tag, t);
}

protected void showPageState(Object eventKey, String state) {
sendData(eventKey, state);
Expand All @@ -36,5 +33,8 @@ protected void showPageState(Object eventKey, String tag, String state) {
sendData(eventKey, tag, state);
}

protected void sendData(Object eventKey, String tag, Object t) {
LiveBus.getDefault().postEvent(eventKey, tag, t);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void loadWorkRecommendData(String correctId) {
}

public void loadWorkMergeData() {
addDisposable(Flowable.concat(mWorkDetail, mWorkRecommend)
addDisposable(Flowable.concatArrayDelayError(mWorkDetail, mWorkRecommend)
.compose(RxSchedulers.<Object>io_main())
.subscribeWith(new RxSubscriber<Object>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ private void initAdapter() {

@Override
protected void dataObserver() {
Log.e("dataObserver", String.valueOf(this.getClass().hashCode()));
LiveBus.getDefault().subscribe(Constants.EVENT_KEY_WORK_STATE).observe(this, observer);

LiveBus.getDefault().subscribe(Constants.EVENT_KEY_WORK, WorkMergeVo.class).observe(this, new Observer<WorkMergeVo>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ protected void dataObserver() {

}


@Override
protected RecyclerView.LayoutManager createLayoutManager() {
return new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
}

@Override
protected DelegateAdapter createAdapter() {
DelegateAdapter adapter = AdapterPool.newInstance().getHomeAdapter(getActivity())
return AdapterPool.newInstance().getHomeAdapter(getActivity())
.setOnItemClickListener(this)
.build();
return adapter;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public ArticleViewModel(@NonNull Application application) {
}

public void getArticleList(String lectureLevel1, String lastId) {
checkNotNull(lectureLevel1);
mRepository.loadArticleRemList(lectureLevel1, lastId, Constants.PAGE_RN);
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/code/mvvm/core/vm/BookViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public BookViewModel(@NonNull Application application) {
}

public void getBookList(String mCatalogId, String lastId) {
checkNotNull(mCatalogId);
mRepository.loadBookList(mCatalogId, lastId, Constants.PAGE_RN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public void getCourseTypeData() {
}

public void getCourseList(String fCatalogId, String lastId) {
checkNotNull(fCatalogId);
mRepository.loadCourseList(fCatalogId, lastId, Constants.PAGE_RN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public DynamicViewModel(@NonNull Application application) {


public void getDynamicList(String token, String lastId) {
checkNotNull(token);
mRepository.loadDynamicList(Constants.PAGE_RN, token, lastId);

}
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/code/mvvm/core/vm/WorkViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ public LiveData<WorkRecommentVo> getWorkRecommentData() {
}

public void getWorkMoreData(String corrected, String lastId, String utime) {
checkNotNull(corrected);
checkNotNull(lastId);
checkNotNull(utime);
mRepository.loadWorkMoreData(corrected, lastId, utime, Constants.PAGE_RN);
}

public void getWorkData(String corrected, String rn) {
checkNotNull(corrected);
checkNotNull(rn);
mRepository.loadWorkData(corrected, rn);

}
Expand Down
82 changes: 34 additions & 48 deletions app/src/main/java/com/code/mvvm/util/AdapterPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,31 @@ public static AdapterPool newInstance() {
return adapterPool;
}

public DelegateAdapter getNoHeadAdapter(DelegateAdapter.Builder builder, Context context) {
return builder
.bind(FootVo.class, new FootViewHolder(context, ProgressStyle.Pacman))
.build();
}

public DelegateAdapter.Builder getNoFootAdapter(DelegateAdapter.Builder builder, Context context,int mProgressStyle) {
return builder
.bind(HeaderVo.class, new HeaderViewHolder(context, mProgressStyle));
private DelegateAdapter.Builder getNoFootAdapter(DelegateAdapter.Builder builder, Context context, int mProgressStyle) {
return builder.bind(HeaderVo.class, new HeaderViewHolder(context, mProgressStyle));
}

public DelegateAdapter.Builder getAdapter(DelegateAdapter.Builder builder, Context context,int mProgressStyle) {
return builder.bind(HeaderVo.class, new HeaderViewHolder(context, mProgressStyle))
.bind(FootVo.class, new FootViewHolder(context,mProgressStyle));
private DelegateAdapter.Builder getAdapter(DelegateAdapter.Builder builder, Context context, int mProgressStyle) {
return builder.bind(HeaderVo.class, new HeaderViewHolder(context, mProgressStyle)).bind(FootVo.class, new FootViewHolder(context, mProgressStyle));
}

public DelegateAdapter.Builder getWorkAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(BannerListVo.class, new BannerItemView(context))
.bind(WorksListVo.Works.class, new CorrectItemHolder(context)), context,ProgressStyle.SysProgress);
return getAdapter(new DelegateAdapter.Builder<>().bind(BannerListVo.class, new BannerItemView(context)).bind(WorksListVo.Works.class, new CorrectItemHolder(context)), context, ProgressStyle.SysProgress);
}

public DelegateAdapter.Builder getSwipeCorrectAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(BannerListVo.class, new BannerItemView(context))
.bind(WorksListVo.Works.class, new CorrectItemHolder(context)), context,ProgressStyle.SysProgress);
return getAdapter(new DelegateAdapter.Builder<>().bind(BannerListVo.class, new BannerItemView(context)).bind(WorksListVo.Works.class, new CorrectItemHolder(context)), context, ProgressStyle.SysProgress);
}

public DelegateAdapter.Builder getBookAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(BookVo.class, new BookListHolder(context)), context,ProgressStyle.BallScaleMultiple);
.bind(BookVo.class, new BookListHolder(context)), context, ProgressStyle.BallScaleMultiple);
}

public DelegateAdapter.Builder getActivityAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(ActivityListVo.DataBean.class, new ActivityItemHolder(context)), context,ProgressStyle.BallRotate);
.bind(ActivityListVo.DataBean.class, new ActivityItemHolder(context)), context, ProgressStyle.BallRotate);
}

public DelegateAdapter.Builder getArticleAdapter(Context context) {
Expand All @@ -122,27 +111,27 @@ public DelegateAdapter.Builder getArticleAdapter(Context context) {
return ArticleRem3ItemHolder.class;
}
return null;
}), context,ProgressStyle.BallPulseSync);
}), context, ProgressStyle.BallPulseSync);
}

public DelegateAdapter.Builder getCourseRemAdapter(Context context) {
return getNoFootAdapter(new DelegateAdapter.Builder<>()
.bind(TypeVo.class, new TypeItemView(context))
.bind(BannerListVo.class, new BannerItemView(context))
.bind(CourseInfoVo.class, new CourseItemHolder(context))
.bind(LiveRecommendVo.class, new HomeLiveItemView(context)), context,ProgressStyle.BallPulseRise);
.bind(LiveRecommendVo.class, new HomeLiveItemView(context)), context, ProgressStyle.BallPulseRise);

}

public DelegateAdapter.Builder getCourseListAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(CourseInfoVo.class, new CourseItemHolder(context)), context,ProgressStyle.BallPulse);
.bind(CourseInfoVo.class, new CourseItemHolder(context)), context, ProgressStyle.BallPulse);

}

public DelegateAdapter.Builder getFollowAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(FollowDrawInfoVo.class, new FollowDrawListHolder(context)), context,ProgressStyle.BallGridPulse);
.bind(FollowDrawInfoVo.class, new FollowDrawListHolder(context)), context, ProgressStyle.BallGridPulse);
}

public DelegateAdapter.Builder getQaAdapter(Context context) {
Expand All @@ -152,22 +141,22 @@ public DelegateAdapter.Builder getQaAdapter(Context context) {

public DelegateAdapter.Builder getMaterialListAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(MaterialInfoVo.class, new MaterialListHolder(context)), context,ProgressStyle.BallClipRotatePulse);
.bind(MaterialInfoVo.class, new MaterialListHolder(context)), context, ProgressStyle.BallClipRotatePulse);
}

public DelegateAdapter.Builder getMaterialRemAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(MatreialSubjectVo.class, new MaterialItemHolder(context)), context,ProgressStyle.BallClipRotateMultiple);
.bind(MatreialSubjectVo.class, new MaterialItemHolder(context)), context, ProgressStyle.BallClipRotateMultiple);
}

public DelegateAdapter.Builder getLiveAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(LiveRecommendVo.class, new LiveListItemHolder(context)), context,ProgressStyle.BallClipRotate);
.bind(LiveRecommendVo.class, new LiveListItemHolder(context)), context, ProgressStyle.BallClipRotate);
}

public DelegateAdapter.Builder getLiveRemAdapter(Context context) {
return getAdapter(new DelegateAdapter.Builder<>()
.bind(LiveRecommendVo.class, new LiveItemHolder(context)), context,ProgressStyle.BallBeat);
.bind(LiveRecommendVo.class, new LiveItemHolder(context)), context, ProgressStyle.BallBeat);
}

public DelegateAdapter.Builder getHomeAdapter(Context context) {
Expand All @@ -178,7 +167,7 @@ public DelegateAdapter.Builder getHomeAdapter(Context context) {
.bind(BookList.class, new BookItemHolder(context))
.bind(CourseInfoVo.class, new CourseItemHolder(context))
.bind(LiveRecommendVo.class, new HomeLiveItemView(context))
.bind(MatreialSubjectVo.class, new HomeMaterialItemView(context)), context,ProgressStyle.Pacman);
.bind(MatreialSubjectVo.class, new HomeMaterialItemView(context)), context, ProgressStyle.Pacman);
}

public DelegateAdapter.Builder getDynamicAdapter(Context context) {
Expand All @@ -190,26 +179,23 @@ public DelegateAdapter.Builder getDynamicAdapter(Context context) {
new DynamicCourseHolder(context),
new DynamicLiveHolder(context),
new DynamicFollowHolder(context))
.withClass(new OneToMany<DynamicInfoVo>() {
@Override
public Class<? extends VHolder<DynamicInfoVo, ?>> onItemView(int i, DynamicInfoVo dynamicInfoVo) {
if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_CORRECT)) {
return DynamicCorrectHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_WORK)) {
return DynamicWorkHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_MATERIAL_SUBJECT)) {
return DynamicSubjectHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_ARTICLE)) {
return DynamicArticleHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_FOLLOW_DRAW)) {
return DynamicFollowHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_LIVE)) {
return DynamicLiveHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_LESSON)) {
return DynamicCourseHolder.class;
}
return null;
.withClass((OneToMany<DynamicInfoVo>) (i, dynamicInfoVo) -> {
if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_CORRECT)) {
return DynamicCorrectHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_WORK)) {
return DynamicWorkHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_MATERIAL_SUBJECT)) {
return DynamicSubjectHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_ARTICLE)) {
return DynamicArticleHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_FOLLOW_DRAW)) {
return DynamicFollowHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_LIVE)) {
return DynamicLiveHolder.class;
} else if (dynamicInfoVo.subjecttype.equals(Constants.TYPE_LESSON)) {
return DynamicCourseHolder.class;
}
}), context,ProgressStyle.BallSpinFadeLoader);
return null;
}), context, ProgressStyle.BallSpinFadeLoader);
}
}
12 changes: 6 additions & 6 deletions mvvm/src/main/java/com/mvvm/base/AbsLifecycleFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class AbsLifecycleFragment<T extends AbsViewModel> extends BaseF

protected String mStateEventTag;

private List<Object> events = new ArrayList<>();
private List<Object> eventKeys = new ArrayList<>();

@Override
public void initView(Bundle state) {
Expand All @@ -41,7 +41,7 @@ public void initView(Bundle state) {
dataObserver();
mStateEventKey = getStateEventKey();
mStateEventTag = getStateEventTag();
events.add(new StringBuilder((String) mStateEventKey).append(mStateEventTag).toString());
eventKeys.add(new StringBuilder((String) mStateEventKey).append(mStateEventTag).toString());
LiveBus.getDefault().subscribe(mStateEventKey, mStateEventTag).observe(this, observer);
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ protected <T> MutableLiveData<T> registerObserver(Object eventKey, String tag, C
} else {
event = eventKey + tag;
}
events.add(event);
eventKeys.add(event);
return LiveBus.getDefault().subscribe(eventKey, tag, tClass);
}

Expand Down Expand Up @@ -144,9 +144,9 @@ public void onChanged(@Nullable String state) {
@Override
public void onDestroyView() {
super.onDestroyView();
if (events != null && events.size() > 0) {
for (int i = 0; i < events.size(); i++) {
LiveBus.getDefault().clear(events.get(i));
if (eventKeys != null && eventKeys.size() > 0) {
for (int i = 0; i < eventKeys.size(); i++) {
LiveBus.getDefault().clear(eventKeys.get(i));
}
}
}
Expand Down
Loading

0 comments on commit 1a6c4d5

Please sign in to comment.