add 换源

fix bugs
This commit is contained in:
mwang 2019-04-18 17:19:42 +08:00
parent 0e5e8968d6
commit 02df9f1114
29 changed files with 651 additions and 139 deletions

View File

@ -64,8 +64,8 @@
android:value=".Main7Activity" />
</activity>
<activity
android:name=".Main5Activity"
android:label="@string/title_activity_main5" />
android:name=".Activity_ChgSource"
android:label="@string/title_Activity_ChgSource" />
<activity
android:name=".BookActivity"
android:label="@string/title_activity_book"

View File

@ -0,0 +1,219 @@
package com.novelbook.android;
import android.content.Context;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;
import com.novelbook.android.bean.Site;
import com.novelbook.android.db.Novel;
import com.novelbook.android.utils.PageFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class Activity_ChgSource extends Activity_base {
private static final String TAG = Activity_ChgSource.class.getSimpleName();
@BindView(R.id.recycleView)
RecyclerView recyclerView;
private ArrayList<Fragment> mFragments;
String chaptTitle;
int chaptId;
String domain;
public final static String EXTR_TITLE="title";
public final static String EXTR_ID="id";
public final static String EXTR_SITE="site";
PageFactory pageFactory;
List<Site> mSites;
@Override
public int getLayoutRes() {
return R.layout.activity_chgsource;
}
@Override
protected void initViews() {
}
@Override
protected void setTitle() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
}
chaptTitle = getIntent().getStringExtra(EXTR_TITLE);
chaptId = getIntent().getIntExtra(EXTR_ID,1);
domain = getIntent().getStringExtra(EXTR_SITE);
this.setTitle(chaptTitle);
}
@Override
protected void initData() {
pageFactory =PageFactory.getInstance();
mSites = new ArrayList<Site>(Arrays.asList(pageFactory.getNovelSites().getSites()));
SiteAdapter mAdapter = new SiteAdapter(this, mSites, R.layout.recycle_list_one_item, new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Site site = mSites.get(position);
Log.d(TAG, "changing Source: " + site.getDomain());
pageFactory.changeSource(site.getDomain(),chaptId,chaptTitle);
finish();
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(mAdapter);
}
interface OnItemClickListener
{
void onItemClick(View view, int position);
}
class SiteAdapter extends RecyclerView.Adapter<SiteAdapter.SiteViewHolder> {
private final int EMPTY_VIEW = 1;
private final int PROGRESS_VIEW = 2;
private final int IMAGE_VIEW = 3;
private Context context;
private List<Site> mDatas ;
private OnItemClickListener mOnItemClickListener;
private int listItemID;
private List<Novel> mSites;
public SiteAdapter(Context context, List<Site> mSites, int listItemID, OnItemClickListener clickLitener) {
this.context = context;
this.mDatas = mSites;
this.mOnItemClickListener = clickLitener;
this.listItemID = listItemID;
}
public SiteAdapter(Context context, OnItemClickListener clickLitener) {
this.context = context;
this.mOnItemClickListener = clickLitener;
}
public void setListener(OnItemClickListener clickLitener){
this.mOnItemClickListener = 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 SiteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
SiteAdapter.SiteViewHolder holder = new SiteViewHolder(LayoutInflater.from(
context).inflate(listItemID, parent,
false));
return holder;
}
public void setParameters(List<Site> mDatas, int listItemID) {
this.mDatas = mDatas;
this.listItemID = listItemID;
}
public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
this.mOnItemClickListener = mOnItemClickLitener;
}
@Override
public void onBindViewHolder( SiteViewHolder holder, int position) {
String title =mDatas.get(position).getDomain();
Log.d(TAG, String.format("onBindViewHolder: domain is '%s', title is '%s'",domain ,title));
if(title.equals(domain)){
title +=" (当前源)";
}
holder.tvTitle.setText(title); //.getName()
// 如果设置了回调则设置点击事件
if (mOnItemClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = holder.getLayoutPosition();
mOnItemClickListener.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);
}
public class SiteViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tvText)
TextView tvTitle;
public SiteViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
//tvTitle = (TextView) view.findViewById(R.id.title);
// tvAuthor = (TextView) view.findViewById(R.id.author);
}
}
}
}

View File

@ -87,8 +87,10 @@ public abstract class Activity_base extends AppCompatActivity {
@Override
public void onItemClick(View view, int position)
{
// showBook("射雕" +position);
showBookDetail(mDatas.get(position));
finish();
}
@Override

View File

@ -279,7 +279,7 @@ public class BookActivity extends Activity_base {
.load( Uri.decode(NetUtil.getCoverUrl(mNovel.getCover())))
.dontAnimate()
// .error(R.mipmap.side_bg2)
.transform(new GaoSiTransForm(this, 50, 3)) // "14":模糊度"3":图片缩放3倍后再进行模糊
.transform(new GaoSiTransForm(this, 100, 3)) // "14":模糊度"3":图片缩放3倍后再进行模糊
.into(imageViewHead);

View File

@ -1,7 +1,5 @@
package com.novelbook.android;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -10,7 +8,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@ -18,7 +15,6 @@ import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
@ -31,14 +27,11 @@ import com.novelbook.android.Fragments.BasicFragment;
import com.novelbook.android.Fragments.Fragment_Shelf;
import com.novelbook.android.Fragments.Fragment_bookStore;
import com.novelbook.android.Fragments.Fragment_paihang;
import com.novelbook.android.utils.Config;
import com.novelbook.android.utils.Constants;
import org.litepal.util.Const;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
public class Main2Activity extends Activity_base

View File

@ -1,47 +0,0 @@
package com.novelbook.android;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;
import io.alterac.blurkit.BlurLayout;
public class Main5Activity extends AppCompatActivity {
private BlurLayout blurLayout;
private float movement = 150;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main5);
blurLayout = (BlurLayout) findViewById(R.id.blurLayout);
blurLayout.animate().translationY(movement).setDuration(1500).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
movement = movement > 0 ? -150 : 150;
blurLayout.animate().translationY(movement).setDuration(1500).setListener(this).start();
}
}).start();
}
@Override
protected void onStart() {
super.onStart();
blurLayout.startBlur();
blurLayout.lockView();
}
@Override
protected void onStop() {
super.onStop();
blurLayout.pauseBlur();
}
}

View File

@ -1,22 +1,17 @@
package com.novelbook.android;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.design.widget.AppBarLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import com.astuetz.PagerSlidingTabStrip;
import com.flyco.tablayout.SlidingTabLayout;
import com.novelbook.android.adapter.MyPagerAdapter;
import com.novelbook.android.db.Chapter;
import com.novelbook.android.db.Novel;
import com.novelbook.android.utils.FileUtils;
import com.novelbook.android.utils.Config;
import com.novelbook.android.utils.PageFactory;
import java.util.ArrayList;

View File

@ -3,13 +3,11 @@ package com.novelbook.android;
import android.app.Application;
import android.content.Context;
import com.novelbook.android.utils.Config;
import com.novelbook.android.utils.PageFactory;
import org.litepal.LitePal;
import io.alterac.blurkit.BlurKit;
public class MyApp extends Application {
public static volatile Context applicationContext = null;
@Override

View File

@ -2,7 +2,6 @@ package com.novelbook.android;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@ -42,6 +41,7 @@ import com.novelbook.android.dialog.PageModeDialog;
import com.novelbook.android.dialog.SettingDialog;
import com.novelbook.android.utils.AdInterface;
import com.novelbook.android.utils.BrightnessUtil;
import com.novelbook.android.utils.Config;
import com.novelbook.android.utils.PageFactory;
import com.novelbook.android.view.PageWidget;
@ -430,8 +430,10 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
Log.d(TAG, "onKeyDown: pressed key");
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.d(TAG, "onKeyDown: pressed back");
if (isShow){
hideReadSetting();
return true;
@ -533,7 +535,8 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
}
}
}
}else if (id == R.id.action_read_book){
}
/* else if (id == R.id.action_read_book){
initialTts();
if (mSpeechSynthesizer != null){
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOLUME, "5");
@ -552,6 +555,13 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
isSpeaking = true;
}
}
}*/
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);
}
return super.onOptionsItemSelected(item);

View File

@ -8,7 +8,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.novelbook.android.Config;
import com.novelbook.android.utils.Config;
import com.novelbook.android.R;
import com.novelbook.android.db.Chapter;
@ -62,7 +62,7 @@ public class CatalogueAdapter extends BaseAdapter {
}else {
viewHolder = (ViewHolder)convertView.getTag();
}
if (currentCharter == position){
if (currentCharter == position+1){
viewHolder.catalogue_tv.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDark));
}else{
viewHolder.catalogue_tv.setTextColor(mContext.getResources().getColor(R.color.dark_gray));

View File

@ -9,12 +9,11 @@ import android.widget.BaseAdapter;
import android.widget.TextView;
import com.novelbook.android.Config;
import com.novelbook.android.utils.Config;
import com.novelbook.android.R;
import com.novelbook.android.db.BookMarks;
import com.novelbook.android.utils.PageFactory;
import java.text.DecimalFormat;
import java.util.List;

View File

@ -1,6 +1,7 @@
package com.novelbook.android.bean;
public class Site {
private String name;
private String domain;
private String muluUrl;
private Boolean selectedByDefault;
@ -28,4 +29,12 @@ public class Site {
public void setSelectedByDefault(Boolean selectedByDefault) {
this.selectedByDefault = selectedByDefault;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -9,7 +9,7 @@ import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.novelbook.android.Config;
import com.novelbook.android.utils.Config;
import com.novelbook.android.R;

View File

@ -13,7 +13,7 @@ import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import com.novelbook.android.Config;
import com.novelbook.android.utils.Config;
import com.novelbook.android.R;
import com.novelbook.android.view.BookPageWidget;

View File

@ -14,7 +14,7 @@ import android.widget.TextView;
import com.baidu.android.common.logging.Log;
import com.novelbook.android.Config;
import com.novelbook.android.utils.Config;
import com.novelbook.android.R;
import com.novelbook.android.utils.DisplayUtils;
import com.novelbook.android.view.CircleImageView;

View File

@ -5,6 +5,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@ -115,6 +116,10 @@ public class BookUtil {
private Site mSite;
private SiteRule mSiteRule;
public NovelSites getmNovelSites() {
return mNovelSites;
}
public synchronized void openBook(Novel novel) throws IOException, InterruptedException {
this.mNovel = novel;
//如果当前缓存不是要打开的书本就缓存书本同时删除缓存
@ -306,15 +311,190 @@ public class BookUtil {
}
private boolean isChangeSource =false;
private int mChangeChapId;
private String mChangeTitle;
public void changeSource(String domain,int chapId,String chapTitle) {
Log.d(TAG, String.format("changing Source: target domain %s chaptId %s, chapt title %s ",domain,chapId,chapTitle) );
if(mSite.getDomain().equals(domain)){ //当前源
Log.d(TAG, "changing Source: same site with original " + domain);
return;
}
mChangeChapId = chapId;
mChangeTitle =chapTitle;
for (Site site:mNovelSites.getSites() ) {
if(site.getDomain().equals(domain)){
mSite = site;
break;
}
}
setSiteInfo();
showProgressDialog("正在换源",false);
isChangeSource = true;
mChapters.clear();
getSiteRule();
BookTask btsk = new BookTask();
btsk.execute( domain, chapId+"", chapTitle);
}
public String getSite() {
return mSite !=null? mSite.getDomain():"";
}
private class BookTask extends AsyncTask<String,Void,Boolean> {
private String domain;
private int chapId;
private String chapTitle;
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
Log.d("onPostExecute",isCancelled() + "");
if (isCancelled()){
return;
}
if (result) {
Log.d(TAG, "changing Source:successed get chapters for " + mSite.getDomain() );
int chId=chapterNo;
String title ="";
if( mChapters.size() >= mChangeChapId && mChapters.get(mChangeChapId-1)!=null ){
title= mChapters.get(mChangeChapId-1).getChapterName();
Log.d(TAG, "changing Source:chapter name in new site " + title );
}
if(title.equals(mChangeTitle)) {
Log.d(TAG, "changing Source:successed find chapter by original chaptId " + mChangeChapId + ":" + mChangeTitle);
chId = mChangeChapId;
}
else {
int i = 1;
for (Chapter chapter : mChapters) {
Log.d(TAG, "changing Source: finding chapter " + i + ":" + chapter.getChapterName());
if (chapter.getChapterName().equals(mChangeTitle)) {
Log.d(TAG, "changing Source:successed find chapter by original title " + i + ":" + mChangeTitle);
chId = i;
break;
}
i++;
}
}
chId = chId <= mChapters.size() ? chId: mChapters.size();
Log.d(TAG, "changing Source: to open chapter with new site source " + chId + " : "+ mChangeTitle );
pagefactory.changeChapter(chId);
Toast.makeText(mContext,"换源成功",Toast.LENGTH_LONG).show();
}else{
Log.d(TAG, "changing Source: failed " );
}
}
@Override
protected Boolean doInBackground(String... params) {
domain = params[0];
chapId = Integer.parseInt( params[1]);
chapTitle = params[2];
int splet =0;
while(isChangeSource){
try {
Thread.sleep(50);
splet++;
Log.d(TAG, String.format("changing Source slept %s,isChangeSource %s ", splet, isChangeSource ));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return true;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
/**
* 新线程换源 handler 有问题
* @param domain
* @param chapId
* @param chapTitle
*/
public void changeSourceNewThread(String domain,int chapId,String chapTitle) {
Log.d(TAG, String.format("changing Source: target domain %s chaptId %s, chapt title %s ",domain,chapId,chapTitle) );
if(mSite.getDomain().equals(domain)){ //当前源
Log.d(TAG, "changing Source: same site with original " + domain);
// return;
}
mChangeChapId = chapId;
mChangeTitle =chapTitle;
for (Site site:mNovelSites.getSites() ) {
if(site.getDomain().equals(domain)){
mSite = site;
break;
}
}
setSiteInfo();
// showProgressDialog();
isChangeSource = true;
new Thread(){
@Override
public void run() {
Log.d(TAG, "changing Source: to get site rule" );
getSiteRule();
}
}.start();
/*
while(isChangeSource){
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
new Thread(){
@Override
public void run() {
Log.d(TAG, "changing Source: to get site rule" );
getSiteRule();
}
}.start();*/
}
enum MuluStatus{
isDownloading,
isDone,
failed
}
private void showProgressDialog() {
private void showProgressDialog(String title,boolean canBreak) {
if ( null == progressDialog) {
progressDialog =new ProgressDialog(mContext);
}
progressDialog.setMessage(title);
progressDialog.setCancelable(canBreak);
progressDialog.show();
// progressDialog.show(mContext,"网络不给力","正努力加载",false,true);
}
@ -335,38 +515,7 @@ public class BookUtil {
// String getMuluUrl() {
// return "https://www.qu.la/book/390/";
// }
/* void readChapters( String url){
Request request = getTagRequest(url);
ResponseBody body =null;
try {
long startTime= new Date().getTime();
Log.d(TAG,String.format("loadChaptContent----start download %s 目录 from %s", mNovel.getName() ,url ));
Response response = HttpMethods.getOkClient().newCall(request).execute();
Log.d(TAG,String.format("loadChaptContent----end download %s 目录, 目录数量 %s, cost %s", mNovel.getName() , mChapters.size(), new Date().getTime() -startTime ));
startTime= new Date().getTime();
body = response.body();
String bodyStr = body.string();
Log.d(TAG, "onResponse: " +bodyStr);
buildCharacters(bodyStr,url);
Log.d(TAG,String.format("loadChaptContent----end build %s 目录, 目录数量 %s, cost %s", mNovel.getName() , mChapters.size(), new Date().getTime() -startTime ));
} catch (IOException e) {
e.printStackTrace();
}finally {
if(body!=null){
body.close();;
}
}
}*/
void readChaptersAsync( ) {
String url = mSite.getMuluUrl();
@ -383,6 +532,7 @@ public class BookUtil {
Log.e(TAG, "loadChapts---- failed: ",e );
Log.d(TAG,String.format("loadChapts---- failed %s 目录 from %s", mNovel.getName() ,url ));
handler.sendEmptyMessage(3);
//TODO 如果是取消了访问则返回
if( mNovelSites.getSites().length ==1){ //仅有一个rule,且失败了
@ -406,7 +556,7 @@ public class BookUtil {
ResponseBody body = response.body();
if(response.code()!=200){
Log.d(TAG,String.format("loadChapts----failed, %s 目录 from %s,return code %s", mNovel.getName() ,url,response.code() ));
handler.sendEmptyMessage(3);
mMuluStatus = MuluStatus.failed;
return;
}
@ -426,6 +576,7 @@ public class BookUtil {
e.printStackTrace();
}finally {
body.close();
handler.sendEmptyMessage(3);
}
}
@ -858,26 +1009,65 @@ public class BookUtil {
isDownloadChapt = flag;
Log.d("loadChaptContent",String.format("set download flat",isDownloadChapt) );
}
final Handler handler = new Handler() {
public ChangeSource pagefactory;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int wt = msg.what;
handlerMsg(msg);
dismissProgressDialog();
if (msg.what == 123) {
isDownloadChapt =true;
Log.d("loadChaptContent",String.format("handler msg, download %s",isDownloadChapt) );
}else if(msg.what==1){
isDownloadChapt =true;
// Toast.makeText(mContext,"网络错误",Toast.LENGTH_LONG).show();
}
}
};
void handlerMsg(Message msg){
if (msg.what == 123) {
isDownloadChapt =true;
Log.d("loadChaptContent",String.format("handler msg, download %s",isDownloadChapt) );
}else if(msg.what==1){
isDownloadChapt =true;
// Toast.makeText(mContext,"网络错误",Toast.LENGTH_LONG).show();
}else if(msg.what==3){ //change source
isChangeSource =false;
Log.d(TAG, "changing Source:successed get chapters for " + mSite.getDomain() );
/*if(isChangeSource){
Log.d(TAG, "changing Source:successed get chapters for " + mSite.getDomain() );
isChangeSource =false;
int chapId=chapterNo;
if( mChapters.size() >= mChangeChapId && mChapters.get(mChangeChapId-1)!=null ){
String title = mChapters.get(mChangeChapId-1).getChapterName();
Log.d(TAG, "changing Source:chapter name in new site " + title );
if(title.equals(mChangeTitle)) {
Log.d(TAG, "changing Source:successed find chapter by original chaptId " + mChangeChapId + ":" + mChangeTitle);
chapId = mChangeChapId;
}
}else{
int i =1;
for (Chapter chapter : mChapters) {
if (chapter.getChapterName().equals(mChangeTitle)) {
Log.d(TAG, "changing Source:successed find chapter by original title " +i + ":"+ mChangeTitle );
chapId = i;
break;
}
i++;
}
}
chapId = chapId <= mChapters.size() ? chapId: mChapters.size();
Log.d(TAG, "changing Source: to open chapter with new site source " + chapId + " : "+ mChangeTitle );
pagefactory.changeChapter(chapId);
}
*/
}
}
private Map<Integer,Cache> chaptCache = new HashMap<Integer,Cache>();
private Map<Integer,DownloadStatus> chaptDownStatus = new HashMap<Integer, DownloadStatus>();
DownloadStatus downloadStatus = DownloadStatus.notStart;
@ -887,6 +1077,42 @@ public class BookUtil {
failure,
success
}
public boolean isChapterContentExist(int index) {
char[] block = null;
if (chaptCache.containsKey(Integer.valueOf(index))) {
block = chaptCache.get(index).getData().get();
}
if (block == null) {
// cleanCacheFile(); //to remove
File file = new File(fileChapterName(index));
if (!file.exists()) {
showProgressDialog("请稍候",false);
new Thread(){
@Override
public void run() {
try {
loadChaptContent(index);
} catch (JSONException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
return false;
}
}
return true;
}
//获取chapter 缓存
public char[] chaptChars(final int index) {
char[] block=null;
@ -924,7 +1150,7 @@ public class BookUtil {
Log.d(TAG,String.format("loadChaptContent----start %s" ,new Date().toString() ));
//showProgressDialog();//why not show
Log.d( "loadChaptContent",String.format("begin to load content for chapter %s",index));
Log.d( "loadChaptContent",String.format("isDownloadChapt: %s",isDownloadChapt));
@ -1015,6 +1241,7 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
Chapter chapter = mChapters.get(index -1);
String url = chapter.getChapterUrl();
if( TextUtils.isEmpty( url)){
handler.sendEmptyMessage(1);
return ;
}
long startTime= new Date().getTime();

View File

@ -0,0 +1,5 @@
package com.novelbook.android.utils;
public interface ChangeSource {
public void changeChapter(int chapNum);
}

View File

@ -1,9 +1,11 @@
package com.novelbook.android;
package com.novelbook.android.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import com.novelbook.android.R;
public class Config {
private final static String SP_NAME = "config";

View File

@ -1,5 +1,6 @@
package com.novelbook.android.utils;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
@ -15,12 +16,12 @@ import android.graphics.Typeface;
import android.os.AsyncTask;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
import com.novelbook.android.Config;
import com.novelbook.android.R;
import com.novelbook.android.bean.NovelSites;
import com.novelbook.android.bean.Site;
import com.novelbook.android.db.Chapter;
import com.novelbook.android.db.Novel;
import com.novelbook.android.netutils.NetUtil;
@ -37,7 +38,7 @@ import java.util.List;
//import static com.baidu.tts.loopj.AsyncHttpClient.log;
public class PageFactory {
public class PageFactory implements ChangeSource{
private static final String TAG = "PageFactory";
private static PageFactory pageFactory;
@ -171,7 +172,7 @@ public class PageFactory {
chaptId = mChapters!=null && mChapters.size() <= chaptId ? 1 : chaptId;
// Log.d(TAG, String.format("prepare book to open chapter %s ",chaptId ) );
Log.d(TAG, String.format("changing Source prepare book to open chapter %s ",chaptId ) );
char[] chars = mBookUtil.chaptChars(chaptId);
String s = new String(chars);
// Log.d(TAG, String.format("prepare book to open chapter %s,chars %s ",chaptId ,s ) );
@ -215,6 +216,39 @@ public class PageFactory {
private static Status mStatus = Status.OPENING;
public NovelSites getNovelSites() {
return mBookUtil.getmNovelSites();
}
private ProgressDialog progressDialog;
private void showProgressDialog() {
if ( null == progressDialog) {
progressDialog =new ProgressDialog(mContext);
}
progressDialog.show();
// progressDialog.show(mContext,"网络不给力","正努力加载",false,true);
}
private void dismissProgressDialog() {
if ( null != progressDialog) {
progressDialog.dismiss();
}
}
public void changeSource(String domain,int chapId,String chapTitle) {
mBookUtil.changeSource(domain, chapId, chapTitle);
}
public String getChapterName() {
return getChapters().get(currentChapter-1).getChapterName();
}
public String getSite() {
return mBookUtil.getSite();
}
public enum Status {
@ -494,7 +528,7 @@ public class PageFactory {
}else*/
if (getChapters().size() > 0)
{
String chapterName = CommonUtil.subString(getChapters().get(currentChapter-1).getChapterName(),16);
String chapterName = CommonUtil.subString(getChapterName(),16);
int nChaterWidth = (int) mBatterryPaint.measureText(chapterName) + 1;
c.drawText(chapterName, mWidth - marginWidth - nChaterWidth, statusMarginBottom + mBatterryFontSize, mBatterryPaint);
@ -612,6 +646,7 @@ public class PageFactory {
mBookUtil = new BookUtil();
}
mBookUtil.setContext(context);
mBookUtil.pagefactory=this;
//清空数据
currentChapter = 0;
// m_mbBufLen = 0;

View File

@ -13,7 +13,6 @@ import android.view.WindowManager;
import android.view.animation.LinearInterpolator;
import android.widget.Scroller;
import com.novelbook.android.Config;
import com.novelbook.android.utils.PageFactory;
import com.novelbook.android.view.animation.AnimationProvider;
import com.novelbook.android.view.animation.CoverAnimation;
@ -21,7 +20,7 @@ import com.novelbook.android.view.animation.NoneAnimation;
import com.novelbook.android.view.animation.SimulationAnimation;
import com.novelbook.android.view.animation.SlideAnimation;
import static com.novelbook.android.Config.*;
import static com.novelbook.android.utils.Config.*;

View File

@ -100,13 +100,15 @@
<TextView
android:id="@+id/author"
style="@style/TextViewNovelAuthor"
android:layout_marginTop="3dp"
android:layout_marginBottom="1dp"
android:text=""
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginTop="3dp"
android:orientation="horizontal">
<TextView
android:id="@+id/category"
@ -122,8 +124,10 @@
</LinearLayout>
<TextView
android:layout_marginTop="2dp"
android:id="@+id/progress"
style="@style/TextViewNovelAuthor"
android:textColor="@color/common_google_signin_btn_text_light"
android:text=""
/>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Activity_ChgSource">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/ToolBarTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbarHeight"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolBarTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:divider="@color/list_item_divider"
>
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>

View File

@ -20,6 +20,8 @@
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main2"
app:menu="@menu/activity_main2_drawer" />
app:menu="@menu/activity_main2_drawer"
/>
</android.support.v4.widget.DrawerLayout>

View File

@ -21,8 +21,9 @@
<!--android:layout_height="?attr/actionBarSize"-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/Toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_height="@dimen/toolbarHeight"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolBarTheme.PopupOverlay" >
<TextView

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loadLayout"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/item_selector"
android:gravity="center"
android:orientation="vertical">
<TextView
style="@style/TextViewNovelTitle.horizon.bold"
android:id="@+id/tvText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/noRecord"
/>
<!-- <LinearLayout style="@style/llGraySplit.2dp"/>-->
</LinearLayout>

View File

@ -12,9 +12,5 @@
android:orderInCategory="90"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_read_book"
android:title="@string/action_read_book"
android:orderInCategory="90"
app:showAsAction="ifRoom" />
</menu>

View File

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

View File

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

View File

@ -404,7 +404,7 @@
<item name="android:textSize">14sp</item><!--bookdetail toolbar 展开后字体大小-->
</style>
<style name="Toolbar"></style>
</resources>