无网络状况应对
This commit is contained in:
parent
181bba2a4b
commit
82c1c1ee3d
|
@ -80,8 +80,8 @@ dependencies {
|
|||
implementation 'com.github.bumptech.glide:glide:4.9.0'
|
||||
implementation 'jp.wasabeef:glide-transformations:2.0.1'
|
||||
implementation 'com.timqi.collapsibletextview:library:1.1.2'
|
||||
// implementation 'com.ms-square:expandableTextView:0.1.4'
|
||||
// implementation 'com.github.tangguna:SearchBox:1.0.1'
|
||||
implementation 'com.github.chengzipi:Searchbox:v1.0.0'
|
||||
// implementation 'com.ms-square:expandableTextView:0.1.4'
|
||||
// implementation 'com.github.tangguna:SearchBox:1.0.1'
|
||||
implementation 'com.github.chengzipi:Searchbox:v1.0.0'
|
||||
|
||||
}
|
||||
|
|
|
@ -79,7 +79,15 @@ public abstract class Activity_base extends AppCompatActivity {
|
|||
protected abstract void setTitle();
|
||||
|
||||
protected abstract void initData() ;
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
@Override
|
||||
protected void onPause(){
|
||||
super.onPause();
|
||||
hideProgress();
|
||||
}
|
||||
protected BookListAdapter getBookListAdapter(List<Novel> mDatas,int itemResourceId){
|
||||
BookListAdapter mAdapter = new BookListAdapter(this ,mDatas,itemResourceId,new OnItemClickListener()
|
||||
{
|
||||
|
@ -143,6 +151,7 @@ public abstract class Activity_base extends AppCompatActivity {
|
|||
|
||||
|
||||
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.title)
|
||||
TextView tvTitle;
|
||||
|
|
|
@ -297,6 +297,9 @@ public class BookActivity extends Activity_base {
|
|||
@OnClick({R.id.btnRead, R.id.btnCacheBook, R.id.btnShelf,R.id.llCate,R.id.btnFistPage})
|
||||
void submitButton(View view) {
|
||||
Intent intent;
|
||||
if(mNovel==null){
|
||||
return;
|
||||
}
|
||||
switch (view.getId()) {
|
||||
case R.id.btnFistPage:
|
||||
intent = new Intent(BookActivity.this, Main2Activity.class);
|
||||
|
|
|
@ -46,6 +46,7 @@ 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.NetUtil;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
||||
import com.novelbook.android.utils.ImageUtil;
|
||||
|
@ -137,6 +138,7 @@ public abstract class BasicFragment extends Fragment {
|
|||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
|
||||
|
||||
int wt = msg.what;
|
||||
|
||||
if (msg.what == 1) {
|
||||
|
@ -151,6 +153,11 @@ public abstract class BasicFragment extends Fragment {
|
|||
// Toast.makeText(getActivity(), " ", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
if(getActivity()!=null && !NetUtil.isNetworkConnected()){
|
||||
Toast.makeText(getActivity(),"好像没有网络啦",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
hideProgress();
|
||||
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@ import com.novelbook.android.adapter.CatalogueAdapter;
|
|||
import com.novelbook.android.db.Chapter;
|
||||
import com.novelbook.android.db.DownloadTask;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.netutils.NetUtil;
|
||||
import com.novelbook.android.utils.PageFactory;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
@ -27,6 +29,7 @@ import butterknife.ButterKnife;
|
|||
* Created by Administrator on 2016/8/31 0031.
|
||||
*/
|
||||
public class CatalogFragment extends BasicFragment {
|
||||
public static final String TAG=CatalogFragment.class.getSimpleName();
|
||||
public static final String ARGUMENT = "argument";
|
||||
|
||||
private PageFactory pageFactory;
|
||||
|
@ -67,22 +70,22 @@ public class CatalogFragment extends BasicFragment {
|
|||
|
||||
pageFactory = PageFactory.getInstance();
|
||||
|
||||
Log.d(TAG, String .format("prepareBook: start to open book cate of %s" , pageFactory.getNovle().getName()));
|
||||
Log.d(TAG, String .format("prepare book: start to open book cate of %s" , pageFactory.getNovle().getName()));
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
int slepttime = 0;
|
||||
while (slepttime < 1000 && ( pageFactory.isReadingCatalogs() || pageFactory.getChapters().size() == 0)) {
|
||||
while (NetUtil.isNetworkConnected() &&( slepttime < 1000 && ( pageFactory.isReadingCatalogs() || pageFactory.getChapters().size() == 0))) {
|
||||
try {
|
||||
Log.d(TAG, String .format("prepareBook: to open book cate to sleep %s" , 50));
|
||||
Log.d(TAG, String .format("prepare book: to open book cate to sleep %s" , 50));
|
||||
sleep(50);
|
||||
slepttime++;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Log.d(TAG, String .format("prepareBook:to open book cate slept %s" , slepttime*50));
|
||||
Log.d(TAG, String .format("prepare book:to open book cate slept %s" , slepttime*50));
|
||||
if ( !pageFactory.isReadingCatalogs() && pageFactory.getChapters().size() == 0) {
|
||||
|
||||
handler.sendEmptyMessage(2);
|
||||
|
@ -106,50 +109,66 @@ public class CatalogFragment extends BasicFragment {
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
showProgressDialog(true,"请稍等");
|
||||
if(pageFactory.getPageWidget()==null){
|
||||
Log.d(TAG, String .format("prepare book: getPageWidget is null? %s",pageFactory.getPageWidget()==null));
|
||||
// if(pageFactory.getPageWidget()==null){
|
||||
|
||||
Novel novel = pageFactory.getNovle();
|
||||
if(novel!=null){
|
||||
novel.setLastReadChapt(position+1);
|
||||
novel.setLastReadPos(1);
|
||||
ReadActivity.openBook(novel,getActivity());
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sleep(40);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ReadActivity.openBook(novel, getActivity());
|
||||
}}.start();
|
||||
}
|
||||
|
||||
}else {
|
||||
pageFactory.changeChapter(position+1);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
int slepttime =0;
|
||||
int chapid = position+1;
|
||||
// }else {
|
||||
// pageFactory.changeChapter(position+1);
|
||||
// }
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
int slepttime =0;
|
||||
int chapid = position+1;
|
||||
|
||||
while( pageFactory.getChapters().size() ==0 || pageFactory.getChapters().get(chapid-1).getId() ==0 ){
|
||||
try {
|
||||
sleep(50);
|
||||
slepttime+=1;
|
||||
if(pageFactory.getChapters().size()>0){
|
||||
Log.d(TAG, String .format("prepare Book: slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
|
||||
File f = new File(pageFactory.getChapterFileName(chapid)) ;
|
||||
|
||||
}else{
|
||||
Log.d(TAG, String .format("prepare Book: slept %s for loading pageFactory.getChapters().size() %s " , slepttime*50, pageFactory.getChapters().size()));
|
||||
while( pageFactory.getChapters().size() ==0 || !f.exists()){
|
||||
try {
|
||||
sleep(50);
|
||||
slepttime+=1;
|
||||
if(pageFactory.getChapters().size()>0){
|
||||
//Log.d(TAG, String .format("prepare book: slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
|
||||
|
||||
}else{
|
||||
// Log.d(TAG, String .format("prepare book: slept %s for loading pageFactory.getChapters().size() %s " , slepttime*50, pageFactory.getChapters().size()));
|
||||
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(slepttime>100)
|
||||
{
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(slepttime>100)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Log.d(TAG, String .format("prepare Book: total slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
|
||||
|
||||
handler.sendEmptyMessage(2);
|
||||
|
||||
}
|
||||
}.start();
|
||||
Log.d(TAG, String .format("prepare book: total slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
|
||||
|
||||
handler.sendEmptyMessage(2);
|
||||
/* if(getActivity()!=null) {
|
||||
getActivity().finish();
|
||||
}*/
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
getActivity().finish();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,298 @@
|
|||
package com.novelbook.android.Fragments;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.novelbook.android.Activity_cate_books;
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.activity_cates;
|
||||
import com.novelbook.android.bean.Cataloge;
|
||||
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.ImageUtil;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class FragmentCates extends BasicFragment {
|
||||
public static final String TAG =FragmentCates.class.getSimpleName();
|
||||
@BindView(R.id.mRecyclerView)
|
||||
RecyclerView mRecyclerView;
|
||||
private BookListAdapter mAdapter;
|
||||
private List<Cataloge> mCataloges;
|
||||
|
||||
@Override
|
||||
protected int getLayoutRes() {
|
||||
return R.layout.fragment_cates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
|
||||
showProgressDialog(true, "正在加载");
|
||||
BookSubscribe.getCates(Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
|
||||
// mFirstPage= gson.fromJson(result, FirstPage.class);
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
String resultstr = jsonObject.getString("nts");
|
||||
mCataloges = parserJsonArray(resultstr);
|
||||
handler.sendEmptyMessage(1);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
handler.sendEmptyMessage(1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault(String errorMsg) {
|
||||
//失败
|
||||
Log.d(TAG, "error on get firstpage: " + errorMsg);
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
}, getActivity()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillData() {
|
||||
List<Cataloge> cates = new ArrayList<>();
|
||||
for(Cataloge cate:mCataloges){
|
||||
if(cate!=null && cate.getNovelCount()>0){
|
||||
cates.add(cate);
|
||||
}
|
||||
}
|
||||
|
||||
mAdapter = new BookListAdapter(getActivity(), cates, R.layout.recycle_list_item_cates, new OnItemClickLitener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(View view, int position) {
|
||||
Cataloge cl = cates.get(position);
|
||||
showCateList(cl.getName());
|
||||
|
||||
}
|
||||
});
|
||||
initReceyleView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
}
|
||||
|
||||
public FragmentCates() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
void initReceyleView() {
|
||||
|
||||
// mRecyclerView.setLayoutManager(new LinearLayoutManager(this.activity));
|
||||
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(),3));
|
||||
mRecyclerView.setAdapter(mAdapter );
|
||||
|
||||
}
|
||||
|
||||
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static FragmentCates newInstance() {
|
||||
FragmentCates fragment = new FragmentCates();
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private void showCateList(String s) {
|
||||
Intent intent = new Intent(getActivity(), Activity_cate_books.class);
|
||||
intent.putExtra(Activity_cate_books.EXTRNAME,s);
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void processArguments() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setFTag() {
|
||||
|
||||
}
|
||||
class BookListAdapter extends RecyclerView.Adapter<BookListAdapter.MyViewHolder> {
|
||||
private final int EMPTY_VIEW = 1;
|
||||
private final int PROGRESS_VIEW = 2;
|
||||
private final int IMAGE_VIEW = 3;
|
||||
|
||||
private Context context;
|
||||
private List<Cataloge> mDatas = new ArrayList<Cataloge>();
|
||||
private OnItemClickLitener mOnItemClickLitener;
|
||||
private int listItemID;
|
||||
public BookListAdapter(Context context, List<Cataloge> mDatas, int listItemID, OnItemClickLitener clickLitener) {
|
||||
this.context = context;
|
||||
this.mDatas = mDatas;
|
||||
this.mOnItemClickLitener = clickLitener;
|
||||
this.listItemID = listItemID;
|
||||
}
|
||||
public BookListAdapter(Context context, OnItemClickLitener clickLitener) {
|
||||
this.context = context;
|
||||
this.mOnItemClickLitener = clickLitener;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if(mDatas.size() == 0){
|
||||
return EMPTY_VIEW;
|
||||
} else if(mDatas.get(position) == null){
|
||||
return PROGRESS_VIEW;
|
||||
} else {
|
||||
return super.getItemViewType(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
|
||||
{
|
||||
BookListAdapter.MyViewHolder holder = new BookListAdapter.MyViewHolder(LayoutInflater.from(
|
||||
context).inflate(listItemID, parent,
|
||||
false));
|
||||
return holder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setParameters(List<Cataloge> mDatas,int listItemID ) {
|
||||
this.mDatas = mDatas;
|
||||
this.listItemID = listItemID;
|
||||
}
|
||||
|
||||
public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
|
||||
{
|
||||
this.mOnItemClickLitener = mOnItemClickLitener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(BookListAdapter.MyViewHolder holder, int position)
|
||||
{
|
||||
holder.tvTitle.setText(mDatas.get(position).getName());
|
||||
holder.tvNum.setText(mDatas.get(position).getNovelCount()+"");
|
||||
if( mDatas.get(position).getNovel()!=null) {
|
||||
ImageUtil.loadImage(context, mDatas.get(position).getNovel().getCover(), holder.imageView);
|
||||
}
|
||||
|
||||
|
||||
// 如果设置了回调,则设置点击事件
|
||||
if (mOnItemClickLitener != null)
|
||||
{
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
int pos = holder.getLayoutPosition();
|
||||
mOnItemClickLitener.onItemClick(holder.itemView, pos);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return mDatas.size();
|
||||
}
|
||||
public void addData(int position) {
|
||||
// mDatas.add(position, "Insert One");
|
||||
// notifyItemInserted(position);
|
||||
}
|
||||
|
||||
public void removeData(int position) {
|
||||
mDatas.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
class MyViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@BindView(R.id.tvCateName)
|
||||
TextView tvTitle;
|
||||
@BindView(R.id.tvCateNums)
|
||||
TextView tvNum;
|
||||
@BindView(R.id.imageViewCate)
|
||||
ImageView imageView;
|
||||
|
||||
public MyViewHolder(View view)
|
||||
{
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
//tvTitle = (TextView) view.findViewById(R.id.title);
|
||||
// tvAuthor = (TextView) view.findViewById(R.id.author);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
interface OnItemClickLitener
|
||||
{
|
||||
void onItemClick(View view, int position);
|
||||
|
||||
}
|
||||
public List<Cataloge> parserJsonArray(String strJson) {
|
||||
|
||||
List<Cataloge> list = new ArrayList<Cataloge>();
|
||||
//创建一个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((Cataloge) gson.fromJson(e, Cataloge.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -83,10 +83,11 @@ public class Fragment_bookStore extends BasicFragment {
|
|||
|
||||
if(mFragments ==null || mFragments.size() ==0){
|
||||
// mTitle = new String[]{"精选", "榜单", "书单"};
|
||||
mTitle = new String[]{"精选", "榜单"};
|
||||
mTitle = new String[]{"精选", "榜单","分类"};
|
||||
mFragments = new ArrayList<>();
|
||||
mFragments.add(new Fragment_jingxuan());
|
||||
mFragments.add(new Fragment_bangdan());
|
||||
mFragments.add(FragmentCates.newInstance());
|
||||
// mFragments.add(new Fragment_shudan());
|
||||
Log.d(TAG,"initial fragments in tabs ");
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ public class Fragment_bookStore extends BasicFragment {
|
|||
return mTitle[position];
|
||||
}
|
||||
};
|
||||
mViewpager.setOffscreenPageLimit(3);//预加载设置
|
||||
mViewpager.setOffscreenPageLimit(4);//预加载设置
|
||||
mViewpager.setAdapter(mAdapter);
|
||||
tabLayout.setViewPager(mViewpager);
|
||||
// tabLayout.setViewPager(mViewpager, mTitle, activity, mFragments);
|
||||
|
|
|
@ -142,13 +142,15 @@ public class Main2Activity extends Activity_base
|
|||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int menuItemId = item.getItemId();
|
||||
if (menuItemId == R.id.menuFenlei) {
|
||||
/* if (menuItemId == R.id.menuFenlei) {
|
||||
|
||||
Intent intent = new Intent(Main2Activity.this, activity_cates.class);
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
}else if(menuItemId == R.id.menuMore) {
|
||||
}else */
|
||||
|
||||
if(menuItemId == R.id.menuMore) {
|
||||
showShelfMoreSheet();
|
||||
}
|
||||
else if(menuItemId == R.id.menuFinshi) {
|
||||
|
@ -325,21 +327,21 @@ private int bottomSelectedIndex;
|
|||
if(bottomSelectedIndex==0) {
|
||||
menu.findItem(R.id.menuFinshi).setVisible(isShelfZhengli);
|
||||
if(isShelfZhengli){
|
||||
menu.findItem(R.id.menuFenlei).setVisible(false);
|
||||
// menu.findItem(R.id.menuFenlei).setVisible(false);
|
||||
menu.findItem(R.id.menuMore).setVisible(false);
|
||||
menu.findItem(R.id.menuSearch).setVisible(false);
|
||||
}else {
|
||||
menu.findItem(R.id.menuFenlei).setVisible(false);
|
||||
// menu.findItem(R.id.menuFenlei).setVisible(false);
|
||||
menu.findItem(R.id.menuMore).setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
}else if(bottomSelectedIndex==1) {
|
||||
menu.findItem(R.id.menuFenlei).setVisible(true);
|
||||
// menu.findItem(R.id.menuFenlei).setVisible(true);
|
||||
menu.findItem(R.id.menuMore).setVisible(false);
|
||||
|
||||
}else if(bottomSelectedIndex==2) {
|
||||
menu.findItem(R.id.menuFenlei).setVisible(false);
|
||||
// menu.findItem(R.id.menuFenlei).setVisible(false);
|
||||
menu.findItem(R.id.menuMore).setVisible(false);
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import com.novelbook.android.db.Novel;
|
|||
import com.novelbook.android.db.BookMarks;
|
||||
import com.novelbook.android.dialog.PageModeDialog;
|
||||
import com.novelbook.android.dialog.SettingDialog;
|
||||
import com.novelbook.android.netutils.NetUtil;
|
||||
import com.novelbook.android.utils.AdInterface;
|
||||
import com.novelbook.android.utils.BrightnessUtil;
|
||||
import com.novelbook.android.utils.Config;
|
||||
|
@ -158,7 +159,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
|
||||
toolbar.setTitle("");
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setNavigationIcon(R.mipmap.return_button);
|
||||
//toolbar.setNavigationIcon(R.mipmap.return_button);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -217,6 +218,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
// mChapter = ( Chapter ) intent.getSerializableExtra(EXTRA_CHAPTER);
|
||||
bookpage.setPageMode(config.getPageMode());
|
||||
pageFactory.setPageWidget(bookpage);
|
||||
sb_progress.setVisibility(book.isLocalBook()?View.VISIBLE:View.INVISIBLE);
|
||||
Log.d(TAG, String .format("prepare Book: set pagewidget %s" , book.getName()));
|
||||
try {
|
||||
|
||||
|
@ -231,26 +233,31 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
int slepttime =0;
|
||||
int chapid = book.getLastReadChapt();
|
||||
|
||||
while( pageFactory.getChapters().size() ==0 || pageFactory.getChapters().get(chapid-1).getId() ==0 ){
|
||||
while( pageFactory.getChapters().size() ==0 ||(chapid-1 < pageFactory.getChapters().size() ) && pageFactory.getChapters().get(chapid-1).getId() ==0 ){
|
||||
try {
|
||||
|
||||
if(!NetUtil.isNetworkConnected()){
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(50);
|
||||
slepttime+=1;
|
||||
if(pageFactory.getChapters().size()>0){
|
||||
Log.d(TAG, String .format("prepare Book: slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
|
||||
// Log.d(TAG, String .format("prepare Book: slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
|
||||
|
||||
}else{
|
||||
Log.d(TAG, String .format("prepare Book: slept %s for loading pageFactory.getChapters().size() %s " , slepttime*50, pageFactory.getChapters().size()));
|
||||
// Log.d(TAG, String .format("prepare Book: slept %s for loading pageFactory.getChapters().size() %s " , slepttime*50, pageFactory.getChapters().size()));
|
||||
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(slepttime>200)
|
||||
if(slepttime>40)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Log.d(TAG, String .format("prepare Book: total slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
|
||||
Log.d(TAG, String .format("prepare Book: total slept %s for loading chapter content %s, " , slepttime*50, chapid ));
|
||||
|
||||
mHandler.sendEmptyMessage(1);
|
||||
|
||||
|
@ -378,6 +385,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
|
||||
@Override
|
||||
public Boolean prePage() {
|
||||
|
||||
if (isShow) {
|
||||
hideReadSetting();
|
||||
return false;
|
||||
|
@ -387,7 +395,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
}
|
||||
|
||||
pageFactory.prePage();
|
||||
if (pageFactory.isfirstPage()) {
|
||||
if (pageFactory.isfirstPage() || !pageFactory.isReady()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -406,7 +414,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
}
|
||||
|
||||
pageFactory.nextPage();
|
||||
if (pageFactory.islastPage()) {
|
||||
if (pageFactory.islastPage() || !pageFactory.isReady()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -485,7 +493,11 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
return true;
|
||||
}
|
||||
|
||||
showNormalDialog();//finish();
|
||||
|
||||
if(!pageFactory.canExitSilent()){
|
||||
showNormalDialog();
|
||||
}
|
||||
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
@ -540,6 +552,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.action_add_bookmark){
|
||||
if( pageFactory.isReady())
|
||||
if (pageFactory.getCurrentPage() != null) {
|
||||
List<BookMarks> bookMarksList = LitePal.where("novelId = ? and chapt = ? " +
|
||||
" and begin = ?", pageFactory.getNovle().getId()+"",pageFactory.getCurrentChapter()+"",pageFactory.getCurrentPage().getBegin() + "").find(BookMarks.class);
|
||||
|
@ -595,11 +608,13 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
}
|
||||
}*/
|
||||
else if (id == R.id.action_change_source) {
|
||||
Intent intent = new Intent(ReadActivity.this, Activity_ChgSource.class);
|
||||
intent.putExtra(Activity_ChgSource.EXTR_ID,pageFactory.getCurrentChapter());
|
||||
intent.putExtra(Activity_ChgSource.EXTR_TITLE,pageFactory.getChapterName());
|
||||
intent.putExtra(Activity_ChgSource.EXTR_SITE,pageFactory.getSite());
|
||||
startActivity(intent);
|
||||
if( pageFactory.getChapters().size()>0) {
|
||||
Intent intent = new Intent(ReadActivity.this, Activity_ChgSource.class);
|
||||
intent.putExtra(Activity_ChgSource.EXTR_ID, pageFactory.getCurrentChapter());
|
||||
intent.putExtra(Activity_ChgSource.EXTR_TITLE, pageFactory.getChapterName());
|
||||
intent.putExtra(Activity_ChgSource.EXTR_SITE, pageFactory.getSite());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -806,6 +821,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})
|
||||
public void onClick(View view) {
|
||||
if( pageFactory.isReady())
|
||||
switch (view.getId()) {
|
||||
// case R.id.btn_return:
|
||||
// finish();
|
||||
|
|
|
@ -45,17 +45,17 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
|
||||
public class activity_cates extends Activity_base {
|
||||
|
||||
private String TAG = activity_cates.class.getSimpleName();
|
||||
@BindView(R.id.recycleViewCateList)
|
||||
RecyclerView mRecyclerView;
|
||||
private List<String> mDatas;
|
||||
private BookListAdapter mAdapter;
|
||||
private String TAG = activity_cates.class.getSimpleName();
|
||||
private List<Cataloge> mCataloges;
|
||||
|
||||
@Override
|
||||
public int getLayoutRes() {
|
||||
return R.layout.activity_cates;
|
||||
}
|
||||
private List<Cataloge> mCataloges;
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
creatToolbar();
|
||||
|
|
|
@ -245,7 +245,7 @@ public class HttpMethods {
|
|||
public Response intercept(Chain chain) throws IOException {
|
||||
Response originalResponse = chain.proceed(chain.request());
|
||||
String cacheControl = originalResponse.header("Cache-Control");
|
||||
int maxAge =60*60; //一小时
|
||||
int maxAge = 60*60; //一小时
|
||||
if (cacheControl == null || cacheControl.contains("no-store") || cacheControl.contains("no-cache") ||
|
||||
cacheControl.contains("must-revalidate") || cacheControl.contains("max-age=0")) { //目标网站禁用cache则设置为1小时
|
||||
return originalResponse.newBuilder()
|
||||
|
@ -257,7 +257,7 @@ public class HttpMethods {
|
|||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, max-age=" + maxAge)
|
||||
.build();*/
|
||||
return originalResponse;
|
||||
return originalResponse;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -267,7 +267,7 @@ public class HttpMethods {
|
|||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
if (!NetUtil.isNetworkConnected()) {
|
||||
int maxStale = 0;// 60 * 60 * 24 * 28;
|
||||
int maxStale = 60 * 60 * 24 * 28;
|
||||
request = request.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
|
||||
|
|
|
@ -22,6 +22,10 @@ public class NetUtil {
|
|||
|
||||
private static final String TAG= NetUtil.class.getSimpleName();
|
||||
public static int currentRequestTag =0;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否有网络连接
|
||||
*
|
||||
|
@ -40,6 +44,8 @@ public class NetUtil {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 判断WIFI网络是否可用
|
||||
*
|
||||
|
|
|
@ -123,7 +123,7 @@ public class OnSuccessAndFaultSub extends DisposableObserver<ResponseBody>
|
|||
} else if (e instanceof HttpException) {//请求的地址不存在
|
||||
int code = ((HttpException) e).code();
|
||||
if (code == 504) {
|
||||
// ToastManager.showShortToast("网络异常,请检查您的网络状态");
|
||||
Toast.makeText(context,"网络异常,请检查您的网络状态",Toast.LENGTH_LONG).show();
|
||||
mOnSuccessAndFaultListener.onFault("网络异常,请检查您的网络状态");
|
||||
} else if (code == 404) {
|
||||
// ToastManager.showShortToast("请求的地址不存在");
|
||||
|
@ -132,7 +132,10 @@ public class OnSuccessAndFaultSub extends DisposableObserver<ResponseBody>
|
|||
// ToastManager.showShortToast("请求的地址不存在");
|
||||
mOnSuccessAndFaultListener.onFault("权限验证错误");
|
||||
} else if(code == 500) {
|
||||
// ToastManager.showShortToast("请求失败");
|
||||
// Toast.makeText(context,"网关错误 ,请检查您的网络状态",Toast.LENGTH_LONG).show();
|
||||
mOnSuccessAndFaultListener.onFault("服务错误");
|
||||
}else if(code == 502) {
|
||||
Toast.makeText(context,"网关错误 ,请检查您的网络状态",Toast.LENGTH_LONG).show();
|
||||
mOnSuccessAndFaultListener.onFault("服务错误");
|
||||
}else {
|
||||
// ToastManager.showShortToast("请求失败");
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.novelbook.android.db.Chapter;
|
|||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.netsubscribe.BookSubscribe;
|
||||
import com.novelbook.android.netutils.HttpMethods;
|
||||
import com.novelbook.android.netutils.NetUtil;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
||||
|
||||
|
@ -153,8 +154,14 @@ public class BookUtil {
|
|||
|
||||
// Log.d(TAG,String.format("mulu on Site %s download status %s",mSite.getDomain(),mMuluStatus));
|
||||
Log.d(TAG, String.format("prepare book %s open book in background.... mMuluStatus %s,mSiteRule %s,thread %s",mNovel.getName(),mMuluStatus,mSiteRule,Thread.currentThread().getName()) );
|
||||
|
||||
int sleptTime =0;
|
||||
while( mSiteRule ==null || mMuluStatus==null || mMuluStatus == MuluStatus.isDownloading){
|
||||
|
||||
sleptTime++;
|
||||
if(sleptTime >100 || !NetUtil.isNetworkConnected()){
|
||||
break;
|
||||
}
|
||||
Thread.sleep(50);
|
||||
Log.d(TAG,String.format("prepare book %s waiting for mulu downloading ,mMuluStatus %s,msiteRule %s" ,mNovel.getName(),mMuluStatus,mSiteRule));
|
||||
if(mMuluStatus == MuluStatus.failed){
|
||||
|
@ -535,7 +542,8 @@ public class BookUtil {
|
|||
handler.sendEmptyMessage(3);
|
||||
|
||||
//TODO 如果是取消了访问,则返回
|
||||
if(e.getMessage().contains("Canceled")){
|
||||
if(e.toString().contains("closed") ||e.getMessage().contains("Canceled"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -594,9 +602,14 @@ public class BookUtil {
|
|||
JSONObject siteJson = new JSONObject();
|
||||
|
||||
siteJson.put("chapterUrlPattern", mSiteRule.getChapterUrlPattern());
|
||||
siteJson.put("chapterUrlRegexOnMulu", mSiteRule.getChapterUrlRegexOnMulu());//示例接口表达式有问题
|
||||
// siteJson.put("chapterUrlRegexOnMulu", "<dd> <a[^>]*href=\"(/book/[\\d]+/[\\d]+\\.html)\">([^<]+)</a></dd>");
|
||||
/* if(mSiteRule.getDomain().equals("qu.la")){
|
||||
siteJson.put("chapterUrlRegexOnMulu", "<dd> <a[^>]*href=\"(/book/[\\d]+/[\\d]+\\.html)\">([^<]+)</a></dd>");
|
||||
}else{
|
||||
siteJson.put("chapterUrlRegexOnMulu", mSiteRule.getChapterUrlRegexOnMulu());
|
||||
}*/
|
||||
siteJson.put("chapterUrlRegexOnMulu", mSiteRule.getChapterUrlRegexOnMulu());
|
||||
//
|
||||
|
||||
mChapters = NovelParseUtil.getChapters(mSite.getDomain(),url, content, siteJson);
|
||||
Log.d(TAG,String.format("mulu on Site %s download status %s",mSite.getDomain(),mMuluStatus));
|
||||
/* if (mChapters != null) {
|
||||
|
@ -707,7 +720,7 @@ public class BookUtil {
|
|||
|
||||
|
||||
int i = (int)position-1;
|
||||
i = i<= charArray.length? i:charArray.length;
|
||||
i = i< charArray.length? i:charArray.length-1;
|
||||
return charArray[i];
|
||||
}
|
||||
public char current(){
|
||||
|
@ -1135,7 +1148,7 @@ public class BookUtil {
|
|||
// getTargetSites();
|
||||
}
|
||||
int slept = 0;
|
||||
while(slept <100 && mMuluStatus ==MuluStatus.isDownloading){
|
||||
while(NetUtil.isNetworkConnected() && slept <100 && mMuluStatus ==MuluStatus.isDownloading){
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
slept++;
|
||||
|
@ -1146,9 +1159,9 @@ public class BookUtil {
|
|||
}
|
||||
}
|
||||
|
||||
if( mChapters ==null || mChapters.size() ==0){
|
||||
if( !NetUtil.isNetworkConnected() || mChapters ==null || mChapters.size() ==0){
|
||||
Log.d(TAG,String.format("loadChapts----超时。。。或出错了 %s 目录, 目录数量 %s, slept %s, MuluStatus %s,thread %s", mNovel.getName() , mChapters.size(),slept ,mMuluStatus,Thread.currentThread().getName() ));
|
||||
String error = " ";
|
||||
String error = "网络不给力";
|
||||
return error.toCharArray();
|
||||
}
|
||||
|
||||
|
@ -1170,7 +1183,7 @@ public class BookUtil {
|
|||
int slepttime =0;
|
||||
// while(!file.exists() && !getDownloadStatus()){//&& slepttime <maxSleep){
|
||||
// while( !getDownloadStatus() && slepttime <maxSleep){
|
||||
while( !getDownloadStatus() && chaptDownStatus.get(Integer.valueOf(index)) == DownloadStatus.downloading && slepttime <maxSleep){
|
||||
while( NetUtil.isNetworkConnected() && !getDownloadStatus() && chaptDownStatus.get(Integer.valueOf(index)) == DownloadStatus.downloading && slepttime <maxSleep){
|
||||
Thread.sleep(50);
|
||||
slepttime+=50;
|
||||
Log.d(TAG,String.format(" prepare book loadChaptContent slept %s for downloading,isDownload %s ,thread %s ",slepttime,getDownloadStatus(),Thread.currentThread().getName() ) );
|
||||
|
@ -1181,7 +1194,7 @@ public class BookUtil {
|
|||
Log.d(TAG,String.format("loadChaptContent slept %s for downloading chaptercontent ",slepttime ));
|
||||
}
|
||||
Log.d( "loadChaptContent",String.format(" %s, file.exists()? %s", file.getPath(),file.exists()));
|
||||
if(!file.exists()) {
|
||||
if(!file.exists() || !NetUtil.isNetworkConnected()) {
|
||||
|
||||
String error = "网络不给力";
|
||||
return error.toCharArray();
|
||||
|
@ -1191,11 +1204,21 @@ public class BookUtil {
|
|||
File file2 = new File(fileChapterName(index+1));
|
||||
|
||||
if(!file2.exists()) {
|
||||
Log.d(TAG,String.format(" prepare book to load next chapt %s",index+1));
|
||||
loadChaptContent(index + 1);
|
||||
}
|
||||
|
||||
}
|
||||
if( index >1 && index -1 < mChapters.size() ) {
|
||||
|
||||
File file2 = new File(fileChapterName(index-1));
|
||||
|
||||
if(!file2.exists()) {
|
||||
Log.d(TAG,String.format(" prepare book to load pre chapt %s",index-1));
|
||||
loadChaptContent(index - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int size = (int)file.length();
|
||||
if (size < 0) {
|
||||
|
@ -1237,6 +1260,11 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
|
|||
2. 查询主服务器,若有地址更新则更新本地信息,并重复1,若没有更新地址,则地址无效,返回章节内容正待手打
|
||||
*/
|
||||
//
|
||||
if(!NetUtil.isNetworkConnected() || mChapters.size()==0){
|
||||
handler.sendEmptyMessage(1);
|
||||
return ;
|
||||
}
|
||||
|
||||
final int index = mChapters.size() < chapterIndex ? 1 : chapterIndex;
|
||||
if(mChapters.size() <chapterIndex){
|
||||
Log.d(TAG,String.format("loadChaptContent----wrong index, chapter size %s,load index %s,bookname %s", mChapters.size(),index,mNovel.getName() ));
|
||||
|
@ -1261,6 +1289,11 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
|
|||
HttpMethods.getOkClient().newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
if(e.toString().contains("closed") ||e.getMessage().contains("Canceled"))
|
||||
{
|
||||
// return;
|
||||
}
|
||||
|
||||
handler.sendEmptyMessage(123);
|
||||
handler.sendEmptyMessage(1);
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
|
|
|
@ -4,5 +4,5 @@ public class Constants {
|
|||
public static final String BLOCK_TITLE_NOVELS = "ns";
|
||||
public static final int NOVEL_SPAN_CNT =3 ; //grid columns
|
||||
public static int SEX=1;
|
||||
|
||||
public static String A_Regex = "<a[^>]+href[\\s]*=[\\s]*['\"]?([^'\"]+)['\"\\s]?[^>]*>([^<]+)<"; //TODO: 从服务器更新
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Set;
|
|||
|
||||
public class NovelParseUtil {
|
||||
|
||||
private static final String A_Regex = "<a[^>]+href[\\s]*=[\\s]*['\"]?([^'\"]+)['\"\\s]?[^>]*>([^<]+)<";
|
||||
private static final String A_Regex =Constants.A_Regex ;//"<a[^>]+href[\\s]*=[\\s]*['\"]?([^'\"]+)['\"\\s]?[^>]*>([^<]+)<";
|
||||
public static String[] getChaptersArray(String muluUrl, String html, JSONObject siteJson) throws JSONException {
|
||||
|
||||
Map<String, String> muluMap = getChaptersMap(muluUrl, html, siteJson);
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.novelbook.android.view.PageWidget;
|
|||
|
||||
import org.litepal.LitePal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -168,7 +169,43 @@ public class PageFactory implements ChangeSource{
|
|||
mAd =ad;
|
||||
}
|
||||
private List<TRPage> loadCurrentChapt(int chaptId){
|
||||
|
||||
chaptId = chaptId >getChapters().size()?getChapters().size():chaptId;
|
||||
|
||||
chaptId = chaptId >0?chaptId:1;
|
||||
|
||||
List<TRPage> chaptPages = new ArrayList<TRPage>();
|
||||
chaptPages.add(new TRPage());
|
||||
|
||||
|
||||
|
||||
if(!mBook.isLocalBook()) {
|
||||
|
||||
mStatus = Status.OPENING;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
|
||||
File file = new File(getChapterFileName(chaptId));
|
||||
if (!file.exists()) {
|
||||
|
||||
if( !NetUtil.isNetworkConnected()){ //TODO: 500错误处理
|
||||
mStatus = Status.NETWORKFAILE;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
return chaptPages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}else if(getChapters().size()==0) {
|
||||
mStatus = Status.FAIL;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
return chaptPages;
|
||||
}
|
||||
|
||||
chaptPages.clear();
|
||||
|
||||
|
||||
chaptId = mChapters!=null && mChapters.size() <= chaptId ? 1 : chaptId;
|
||||
|
||||
|
@ -198,7 +235,9 @@ public class PageFactory implements ChangeSource{
|
|||
chaptPages.add(page);
|
||||
length= page.getEnd();
|
||||
}
|
||||
|
||||
mStatus = Status.FINISH;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
return chaptPages;
|
||||
}
|
||||
public TRPage getNextChapterPage(long position){
|
||||
|
@ -250,11 +289,17 @@ public class PageFactory implements ChangeSource{
|
|||
return mBookUtil.getSite();
|
||||
}
|
||||
|
||||
public String getChapterFileName(int chapid) {
|
||||
return mBookUtil.fileChapterName(chapid);
|
||||
}
|
||||
|
||||
|
||||
public enum Status {
|
||||
OPENING,
|
||||
FINISH,
|
||||
FAIL,
|
||||
NETWORKFAILE,
|
||||
SERVERERROR
|
||||
}
|
||||
|
||||
public static synchronized PageFactory getInstance(){
|
||||
|
@ -375,6 +420,12 @@ public class PageFactory implements ChangeSource{
|
|||
case FAIL:
|
||||
status = "打开书本失败!";
|
||||
break;
|
||||
case NETWORKFAILE:
|
||||
status = "请开启网络";
|
||||
break;
|
||||
case SERVERERROR:
|
||||
status = "服务器故障";
|
||||
break;
|
||||
}
|
||||
|
||||
Canvas c = new Canvas(bitmap);
|
||||
|
@ -396,18 +447,23 @@ public class PageFactory implements ChangeSource{
|
|||
}
|
||||
|
||||
public void onDraw(Bitmap bitmap,List<String> m_lines,Boolean updateChapter) {
|
||||
if(m_lines.size()==0){
|
||||
return;
|
||||
}
|
||||
if (getChapters().size() > 0 && updateChapter) {
|
||||
currentChapter = getCurrentChapter();
|
||||
}
|
||||
//更新数据库进度
|
||||
if (currentPage != null && mBook != null){
|
||||
if ( mStatus ==Status.FINISH && currentPage != null && mBook != null){
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
if(mBook.getLastReadChapt() !=currentChapter || mBook.getLastReadPos()!=currentPage.getBegin()) {
|
||||
if(currentChapter >1) {
|
||||
mBook.setLastReadChapt(currentChapter);
|
||||
|
||||
mBook.setLastReadChapt(currentChapter);
|
||||
|
||||
}else{
|
||||
mBook.setToDefault("lastReadChapt");
|
||||
}
|
||||
|
@ -550,6 +606,7 @@ public class PageFactory implements ChangeSource{
|
|||
|
||||
//向前翻页
|
||||
public void prePage(){
|
||||
|
||||
if(null == currentPage){
|
||||
return;
|
||||
}
|
||||
|
@ -575,6 +632,9 @@ public class PageFactory implements ChangeSource{
|
|||
|
||||
//向后翻页
|
||||
public void nextPage(){
|
||||
|
||||
m_islastPage = false;
|
||||
|
||||
if(null == currentPage){
|
||||
return;
|
||||
}
|
||||
|
@ -582,7 +642,6 @@ public class PageFactory implements ChangeSource{
|
|||
return;
|
||||
}
|
||||
|
||||
m_islastPage = false;
|
||||
if (currentPage.getEnd() >= mBookUtil.getBookLen()) {
|
||||
Log.d(TAG,"已经是本章最后一页了");
|
||||
|
||||
|
@ -606,7 +665,7 @@ public class PageFactory implements ChangeSource{
|
|||
|
||||
//取消翻页
|
||||
public void cancelPage(){
|
||||
if(cancelPage.isLastPage() || cancelPage.isFirstPage()){
|
||||
if(cancelPage !=null && (cancelPage.isLastPage() || cancelPage.isFirstPage())){
|
||||
mBookUtil.setChapterNo(cancelPage.getChapterNo());
|
||||
currentChaptPages = loadCurrentChapt(cancelPage.getChapterNo());
|
||||
currentPage = getPageForBegin(cancelPage.getBegin()) ;// currentChaptPages.get(0);
|
||||
|
@ -693,8 +752,8 @@ public class PageFactory implements ChangeSource{
|
|||
if (mBookPageWidget != null) {
|
||||
currentPage(true);
|
||||
}
|
||||
Log.d(TAG, String.format("prepare book set PageFactory.mStatus %s .",PageFactory.Status.FINISH ) );
|
||||
PageFactory.mStatus = PageFactory.Status.FINISH;
|
||||
// Log.d(TAG, String.format("prepare book set PageFactory.mStatus %s .",PageFactory.Status.FINISH ) );
|
||||
// PageFactory.mStatus = PageFactory.Status.FINISH;
|
||||
}else{
|
||||
PageFactory.mStatus = PageFactory.Status.FAIL;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
|
@ -774,7 +833,7 @@ public class PageFactory implements ChangeSource{
|
|||
nextChaptPages =currentChaptPages;
|
||||
currentChapter--;
|
||||
if(currentChapter ==0) {
|
||||
return new TRPage();
|
||||
return new TRPage("没有内容了");
|
||||
}
|
||||
mBookUtil.setChapterNo(currentChapter);
|
||||
currentChaptPages = loadCurrentChapt(currentChapter ) ;
|
||||
|
@ -1218,10 +1277,21 @@ public class PageFactory implements ChangeSource{
|
|||
public boolean isfirstPage() {
|
||||
return m_isfirstPage;
|
||||
}
|
||||
//询问是否可以退出阅读
|
||||
public boolean canExitSilent(){
|
||||
return m_islastPage
|
||||
|| mStatus==Status.FAIL
|
||||
||mStatus==Status.NETWORKFAILE
|
||||
|| mStatus==Status.SERVERERROR;
|
||||
}
|
||||
//是否是最后一页
|
||||
public boolean islastPage() {
|
||||
return m_islastPage;
|
||||
}
|
||||
//是否可以翻页
|
||||
public boolean isReady() {
|
||||
return mStatus==Status.FINISH;
|
||||
}
|
||||
//设置页面背景
|
||||
public void setBgBitmap(Bitmap BG) {
|
||||
m_book_bg = BG;
|
||||
|
|
|
@ -12,6 +12,13 @@ public class TRPage {
|
|||
private boolean isLastPage;
|
||||
private boolean isFirstPage;
|
||||
private List<String> lines = new ArrayList<>();
|
||||
public TRPage( ){
|
||||
|
||||
}
|
||||
public TRPage(String line){
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
|
||||
public int getChapterNo() {
|
||||
return chapterNo;
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<corners
|
||||
android:radius="6dp" />
|
||||
<padding
|
||||
android:left="15dp"
|
||||
android:left="5dp"
|
||||
android:top="5dp"
|
||||
android:right="15dp"
|
||||
android:right="5dp"
|
||||
android:bottom="5dp" />
|
||||
</shape>
|
|
@ -121,22 +121,7 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
android:scaleType="centerCrop"
|
||||
|
||||
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout style="@style/llGraySplit" />
|
||||
|
||||
|
@ -145,7 +130,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<!-- <LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
|
@ -165,7 +150,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="目录" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>-->
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llCate"
|
||||
|
@ -177,8 +162,8 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="10dp"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:layout_marginRight="5dp"
|
||||
|
@ -199,7 +184,7 @@
|
|||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/txtLatestUpdate"
|
||||
style="@style/TextViewDesc"
|
||||
style="@style/TextViewDesc.small"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
|
@ -214,14 +199,8 @@
|
|||
|
||||
/>
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout style="@style/llGraySplit" />
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="@style/llOutside"
|
||||
tools:context=".Fragments.FragmentCates">
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/mRecyclerView"
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="30dp"
|
||||
|
||||
/>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -1,7 +1,7 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
style="@style/llOutside"
|
||||
tools:context=".Fragments.Fragment_booklist">
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeLayout"
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
style="@style/llOutside"
|
||||
>
|
||||
<LinearLayout
|
||||
android:id="@+id/ll1"
|
||||
android:id="@+id/ll1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="65dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/item_selector"
|
||||
android:clickable="true"
|
||||
|
@ -54,5 +48,3 @@
|
|||
</LinearLayout>
|
||||
<LinearLayout style="@style/llGraySplit.2dp.gray" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
android:gravity="center"
|
||||
android:background="@drawable/item_selector"
|
||||
android:clickable="true"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingTop="4dp"
|
||||
android:layout_weight="1">
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
android:src="@color/whitesmoke"
|
||||
android:scaleType="centerCrop"
|
||||
|
||||
|
||||
|
@ -43,13 +43,14 @@
|
|||
android:layout_alignParentTop="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:theme="@style/AppTheme.AppBarOverlay"
|
||||
|
||||
android:visibility="gone">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:background="@color/read_dialog_bg"
|
||||
android:fitsSystemWindows="true"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:max="10000"
|
||||
android:visibility="invisible"
|
||||
android:layout_gravity="center_vertical">
|
||||
</SeekBar>
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
|
||||
android:fitsSystemWindows="true">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
android:id="@+id/sb_brightness"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="4"
|
||||
android:gravity="center"
|
||||
android:max="100"
|
||||
android:layout_gravity="center_vertical">
|
||||
|
@ -52,7 +52,7 @@
|
|||
<TextView
|
||||
android:id="@+id/tv_xitong"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/setting_system" />
|
||||
</LinearLayout>
|
||||
|
@ -65,7 +65,7 @@
|
|||
android:id="@+id/tv_subtract"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_weight="1"
|
||||
android:textSize="30sp"
|
||||
android:textSize="25sp"
|
||||
android:background="@null"
|
||||
android:textColor="@color/read_dialog_button_select"
|
||||
android:text="@string/setting_subtract" />
|
||||
|
@ -84,7 +84,7 @@
|
|||
android:id="@+id/tv_add"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_weight="1"
|
||||
android:textSize="30sp"
|
||||
android:textSize="25sp"
|
||||
android:background="@null"
|
||||
android:textColor="@color/read_dialog_button_select"
|
||||
android:text="@string/setting_add" />
|
||||
|
@ -93,6 +93,7 @@
|
|||
android:id="@+id/tv_size_default"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/setting_default" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
|
@ -103,7 +104,7 @@
|
|||
android:id="@+id/tv_lhreduct"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_weight="1"
|
||||
android:textSize="30sp"
|
||||
android:textSize="25sp"
|
||||
android:background="@null"
|
||||
android:textColor="@color/read_dialog_button_select"
|
||||
android:text="@string/setting_subtract_line_space" />
|
||||
|
@ -122,7 +123,7 @@
|
|||
android:id="@+id/tv_lhadd"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_weight="1"
|
||||
android:textSize="30sp"
|
||||
android:textSize="25sp"
|
||||
android:background="@null"
|
||||
android:textColor="@color/read_dialog_button_select"
|
||||
android:text="@string/setting_add_line_space" />
|
||||
|
@ -131,6 +132,7 @@
|
|||
android:id="@+id/tv_lhsize_default"
|
||||
style="@style/setting_dialog_button"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/setting_default" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
android:orderInCategory="100"
|
||||
android:title="@string/more"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
<!-- <item
|
||||
android:id="@+id/menuFenlei"
|
||||
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/fenlei"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="ifRoom" />-->
|
||||
<item
|
||||
android:id="@+id/menuFinshi"
|
||||
android:orderInCategory="100"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<!-- 书本字体最大大小 -->
|
||||
<dimen name="reading_max_text_size">30sp</dimen>
|
||||
<!-- 设置行高 -->
|
||||
<dimen name="setting_height">60dp</dimen>
|
||||
<dimen name="setting_height">50dp</dimen>
|
||||
|
||||
<!-- 设置tab 选择块宽 -->
|
||||
<dimen name="tabBlock_width">50dp</dimen>
|
||||
|
|
|
@ -140,11 +140,15 @@
|
|||
<style name="TextViewDesc">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
||||
<item name="android:textColor">@color/common_google_signin_btn_text_light</item>
|
||||
<item name="android:textSize">15sp</item>
|
||||
</style>
|
||||
|
||||
<style name="TextViewDesc.small">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">@color/common_google_signin_btn_text_light</item>
|
||||
<item name="android:textSize">13sp</item>
|
||||
</style>
|
||||
<style name="llGallaryImage">
|
||||
<item name="android:layout_width">100dp</item>
|
||||
<item name="android:layout_height">120dp</item>
|
||||
|
@ -305,6 +309,7 @@
|
|||
<item name="android:layout_gravity">left</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:lines">1</item>
|
||||
<item name="android:textSize">14dp</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue