广场动态空布局优化
This commit is contained in:
@@ -2,6 +2,7 @@ package com.yizhuan.erban.community.square;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -19,6 +20,7 @@ import com.yizhuan.erban.UIHelper;
|
||||
import com.yizhuan.erban.avroom.activity.AVRoomActivity;
|
||||
import com.yizhuan.erban.base.BaseMvpActivity;
|
||||
import com.yizhuan.erban.base.BaseMvpFragment;
|
||||
import com.yizhuan.erban.common.EmptyViewHelper;
|
||||
import com.yizhuan.erban.common.widget.dialog.DialogManager;
|
||||
import com.yizhuan.erban.community.helper.ShareDynamicHelper;
|
||||
import com.yizhuan.erban.community.square.adapter.SquareDynamicAdapter;
|
||||
@@ -69,7 +71,7 @@ import io.reactivex.functions.BiConsumer;
|
||||
* create by lvzebiao @2020/1/7
|
||||
*/
|
||||
@CreatePresenter(MiniWorldCategoryPresenter.class)
|
||||
public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryView, MiniWorldCategoryPresenter> implements IMiniWorldCategoryView{
|
||||
public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryView, MiniWorldCategoryPresenter> implements IMiniWorldCategoryView {
|
||||
|
||||
public static final String EXTRA_SQUARE_TYPE = "square_type";
|
||||
|
||||
@@ -96,7 +98,6 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
|
||||
private SquareDynamicAdapter adapter;
|
||||
|
||||
private View footerView;
|
||||
|
||||
private View headerView;
|
||||
|
||||
@@ -104,9 +105,6 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
|
||||
private RecommendTopicListAdapter mRecommendTopicAdapter;
|
||||
|
||||
private long mLastOpen;
|
||||
|
||||
|
||||
public static SquareDynamicFragment newInstance(int type) {
|
||||
SquareDynamicFragment fragment = new SquareDynamicFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
@@ -142,10 +140,6 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
}
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
adapter = new SquareDynamicAdapter(getActivity(), squareType);
|
||||
//添加分割线
|
||||
// HorizontalDecoration decoration = new HorizontalDecoration(UIUtil.dip2px(mContext, 15), true, true);
|
||||
// decoration.setBottomPx(UIUtil.dip2px(mContext, 45));
|
||||
// recyclerView.addItemDecoration(decoration);
|
||||
|
||||
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
|
||||
|
||||
@@ -161,12 +155,13 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
});
|
||||
|
||||
|
||||
if (squareType == SquareFragment.TAB_TYPE_RECOMMEND){
|
||||
if (squareType == SquareFragment.TAB_TYPE_RECOMMEND) {
|
||||
initHeader();
|
||||
}
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.setPreLoadNumber(2);
|
||||
adapter.setOnLoadMoreListener(() -> loadData(false),recyclerView);
|
||||
adapter.setHeaderAndEmpty(true);
|
||||
adapter.setOnLoadMoreListener(() -> loadData(false), recyclerView);
|
||||
adapter.setOnItemChildClickListener((baseQuickAdapter, view, pos) -> {
|
||||
WorldDynamicBean bean = adapter.getItem(pos);
|
||||
if (bean == null) {
|
||||
@@ -189,25 +184,24 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
getDialogManager().showCommonPopupDialog(list, "取消");
|
||||
} else if (view.getId() == R.id.ll_share) {
|
||||
new ShareDynamicHelper(getActivity()).share(bean);
|
||||
} else if (view.getId() == R.id.iv_in_room){
|
||||
// openRoom(bean.getUid());
|
||||
if (bean.getInRoomUid() == null){
|
||||
} else if (view.getId() == R.id.iv_in_room) {
|
||||
if (bean.getInRoomUid() == null) {
|
||||
return;
|
||||
}
|
||||
AVRoomActivity.start(mContext,bean.getInRoomUid());
|
||||
AVRoomActivity.start(mContext, bean.getInRoomUid());
|
||||
}
|
||||
});
|
||||
|
||||
refreshLayout = mView.findViewById(R.id.refresh_layout);
|
||||
refreshLayout.setOnRefreshListener(() -> {
|
||||
loadData(true);
|
||||
if (squareType == SquareFragment.TAB_TYPE_RECOMMEND){
|
||||
if (squareType == SquareFragment.TAB_TYPE_RECOMMEND) {
|
||||
getMvpPresenter().getMiniWorldList(TOPIC_CATEGORY_ID, 1);
|
||||
}
|
||||
});
|
||||
|
||||
loadData(true);
|
||||
if (squareType == SquareFragment.TAB_TYPE_RECOMMEND){
|
||||
if (squareType == SquareFragment.TAB_TYPE_RECOMMEND) {
|
||||
getMvpPresenter().getMiniWorldList(TOPIC_CATEGORY_ID, 1);
|
||||
}
|
||||
}
|
||||
@@ -216,8 +210,7 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
if (isRefresh) {
|
||||
nextDynamicId = null;
|
||||
page = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
page++;
|
||||
}
|
||||
|
||||
@@ -227,7 +220,7 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
if (squareType == SquareFragment.TAB_TYPE_ATTENT) {
|
||||
single = SquareModel.get().getFollowerDynamics(nextDynamicId,
|
||||
CommunityConstant.DYNAMIC_PAGE_SIZE);
|
||||
} else if (squareType == SquareFragment.TAB_TYPE_RECOMMEND){
|
||||
} else if (squareType == SquareFragment.TAB_TYPE_RECOMMEND) {
|
||||
single = SquareModel.get().getRecommendDynamics(page, CommunityConstant.DYNAMIC_PAGE_SIZE)
|
||||
.map(list -> {
|
||||
WorldDynamicListResult result = new WorldDynamicListResult();
|
||||
@@ -235,7 +228,7 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
return result;
|
||||
});
|
||||
} else {
|
||||
single = SquareModel.get().getLatestDynamics(page, CommunityConstant.DYNAMIC_PAGE_SIZE,nextDynamicId);
|
||||
single = SquareModel.get().getLatestDynamics(page, CommunityConstant.DYNAMIC_PAGE_SIZE, nextDynamicId);
|
||||
}
|
||||
|
||||
single.compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
|
||||
@@ -244,9 +237,8 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
public void accept(WorldDynamicListResult result, String error) {
|
||||
super.accept(result, error);
|
||||
refreshLayout.setRefreshing(false);
|
||||
hideStatus();
|
||||
if (error != null) {
|
||||
if (!isRefresh) adapter.loadMoreFail();
|
||||
if (!isRefresh) adapter.loadMoreFail();
|
||||
return;
|
||||
}
|
||||
//接口访问正确的处理
|
||||
@@ -263,14 +255,12 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
if (squareType == SquareFragment.TAB_TYPE_ATTENT) {
|
||||
emptyTips = "暂无动态,去推荐看看吧~";
|
||||
}
|
||||
showNoData(R.drawable.icon_common_failure,
|
||||
emptyTips);
|
||||
adapter.setEmptyView(EmptyViewHelper.createEmptyView(getContext(), emptyTips));
|
||||
}
|
||||
} else {
|
||||
if (list.isEmpty()){
|
||||
if (list.isEmpty()) {
|
||||
adapter.loadMoreEnd();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
adapter.addData(list);
|
||||
adapter.loadMoreComplete();
|
||||
}
|
||||
@@ -318,7 +308,7 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
});
|
||||
}
|
||||
|
||||
private void initHeader(){
|
||||
private void initHeader() {
|
||||
headerView = LayoutInflater.from(mContext).inflate(R.layout.layout_recommend_topic_header, null);
|
||||
tvTitleTopic = headerView.findViewById(R.id.tv_title_topic);
|
||||
tvTitleTopic.setOnClickListener(v -> {
|
||||
@@ -371,58 +361,6 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
recyclerView.setAdapter(mRecommendTopicAdapter);
|
||||
}
|
||||
|
||||
@SuppressWarnings("CheckResult")
|
||||
private void openRoom(long uid) {
|
||||
if (System.currentTimeMillis() - mLastOpen < 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mContext instanceof BaseMvpActivity) {
|
||||
mLastOpen = System.currentTimeMillis();
|
||||
BaseMvpActivity activity = (BaseMvpActivity) mContext;
|
||||
activity.getDialogManager().showProgressDialog(mContext, "请稍后...");
|
||||
|
||||
|
||||
AvRoomModel.get()
|
||||
.getUserRoom(uid)
|
||||
.compose(RxHelper.singleMainResult())
|
||||
.compose(RxHelper.handleSchAndExce())
|
||||
.compose(activity.bindToLifecycle())
|
||||
.subscribe(new BiConsumer<RoomInfo, Throwable>() {
|
||||
@Override
|
||||
public void accept(RoomInfo roomInfo, Throwable throwable) throws Exception {
|
||||
if (throwable == null) {
|
||||
if (roomInfo != null && roomInfo.getUid() > 0) {
|
||||
AVRoomActivity.start(mContext, roomInfo.getUid(), roomInfo.getType());
|
||||
} else {
|
||||
SingleToastUtil.showToast("对方不在房间内");
|
||||
}
|
||||
} else {
|
||||
SingleToastUtil.showToast("可能暂时不在房间哟");
|
||||
}
|
||||
activity.getDialogManager().dismissDialog();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
SingleToastUtil.showToast("出现异常");
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToTop() {
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recyclerView.smoothScrollToPosition(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReloadData() {
|
||||
loadData(true);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onDynamicPublishEvent(DynamicPublishEvent event) {
|
||||
if (squareType == SquareFragment.TAB_TYPE_ATTENT) {
|
||||
@@ -437,8 +375,6 @@ public class SquareDynamicFragment extends BaseMvpFragment<IMiniWorldCategoryVie
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getRootLayoutId() {
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user