Commit 3b4df2ad by 严久程

动态主页、三个分类切换时不在顶部的问题

parent 6760ab4d
ext {
kotlin_version = "1.3.21"
dev_mode = false
dev_mode = true
ydl_app = [
appName : "心理咨询壹点灵",
......
......@@ -122,7 +122,7 @@ public class TrendsListInteractor {
// LogUtil.i("get Response: " + trendsListBean.toString());
if (callBack != null) {
//更新缓存
updateCache(tab,trendsListBean);
// updateCache(tab,trendsListBean);
callBack.onTrendsListFetched(trendsListBean);
}
}, throwable -> {
......
......@@ -10,7 +10,7 @@ import android.support.v4.app.FragmentPagerAdapter;
public class TrendsHomeVpAdapter extends FragmentPagerAdapter {
public final static int dataSize=3;
public final static int dataSize = 3;
private Fragment[] mFragments;
private String[] titles = new String[]{
"推荐", "最新", "关注", "待回答", "我回答的"
......@@ -25,8 +25,8 @@ public class TrendsHomeVpAdapter extends FragmentPagerAdapter {
mFragments = fragments;
}
public void setDatas(Fragment[] fragments){
mFragments=fragments;
public void setDatas(Fragment[] fragments) {
mFragments = fragments;
}
@Override
......@@ -39,12 +39,12 @@ public class TrendsHomeVpAdapter extends FragmentPagerAdapter {
@Override
public int getCount() {
return mFragments!=null&&mFragments.length > 0 ? mFragments.length : 0;
return mFragments != null && mFragments.length > 0 ? mFragments.length : 0;
}
@Override
public CharSequence getPageTitle(int position) {
if (mFragments.length>0){
if (mFragments.length > 0) {
return titles[position];
}
return super.getPageTitle(position);
......
......@@ -23,7 +23,6 @@ import com.ydl.ydlcommon.base.BaseFragment;
import com.ydl.ydlcommon.utils.BuryPointUtils;
import com.ydl.ydlcommon.utils.SharedPreferencesEditor;
import com.ydl.ydlcommon.view.WrapContentLinearLayoutManager;
import com.ydl.ydlcommon.view.listener.EndlessRecyclerViewScrollListener;
import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.dynamic.R;
......@@ -45,6 +44,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
;
/**
* @author Jim
* @描述:
......@@ -78,6 +78,7 @@ public class TrendsContentListFragment extends BaseFragment implements ITrendsLi
private TrendsCotentListAdapter mRcvAdapter;
private List<TrendsListBean.Trend> trendsDatas;
private RecyclerView.OnScrollListener mScrollListener;
private int lastVisibleItem = 0;
public static TrendsContentListFragment newInstance(int tabType, int topicId, String trendType, String trendUserid) {
TrendsContentListFragment fragment = new TrendsContentListFragment();
......@@ -179,36 +180,70 @@ public class TrendsContentListFragment extends BaseFragment implements ITrendsLi
trendsRcv.setAdapter(mRcvAdapter);
trendsRcv.setLayoutManager(layoutManager);
trendsRcv.getItemAnimator().setChangeDuration(0); //解决局部刷新闪屏
mScrollListener = new EndlessRecyclerViewScrollListener(layoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, @org.jetbrains.annotations.Nullable RecyclerView view) {
if (!isRefresh) {
resetState();
last_id = getLastId();
LogUtil.i("loadMore last id: " + last_id + " page: " + page);
TrendsContentListFragment.this.page++;
switchDataToFetch();
}
}
mRcvAdapter.addFooterView(getFooterView());
// mScrollListener = new DynamicRecyclerViewScrollListener(layoutManager) {
// @Override
// public void onLoadMore(int page, int totalItemsCount, @org.jetbrains.annotations.Nullable RecyclerView view) {
// LogUtil.e("tab=" + tab + ",onLoadMore");
// LogUtil.e("tab=" + tab + ",==数据长度:" + mRcvAdapter.getDatas().size());
// if (!isRefresh) {
// resetState();
// last_id = getLastId();
// LogUtil.i("loadMore last id: " + last_id + " page: " + page);
// TrendsContentListFragment.this.page++;
// switchDataToFetch();
// }
// }
//
// @Override
// protected void onScrollDown() {
// LogUtil.e("tab=" + tab + ",onScrollDown");
//// ((TrendsHomeFragment) getParentFragment()).onScrollDown();
// }
//
// @Override
// protected void onScrollUp() {
// LogUtil.e("tab=" + tab + ",onScrollUp");
//// ((TrendsHomeFragment) getParentFragment()).onScrollUp();
// }
//
// @Override
// public void onScrollTop() {
// LogUtil.e("tab=" + tab + ",onScrollTop");
//// ((TrendsHomeFragment) getParentFragment()).onScrollTop();
// }
// };
mScrollListener = new RecyclerView.OnScrollListener() {
@Override
protected void onScrollDown() {
// ((TrendsHomeFragment) getParentFragment()).onScrollDown();
}
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
LogUtil.e("tab===停止滑动" + System.currentTimeMillis());
}
@Override
protected void onScrollUp() {
// ((TrendsHomeFragment) getParentFragment()).onScrollUp();
if (newState == RecyclerView.SCROLL_STATE_IDLE //停止滚动
&& lastVisibleItem >= (mRcvAdapter.getItemCount() - mRcvAdapter.getFootersCount())//最后一个显示的item序号大于适配器item数量,即显示了footer
&& mRcvAdapter.getFooterState() == TrendsCotentListAdapter.FOOTRE_STATE_LOAD_MORE
) {
LogUtil.e("tab=" + tab + ",onLoadMore");
LogUtil.e("tab=" + tab + ",==数据长度:" + mRcvAdapter.getDatas().size());
if (!isRefresh) {
LogUtil.e("tab===加载数据" + System.currentTimeMillis());
last_id = getLastId();
LogUtil.i("loadMore last id: " + last_id + " page: " + page);
TrendsContentListFragment.this.page++;
switchDataToFetch();
}
}
}
@Override
public void onScrollTop() {
// ((TrendsHomeFragment) getParentFragment()).onScrollTop();
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
lastVisibleItem = layoutManager.findLastVisibleItemPosition();
}
};
trendsRcv.addOnScrollListener(mScrollListener);
mRcvAdapter.addFooterView(getFooterView());
}
private void doLikeAction(View view, int position, List<TrendsListBean.Trend> mDatas) {
......@@ -222,7 +257,7 @@ public class TrendsContentListFragment extends BaseFragment implements ITrendsLi
}
}
private void localData(){
private void localData() {
if (mPresenter != null) {
mPresenter.localData(tab);
}
......@@ -297,7 +332,7 @@ public class TrendsContentListFragment extends BaseFragment implements ITrendsLi
}
SharedPreferencesEditor.putString("trend_state", "");
LogUtil.d("trendType " + trendType);
localData();
// localData();
fetchTrendsList();
}
......@@ -391,8 +426,8 @@ public class TrendsContentListFragment extends BaseFragment implements ITrendsLi
@Override
public void showBanner(List<TrendsListBean.Banner> banner) {
//更新banner数据
if (getParentFragment() instanceof TrendsHomeFragment){
((TrendsHomeFragment)getParentFragment()).setBannerData(banner);
if (getParentFragment() instanceof TrendsHomeFragment) {
((TrendsHomeFragment) getParentFragment()).setBannerData(banner);
}
}
......@@ -400,16 +435,16 @@ public class TrendsContentListFragment extends BaseFragment implements ITrendsLi
public void showTrendsListView(List<TrendsListBean.Trend> data) {
isTrendsListLoading = false;
showLoadSuccessView();
if (page == 1){
if (null == trendsDatas){
if (page == 1) {
if (null == trendsDatas) {
trendsDatas = new ArrayList();
}else {
} else {
trendsDatas.clear();
}
if (null != data){
if (null != data) {
trendsDatas.addAll(data);
}
mRcvAdapter.setDatas(trendsDatas, mRcvAdapter.FOOTRE_STATE_INIT);
mRcvAdapter.setDatas(trendsDatas, mRcvAdapter.FOOTRE_STATE_LOAD_MORE);
mRcvAdapter.notifyDataSetChanged();
return;
}
......
......@@ -77,7 +77,7 @@ public class TrendsCotentListAdapter extends RecyclerView.Adapter<BaseViewHolder
public TrendsCotentListAdapter(Context context, List<TrendsListBean.Trend> datas) {
mContext = context;
mDatas = datas;
footerState = FOOTRE_STATE_INIT;
footerState = FOOTRE_STATE_LOAD_MORE;
}
public void setDatas(List<TrendsListBean.Trend> datas) {
......@@ -89,6 +89,10 @@ public class TrendsCotentListAdapter extends RecyclerView.Adapter<BaseViewHolder
this.footerState = footerState;
}
public int getFooterState() {
return footerState;
}
public void addDatas(List<TrendsListBean.Trend> datas, int footerState) {
this.footerState = footerState;
if (mDatas == null) {
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dynamic_white">
<android.support.v7.widget.RecyclerView
android:id="@+id/recommend_dynamic_rcv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:visibility="visible"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/trend_no_data_rel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/trend_no_data_iv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:src="@drawable/dynamic_blank"/>
<TextView
android:id="@+id/trend_no_data_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="暂无数据"
android:textColor="@color/dynamic_text_gray"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:background="@color/dynamic_white">
<android.support.v7.widget.RecyclerView
android:id="@+id/recommend_dynamic_rcv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:visibility="visible"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/trend_no_data_rel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/trend_no_data_iv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:src="@drawable/dynamic_blank"/>
<TextView
android:id="@+id/trend_no_data_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="暂无数据"
android:textColor="@color/dynamic_text_gray"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F4F5">
<TextView
android:id="@+id/loop_content_before"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="15dp"
android:textColor="#999999"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:background="@drawable/dynamic_bg_radius_white_20"
tools:text="置顶 xxxxxx"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F4F5">
<TextView
android:id="@+id/loop_content_before"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="5dp"
android:background="@drawable/dynamic_bg_radius_white_20"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:textColor="#999999"
tools:text="置顶 xxxxxx" />
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment