Commit 3b4df2ad by 严久程

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

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