diff --git a/zhuike/build.gradle b/zhuike/build.gradle index 414e1a9..83713ec 100644 --- a/zhuike/build.gradle +++ b/zhuike/build.gradle @@ -168,4 +168,8 @@ dependencies { implementation 'com.github.ixiaow:multilayout:1.0.0' implementation 'com.umeng.umsdk:analytics:8.0.2' implementation 'com.umeng.umsdk:common:2.0.2' + + + implementation 'q.rorbin:VerticalTabLayout:1.2.5' + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16' } diff --git a/zhuike/src/main/AndroidManifest.xml b/zhuike/src/main/AndroidManifest.xml index 4e43144..d5be0dd 100644 --- a/zhuike/src/main/AndroidManifest.xml +++ b/zhuike/src/main/AndroidManifest.xml @@ -49,6 +49,7 @@ mFragments; ArrayList mList; String[] mTitle; - public static String TAG="com.novelbook.android.Activity_cate_books"; + + private int tabPos; @Override public int getLayoutRes() { @@ -40,7 +54,7 @@ public class Activity_cate_books extends Activity_base { @Override protected void initViews() { creatToolbar(); - initTabs(); + initTabs2(); } @@ -62,17 +76,37 @@ public class Activity_cate_books extends Activity_base { //---------tabs------------- void initTabs() { - - if (mFragments == null || mFragments.size() == 0) { - mTitle = new String[]{"新书", "连载", "完本"}; - mFragments = new ArrayList(); - - 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 "); + List lstType = new ArrayList() ;//Arrays.asList(lstProgress); + for(ProgressType progressType : Constants.lstProgressType){ + lstType.add(progressType.getName()); } + topic_layout.initTabNames(lstType) ; + topic_layout.setOnTabSelectListener(new MultiLayout.OnTabSelectListener() { + @Override + public void select(TextView textView, int i, int i1) { + Log.d(TAG, String.format("select: text %s,i %s i1 %s ",textView.getText(),i,i1)); + tabPos = i1; + tabChanged(); + } + }); + + + } + void initTabs2() { + + + if (mFragments == null ) { + + mFragments = new ArrayList(); + } + mFragments.clear(); + + for(ProgressType progressType : Constants.lstProgressType) { + mFragments.add(Fragment_booklist.newInstance(cate, progressType.getId())); + } + + 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(getSupportFragmentManager()) { @@ -89,20 +123,71 @@ public class Activity_cate_books extends Activity_base { //ViewPager与TabLayout绑定后,这里获取到PageTitle就是Tab的Text @Override public CharSequence getPageTitle(int position) { - return mTitle[position]; + return Constants.lstProgressType.get(position).getName(); } }; mViewpager.setAdapter(mAdapter); - mViewpager.setOffscreenPageLimit(3); - - - - tabLayout.setViewPager(mViewpager); + mViewpager.setOffscreenPageLimit( Constants.lstProgressType.size()+1); + tabLayout.setViewPager(mViewpager); // tabLayout.setViewPager(mViewpager, mTitle, activity, mFragments); mViewpager.setCurrentItem(0); + + } + int tmp=0; + private void tabChanged() { + + Log.d(TAG, String.format("tabChanged: to load data tmp %s" , tmp )); + tmp++; + + if(lstSex==null) return; + + + + if (mFragments == null ) { + + mFragments = new ArrayList(); + } + mFragments.clear(); + + mFragments.add(Fragment_booklist.newInstance(cate, Constants.lstProgressType.get(tabPos).getId())); + + + 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(getSupportFragmentManager()) { + @Override + public Fragment getItem(int position) { + return mFragments.get(position); + } + + @Override + public int getCount() { + return mFragments.size(); + } + + //ViewPager与TabLayout绑定后,这里获取到PageTitle就是Tab的Text + @Override + public CharSequence getPageTitle(int position) { + return mTitle[position]; + } + }; + mViewpager.setAdapter(mAdapter); + mViewpager.setOffscreenPageLimit(2); + + + + // tabLayout.setViewPager(mViewpager); + // tabLayout.setViewPager(mViewpager, mTitle, activity, mFragments); + mViewpager.setCurrentItem(0); + + } + + @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. diff --git a/zhuike/src/main/java/com/novelbook/android/Activity_paihangbang.java b/zhuike/src/main/java/com/novelbook/android/Activity_paihangbang.java index 4ba1212..3389b02 100644 --- a/zhuike/src/main/java/com/novelbook/android/Activity_paihangbang.java +++ b/zhuike/src/main/java/com/novelbook/android/Activity_paihangbang.java @@ -30,6 +30,7 @@ public static String TAG ="com.novelbook.android.paihangbang"; @BindView(R.id.tab_layout) SlidingTabLayout tabLayout; public static final String EXTR_FN="fn"; + public static final String EXTR_CID="cid"; public static final String EXTR_TITLE="title"; public static final String EXTR_BANGDAN ="bangdan"; public static final String EXTR_SEARCH ="search"; @@ -47,7 +48,7 @@ public static String TAG ="com.novelbook.android.paihangbang"; initTabs(); } - + int cid; String bangdan,fn,keyword,histroy; @Override @@ -58,7 +59,7 @@ public static String TAG ="com.novelbook.android.paihangbang"; } fn = getIntent().getStringExtra(EXTR_FN); - + cid = getIntent().getIntExtra(EXTR_CID,-1); bangdan = getIntent().getStringExtra(EXTR_BANGDAN); String title = getIntent().getStringExtra(EXTR_TITLE); @@ -95,6 +96,8 @@ public static String TAG ="com.novelbook.android.paihangbang"; }else if(!TextUtils.isEmpty(fn)){ mFragments.add(Fragment_booklist.newInstance(fn, bangdan)); //首页更多 + }else if(cid>0){ + mFragments.add(Fragment_booklist.newInstance(cid, bangdan)); //首页更多 } diff --git a/zhuike/src/main/java/com/novelbook/android/BookActivity.java b/zhuike/src/main/java/com/novelbook/android/BookActivity.java index 61fc06b..64503fc 100644 --- a/zhuike/src/main/java/com/novelbook/android/BookActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/BookActivity.java @@ -268,7 +268,12 @@ public class BookActivity extends Activity_base { this.txtLatestCate.setText(mNovel.getChapterName()); tvLastUpdate.setText(CommonUtil.getDateString( mNovel.getLastUpdateTime())); loadImageView(mNovel.getCover(),imageView); - gaosiHeadPic(); + try { + gaosiHeadPic(); + }catch (Exception e){ + Log.e(TAG, "setBookDetailInfo: gosiheadpic error", e); + } + } void gaosiHeadPic(){ //new BlurTransformation(BookActivity.this, 10)).into(mImageView); diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java b/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java index 9367b07..6202e47 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java @@ -134,7 +134,7 @@ public abstract class BasicFragment extends Fragment { } - public abstract void setFTag(); + public void setFTag(){}; Handler handler = new Handler() { @Override @@ -380,7 +380,7 @@ public abstract class BasicFragment extends Fragment { Intent intent = new Intent(activity, Activity_paihangbang.class); String title = TextUtils.isEmpty(nb.getTitle()) ? nb.getName() : nb.getTitle() ; - intent.putExtra(Activity_paihangbang.EXTR_FN,nb.getFn() ); + intent.putExtra(Activity_paihangbang.EXTR_CID,nb.getCid() ); intent.putExtra(Activity_paihangbang.EXTR_TITLE,title ); intent.putExtra(Activity_paihangbang.EXTR_BANGDAN,title ); startActivity(intent); diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/CatalogFragment.java b/zhuike/src/main/java/com/novelbook/android/Fragments/CatalogFragment.java index ebe4510..b9134f4 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/CatalogFragment.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/CatalogFragment.java @@ -177,7 +177,7 @@ public class CatalogFragment extends BasicFragment implements MarkActivity.Sortc } } - int maxSlept =NetUtil.isNetworkConnected()?50 :200; + int maxSlept =NetUtil.isNetworkConnected()?250 :100; int slepttime = 0; while ( slepttime < maxSlept && ( pageFactory.isReadingCatalogs() || pageFactory.getChapters().size() == 0)) { try { diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java index 06689cd..5b9bd28 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java @@ -80,6 +80,7 @@ public class Fragment_Shelf extends BasicFragment { private List bookLists; // private ShelfAdapter adapter; private String noveIds ; + BottomSheetDialog bottomSheetDialog; public Fragment_Shelf() { // Required empty public constructor } @@ -330,7 +331,7 @@ void test(int maxAge){ private void initDialog(int position) { - BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this.activity); + bottomSheetDialog = new BottomSheetDialog(this.activity); bottomSheetDialog.setContentView(R.layout.fragment_shelf_botoomsheetdialog); //给布局设置透明背景色 bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet) @@ -488,7 +489,9 @@ void test(int maxAge){ public void onResume() { super.onResume(); getUpdatedData(); //TODO: 更新书的状态,是不有更新 - + if(bottomSheetDialog!=null){ + bottomSheetDialog.hide(); + } } diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bangdan.java b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bangdan.java index 684fcaa..32845a8 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bangdan.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bangdan.java @@ -31,8 +31,7 @@ public class Fragment_bangdan extends BasicFragment { public static final String TAG=Fragment_bangdan.class.getSimpleName(); // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; + private static final String ARG_CID = "CID"; private BandanAdapterNew mAdapter; private List mBlocks; private List mMoreBlocks; @@ -42,11 +41,11 @@ public class Fragment_bangdan extends BasicFragment { // @BindView(R.id.topic_layout) // MultiLayout topic_layout; - public static Fragment_bangdan newInstance(String param1, String param2) { + private int cid; + public static Fragment_bangdan newInstance(int cid) { Fragment_bangdan fragment = new Fragment_bangdan(); Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); + args.putInt(ARG_CID, cid); fragment.setArguments(args); return fragment; } @@ -74,6 +73,11 @@ public class Fragment_bangdan extends BasicFragment { @Override public void initData() { + + if (getArguments() != null) { + cid = getArguments().getInt(ARG_CID); + } + if(pageNo==1) { if(mBlocks!=null){ //下拉刷新 @@ -116,7 +120,7 @@ public class Fragment_bangdan extends BasicFragment { showProgressDialog(true, "正在加载"); mMoreBlocks =null; - BookSubscribe.getSiteRanks( Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { + BookSubscribe.getPaihangBangByCate( Constants.SEX,cid,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { @Override public void onSuccess(String result) { diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bangdans.java b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bangdans.java new file mode 100644 index 0000000..8f325b2 --- /dev/null +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bangdans.java @@ -0,0 +1,185 @@ +package com.novelbook.android.Fragments; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.ViewPager; +import android.util.Log; +import android.view.View; + +import com.flyco.tablayout.SlidingTabLayout; +import com.novelbook.android.R; +import com.novelbook.android.bean.BangdanCate; +import com.novelbook.android.netsubscribe.BookSubscribe; +import com.novelbook.android.netutils.OnSuccessAndFaultListener; +import com.novelbook.android.netutils.OnSuccessAndFaultSub; +import com.novelbook.android.utils.Constants; +import com.novelbook.android.utils.GsonUtil; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import q.rorbin.verticaltablayout.VerticalTabLayout; + + +public class Fragment_bangdans extends BasicFragment { + + public static String TAG= Fragment_bangdans.class.getSimpleName(); + + @BindView(R.id.viewpager) + ViewPager mViewpager; + @BindView(R.id.tablayout) + VerticalTabLayout tabLayout; + private FragmentStatePagerAdapter mAdapter =null; + private ArrayList mFragments; + ArrayList mList; + String[] mTitle; + + List mCateList; + protected void processArguments(){ + if (getArguments() != null) { + Bundle bundle = getArguments() ; + + + + } + } + + + public static Fragment_bangdans newInstance(String param1, String param2) { + Fragment_bangdans fragment = new Fragment_bangdans(); + Bundle args = new Bundle(); + + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (getArguments() != null) { + // mParam1 = getArguments().getString(ARG_PARAM1); + // mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + + + @Override + protected int getLayoutRes() { + return R.layout.fragment_bangdans; + } + + @Override + public void initData() { + + showProgressDialog(false,"正在加载榜单列表"); + getCateTabTtitle(); + + } + @Override + public void fillData() { + + // initTabs(); + }; + + public void onSexSwitch(){ + if(mAdapter!=null) { + for(BasicFragment bf:mFragments){ + bf.initData(); + } + mAdapter.notifyDataSetChanged(); + + } + } + + @Override + public void initViews(){ + mFragments = new ArrayList<>(); + mAdapter = new FragmentStatePagerAdapter(getChildFragmentManager()) { + @Override + public Fragment getItem(int position) { + return mFragments.get(position); + } + + @Override + public int getCount() { + return mFragments.size(); + } + //ViewPager与TabLayout绑定后,这里获取到PageTitle就是Tab的Text + @Override + public CharSequence getPageTitle(int position) { + return mCateList.get(position).getName(); + } + }; + + + // mViewpager.setAdapter(mAdapter); + // tabLayout.setupWithViewPager(mViewpager); + } + + //---------tabs------------- + + void initTabs() { + Log.d(TAG, "getCateTabTtitle: init tabs"); + // if(mFragments ==null || mFragments.size() ==0) + { + // mTitle = new String[]{"精选", "榜单", "书单"}; + mFragments.clear(); + + for(BangdanCate bangdanCate : mCateList) { + mFragments.add(Fragment_bangdan.newInstance(bangdanCate.getCid())); + } + + // 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 + mAdapter.notifyDataSetChanged(); + // mViewpager.setOffscreenPageLimit(30);//预加载设置 + if(mCateList!=null){ + mViewpager.setOffscreenPageLimit(mCateList.size()+1);//预加载设置 + } + mViewpager.setAdapter(mAdapter); + tabLayout.setupWithViewPager(mViewpager); + // tabLayout.setViewPager(mViewpager, mTitle, activity, mFragments); + // mViewpager.setCurrentItem(0); + } + + + void getCateTabTtitle(){ + + Log.d(TAG, "getCateTabTtitle: prepare cate tabs"); + + BookSubscribe.getPaihangBangCateList(Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { + @Override + public void onSuccess(String result) { + try { + + mCateList = GsonUtil.parserBangdanCate(result,"subCategories"); + + initTabs(); + + } catch (Exception e) { + Log.e(TAG, "onSuccess: prepare book",e ); + e.printStackTrace(); + } + handler.sendEmptyMessage(0); + + } + + @Override + public void onFault(String errorMsg) { + //失败 + Log.d(TAG, "error on get firstpage: " + errorMsg); + // getSearchTabTtitle(); + handler.sendEmptyMessage(0); + } + },getActivity())); + + } + +} diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bookStore.java b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bookStore.java index b733782..1d3532a 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bookStore.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_bookStore.java @@ -28,6 +28,7 @@ public class Fragment_bookStore extends BasicFragment { SlidingTabLayout tabLayout; private FragmentStatePagerAdapter mAdapter =null; private ArrayList mFragments; + private ArrayList mFragments_cp; ArrayList mList; String[] mTitle; @@ -75,9 +76,14 @@ public class Fragment_bookStore extends BasicFragment { } public void onSexSwitch(){ if(mAdapter!=null) { - for(BasicFragment bf:mFragments){ + for(BasicFragment bf: mFragments_cp){ bf.initData(); } + /* for(int i=0;i(); mFragments.add(new Fragment_jingxuan()); mFragments.add(FragmentCates.newInstance()); - mFragments.add(new Fragment_bangdan()); - + mFragments.add(new Fragment_bangdans()); + mFragments_cp = new ArrayList<>(); + mFragments_cp.addAll(mFragments); // mFragments.add(new Fragment_shudan()); Log.d(TAG,"initial fragments in tabs "); } diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_booklist.java b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_booklist.java index d364950..024d1dd 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_booklist.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_booklist.java @@ -50,12 +50,13 @@ public class Fragment_booklist extends BasicFragment { private static final String EXTR_FN ="fn" ; private static final String EXTR_BANGDAN ="bangdan" ; private static final String EXTR_HISTORY ="history" ; + private static final String EXTR_CID ="cid" ; private BookListAdapter mAdapter; // private BookListAdapter mAdapter; private List mData;; private List mMoreData; private String cate; - private int progress; + private int progress,cid; private String keyWord ,fn,bangdan,history; private int listItem =R.layout.recycle_list_item_horizon; //private int pageNo=1; @@ -75,6 +76,14 @@ public class Fragment_booklist extends BasicFragment { public Fragment_booklist() { // Required empty public constructor } + public static Fragment_booklist newInstance(int cid,String bangdan) { + Fragment_booklist fragment = new Fragment_booklist(); + Bundle args = new Bundle(); + args.putInt(EXTR_CID,cid); + args.putString(EXTR_BANGDAN,bangdan); + fragment.setArguments(args); + return fragment; + } public static Fragment_booklist newInstance(String fn,String bangdan) { Fragment_booklist fragment = new Fragment_booklist(); Bundle args = new Bundle(); @@ -112,7 +121,7 @@ public class Fragment_booklist extends BasicFragment { Bundle bundle = getArguments() ; bangdan =bundle.getString(EXTR_BANGDAN); fn= bundle.getString(EXTR_FN); - + cid =bundle.getInt(EXTR_CID); if(!TextUtils.isEmpty((fn))){ return; } @@ -230,10 +239,10 @@ public class Fragment_booklist extends BasicFragment { Log.d(TAG,String.format("fn is %s",fn) ); - if(!TextUtils.isEmpty(bangdan) && !TextUtils.isEmpty(fn)){ //榜单 + if(!TextUtils.isEmpty(bangdan) && (cid >0 || !TextUtils.isEmpty(fn))){ //榜单 // showProgressDialog(true, "正在加载榜单"); mAdapter.setShowTop(true); - BookSubscribe.getSiteRankDetail(fn,pageNo,Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { + BookSubscribe.getPaihangBangList(Constants.SEX,pageNo,cid,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { @Override public void onSuccess(String result) { diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_paihang.java b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_paihang.java index fe3fd1b..f8c25ff 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_paihang.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_paihang.java @@ -9,16 +9,13 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; -import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.Toast; -import com.google.gson.Gson; import com.ixiaow.multilayout.MultiLayout; import com.novelbook.android.R; -import com.novelbook.android.adapter.JudgeNestedScrollView; -import com.novelbook.android.bean.Progress; + +import com.novelbook.android.bean.ProgressType; import com.novelbook.android.db.Novel; import com.novelbook.android.netapi.RandomHost; import com.novelbook.android.netsubscribe.BookSubscribe; @@ -31,10 +28,10 @@ import com.novelbook.android.utils.OnItemClickListener; import com.novelbook.android.adapter.BookListAdapter; import com.flyco.tablayout.CommonTabLayout; import com.flyco.tablayout.listener.CustomTabEntity; -import com.flyco.tablayout.listener.OnTabSelectListener; import org.json.JSONArray; import org.json.JSONObject; +import org.litepal.util.Const; import java.util.ArrayList; import java.util.Arrays; @@ -213,7 +210,7 @@ final String TAG = Fragment_paihang.class.getSimpleName(); } }; showProgressDialog(false, "正在加载..."); - BookSubscribe.getCateNovelList(cate, pageNo, tab1Pos+1, tab3Pos+1, new OnSuccessAndFaultSub(successAndFaultListener, getActivity())); + BookSubscribe.getCateNovelList(cate, pageNo, Constants.SEX, Constants.lstProgressType.get(tab3Pos).getId(), new OnSuccessAndFaultSub(successAndFaultListener, getActivity())); } @@ -221,7 +218,7 @@ final String TAG = Fragment_paihang.class.getSimpleName(); public void initViews(){ appBarLayout.setVisibility(View.GONE); if(lstNt==null) { - getSearchTabTtitle(); + // getSearchTabTtitle(); } else { initTabs(); @@ -263,7 +260,10 @@ final String TAG = Fragment_paihang.class.getSimpleName(); }*/ - List lstType = Arrays.asList(lstProgress); + List lstType = new ArrayList() ;//Arrays.asList(lstProgress); + for(ProgressType progressType : Constants.lstProgressType){ + lstType.add(progressType.getName()); + } topic_layout.initTabNames(lstNt) ; topic_layout1.initTabNames( lstSex) ; topic_layout2.initTabNames(lstType) ; @@ -322,8 +322,8 @@ final String TAG = Fragment_paihang.class.getSimpleName(); String sex = lstSex.get(tab1Pos); String cate = lstNt.get(tab2Pos); String selectedKey = lstSex.get(tab1Pos) +" " + - cate +" " + - lstProgress[tab3Pos] ; + cate +" " + Constants.lstProgressType.get(tab3Pos).getName(); + // lstProgress[tab3Pos] ; @@ -331,7 +331,7 @@ final String TAG = Fragment_paihang.class.getSimpleName(); tvHint.setText(selectedKey); Log.d(TAG, String.format("tabChanged: to load data %s,pageno %s, tmp %s" , selectedKey,pageNo ,tmp)); - if( tmp<4) return; + if( tmp height; - if (scrollY <= height) { - // scale = (float) scrollY / height; - // alpha = (int) (255 * scale); - tvHint.setVisibility(View.GONE); - // 随着滑动距离改变透明度 - // Log.e("al=","="+alpha); - // re.setBackgroundColor(Color.argb(alpha, 255, 0, 0)); - mNestedScrollView.setNeedScroll(true); - } else { - tvHint.setVisibility(View.VISIBLE); - // if (alpha < 255) { - // Log.e("执行次数", "=" + (++count)); - // 防止频繁重复设置相同的值影响性能 - // alpha = 255; - // re.setBackgroundColor(Color.argb(alpha, 255, 0, 0)); - // } - mNestedScrollView.setNeedScroll(false); - } - *//* LinearLayoutManager layoutManager = (LinearLayoutManager) NestedScrollView.getLayoutManager(); - int lastVisibleItemPosition = 0; - int totalItemCount = layoutManager.getItemCount(); - - if(v.getChildAt(v.getChildCount() - 1) != null) { - if (scrollY >= (v.getChildAt(v.getChildCount()-1).getMeasuredHeight() - v.getMeasuredHeight()) - && scrollY > oldScrollY) { - if (layoutManager instanceof LinearLayoutManager) { - lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); - } - - if (totalItemCount < previousTotalItemCount) { - this.currentPage = this.startingPageIndex; - this.previousTotalItemCount = totalItemCount; - if (totalItemCount == 0) { - this.loading = true; - } - } - - if (loading && (totalItemCount > previousTotalItemCount)) { - loading = false; - previousTotalItemCount = totalItemCount; - } - - if (!loading && (lastVisibleItemPosition + visibleThreshold) > totalItemCount) { - currentPage++; - onLoadMore(); - loading = true; - } - } - }*//* - - - - } - - }); - - } -*/ @Override public void onResume() { super.onResume(); //mNestedScrollView.smoothScrollBy(1,1); // tvHint.setVisibility(isShowHint? View.VISIBLE:View.GONE); - + tmp=0; } @@ -496,38 +418,6 @@ final String TAG = Fragment_paihang.class.getSimpleName(); } - void getSearchTabTtitle(){ - BookSubscribe.getSearchTitles(Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { - @Override - public void onSuccess(String result) { - - // mFirstPage= gson.fromJson(result, FirstPage.class); - try { - - Constants.lstSex = GsonUtil.parserStringBlocks(result,"sex"); - Constants.lstNt =GsonUtil.parserStringBlocks(result,"nt"); - // Constants.lstProgress =GsonUtil.parserProgressBlocks(result,"progress"); - initTabs(); - loadSearchData(); - } catch (Exception e) { - Log.e(TAG, "onSuccess: prepare book",e ); - e.printStackTrace(); - } - - - } - - @Override - public void onFault(String errorMsg) { - //失败 - Log.d(TAG, "error on get firstpage: " + errorMsg); - // getSearchTabTtitle(); - handler.sendEmptyMessage(0); - } - },getActivity())); - - } - } diff --git a/zhuike/src/main/java/com/novelbook/android/Main2Activity.java b/zhuike/src/main/java/com/novelbook/android/Main2Activity.java index 40a1a7f..5dfa6d5 100644 --- a/zhuike/src/main/java/com/novelbook/android/Main2Activity.java +++ b/zhuike/src/main/java/com/novelbook/android/Main2Activity.java @@ -86,7 +86,7 @@ public class Main2Activity extends Activity_base initialSexOption(); checkUpdate(true); - // getSearchTabTtitle(); + getSearchTabTtitle(); } @@ -551,6 +551,39 @@ private int bottomSelectedIndex; } //----get master domain +void getSearchTabTtitle(){ + BookSubscribe.getSearchTitles(Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { + @Override + public void onSuccess(String result) { + + // mFirstPage= gson.fromJson(result, FirstPage.class); + try { + + Constants.lstSex = GsonUtil.parserStringBlocks(result,"sex"); + Constants.lstNt =GsonUtil.parserStringBlocks(result,"nt"); + Constants.lstProgressType =GsonUtil.parserProgressType(result,"progress"); + + // initTabs(); + // loadSearchData(); + } catch (Exception e) { + Log.e(TAG, "onSuccess: prepare book",e ); + e.printStackTrace(); + } + + + } + + @Override + public void onFault(String errorMsg) { + //失败 + Log.d(TAG, "error on get firstpage: " + errorMsg); + // getSearchTabTtitle(); + handler.sendEmptyMessage(0); + } + },this)); + +} + } diff --git a/zhuike/src/main/java/com/novelbook/android/MarkActivity.java b/zhuike/src/main/java/com/novelbook/android/MarkActivity.java index 913f903..a1db955 100644 --- a/zhuike/src/main/java/com/novelbook/android/MarkActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/MarkActivity.java @@ -11,6 +11,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ImageButton; +import android.widget.ImageView; import com.flyco.tablayout.SlidingTabLayout; import com.novelbook.android.adapter.MyPagerAdapter; diff --git a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java index be3443e..06cfb71 100644 --- a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java @@ -26,6 +26,7 @@ import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.SeekBar; @@ -111,6 +112,8 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis @BindView(R.id.llTopAd) LinearLayout llTopAd; + @BindView(R.id.imgLoading) + pl.droidsonroids.gif.GifImageView imgLoading; private Config config; private WindowManager.LayoutParams lp; @@ -178,6 +181,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis config = Config.getInstance(); pageFactory = PageFactory.getInstance(getApplicationContext()); + pageFactory.clear(); pageFactory.setAd(this); llTopAd.setVisibility(View.GONE); @@ -589,7 +593,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); - + pageFactory.setPageWidget(bookpage); if (id == R.id.action_add_bookmark){ if( pageFactory.isReady()) if (pageFactory.getCurrentPage() != null) { @@ -804,6 +808,21 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis btnRefresh.setVisibility(visible); } + @Override + public void showProgressbar(boolean dismissAble,String msg) { + showProgressDialog(dismissAble,msg); + } + + @Override + public void hideProgressbar() { + + } + + @Override + public void showLoading(boolean isShow) { + imgLoading.setVisibility(isShow?View.VISIBLE:View.GONE); + } + private void showSystemUI() { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE @@ -886,6 +905,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis R.id.tv_dayornight,R.id.tv_pagemode, R.id.tv_setting, R.id.bookpop_bottom, /*R.id.rl_bottom,*/R.id.tv_stop_read ,R.id.llTopAd,R.id.btnRefresh}) public void onClick(View view) { + pageFactory.setPageWidget(bookpage); // if( pageFactory.isReady()) switch (view.getId()) { // case R.id.btn_return: diff --git a/zhuike/src/main/java/com/novelbook/android/bean/BangdanCate.java b/zhuike/src/main/java/com/novelbook/android/bean/BangdanCate.java new file mode 100644 index 0000000..8d228e6 --- /dev/null +++ b/zhuike/src/main/java/com/novelbook/android/bean/BangdanCate.java @@ -0,0 +1,40 @@ +package com.novelbook.android.bean; + +public class BangdanCate { + private int cid; + private String fn; + private String name; + private String title; + + public int getCid() { + return cid; + } + + public void setCid(int cid) { + this.cid = cid; + } + + public String getFn() { + return fn; + } + + public void setFn(String fn) { + this.fn = fn; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/zhuike/src/main/java/com/novelbook/android/bean/NovelBlock.java b/zhuike/src/main/java/com/novelbook/android/bean/NovelBlock.java index 0d819fc..b58cc8c 100644 --- a/zhuike/src/main/java/com/novelbook/android/bean/NovelBlock.java +++ b/zhuike/src/main/java/com/novelbook/android/bean/NovelBlock.java @@ -5,6 +5,7 @@ import com.novelbook.android.db.Novel; import java.util.List; public class NovelBlock{ + private int cid; private String fn; private String title; private int oneself; @@ -14,6 +15,14 @@ public class NovelBlock{ private List pictures; private List ns; + public int getCid() { + return cid; + } + + public void setCid(int cid) { + this.cid = cid; + } + public String getFn() { return fn; } diff --git a/zhuike/src/main/java/com/novelbook/android/bean/Progress.java b/zhuike/src/main/java/com/novelbook/android/bean/ProgressType.java similarity index 92% rename from zhuike/src/main/java/com/novelbook/android/bean/Progress.java rename to zhuike/src/main/java/com/novelbook/android/bean/ProgressType.java index 2328461..05fecbb 100644 --- a/zhuike/src/main/java/com/novelbook/android/bean/Progress.java +++ b/zhuike/src/main/java/com/novelbook/android/bean/ProgressType.java @@ -1,6 +1,6 @@ package com.novelbook.android.bean; -public class Progress { +public class ProgressType { private int id; private String name; diff --git a/zhuike/src/main/java/com/novelbook/android/db/Novel.java b/zhuike/src/main/java/com/novelbook/android/db/Novel.java index af88998..cd4d47b 100644 --- a/zhuike/src/main/java/com/novelbook/android/db/Novel.java +++ b/zhuike/src/main/java/com/novelbook/android/db/Novel.java @@ -272,7 +272,9 @@ public class Novel extends LitePalSupport implements Serializable{ } public static List getNovelsOnShelf(){ - return LitePal.where("isOnShelf=?","1").order("isTop desc,isUpdated desc,lastVisit desc" ).find(Novel.class); + // return LitePal.where("isOnShelf=?","1").order("isTop desc,isUpdated desc,lastVisit desc,lastUpdateTime desc" ).find(Novel.class); + return LitePal.where("isOnShelf=?","1").order("isTop desc,lastUpdateTime desc" ).find(Novel.class); + } public static List getLocalNovels(){ @@ -305,8 +307,12 @@ public class Novel extends LitePalSupport implements Serializable{ } @Override public int update(long id){ - setValues(); - return super.update(id); + setValues();try { + return super.update(id); + }catch (Exception e){ + Log.e("NOVELDB", "update:error ", e); + } + return 0; } public void testUpdate(){ isUpdated=true; diff --git a/zhuike/src/main/java/com/novelbook/android/dialog/SettingDialog.java b/zhuike/src/main/java/com/novelbook/android/dialog/SettingDialog.java index ce59a05..2e5cd43 100644 --- a/zhuike/src/main/java/com/novelbook/android/dialog/SettingDialog.java +++ b/zhuike/src/main/java/com/novelbook/android/dialog/SettingDialog.java @@ -357,22 +357,23 @@ public class SettingDialog extends Dialog { case R.id.iv_bg_default: setBookBg(Config.BOOK_BG_DEFAULT); selectBg(Config.BOOK_BG_DEFAULT); + config.setDayOrNight(false); break; case R.id.iv_bg_1: setBookBg(Config.BOOK_BG_1); - selectBg(Config.BOOK_BG_1); + selectBg(Config.BOOK_BG_1); config.setDayOrNight(false); break; case R.id.iv_bg_2: setBookBg(Config.BOOK_BG_2); - selectBg(Config.BOOK_BG_2); + selectBg(Config.BOOK_BG_2); config.setDayOrNight(false); break; case R.id.iv_bg_3: setBookBg(Config.BOOK_BG_3); - selectBg(Config.BOOK_BG_3); + selectBg(Config.BOOK_BG_3); config.setDayOrNight(false); break; case R.id.iv_bg_4: setBookBg(Config.BOOK_BG_4); - selectBg(Config.BOOK_BG_4); + selectBg(Config.BOOK_BG_4); config.setDayOrNight(false); break; case R.id.tv_lhadd: addLineSpace(); diff --git a/zhuike/src/main/java/com/novelbook/android/netapi/HttpApi.java b/zhuike/src/main/java/com/novelbook/android/netapi/HttpApi.java index 285824e..90b4bbe 100644 --- a/zhuike/src/main/java/com/novelbook/android/netapi/HttpApi.java +++ b/zhuike/src/main/java/com/novelbook/android/netapi/HttpApi.java @@ -74,11 +74,11 @@ public interface HttpApi { @GET("n/{novelId}/author") Observable getNovelsSameAuthor(@Path("novelId") int novelId); //站点榜单http://xiaoshuofenxiang.com/api/page/siteranks?sex=1 - @GET("page/siteranks") +/* @GET("page/siteranks") Observable getSiteRanks(@Query("sex") int Sex); //http://xiaoshuofenxiang.com/api/page/siterank?fn=qidian-yuanchuangfengyunbang&pn=3 @GET("page/siterank") - Observable getSiteRankDetail(@Query("fn")String fn,@Query("pn")int pageNo,@Query("sex") int Sex); + Observable getSiteRankDetail(@Query("fn")String fn,@Query("pn")int pageNo,@Query("sex") int Sex);*/ @GET( "search/{keyword}/{pageno}") Observable getSeachNolvelist(@Path("keyword")String keyWord,@Path("pageno")int pageNo,@Query("sex") int Sex); // 搜索分类 http://xiaoshuofenxiang.com/api/page/topdata @@ -94,5 +94,11 @@ public interface HttpApi { @GET("download/version.xml") Observable getVersion(); + @GET("page/category") + Observable getPaihangBangCateList(@Query("sex") int Sex,@Query("type") String type); + @GET("page/siteranks") + Observable getPaihangBangByCate(@Query("sex") int Sex,@Query("cid") int cid); + @GET("page/siterank") + Observable getPaihangBangList(@Query("sex") int Sex,@Query("cid") int cid,@Query("pn")int pageNo); } diff --git a/zhuike/src/main/java/com/novelbook/android/netsubscribe/BookSubscribe.java b/zhuike/src/main/java/com/novelbook/android/netsubscribe/BookSubscribe.java index 0999be5..2569267 100644 --- a/zhuike/src/main/java/com/novelbook/android/netsubscribe/BookSubscribe.java +++ b/zhuike/src/main/java/com/novelbook/android/netsubscribe/BookSubscribe.java @@ -62,14 +62,14 @@ public class BookSubscribe { HttpMethods.getInstance().toSubscribe(observable, subscriber); } - public static void getSiteRanks( int sex,DisposableObserver subscriber){ +/* public static void getSiteRanks( int sex,DisposableObserver subscriber){ Observable observable = HttpMethods.getInstance("/api/page/siteranks").getHttpApi().getSiteRanks(sex); HttpMethods.getInstance().toSubscribe(observable, subscriber); } public static void getSiteRankDetail( String fn,int pageNo,int sex,DisposableObserver subscriber){ - Observable observable = HttpMethods.getInstance("/api/page/siteranks").getHttpApi().getSiteRankDetail(fn,pageNo,sex); + Observable observable = HttpMethods.getInstance("/api/page/siterank").getHttpApi().getSiteRankDetail(fn,pageNo,sex); HttpMethods.getInstance().toSubscribe(observable, subscriber); - } + }*/ public static void getSearchNovelList( String keyWord,int pageNo,int sex,DisposableObserver subscriber){ Observable observable = HttpMethods.getInstance(String.format("/api/search/%s/%s",keyWord ,pageNo)).getHttpApi().getSeachNolvelist(keyWord,pageNo,sex); @@ -92,5 +92,16 @@ public class BookSubscribe { Observable observable = HttpMethods.getInstance("download/version.xml").getHttpApi().getVersion(); HttpMethods.getInstance().toSubscribe(observable, subscriber); } - + public static void getPaihangBangCateList(int sex,DisposableObserver subscriber){ + Observable observable = HttpMethods.getInstance("page/category").getHttpApi().getPaihangBangCateList(sex,"rank"); + HttpMethods.getInstance().toSubscribe(observable, subscriber); + } + public static void getPaihangBangByCate(int sex,int cid ,DisposableObserver subscriber){ + Observable observable = HttpMethods.getInstance("page/siteranks").getHttpApi().getPaihangBangByCate(sex,cid); + HttpMethods.getInstance().toSubscribe(observable, subscriber); + } + public static void getPaihangBangList(int sex,int pageNo,int cid ,DisposableObserver subscriber){ + Observable observable = HttpMethods.getInstance("page/siterank").getHttpApi().getPaihangBangList(sex,cid,pageNo); + HttpMethods.getInstance().toSubscribe(observable, subscriber); + } } diff --git a/zhuike/src/main/java/com/novelbook/android/netutils/RetryInterceptor.java b/zhuike/src/main/java/com/novelbook/android/netutils/RetryInterceptor.java index 849808f..409b670 100644 --- a/zhuike/src/main/java/com/novelbook/android/netutils/RetryInterceptor.java +++ b/zhuike/src/main/java/com/novelbook/android/netutils/RetryInterceptor.java @@ -31,36 +31,58 @@ public class RetryInterceptor implements Interceptor { public Response intercept(Chain chain) throws IOException { Request request = chain.request(); String oldUrl = request.url().toString(); + Log.d(TAG, "HttpMethods intercept: request url:"+oldUrl); String prefix = REUtil.match("(?i)http[s]?://[^/]+", oldUrl); + Log.d(TAG, "HttpMethods intercept: prefix:"+prefix); + if (prefix == null){ Response response = doRequest(chain, request); + if(response!=null) { return response; }else { - - throw new IOException(); + int i=0; + while(response==null && i<3){ + request = chain.request(); + i++; + } + if(response==null) { + throw new IOException(); + }else { + return response; + } } } String path = oldUrl.substring(prefix.length()); + Log.d(TAG, "HttpMethods intercept: path:"+path); RandomHost rh = null; boolean isMainApi =path.equals("/api/g/"); if(oldUrl.indexOf("xiaoshuofenxiang.com") == -1 || !path.startsWith("/api/") || NetUtil.getHost(isMainApi)==null){ // rh = null; + Response response = doRequest(chain, request); if(response!=null) { return response; }else { + int i=0; + while(response==null && i<3){ + request = chain.request(); + i++; + } + if(response==null) { + throw new IOException(); + }else { + return response; + } - throw new IOException(); } } try { rh = new RandomHost(NetUtil.getHost(isMainApi), path); - Log.d(TAG, "HttpMethods intercept: api path is "+path); Log.d(TAG, "HttpMethods intercept: create new RandomHost--------------------------"); } catch (JSONException e) { @@ -104,10 +126,17 @@ public class RetryInterceptor implements Interceptor { if (response != null) { try {response.close();} catch (IllegalStateException e) {} } + response = doRequest(chain, newRequest); Log.d(TAG, String.format("HttpMethods intercept: response is null? %s", response == null)); + int i=0; + while(response==null && i<3){ + request = chain.request(); + i++; + } + if (response != null) { Log.d(TAG, String.format("HttpMethods intercept: response .code? %s", response.code())); } @@ -173,10 +202,12 @@ public class RetryInterceptor implements Interceptor { private Response doRequest(Chain chain, Request request) throws IOException { Response response = null; + + try { response = chain.proceed(request); } catch (Exception e) { - Log.e(TAG, "doRequest: error 1 ",e ); + Log.e(TAG, "doRequest: error, " + request.url(),e ); } return response; diff --git a/zhuike/src/main/java/com/novelbook/android/service/ServiceDownload.java b/zhuike/src/main/java/com/novelbook/android/service/ServiceDownload.java index 6482436..a77a42e 100644 --- a/zhuike/src/main/java/com/novelbook/android/service/ServiceDownload.java +++ b/zhuike/src/main/java/com/novelbook/android/service/ServiceDownload.java @@ -134,11 +134,13 @@ public class ServiceDownload extends Service { protected void onHandleIntent( Intent intent) { Log.d(TAG,"ServiceDownload onHandleIntent...begin"); - + if(null==intent){ + return; + } String key ="taskId"; int taskId =0; - if(intent.hasExtra(key)){ + if ( intent.hasExtra(key)){ taskId= intent.getExtras().getInt(key); DownloadTask dt = LitePal.find(DownloadTask.class,taskId); diff --git a/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java b/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java index 14caf4d..cdc9c5c 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java @@ -9,4 +9,8 @@ public interface AdInterface { public void showAd(boolean showAd,int height,int adY); public void hideSystemUI(); public void showRefresh(int visible); + public void showProgressbar(boolean dismissAble,String msg); + public void hideProgressbar(); + public void showLoading(boolean isShow); + } diff --git a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java index ae837de..a0749ef 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java @@ -553,7 +553,9 @@ public class BookUtil { if(chaptCache.containsKey(chapterNo)){ chaptCache.remove(chapterNo); } - pagefactory.changeChapter(chapterNo); + if(pagefactory!=null) { + pagefactory.changeChapter(chapterNo); + } } @@ -647,9 +649,10 @@ public class BookUtil { } chId = chId <= mChapters.size() ? chId: mChapters.size(); Log.d(TAG, "changing Source: to open chapter with new site source " + chId + " : "+ mChangeTitle ); - pagefactory.changeChapter(chId); + if(pagefactory!=null) + pagefactory.changeChapter(chId); // mChangeChapId=0; - Toast.makeText(mContext,"换源成功",Toast.LENGTH_LONG).show(); + // Toast.makeText(mContext,"换源成功",Toast.LENGTH_LONG).show(); }else{ Log.d(TAG, "changing Source: failed " ); } @@ -1374,7 +1377,7 @@ int muluRetryCount =0; // isDownloadChapt =true; Log.d(TAG,String.format("handler msg, download %s",true) ); }else if(msg.what==99){ - // Toast.makeText(mContext,"网络拥堵,将帮您切换其它源",Toast.LENGTH_SHORT); + Toast.makeText(mContext,"网络拥堵,已帮您切换其它源",Toast.LENGTH_LONG).show(); // getSiteRule(); // pagefactory .changeChapter(getChapterNo()); diff --git a/zhuike/src/main/java/com/novelbook/android/utils/Constants.java b/zhuike/src/main/java/com/novelbook/android/utils/Constants.java index d95e06d..f3a5d1c 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/Constants.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/Constants.java @@ -1,6 +1,7 @@ package com.novelbook.android.utils; -import com.novelbook.android.bean.Progress; + +import com.novelbook.android.bean.ProgressType; import java.util.List; @@ -22,6 +23,7 @@ public class Constants { public static List lstNt=null; //public static List lstProgress=null; public static String[] lstProgress={"连载中","已完本","新书"}; + public static List lstProgressType=null; public static int retryCnt =5; public static int muluRetryCnt =5; // public static List lstProgress=null; diff --git a/zhuike/src/main/java/com/novelbook/android/utils/GsonUtil.java b/zhuike/src/main/java/com/novelbook/android/utils/GsonUtil.java index 5ada29e..3aec00d 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/GsonUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/GsonUtil.java @@ -5,8 +5,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.novelbook.android.bean.BangdanCate; import com.novelbook.android.bean.NovelBlock; -import com.novelbook.android.bean.Progress; +import com.novelbook.android.bean.ProgressType; +import com.novelbook.android.bean.ProgressType; import com.novelbook.android.db.Novel; import org.json.JSONArray; @@ -49,10 +51,10 @@ public class GsonUtil { } return lst; } - public static List parserProgressBlocks(String restult, String blockName ) throws JSONException { + public static List parserProgressType(String restult, String blockName ) throws JSONException { JSONObject jsonObject = new JSONObject(restult); String strJson = jsonObject.getString(blockName); - List list = new ArrayList(); + List list = new ArrayList(); //创建一个Gson对象 // Gson gson = new Gson(); //创建一个JsonParser @@ -78,10 +80,44 @@ public class GsonUtil { while (it.hasNext()) { JsonElement e = (JsonElement) it.next(); //JsonElement转换为JavaBean对象 - list.add((Progress) gson.fromJson(e, Progress.class)); + list.add((ProgressType) gson.fromJson(e, ProgressType.class)); } return list; } + public static List parserBangdanCate(String restult, String blockName ) throws JSONException { + JSONObject jsonObject = new JSONObject(restult); + String strJson = jsonObject.getString(blockName); + List list = new ArrayList(); + //创建一个Gson对象 + // Gson gson = new Gson(); + //创建一个JsonParser + JsonParser parser = new JsonParser(); + //通过JsonParser对象可以把json格式的字符串解析成一个JsonElement对象 + JsonElement el = parser.parse(strJson); + + //把JsonElement对象转换成JsonObject + JsonObject jsonObj = null; + if (el.isJsonObject()) { + jsonObj = el.getAsJsonObject(); + } + + + //把JsonElement对象转换成JsonArray + JsonArray jsonArray = null; + if (el.isJsonArray()) { + jsonArray = el.getAsJsonArray(); + } + + //遍历JsonArray对象 + Iterator it = jsonArray.iterator(); + while (it.hasNext()) { + JsonElement e = (JsonElement) it.next(); + //JsonElement转换为JavaBean对象 + list.add((BangdanCate) gson.fromJson(e, BangdanCate.class)); + } + return list; + } + public static List parserNovleBlocks(String restult,String blockName ) throws JSONException { JSONObject jsonObject = new JSONObject(restult); String strJson = jsonObject.getString(blockName); diff --git a/zhuike/src/main/java/com/novelbook/android/utils/LogcatHelper.java b/zhuike/src/main/java/com/novelbook/android/utils/LogcatHelper.java index fe04c1d..20d8d80 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/LogcatHelper.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/LogcatHelper.java @@ -102,7 +102,7 @@ public class LogcatHelper { // cmds = "logcat -s way";//打印标签过滤信息 // cmds = "logcat *:e *:i | grep \"(" + mPID + ")\""; cmds = "logcat *:D | grep \"(" + mPID + ")\""; - + // cmds = "logcat *:D"; } public void stopLogs() { diff --git a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java index 623d947..2e9430f 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java @@ -183,7 +183,7 @@ public class PageFactory implements ChangeSource{ private AdInterface mAd; private BookTask bookTask; private int MSG_NEXTPAGE=2; - + private int MSG_HIDEPROGRESS=3; public AdInterface getmAd() { return mAd; } @@ -221,6 +221,13 @@ public class PageFactory implements ChangeSource{ // drawStatus(); Log.d(TAG, "prepare book to load next page"); nextPage(); + } else if (msg.what == MSG_HIDEPROGRESS) { + dismissProgressDialog(); + if(mAd!=null) { + mAd.showRefresh(View.GONE); + // mAd.hideProgressbar(); + mAd.showLoading(false); + } } } Map fileRetryCnt = new HashMap(); @@ -483,11 +490,13 @@ public class PageFactory implements ChangeSource{ mStatus= Status.CHANGESOURCE; statusChangeSource="正在换源..."; if(!TextUtils.isEmpty(domainName)) { - statusChangeSource = "前往 " + domainName + " ..."; + statusChangeSource = "前往 " + domainName.substring(0,domainName.length()>5?5:domainName.length()) + "..."; } drawStatus(); + mBookUtil.pagefactory=this; mBookUtil.changeSource(domain, chapId, chapTitle); + } /* public String getChapterName() { @@ -666,11 +675,16 @@ private void hideSysUI(){ private void drawStatus(Bitmap bitmap){ hideSysUI(); mAd.showRefresh(View.VISIBLE); + mAd.hideProgressbar(); + mAd.showLoading(false); String status = ""; switch (mStatus){ case OPENING: - status = loadingTxt+ "正在拼命加载" ; - mAd.showRefresh(View.GONE); + status = "正在拼命加载" + loadingTxt; + mAd.showRefresh(View.GONE); + // mAd.showProgressbar(false,status); + mAd.showLoading(true); + // showProgressDialog(); break; case FAIL: status = "读取错误,请稍后重试"; @@ -685,6 +699,7 @@ private void hideSysUI(){ case FINISH: status = "加载成功"; mAd.showRefresh(View.GONE); + mAd.hideProgressbar(); break; case CHANGESOURCE: status = statusChangeSource; @@ -736,7 +751,10 @@ private void hideSysUI(){ // Log.d(TAG, String.format(" prepare book onDraw chapter _____________ %s ",currentChapter ) ); //更新数据库进度 + if(mAd!=null){ + handler.sendEmptyMessage(MSG_HIDEPROGRESS); + } if ( mStatus ==Status.FINISH && currentPage != null && getNovel() != null) { @@ -761,6 +779,7 @@ private void hideSysUI(){ } getNovel().setToDefault("isUpdated"); //去除更新标志 getNovel().setLastReadPos(currentPage.getBegin()); + getNovel().update(getNovel().getId()); //If you set a default value to a field, the corresponding // * column won't be updated. // getNovel().save(); @@ -797,9 +816,7 @@ private void hideSysUI(){ float space =m_fontSize + lineSpace; paragraphSpace = prate * lineSpace; - if(mAd!=null){ - mAd.showRefresh(View.GONE); - } + if (m_lines.size() > 0) { float y = marginHeight; @@ -907,11 +924,11 @@ private void hideSysUI(){ String source =String.format("本章节内容来自网络"); if(!TextUtils.isEmpty(sn)){ - source =String.format("本章节内容来自第三方网站:%s",getSite().getName()); + source =String.format("本章节内容来自第三方网站:%s",sn); } - int anny= (int) CommonUtil.convertDpToPixel(mContext,40); + int anny= (int) CommonUtil.convertDpToPixel(mContext,25); c.drawText(source, marginWidth, statusMarginBottom + mBatterryFontSize+anny, mBatterryPaint); - anny= (int) CommonUtil.convertDpToPixel(mContext,60); + anny= (int) CommonUtil.convertDpToPixel(mContext,45); c.drawText( Constants.announcement, marginWidth, statusMarginBottom + mBatterryFontSize+anny, mBatterryPaint); } @@ -1054,7 +1071,7 @@ private void hideSysUI(){ Log.d(TAG, "prepare book: start prepare book " + book.getName()); - clear(); + if(getNovel()!=null &&getNovel().getNovelId() !=book.getNovelId()){ //取消未上本书完成的web请求,待验证效果 try { NetUtil.cancelRequest(getNovel().getNovelId() ); @@ -1066,6 +1083,7 @@ private void hideSysUI(){ } mBookUtil = new BookUtil(); + mBookUtil.pagefactory=this; //this.mBookUtil.setContext(context); this.mBookUtil.setNovel(book); this.mBookUtil.getTargetSites(); @@ -1076,9 +1094,10 @@ private void hideSysUI(){ * @throws IOException */ public void openBook(Novel book ,Context context) throws IOException { -if(book==null){ - return; -} + + if(book==null){ + return; + } if(book.isLocalBook() || mBookUtil==null){ //离线书籍重新初始化加载mBookUtil mBookUtil = new BookUtil(); } @@ -1245,8 +1264,10 @@ if(book==null){ float width = 0; float height = 0; String line = ""; + // boolean isFirstPage =false; + int firstPageLine =0; if(mBookUtil.getPosition(chaptId)==0) { - lines.add("\n");//lines.add("\n"); + lines.add("\n");//lines.add("\n"); } calculateLineCount(); while (mBookUtil.next(true,chaptId) != -1){ @@ -1257,7 +1278,9 @@ if(book==null){ // mBookUtil.next(false); if ( !line.isEmpty()){ if (showChapTitleOnTopWhenNextPage && lines.size() >0 && mBookUtil.isChapterTitle(line)) { - Log.d(TAG,String.format("title is %s\n,size is %s ,position is %s" ,line,line.length(),mBookUtil.getPosition(chaptId) )); + Log.d(TAG,String.format("title is %s\n,size is %s ,position is %s" ,line,line.length(),mBookUtil.getPosition(chaptId) )); + //isFirstPage =true; + firstPageLine=1; break; } // Log.d(TAG, String.format(" loadchapt getNextLines(),chaptId %s, new line with enter '%s' ", chaptId, line+word )); @@ -1267,7 +1290,7 @@ if(book==null){ width = 0; height += paragraphSpace - lineSpace; calculateLineCount(height); - if (lines.size()>= mLineCount){ + if (lines.size()>= mLineCount +firstPageLine){ // Log.d(TAG,String.format("lines count limit a %s,lines size %s",mLineCount,lines.size())); line =""; break; @@ -1296,7 +1319,7 @@ if(book==null){ } } - if (lines.size() == mLineCount){ + if (lines.size() == mLineCount +firstPageLine){ // Log.d(TAG,String.format("loadchapt lines count ,chaptId %s limit c %s,lines size %s",chaptId ,mLineCount,lines.size())); if (!line.isEmpty()){ // mBookUtil.setPostition(mBookUtil.getPosition() - line.length()-2);// mBookUtil.setPostition(mBookUtil.getPosition() - 1); @@ -1314,7 +1337,7 @@ if(book==null){ } }*/ - if (!line.isEmpty() && lines.size() < mLineCount){ + if (!line.isEmpty() && lines.size() < mLineCount +firstPageLine){ if (!(showChapTitleOnTopWhenNextPage && mBookUtil.isChapterTitle(line) ) ) { lines.add(line); @@ -1400,6 +1423,7 @@ if(book==null){ //上一章 public void preChapter(){ fileRetryCnt.clear(); + mBookUtil.fileRetryCnt.clear(); if(currentChapter==1){ Toast.makeText(mContext,"到头了",Toast.LENGTH_SHORT).show(); } @@ -1425,6 +1449,7 @@ if(book==null){ //下一章 public void nextChapter(){ fileRetryCnt.clear(); + mBookUtil.fileRetryCnt.clear(); int num = currentChapter; if (num == 0){ num = getCurrentChapter(); @@ -1648,7 +1673,7 @@ if(book==null){ bookPath = ""; bookName = ""; //getNovel() = null; - mBookPageWidget = null; + // mBookPageWidget = null; mPageEvent = null; cancelPage = null; prePage = null; diff --git a/zhuike/src/main/java/com/novelbook/android/view/PageWidget.java b/zhuike/src/main/java/com/novelbook/android/view/PageWidget.java index 1cead0b..ee3b08e 100644 --- a/zhuike/src/main/java/com/novelbook/android/view/PageWidget.java +++ b/zhuike/src/main/java/com/novelbook/android/view/PageWidget.java @@ -129,7 +129,7 @@ public class PageWidget extends View { @Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); - if ( PageFactory.getStatus() == PageFactory.Status.OPENING){ + if ( PageFactory.getStatus() != PageFactory.Status.FINISH){ return true; } diff --git a/zhuike/src/main/res/layout/content_activity_cate_books.xml b/zhuike/src/main/res/layout/content_activity_cate_books.xml index 2cc1eaf..a828304 100644 --- a/zhuike/src/main/res/layout/content_activity_cate_books.xml +++ b/zhuike/src/main/res/layout/content_activity_cate_books.xml @@ -10,7 +10,16 @@ android:orientation="vertical" > - + + + + + + + + + \ No newline at end of file diff --git a/zhuike/src/main/res/layout/realcontent.xml b/zhuike/src/main/res/layout/realcontent.xml index b736568..38204e0 100644 --- a/zhuike/src/main/res/layout/realcontent.xml +++ b/zhuike/src/main/res/layout/realcontent.xml @@ -12,9 +12,9 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@drawable/common_full_open_on_phone" - > + > + + +