上拉刷新

fix bugs
This commit is contained in:
mwang 2019-04-17 23:28:18 +08:00
parent bcd0d91ffb
commit 0e5e8968d6
27 changed files with 383 additions and 177 deletions

View File

@ -10,6 +10,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.novelbook.android.Fragments.BasicFragment;
import com.novelbook.android.Fragments.Fragment_booklist;
import com.novelbook.android.Fragments.Fragment_shudan_list;
import com.flyco.tablayout.SlidingTabLayout;
@ -26,7 +27,7 @@ public class Activity_cate_books extends Activity_base {
@BindView(R.id.tab_layout)
SlidingTabLayout tabLayout;
String cate="";
private ArrayList<Fragment> mFragments;
private ArrayList<BasicFragment> mFragments;
ArrayList<View> mList;
String[] mTitle;
public static String TAG="com.novelbook.android.Activity_cate_books";
@ -57,17 +58,17 @@ public class Activity_cate_books extends Activity_base {
void initTabs() {
if(mFragments ==null || mFragments.size() ==0){
if (mFragments == null || mFragments.size() == 0) {
mTitle = new String[]{"新书", "连载", "完本"};
mFragments = new ArrayList<>();
mFragments = new ArrayList<BasicFragment>();
mFragments.add( Fragment_booklist.newInstance(cate,1));
mFragments.add( Fragment_booklist.newInstance(cate,2));
mFragments.add( Fragment_booklist.newInstance(cate,3));
mFragments.add(Fragment_booklist.newInstance(cate, 1));
mFragments.add(Fragment_booklist.newInstance(cate, 2));
mFragments.add(Fragment_booklist.newInstance(cate, 3));
Log.d(TAG,"initial fragments in tabs ");
Log.d(TAG, "initial fragments in tabs ");
}
Log.d(TAG,"set viewPager adapter ");
Log.d(TAG, "set viewPager adapter ");
// FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(activity.getSupportFragmentManager()) { 第一次进入没问题再次进入ViewPager的fragment时里面内容就没了,数据丢失 https://blog.csdn.net/allan_bst/article/details/64920076
FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
@ -79,6 +80,7 @@ public class Activity_cate_books extends Activity_base {
public int getCount() {
return mFragments.size();
}
//ViewPager与TabLayout绑定后这里获取到PageTitle就是Tab的Text
@Override
public CharSequence getPageTitle(int position) {
@ -86,13 +88,14 @@ public class Activity_cate_books extends Activity_base {
}
};
mViewpager.setAdapter(mAdapter);
mViewpager.setOffscreenPageLimit(3);
tabLayout.setViewPager(mViewpager);
// tabLayout.setViewPager(mViewpager, mTitle, activity, mFragments);
mViewpager.setCurrentItem(0);
}
@Override

View File

@ -74,6 +74,8 @@ public abstract class BasicFragment extends Fragment {
public static String TAG = "need to be replaced";
protected View rootView;
protected int pageNo=1;
protected int pageCount;
protected abstract int getLayoutRes();
protected abstract void initData();
protected abstract void fillData();
@ -256,9 +258,7 @@ public abstract class BasicFragment extends Fragment {
// 开始刷新设置当前为刷新状态
//swipeRefreshLayout.setRefreshing(true);
// 这里是主线程
// 一些比较耗时的操作比如联网获取数据需要放到子线程去执行
pageNo=1;
initData();
// TODO 获取数据
@ -366,4 +366,7 @@ public abstract class BasicFragment extends Fragment {
public void reload() {
initViews();
}
public void loadData() {
initData();
} //on tab changed
}

View File

@ -8,7 +8,9 @@ import android.view.View;
import com.novelbook.android.R;
import com.novelbook.android.adapter.BandanAdapterNew;
import com.novelbook.android.adapter.BookListAdapter;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netsubscribe.BookSubscribe;
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
@ -17,6 +19,7 @@ import com.novelbook.android.utils.Constants;
import com.novelbook.android.utils.GsonUtil;
import com.novelbook.android.utils.OnItemClickListener;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
@ -29,6 +32,7 @@ public class Fragment_bangdan extends BasicFragment {
private static final String ARG_PARAM2 = "param2";
private BandanAdapterNew mAdapter;
private List<NovelBlock> mBlocks;
private List<NovelBlock> mMoreBlocks;
// private List<Novel> mData;
@BindView(R.id.rvBangdan)
RecyclerView rvBandan;
@ -44,38 +48,11 @@ public class Fragment_bangdan extends BasicFragment {
@Override
protected void fillData() {
if(mBlocks==null){
return;
if(mMoreBlocks!=null) {
mAdapter.AddFooterItem(mMoreBlocks);
mAdapter.notifyDataSetChanged();
}
mAdapter = new BandanAdapterNew(activity ,mBlocks,R.layout.recycle_list_item_bangdannew,new OnItemClickListener()
{
@Override
public void onItemClick(View view, int position)
{
// showBookDetail(mBlocks.get(blockId).getNs().get(novelIndex));
// showPaihangbang(mBlocks.get(position));
// Toast.makeText(getActivity(),"待。。。。。做",Toast.LENGTH_LONG).show();
}
@Override
public void onItemLongClick(View view, int position)
{
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int blockId,int novelIndex) {
// Toast.makeText(activity, "book "+ bookId + " clicked", Toast.LENGTH_SHORT).show();
showPaihangbang(mBlocks.get(blockId));
// showBookDetail(mBlocks.get(blockId).getNs().get(novelIndex));
//showPaihangbang("分类名称" +position);
Log.d(TAG,String.format("clicked: position %s,lineId %s",novelIndex,blockId));
// openBook();
}
});
initialBookList();
}
@ -92,9 +69,47 @@ public class Fragment_bangdan extends BasicFragment {
@Override
public void initData() {
if(pageNo==1) {
if(mBlocks!=null){ //下拉刷新
mBlocks = new ArrayList<NovelBlock>();
mAdapter.setData(mBlocks);
initialBookList();
}else{
mBlocks = new ArrayList<NovelBlock>();
mAdapter = new BandanAdapterNew(activity, mBlocks, R.layout.recycle_list_item_bangdannew, new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
// showBookDetail(mBlocks.get(blockId).getNs().get(novelIndex));
// showPaihangbang(mBlocks.get(position));
// Toast.makeText(getActivity(),"待。。。。。做",Toast.LENGTH_LONG).show();
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int blockId, int novelIndex) {
// Toast.makeText(activity, "book "+ bookId + " clicked", Toast.LENGTH_SHORT).show();
showPaihangbang(mBlocks.get(blockId));
// showBookDetail(mBlocks.get(blockId).getNs().get(novelIndex));
//showPaihangbang("分类名称" +position);
Log.d(TAG, String.format("clicked: position %s,lineId %s", novelIndex, blockId));
// openBook();
}
});
initialBookList();
}
}
showProgressDialog(true, "正在加载");
mMoreBlocks =null;
BookSubscribe.getSiteRanks( Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
@Override
@ -102,7 +117,7 @@ public class Fragment_bangdan extends BasicFragment {
// mFirstPage= gson.fromJson(result, FirstPage.class);
try {
mBlocks = GsonUtil.parserNovleBlocks(result,"ranks");
mMoreBlocks = GsonUtil.parserNovleBlocks(result,"ranks");
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "error on : " + e.getMessage());
@ -128,6 +143,7 @@ public class Fragment_bangdan extends BasicFragment {
}
void initialBookList() {
mAdapter.setShowFootView(true);
rvBandan.setLayoutManager(new LinearLayoutManager(activity));
rvBandan.setAdapter(mAdapter);

View File

@ -89,7 +89,7 @@ public class Fragment_bookStore extends BasicFragment {
mFragments.add(new Fragment_bangdan());
// mFragments.add(new Fragment_shudan());
Log.d(TAG,"initial fragments in tabs ");
}
}
Log.d(TAG,"set viewPager adapter ");
// FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(activity.getSupportFragmentManager()) { 第一次进入没问题再次进入ViewPager的fragment时里面内容就没了,数据丢失 https://blog.csdn.net/allan_bst/article/details/64920076
FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {
@ -108,6 +108,7 @@ public class Fragment_bookStore extends BasicFragment {
return mTitle[position];
}
};
mViewpager.setOffscreenPageLimit(3);//预加载设置
mViewpager.setAdapter(mAdapter);
tabLayout.setViewPager(mViewpager);
// tabLayout.setViewPager(mViewpager, mTitle, activity, mFragments);

View File

@ -1,5 +1,6 @@
package com.novelbook.android.Fragments;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
@ -19,6 +20,7 @@ import com.novelbook.android.Activity_Search;
import com.novelbook.android.Main2Activity;
import com.novelbook.android.R;
import com.novelbook.android.activity_cates;
import com.novelbook.android.adapter.BandanAdapterNew;
import com.novelbook.android.bean.NovelBlock;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netsubscribe.BookSubscribe;
@ -55,12 +57,20 @@ public class Fragment_booklist extends BasicFragment {
private String fn;
private String bangdan;
private int pageNo=1;
//private int pageNo=1;
private int totalCount;
private int pageCount;
// private int pageCount;
@BindView(R.id.rvBooklist)
RecyclerView mRecyclerView;
@SuppressLint("ValidFragment")
public Fragment_booklist(String cate, int progress) {
this.cate =cate;
this.progress = progress;
}
public Fragment_booklist() {
// Required empty public constructor
}
@ -108,39 +118,22 @@ public class Fragment_booklist extends BasicFragment {
@Override
protected void fillData() {
if(mData==null) {
mData = new ArrayList<Novel>();
mAdapter = new BookListAdapter(activity, mData, R.layout.recycle_list_item_horizon, new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
showBookDetail(mData.get(position));
// openBook(mData.get(position),mAdapter);
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position, int llId) {
Toast.makeText(activity, "book " + position + " clicked",
Toast.LENGTH_SHORT).show();
}
});
if(mRecyclerView.getAdapter()==null) {
mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
mRecyclerView.setAdapter(mAdapter);
}
if(mMoreData!=null) {
if(mMoreData.size()>0) {
pageNo++;
}
int status = pageCount > pageNo ? BookListAdapter.PULLUP_LOAD_MORE : BookListAdapter.NO_LOAD_MORE;
int status = pageCount >= pageNo ? BookListAdapter.PULLUP_LOAD_MORE : BookListAdapter.NO_LOAD_MORE;
// mAdapter.setPercent(pageNo/pageCount);
mAdapter.AddFooterItem(mMoreData);
mAdapter.changeMoreStatus(status);
}
}
@ -154,6 +147,43 @@ public class Fragment_booklist extends BasicFragment {
@Override
public void initData() {
int pn = pageNo;
if(pageNo==1) {
if (mData != null) { //下拉刷新
mData = new ArrayList<Novel>();
mAdapter.setData(mData);
} else {
mData = new ArrayList<Novel>();
mAdapter = new BookListAdapter(activity, mData, R.layout.recycle_list_item_horizon, new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
showBookDetail(mData.get(position));
// openBook(mData.get(position),mAdapter);
}
@Override
public void onItemLongClick(View view, int position) {
// initDialog(position);
// mAdapter.removeData(position);
}
@Override
public void onLinearOutClick(View view, int position, int llId) {
Toast.makeText(activity, "book " + position + " clicked",
Toast.LENGTH_SHORT).show();
}
});
mAdapter.setShowFootView(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
mRecyclerView.setAdapter(mAdapter);
}
}
/* if(mAdapter!=null){
mAdapter.changeMoreStatus(BookListAdapter.LOADING_MORE);
}*/
@ -189,7 +219,7 @@ public class Fragment_booklist extends BasicFragment {
Log.d(TAG,String.format("fn is %s",fn) );
if(!TextUtils.isEmpty(bangdan) && !TextUtils.isEmpty(fn)){ //榜单
showProgressDialog(true, "正在加载榜单");
// showProgressDialog(true, "正在加载榜单");
BookSubscribe.getSiteRankDetail(fn,pageNo,Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
@Override
public void onSuccess(String result) {
@ -217,16 +247,16 @@ public class Fragment_booklist extends BasicFragment {
}else if(!TextUtils.isEmpty(fn)){ //首页 更多
showProgressDialog(true, "正在加载更多");
// showProgressDialog(true, "正在加载更多");
BookSubscribe.getNovelPaihang(fn,Constants.SEX,new OnSuccessAndFaultSub(successAndFaultListener, getActivity()));
}
else if(!TextUtils.isEmpty((cate))) { //分类
showProgressDialog(true, "正在加载分类");
// showProgressDialog(true, "正在加载分类");
BookSubscribe.getCateNovelList(cate, pageNo, Constants.SEX, progress, new OnSuccessAndFaultSub(successAndFaultListener, getActivity()));
}else if(!TextUtils.isEmpty(keyWord)){ //搜索
showProgressDialog(true, "正在加载搜索");
// showProgressDialog(true, "正在加载搜索");
BookSubscribe.getSearchNovelList( keyWord,pageNo, Constants.SEX, new OnSuccessAndFaultSub(successAndFaultListener, getActivity()));
}
@ -258,11 +288,15 @@ public class Fragment_booklist extends BasicFragment {
//判断RecyclerView的状态 是空闲时同时是最后一个可见的ITEM时才加载
if(newState==RecyclerView.SCROLL_STATE_IDLE&&lastVisibleItem+1==mAdapter.getItemCount()){
//设置正在加载更多
mAdapter.changeMoreStatus(mAdapter.LOADING_MORE);
if(pageNo <= pageCount) {
//设置正在加载更多
mAdapter.changeMoreStatus(mAdapter.LOADING_MORE);
//改为网络请求
initData();
//改为网络请求
initData();
}else{
mAdapter.changeMoreStatus(mAdapter.NO_LOAD_MORE);
}
}
@ -279,6 +313,11 @@ public class Fragment_booklist extends BasicFragment {
});
}
@Override
public void onResume(){
super.onResume();
pageNo=1;
}
}

View File

@ -1,6 +1,7 @@
package com.novelbook.android.Fragments;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@ -74,14 +75,16 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
MyViewPager mViewpagerTuijian;
//@BindView(R.id.titleIndictator)
// TitlePageIndicator titleIndicator;
@BindView(R.id.imageBlock0)
ImageView imageViewBlock0;
@BindView(R.id.imageBlock1)
ImageView imageViewBlock1;
@BindView(R.id.imageBlock2)
ImageView imageViewBlock2;
@BindView(R.id.imageBlock3)
ImageView imageViewBlock3;
@BindView(R.id.tvBlock0)
TextView tvBlock0;
@BindView(R.id.tvBlock1)
TextView tvBlock1;
@BindView(R.id.tvBlock2)
@ -118,7 +121,7 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
private int INDEX_BANNER =1;
private int INDEX_TUIJIAN =2;
private int blockIndex =3; //从第3个block 开始处理
private int gridItemSpace = 0;
public Fragment_jingxuan() {
// Required empty public constructor
@ -273,7 +276,7 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
@Override
public void initViews() {
gridItemSpace = getResources().getDimensionPixelSize(R.dimen._10dp);
}
@ -393,6 +396,8 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
// mTitle = new String[]{"精选", "榜单", "书单"};
mFragments = new ArrayList<>();
NovelBlock block = mBlocks.get(1);
loadImageView(mBlocks.get(1).getIcon(),imageViewBlock0);
tvBlock0.setText( mBlocks.get(1).getName());
List<Novel> nvs = new ArrayList<Novel>();
for(Novel novel : block.getNs() ){
@ -488,7 +493,10 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
}
if(mHotNewData_g!=null) {
rvHotNewG.setLayoutManager(new GridLayoutManager(activity, spanCnt));
if( rvHotNewG.getItemDecorationCount()>0){
rvHotNewG.removeItemDecorationAt(0);
}
rvHotNewG.addItemDecoration(new SpaceItemDecoration( gridItemSpace));
rvHotNewG.setAdapter(new BookListAdapter(activity, mHotNewData_g, R.layout.recycle_list_item, new OnItemClickListener() {
@Override
@ -538,7 +546,10 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
}
if(mHotLianZaiData_g!=null) {
rvLianZaiG.setLayoutManager(new GridLayoutManager(activity, spanCnt));
if( rvLianZaiG.getItemDecorationCount()>0){
rvLianZaiG.removeItemDecorationAt(0);
}
rvLianZaiG.addItemDecoration(new SpaceItemDecoration( gridItemSpace));
rvLianZaiG.setAdapter(new BookListAdapter(activity, mHotLianZaiData_g, R.layout.recycle_list_item, new OnItemClickListener() {
@Override
@ -589,7 +600,10 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
}
if(mFinishedData_g!=null) {
rvFinishG.setLayoutManager(new GridLayoutManager(activity, spanCnt));
if( rvFinishG.getItemDecorationCount()>0){
rvFinishG.removeItemDecorationAt(0);
}
rvFinishG.addItemDecoration(new SpaceItemDecoration( gridItemSpace));
rvFinishG.setAdapter(new BookListAdapter(activity, mFinishedData_g, R.layout.recycle_list_item, new OnItemClickListener() {
@Override
@ -614,6 +628,40 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
}));
}
}
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpaceItemDecoration(int space) {
this.space = space*3;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//不是第一个的格子都设一个左边和底部的间距
//outRect.left = space;
// outRect.bottom = space;
//由于每行都只有3个所以第一个都是3的倍数把左边距设为0
if (parent.getChildLayoutPosition(view) %getSpanCnt()==0) {
Log.d(TAG, "getItemOffsets: left " +parent.getChildLayoutPosition(view));
//outRect.set(0,0,0,0);
outRect.right=space;
outRect.left=0;
}else if(parent.getChildLayoutPosition(view) %getSpanCnt()==2){
Log.d(TAG, "getItemOffsets: right " +parent.getChildLayoutPosition(view));
// outRect.set(0,0,0,0);
outRect.right=0;
outRect.left=space;
}else {
// outRect.set(space, 0, space, 0);
// outRect.right=space;
// outRect.left=space;
Log.d(TAG, "getItemOffsets: center " +parent.getChildLayoutPosition(view));
}
// outRect.set(0,0,0,0);
}
}
}

View File

@ -91,7 +91,7 @@ public class Fragment_paihang extends BasicFragment {
mData3 = new ArrayList<>();
mData1.add(new TabEntry("男A",0,0) );
mData1.add(new TabEntry("女A",0,0));
for (int i = 'A'; i < 'I'; i++)
for (int i = 'A'; i < 'F'; i++)
{
mData2.add(new TabEntry("" + (char) i,0,0) );
if(i<'D')
@ -171,6 +171,7 @@ public class Fragment_paihang extends BasicFragment {
});
tabLayout2.setTabData(mData2);
tabLayout2.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {

View File

@ -22,7 +22,7 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class BandanAdapterNew extends RecyclerView.Adapter<BandanAdapterNew.MyViewHolder> {
public class BandanAdapterNew extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int EMPTY_VIEW = 1;
private final int PROGRESS_VIEW = 2;
private final int IMAGE_VIEW = 3;
@ -31,6 +31,11 @@ public class BandanAdapterNew extends RecyclerView.Adapter<BandanAdapterNew.MyVi
private List<NovelBlock> mDatas = new ArrayList<NovelBlock>();
private OnItemClickListener mOnItemClickLitener;
private int listItemID;
private boolean showFootView =false;
public void setShowFootView(boolean showFootView) {
this.showFootView = showFootView;
}
public BandanAdapterNew(Context context, List<NovelBlock> mDatas, int listItemID, OnItemClickListener clickLitener) {
this.context = context;
this.mDatas = mDatas;
@ -55,12 +60,16 @@ public class BandanAdapterNew extends RecyclerView.Adapter<BandanAdapterNew.MyVi
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
context).inflate(listItemID, parent,
false));
return holder;
if(viewType == EMPTY_VIEW){
EmptyViewHolder holder = new EmptyViewHolder (LayoutInflater.from(context).inflate(R.layout.recycle_list_empty_item, parent, false));
return holder;
}
MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(listItemID, parent,
false));
return holder;
}
@ -76,9 +85,17 @@ public class BandanAdapterNew extends RecyclerView.Adapter<BandanAdapterNew.MyVi
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position)
public void onBindViewHolder(RecyclerView.ViewHolder hd, int position)
{
if (hd instanceof EmptyViewHolder) {
EmptyViewHolder holder = (EmptyViewHolder)hd;
holder.tvEmpty.setVisibility(View.VISIBLE);
holder.tvEmpty.setText(R.string.noRecord);
return;
}
MyViewHolder holder = (MyViewHolder)hd;
NovelBlock nb = mDatas.get(position);
holder.tvCateName.setText(nb.getName());
if(nb==null){return;}
@ -148,11 +165,29 @@ public class BandanAdapterNew extends RecyclerView.Adapter<BandanAdapterNew.MyVi
// mDatas.add(position, "Insert One");
notifyItemInserted(position);
}
public void setData(List<NovelBlock> items) {
// mDatas.add(position, "Insert One");
mDatas = items;
notifyDataSetChanged();
}
public void removeData(int position) {
mDatas.remove(position);
notifyItemRemoved(position);
}
public void AddFooterItem(List<NovelBlock> items) {
mDatas.addAll(items);
notifyDataSetChanged();
}
class EmptyViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tvLoadText)
TextView tvEmpty;
public EmptyViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this,itemView);
}
}
class MyViewHolder extends RecyclerView.ViewHolder
{
@BindView(R.id.ll1)

View File

@ -32,6 +32,7 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
private final int IMAGE_VIEW = 3;
private static final int TYPE_ITEM = 4;
private static final int TYPE_FOOTER = 5;
private static final int NO_FOOTER = 6;
// private MyImageLoader loader = new MyImageLoader();
private Context context;
private List<Novel> mDatas ;
@ -48,8 +49,19 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
public static final int NO_LOAD_MORE = 2;
//上拉加载更多状态-默认为0
private int mLoadMoreStatus = 0;
private int mLoadMoreStatus = 2;
private boolean showFootView =false;
private float percent =0;
public void setPercent(float percent) {
this.percent = percent;
}
public void setShowFootView(boolean showFootView) {
this.showFootView = showFootView;
}
public BookListAdapter(Context context, List<Novel> datas) {
context = context;
@ -83,10 +95,14 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
public int getItemViewType(int position) {
if (mDatas.size() == 0) {
return EMPTY_VIEW;
} else if (mDatas.get(position) == null) {
return PROGRESS_VIEW;
} else if ( position + 1 == getItemCount()) {
}else if ( position < mDatas.size()) {
//最后一个item设置为footerView
return TYPE_ITEM;
} else if ( position == mDatas.size()) {
//最后一个item设置为footerView
if(!showFootView){
return NO_FOOTER;
}
return TYPE_FOOTER;
} else {
return TYPE_ITEM;
@ -110,6 +126,8 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
}else if(viewType == EMPTY_VIEW){
EmptyViewHolder holder = new EmptyViewHolder (LayoutInflater.from(context).inflate(R.layout.recycle_list_empty_item, parent, false));
return holder;
}else if(viewType == NO_FOOTER){
return new NoShowViewHolder (LayoutInflater.from(context).inflate(R.layout.recycle_list_noshow_item, parent, false));
}
View itemView = mInflater.inflate(listItemID, parent, false);
@ -144,18 +162,31 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
switch (mLoadMoreStatus) {
case PULLUP_LOAD_MORE:
footerViewHolder.mTvLoadText.setText("上拉加载更多...");
footerViewHolder.mTvLoadText.setText(String.format("上拉加载更多.."));
break;
case LOADING_MORE:
footerViewHolder.mTvLoadText.setText("正加载更多...");
break;
case NO_LOAD_MORE:
if(!showFootView){
footerViewHolder.mLoadLayout.setVisibility(View.GONE);
footerViewHolder.itemView.setVisibility(View.GONE);
return;
}
//隐藏加载更多
footerViewHolder.mLoadLayout.setVisibility(View.GONE);
footerViewHolder.mTvLoadText.setText("到底了");
break;
}
}else if (hd instanceof MyViewHolder) {
}else if (hd instanceof EmptyViewHolder) {
EmptyViewHolder holder = (EmptyViewHolder)hd;
holder.tvEmpty.setVisibility(View.VISIBLE);
holder.tvEmpty.setText(R.string.noRecord);
}
else if (hd instanceof MyViewHolder) {
MyViewHolder holder = (MyViewHolder)hd;
holder.tvTitle.setText(mDatas.get(position).getName());
@ -190,7 +221,7 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
@Override
public int getItemCount() {
return mDatas.size();
return mDatas.size()+1;
}
public void addData(int position) {
@ -215,18 +246,30 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
ButterKnife.bind(this,itemView);
}
}
public class EmptyViewHolder extends RecyclerView.ViewHolder {
class EmptyViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tvLoadText)
TextView tvEmpty;
public EmptyViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this,itemView);
}
}
class NoShowViewHolder extends RecyclerView.ViewHolder {
public NoShowViewHolder(View itemView) {
super(itemView);
}
}
public void AddHeaderItem(List<Novel> items) {
mDatas.addAll(0, items);
notifyDataSetChanged();
}
public void setData(List<Novel> items) {
// mDatas.add(position, "Insert One");
mDatas = items;
notifyDataSetChanged();
}
public void AddFooterItem(List<Novel> items) {
mDatas.addAll(items);
notifyDataSetChanged();
@ -239,4 +282,7 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
mLoadMoreStatus=status;
notifyDataSetChanged();
}
}

View File

@ -267,7 +267,7 @@ public class HttpMethods {
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (!NetUtil.isNetworkConnected()) {
int maxStale = 60 * 60 * 24 * 28;
int maxStale = 0;// 60 * 60 * 24 * 28;
request = request.newBuilder()
.removeHeader("Pragma")
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)

View File

@ -73,6 +73,7 @@ public class OnSuccessAndFaultSub extends DisposableObserver<ResponseBody>
private void showProgressDialog() {
if (showProgress && null != progressDialog) {
progressDialog.setMessage("正在请求网络");
progressDialog.show();
}
}

View File

@ -18,11 +18,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ToolBarTheme.AppBarOverlay">
<!--android:layout_height="?attr/actionBarSize"-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_height="40dp"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolBarTheme.PopupOverlay" >
<TextView

View File

@ -1,19 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/llOutside"
tools:showIn="@layout/activity_cates"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity_cates"
tools:showIn="@layout/activity_cates">
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleViewCateList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
>
</android.support.v7.widget.RecyclerView>
<!--android:background="@color/whitesmoke"-->
</android.support.constraint.ConstraintLayout>
</LinearLayout>

View File

@ -20,8 +20,10 @@
android:layout_weight="1"
android:divider="#ffff0000"
android:dividerHeight="10dp"
android:paddingTop="20dp"
android:paddingBottom="40dp" />
android:paddingTop="1dp"
android:paddingBottom="40dp"
/>
<LinearLayout
android:id="@+id/llShelfBottom"

View File

@ -10,11 +10,11 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/rvBangdan"
android:divider="#ffff0000"
android:dividerHeight="10dp"
android:dividerHeight="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:paddingBottom="50dp"
android:paddingBottom="30dp"
android:layout_marginBottom="-2dp"
/>

View File

@ -14,7 +14,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:paddingTop="10dp"
android:paddingTop="5dp"
/>
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -45,12 +45,14 @@
style="@style/NovelBlockHead"
>
<ImageView
android:id="@+id/imageBlock0"
style="@style/NovelBlockImg"
android:src="@drawable/googleg_standard_color_18" />
/>
<TextView
android:id="@+id/tvBlock0"
style="@style/NovelBlockTitle"
android:text="重磅推荐"
android:text=""
/>
<Button
@ -102,7 +104,7 @@
<ImageView
android:id="@+id/imageBlock1"
style="@style/NovelBlockImg"
android:src="@drawable/googleg_standard_color_18" />
/>
<TextView
android:id="@+id/tvBlock1"
@ -124,10 +126,13 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/rvHotNewL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:divider="#ffff0000"
android:dividerHeight="10dp"
android:nestedScrollingEnabled="false" />
android:nestedScrollingEnabled="false"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvHotNewG"
@ -158,7 +163,7 @@
<ImageView
android:id="@+id/imageBlock2"
style="@style/NovelBlockImg"
android:src="@drawable/googleg_standard_color_18" />
/>
<TextView
android:id="@+id/tvBlock2"
@ -216,7 +221,7 @@
<ImageView
android:id="@+id/imageBlock3"
style="@style/NovelBlockImg"
android:src="@drawable/googleg_standard_color_18" />
/>
<TextView
android:id="@+id/tvBlock3"
@ -277,7 +282,7 @@
<ImageView
android:id="@+id/imageBlock4"
style="@style/NovelBlockImg"
android:src="@drawable/googleg_standard_color_18" />
/>
<TextView
android:id="@+id/tvBlock4"
@ -305,7 +310,7 @@
android:nestedScrollingEnabled="false"
/>
<LinearLayout style="@style/llGraySplit.2dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvG"
android:layout_width="match_parent"

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loadLayout"
android:padding="10dp"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -17,10 +17,12 @@
<ProgressBar
android:id="@+id/pbLoad"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_width="5dp"
android:layout_height="5dp"
android:layout_centerVertical="true"
android:indeterminate="false"/>
android:indeterminate="false"
android:visibility="gone"
/>
<TextView
android:id="@+id/tvLoadText"
@ -32,8 +34,8 @@
android:layout_toRightOf="@id/pbLoad"
android:clickable="true"
android:text="魂牵梦萦 魂牵梦萦 "
android:textColor="#000000"
android:textSize="16sp"/>
style="@style/TextViewNovelDesc.titles"
/>
</RelativeLayout>
</LinearLayout>

View File

@ -8,32 +8,15 @@
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:gravity="center">
<ProgressBar
android:id="@+id/pbLoad"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:indeterminate="false"/>
<TextView
android:id="@+id/tvLoadText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginLeft="4dip"
android:layout_toRightOf="@id/pbLoad"
android:clickable="true"
android:text="没有数据 "
android:textColor="#000000"
android:textSize="16sp"/>
</RelativeLayout>
<TextView
style="@style/TextViewNovelDesc.titles"
android:id="@+id/tvLoadText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/noRecord"
/>
</LinearLayout>

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/item_selector"
android:clickable="true"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_margin="0dp"
android:padding="2dp">
<FrameLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
@ -30,6 +30,7 @@
<TextView
android:id="@+id/title"
style="@style/TextViewNovelTitle"
android:layout_gravity="center_horizontal"
android:layout_width="75dp"
android:gravity="top|center"
android:text="天龙八部天龙八部天龙八部"

View File

@ -2,11 +2,12 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/item_selector"
android:orientation="vertical">
<LinearLayout style="@style/llGraySplit" />
<LinearLayout
<!--<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center_horizontal"
@ -25,14 +26,14 @@
android:text="更多"
/>
</LinearLayout>
</LinearLayout>-->
<LinearLayout
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
android:background="@drawable/item_selector"
android:clickable="true"
android:gravity="center"
android:orientation="vertical">

View File

@ -3,13 +3,13 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView"
android:layout_marginRight="2dp"
android:layout_marginLeft="2dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
app:cardCornerRadius="6dp"
@ -27,10 +27,12 @@
android:layout_weight="0"
android:padding="2dp"
android:layout_marginTop="5dp"
android:id="@+id/imageViewCate"
android:layout_width="80dp"
android:layout_height="100dp"
android:scaleType="fitCenter"
android:layout_gravity="center_horizontal"
android:src="@drawable/googleg_standard_color_18"
tools:ignore="ContentDescription" />

View File

@ -23,7 +23,7 @@
android:id="@+id/title"
style="@style/TextViewNovelTitle.horizon"
android:text="射雕英雄传"
android:text=" "
/>
<LinearLayout
android:layout_marginTop="2dp"
@ -35,12 +35,12 @@
<TextView
style="@style/TextViewNovelType"
android:id="@+id/category"
android:text="武侠小说"
android:text=" "
/>
<TextView
android:id="@+id/author"
style="@style/TextViewNovelAuthor"
android:text="金庸"
android:text=" "
/>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loadLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>

View File

@ -45,6 +45,7 @@
<dimen name="marginBottom">5dp</dimen>
<!-- 底部导航栏高度 -->
<dimen name="botoomNavi">42dp</dimen>
<dimen name="_10dp">10dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->

View File

@ -184,6 +184,7 @@
<string name="readseting">设置</string>
<string name="aboutContent">如风小说阅读是专注于提供更舒适的阅读体验,主打本地阅读,操作方式简单易上手,目前支持txt格式。</string>
<string name="noRecord">没有数据</string>
<string-array name="voicer_cloud_entries">
<item>小燕—女青、中英、普通话</item>

View File

@ -158,6 +158,7 @@
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:scaleType">fitStart</item>
<item name="android:paddingTop">2dp</item>
</style>
<style name="NovelImage.horizon">
<item name="android:layout_weight">0</item>
@ -213,7 +214,7 @@
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
</style>
<!-- <item name="android:background">@color/colorAccent</item>-->
<style name="llOutside">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>