章节缓存预先读取
This commit is contained in:
parent
de25db0635
commit
193fa3550b
|
@ -15,33 +15,16 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/ToolBarTheme"
|
||||
android:launchMode="singleInstance"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity
|
||||
android:name=".Activity_shudan_my"
|
||||
android:label="@string/title_activity_shudan_my"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar"></activity>
|
||||
<activity
|
||||
android:name=".Activity_createShudan"
|
||||
android:label="@string/title_activity_create_shudan"
|
||||
android:parentActivityName=".Main2Activity"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".Activity_shudan"
|
||||
android:label="@string/title_activity_shudan"
|
||||
android:parentActivityName=".Main2Activity"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".Activity_cate_books"
|
||||
android:label="@string/title_activity_cate_books"
|
||||
android:launchMode="singleTask"
|
||||
android:parentActivityName=".activity_cates"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".activity_cates"
|
||||
android:label="@string/title_activity_cates"
|
||||
android:launchMode="singleTask"
|
||||
android:parentActivityName=".Main2Activity"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar" />
|
||||
|
||||
|
||||
<activity
|
||||
android:name=".Activity_Search"
|
||||
|
@ -49,19 +32,13 @@
|
|||
android:launchMode="singleTask"
|
||||
android:parentActivityName=".Main2Activity"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar" />
|
||||
<activity
|
||||
|
||||
android:name=".ScrollingActivity"
|
||||
android:label="@string/title_activity_scrolling"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".Activity_paihangbang"
|
||||
android:label="@string/title_activity_paihangbang"
|
||||
android:parentActivityName=".Main2Activity"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar">
|
||||
<meta-data
|
||||
android:name="android.app.default_searchable"
|
||||
android:value=".Main7Activity" />
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".Activity_ChgSource"
|
||||
|
@ -69,7 +46,7 @@
|
|||
<activity
|
||||
android:name=".BookActivity"
|
||||
android:label="@string/title_activity_book"
|
||||
android:parentActivityName=".Main2Activity"
|
||||
|
||||
android:theme="@style/ToolBarTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".ReadActivity"
|
||||
|
@ -80,7 +57,7 @@
|
|||
<activity
|
||||
android:name=".Main2Activity"
|
||||
|
||||
android:launchMode="singleTask"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/ToolBarTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -88,9 +65,6 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.default_searchable"
|
||||
android:value=".Main7Activity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
|
|
|
@ -534,13 +534,13 @@ public class BookActivity extends Activity_base {
|
|||
if (!isLocalDbExist) {
|
||||
// nv.saveAsync();
|
||||
nv.save();
|
||||
|
||||
mNovel =nv;
|
||||
} else {
|
||||
|
||||
nv.updateAll("novelId=?", novelId+"");
|
||||
|
||||
mNovel = Novel.getNovelBySvrId(novelId);
|
||||
}
|
||||
mNovel = Novel.getNovelBySvrId(novelId);
|
||||
|
||||
if (null != mNovel) {
|
||||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
|
@ -685,10 +685,10 @@ void onResponseProcess( String content ,String url){
|
|||
registerReceiver(receiver,filter);
|
||||
if(mNovel!=null && mNovel.getId()>0) {
|
||||
mNovel = LitePal.find(Novel.class, mNovel.getId()); //更新最新进度
|
||||
if(pageFactory==null){
|
||||
if(pageFactory==null){
|
||||
pageFactory = PageFactory.getInstance(getApplicationContext());
|
||||
}
|
||||
if(( pageFactory.getNovle()==null || mNovel.getId() !=pageFactory.getNovle().getId())){
|
||||
if( pageFactory.isWorking() && ( pageFactory.getNovle()==null || mNovel.getId() !=pageFactory.getNovle().getId())){
|
||||
pageFactory.prepareBook(mNovel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ public abstract class BasicFragment extends Fragment {
|
|||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
|
||||
|
||||
hideProgress();
|
||||
int wt = msg.what;
|
||||
|
||||
if (msg.what == 1) {
|
||||
|
@ -159,7 +159,7 @@ public abstract class BasicFragment extends Fragment {
|
|||
Toast.makeText(getActivity(),"好像没有网络啦",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
hideProgress();
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
@ -385,7 +385,7 @@ public abstract class BasicFragment extends Fragment {
|
|||
|
||||
|
||||
public void reload() {
|
||||
initViews();
|
||||
loadData();
|
||||
}
|
||||
public void loadData() {
|
||||
initData();
|
||||
|
|
|
@ -174,6 +174,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
}
|
||||
});
|
||||
|
||||
mAdapter.setNorecord(R.string.noRecordInshelf);
|
||||
((Main2Activity) activity).setShelfFragment(this);
|
||||
}
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.novelbook.android.Fragments;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
@ -25,8 +26,8 @@ public class Fragment_bookStore extends BasicFragment {
|
|||
ViewPager mViewpager;
|
||||
@BindView(R.id.tab_layout)
|
||||
SlidingTabLayout tabLayout;
|
||||
|
||||
private ArrayList<Fragment> mFragments;
|
||||
private FragmentStatePagerAdapter mAdapter =null;
|
||||
private ArrayList<BasicFragment> mFragments;
|
||||
ArrayList<View> mList;
|
||||
String[] mTitle;
|
||||
|
||||
|
@ -69,8 +70,16 @@ public class Fragment_bookStore extends BasicFragment {
|
|||
|
||||
@Override
|
||||
public void initData() {
|
||||
mTitle = new String[]{"精选", "榜单","分类"};
|
||||
|
||||
if(mAdapter!=null) {
|
||||
for(BasicFragment bf:mFragments){
|
||||
bf.initData();
|
||||
}
|
||||
// mViewpager.setCurrentItem(0);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void initViews(){
|
||||
|
@ -83,17 +92,17 @@ public class Fragment_bookStore extends BasicFragment {
|
|||
|
||||
if(mFragments ==null || mFragments.size() ==0){
|
||||
// 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 ");
|
||||
}
|
||||
Log.d(TAG,"set viewPager adapter ");
|
||||
// FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(activity.getSupportFragmentManager()) { 第一次进入没问题,再次进入ViewPager的fragment时里面内容就没了,数据丢失 https://blog.csdn.net/allan_bst/article/details/64920076
|
||||
FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {
|
||||
mAdapter = new FragmentStatePagerAdapter(getChildFragmentManager()) {
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return mFragments.get(position);
|
||||
|
@ -112,11 +121,15 @@ public class Fragment_bookStore extends BasicFragment {
|
|||
mViewpager.setOffscreenPageLimit(4);//预加载设置
|
||||
mViewpager.setAdapter(mAdapter);
|
||||
tabLayout.setViewPager(mViewpager);
|
||||
|
||||
|
||||
// tabLayout.setViewPager(mViewpager, mTitle, activity, mFragments);
|
||||
mViewpager.setCurrentItem(0);
|
||||
// mViewpager.setCurrentItem(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setFTag() {
|
||||
TAG="com.novelbook.android.Fragment_Store";
|
||||
|
|
|
@ -42,6 +42,7 @@ import butterknife.BindView;
|
|||
|
||||
|
||||
public class Fragment_booklist extends BasicFragment {
|
||||
public static String TAG = Fragment_booklist.class.getSimpleName();
|
||||
private static final String EXTR_CATE ="cate" ;
|
||||
private static final String EXTR_PROGRESS ="progress" ;
|
||||
private static final String EXTR_SEARCH ="search";
|
||||
|
@ -266,6 +267,9 @@ public class Fragment_booklist extends BasicFragment {
|
|||
}
|
||||
@Override
|
||||
public void initViews(){
|
||||
//mRecyclerView
|
||||
|
||||
//lv_catalogue.setFastScrollStyle(R.style.FastScrollTheme); //不起作用
|
||||
initLoadMoreListener();
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,6 @@ final String TAG = Fragment_paihang.class.getSimpleName();
|
|||
|
||||
@Override
|
||||
public void initData() {
|
||||
tmp=0;
|
||||
loadSearchData();
|
||||
}
|
||||
private void loadSearchData(){
|
||||
|
@ -212,7 +211,7 @@ final String TAG = Fragment_paihang.class.getSimpleName();
|
|||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
};
|
||||
showProgressDialog(false,"正在加载...");
|
||||
showProgressDialog(false, "正在加载...");
|
||||
BookSubscribe.getCateNovelList(cate, pageNo, tab1Pos+1, tab3Pos+1, new OnSuccessAndFaultSub(successAndFaultListener, getActivity()));
|
||||
|
||||
|
||||
|
@ -330,9 +329,10 @@ final String TAG = Fragment_paihang.class.getSimpleName();
|
|||
Toast.makeText(activity, selectedKey,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
tvHint.setText(selectedKey);
|
||||
Log.d(TAG, String.format("tabChanged: to load data %s,pageno %s" , selectedKey,pageNo ));
|
||||
Log.d(TAG, String.format("tabChanged: to load data %s,pageno %s, tmp %s" , selectedKey,pageNo ,tmp));
|
||||
|
||||
if( tmp<4) return;
|
||||
|
||||
loadSearchData();
|
||||
|
||||
|
||||
|
|
|
@ -427,6 +427,12 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
public void cancel() {
|
||||
pageFactory.cancelPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canCancel() {
|
||||
// Log.d(TAG, "canCancel: cancelPage canCancel ?" + pageFactory.canCancelPage());
|
||||
return true;//pageFactory.canCancelPage();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -54,6 +54,11 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
|
|||
private boolean showFootView =false;
|
||||
|
||||
private float percent =0;
|
||||
private int norecord =R.string.noRecord;
|
||||
|
||||
public void setNorecord(int norecord) {
|
||||
this.norecord = norecord;
|
||||
}
|
||||
|
||||
public void setPercent(float percent) {
|
||||
this.percent = percent;
|
||||
|
@ -183,7 +188,7 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol
|
|||
}else if (hd instanceof EmptyViewHolder) {
|
||||
EmptyViewHolder holder = (EmptyViewHolder)hd;
|
||||
holder.tvEmpty.setVisibility(View.VISIBLE);
|
||||
holder.tvEmpty.setText(R.string.noRecord);
|
||||
holder.tvEmpty.setText(norecord);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -114,7 +114,9 @@ public class OnSuccessAndFaultSub extends DisposableObserver<ResponseBody>
|
|||
public void onError(Throwable e) {
|
||||
try {
|
||||
|
||||
if (e instanceof SocketTimeoutException) {//请求超时
|
||||
if (e instanceof SocketTimeoutException) {
|
||||
mOnSuccessAndFaultListener.onFault("网络连接超时");
|
||||
//请求超时
|
||||
} else if (e instanceof ConnectException) {//网络连接超时
|
||||
// ToastManager.showShortToast("网络连接超时");
|
||||
mOnSuccessAndFaultListener.onFault("网络连接超时");
|
||||
|
|
|
@ -117,6 +117,13 @@ public class BookUtil {
|
|||
private Site mSite;
|
||||
private SiteRule mSiteRule;
|
||||
|
||||
private Map<Integer,Cache> chaptCache = new HashMap<Integer,Cache>();
|
||||
private Map<Integer,DownloadStatus> chaptDownStatus = new HashMap<Integer, DownloadStatus>();
|
||||
DownloadStatus downloadStatus = DownloadStatus.notStart;
|
||||
|
||||
|
||||
|
||||
|
||||
public NovelSites getmNovelSites() {
|
||||
return mNovelSites;
|
||||
}
|
||||
|
@ -143,7 +150,7 @@ public class BookUtil {
|
|||
if (mChapters.isEmpty()) { //1. 首次打开 本地导入的书
|
||||
|
||||
if (bookPath == null || !bookPath.equals(mNovel.getNovelPath())) {
|
||||
cleanCacheFile();
|
||||
cleanCacheFile();
|
||||
this.bookPath = mNovel.getNovelPath();
|
||||
bookName = FileUtils.getFileName(bookPath);
|
||||
cacheBook();
|
||||
|
@ -332,6 +339,11 @@ public class BookUtil {
|
|||
return false;
|
||||
|
||||
}
|
||||
private long tmpChaptLen=0;
|
||||
|
||||
public void setTmpChaptLen(long tmpChaptLen) {
|
||||
this.tmpChaptLen = tmpChaptLen;
|
||||
}
|
||||
|
||||
private boolean isChangeSource =false;
|
||||
private int mChangeChapId;
|
||||
|
@ -342,6 +354,12 @@ public class BookUtil {
|
|||
Log.d(TAG, "changing Source: same site with original " + domain);
|
||||
return;
|
||||
}
|
||||
|
||||
this.muluRetryCount=0;
|
||||
this.downloadStatus = DownloadStatus.notStart;
|
||||
chaptDownStatus.clear();
|
||||
chaptCache.clear();
|
||||
|
||||
mChangeChapId = chapId;
|
||||
mChangeTitle =chapTitle;
|
||||
for (Site site:mNovelSites.getSites() ) {
|
||||
|
@ -375,6 +393,7 @@ public class BookUtil {
|
|||
return f.exists();
|
||||
}
|
||||
|
||||
|
||||
private class BookTask extends AsyncTask<String,Void,Boolean> {
|
||||
private String domain;
|
||||
private int chapId;
|
||||
|
@ -725,8 +744,8 @@ int muluRetryCount =0;
|
|||
|
||||
public int next(boolean back){
|
||||
position += 1;
|
||||
if (position > bookLen){
|
||||
position = bookLen;
|
||||
if (position > tmpChaptLen){
|
||||
position = tmpChaptLen;
|
||||
return -1;
|
||||
}
|
||||
char result = chaptCurrent(); //current();
|
||||
|
@ -737,11 +756,11 @@ int muluRetryCount =0;
|
|||
}
|
||||
|
||||
public char[] nextLine(){
|
||||
if (position >= bookLen){
|
||||
if (position >= tmpChaptLen){
|
||||
return null;
|
||||
}
|
||||
String line = "";
|
||||
while (position < bookLen){
|
||||
while (position < tmpChaptLen){
|
||||
int word = next(false);
|
||||
if (word == -1){
|
||||
break;
|
||||
|
@ -1147,9 +1166,7 @@ int muluRetryCount =0;
|
|||
}
|
||||
|
||||
|
||||
private Map<Integer,Cache> chaptCache = new HashMap<Integer,Cache>();
|
||||
private Map<Integer,DownloadStatus> chaptDownStatus = new HashMap<Integer, DownloadStatus>();
|
||||
DownloadStatus downloadStatus = DownloadStatus.notStart;
|
||||
|
||||
private enum DownloadStatus{
|
||||
notStart,
|
||||
downloading,
|
||||
|
@ -1194,6 +1211,7 @@ int muluRetryCount =0;
|
|||
|
||||
//获取chapter 缓存
|
||||
public char[] chaptChars(final int index) {
|
||||
// Log.d(TAG, String.format("prepare book begin to load content for chapter %s ------------------------------------------------------------------------->", index));
|
||||
char[] block=null;
|
||||
if(chaptCache.containsKey(Integer.valueOf(index))) {
|
||||
block = chaptCache .get(index).getData().get();
|
||||
|
|
|
@ -36,9 +36,11 @@ import java.io.IOException;
|
|||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//import static com.baidu.tts.loopj.AsyncHttpClient.log;
|
||||
|
||||
|
@ -165,7 +167,7 @@ public class PageFactory implements ChangeSource{
|
|||
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
ConcurrentHashMap<Integer,List<TRPage>> chaptMap;
|
||||
private List<TRPage> currentChaptPages;
|
||||
private List<TRPage> nextChaptPages;
|
||||
private List<TRPage> preChaptPages;
|
||||
|
@ -209,23 +211,20 @@ public class PageFactory implements ChangeSource{
|
|||
List<TRPage> chaptPages = new ArrayList<TRPage>();
|
||||
chaptPages.add(new TRPage());
|
||||
|
||||
long starttime = new Date().getTime();
|
||||
|
||||
|
||||
if (fileRetryCnt.containsKey(chaptId)) {
|
||||
fileRetryCnt.put(chaptId, fileRetryCnt.get(chaptId) + 1);
|
||||
} else {
|
||||
fileRetryCnt.clear();//只保留一个章节数据
|
||||
fileRetryCnt.put(chaptId, 1);
|
||||
if(chaptMap==null) {
|
||||
chaptMap = new ConcurrentHashMap<Integer, List<TRPage>>();
|
||||
}
|
||||
if(chaptMap.containsKey(chaptId)){
|
||||
chaptPages =chaptMap.get(chaptId);
|
||||
mBookUtil.setBookLen( chaptPages.get(chaptPages.size()-1).getEnd());
|
||||
mBookUtil.setChapterNo(chaptId);
|
||||
Log.d(TAG, String.format("prepare book to load chapt %s, cost %s ",chaptId ,new Date().getTime() -starttime) );
|
||||
return chaptMap.get(chaptId);
|
||||
}
|
||||
|
||||
Log.d(TAG, String.format("prepare book loadCurrentChapt %s, rertying count %s ",chaptId, fileRetryCnt.get(chaptId)));
|
||||
|
||||
if(fileRetryCnt.get(chaptId) > Constants.retryCnt){
|
||||
mStatus = Status.FAIL;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
return chaptPages;
|
||||
}
|
||||
final File file = new File(getChapterFileName(chaptId));
|
||||
|
||||
if (!file.exists()) { //待下载
|
||||
|
@ -235,15 +234,9 @@ public class PageFactory implements ChangeSource{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(!mBook.isLocalBook()) {
|
||||
|
||||
mStatus = Status.OPENING;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
|
||||
// final File file = new File(getChapterFileName(chaptId));
|
||||
|
||||
|
@ -251,7 +244,25 @@ public class PageFactory implements ChangeSource{
|
|||
|
||||
if (!file.exists()) {
|
||||
|
||||
mStatus = Status.OPENING;
|
||||
if (fileRetryCnt.containsKey(chaptId)) {
|
||||
fileRetryCnt.put(chaptId, fileRetryCnt.get(chaptId) + 1);
|
||||
} else {
|
||||
fileRetryCnt.clear();//只保留一个章节数据
|
||||
fileRetryCnt.put(chaptId, 1);
|
||||
}
|
||||
|
||||
Log.d(TAG, String.format("prepare book loadCurrentChapt %s, rertying count %s ",chaptId, fileRetryCnt.get(chaptId)));
|
||||
|
||||
if(fileRetryCnt.get(chaptId) > Constants.retryCnt){
|
||||
mStatus = Status.FAIL;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
return chaptPages;
|
||||
}
|
||||
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
|
||||
if( !NetUtil.isNetworkConnected()){ //TODO: 500错误处理
|
||||
mStatus = Status.NETWORKFAILE;
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
|
@ -303,46 +314,73 @@ public class PageFactory implements ChangeSource{
|
|||
super.run();
|
||||
}}.start();
|
||||
|
||||
|
||||
|
||||
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();
|
||||
chaptPages =readChaptCache(chaptId);
|
||||
chaptMap.put(chaptId,chaptPages);
|
||||
mBookUtil.setBookLen( chaptPages.get(chaptPages.size()-1).getEnd());
|
||||
mBookUtil.setChapterNo(chaptId);
|
||||
|
||||
Log.d(TAG, String.format("prepare book to load chapt %s, cost %s ",chaptId ,new Date().getTime() -starttime) );
|
||||
mStatus = Status.FINISH;
|
||||
Log.d(TAG, String.format("changing Source prepare book to draw chapter %s, currentChapter %s ",chaptId ,currentChapter ) );
|
||||
/* drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());*/
|
||||
return chaptPages;
|
||||
}
|
||||
|
||||
void preReadChaptCache(final int chaptId){
|
||||
if(chaptMap==null) {
|
||||
chaptMap = new ConcurrentHashMap<Integer, List<TRPage>>();
|
||||
}
|
||||
if(chaptMap.containsKey(chaptId)){
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, String.format("prepare book to preLoad chapt %s, current chapt %s --->",chaptId ,currentChapter) );
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, String.format("prepare book to preRead chapter %s ,thread.name %s",chaptId,Thread.currentThread().getName() ) );
|
||||
File file = new File(getChapterFileName(chaptId));
|
||||
if(file.exists()) {
|
||||
chaptMap.put(chaptId, readChaptCache(chaptId));
|
||||
Log.d(TAG, String.format("prepare book to preLoad success " ) );
|
||||
}
|
||||
Log.d(TAG, String.format("prepare book to preLoad done <-----" ) );
|
||||
super.run();
|
||||
}}.start();
|
||||
}
|
||||
|
||||
|
||||
// chaptId = mChapters!=null && mChapters.size() <= chaptId ? 1 : chaptId;
|
||||
|
||||
Log.d(TAG, String.format("changing Source prepare book to open chapter %s, currentChapter %s ",chaptId ,currentChapter ) );
|
||||
char[] chars = mBookUtil.chaptChars(chaptId);
|
||||
String s = new String(chars);
|
||||
// Log.d(TAG, String.format("prepare book open chapter %s,chars %s ",chaptId ,s ) );
|
||||
mBookUtil.setBookLen(chars.length);
|
||||
mBookUtil.setChapterNo(chaptId);
|
||||
// TRPage page = new TRPage();
|
||||
/**
|
||||
* only read chapt that cached already
|
||||
* @param chaptId
|
||||
* @return
|
||||
*/
|
||||
List<TRPage> readChaptCache(int chaptId){
|
||||
List<TRPage> chaptPages = new ArrayList<TRPage>();
|
||||
Log.d(TAG, String.format("changing Source prepare book to open chapter %s, currentChapter %s ",chaptId ,currentChapter ) );
|
||||
char[] chars = mBookUtil.chaptChars(chaptId);
|
||||
mBookUtil.setTmpChaptLen(chars.length);
|
||||
// mBookUtil.setChapterNo(chaptId);
|
||||
// TRPage page = new TRPage();
|
||||
long length =0;
|
||||
int pageNo =0;
|
||||
while(length <chars.length ) {
|
||||
pageNo++;
|
||||
TRPage page = getNextChapterPage(length);
|
||||
// Log.d(TAG,"prepare book page.getBegin :" + page.getBegin()+ ",chapter length "+ mBookUtil.getBookLen());
|
||||
// Log.d(TAG,"prepare book page.getBegin :" + page.getBegin()+ ",chapter length "+ mBookUtil.getBookLen());
|
||||
|
||||
// if(page.getBegin() == mBookUtil.getBookLen() ){ //最后一页空白的情况。。。
|
||||
// if(page.getBegin() == mBookUtil.getBookLen() ){ //最后一页空白的情况。。。
|
||||
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
page.setChapterNo(chaptId);
|
||||
page.setLastPage(page.getEnd()==chars.length);
|
||||
|
@ -351,12 +389,12 @@ public class PageFactory implements ChangeSource{
|
|||
chaptPages.add(page);
|
||||
length= page.getEnd();
|
||||
}
|
||||
mStatus = Status.FINISH;
|
||||
Log.d(TAG, String.format("changing Source prepare book to draw chapter %s, currentChapter %s ",chaptId ,currentChapter ) );
|
||||
drawStatus(mBookPageWidget.getCurPage());
|
||||
drawStatus(mBookPageWidget.getNextPage());
|
||||
return chaptPages;
|
||||
return chaptPages;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public TRPage getNextChapterPage(long position){
|
||||
mBookUtil.setPostition(position);
|
||||
|
||||
|
@ -397,11 +435,8 @@ public class PageFactory implements ChangeSource{
|
|||
}
|
||||
}
|
||||
public void changeSource(String domain,int chapId,String chapTitle) {
|
||||
|
||||
mBookUtil.changeSource(domain, chapId, chapTitle);
|
||||
|
||||
|
||||
|
||||
fileRetryCnt.clear();
|
||||
mBookUtil.changeSource(domain, chapId, chapTitle);
|
||||
}
|
||||
|
||||
public String getChapterName() {
|
||||
|
@ -565,6 +600,9 @@ public static boolean busy(){
|
|||
case SERVERERROR:
|
||||
status = "服务器故障";
|
||||
break;
|
||||
/* case FINISH:
|
||||
status = "加载成功";
|
||||
break;*/
|
||||
}
|
||||
|
||||
Canvas c = new Canvas(bitmap);
|
||||
|
@ -944,17 +982,6 @@ public static boolean busy(){
|
|||
}
|
||||
|
||||
public TRPage getNextPage(){
|
||||
/*
|
||||
mBookUtil.setPostition(currentPage.getEnd());
|
||||
|
||||
TRPage trPage = new TRPage();
|
||||
trPage.setBegin(currentPage.getEnd() +1);
|
||||
Log.d(TAG,"page postion next begin:" + (currentPage.getEnd() + 1) + "");
|
||||
trPage.setLines(getNextLines());
|
||||
Log.d(TAG,"page postion next end:" +mBookUtil.getPosition() + "");
|
||||
trPage.setEnd(mBookUtil.getPosition());
|
||||
return trPage;
|
||||
*/
|
||||
|
||||
int nextPageNo =currentPage.getPageNo();
|
||||
Log.e(TAG,String.format("prepare book getNextPage() currentChapter %s, currentChaptPages .size() is %s,currentpage pageno is %s"
|
||||
|
@ -965,25 +992,19 @@ public static boolean busy(){
|
|||
mBookUtil.setChapterNo(currentChapter);
|
||||
currentChaptPages = loadCurrentChapt(currentChapter ) ;
|
||||
nextPageNo =0;
|
||||
}else {
|
||||
preReadChaptCache(currentChapter + 1);
|
||||
}
|
||||
return currentChaptPages.get(nextPageNo);
|
||||
}
|
||||
|
||||
public TRPage getPrePage(){
|
||||
/*
|
||||
mBookUtil.setPostition(currentPage.getBegin());
|
||||
|
||||
TRPage trPage = new TRPage();
|
||||
trPage.setEnd(mBookUtil.getPosition() -1);
|
||||
Log.d(TAG,"page postion pre end:" + (mBookUtil.getPosition() - 1 )+ "");
|
||||
trPage.setLines(getPreLines());
|
||||
Log.d(TAG,"page postion pre begin:" +mBookUtil.getPosition() + "");
|
||||
trPage.setBegin(mBookUtil.getPosition() );
|
||||
return trPage;
|
||||
*/
|
||||
|
||||
int prePageNo =currentPage.getPageNo()-1;
|
||||
Log.d(TAG,String.format("currentPageno %s,total pagno %s",currentPage.getPageNo(),currentChaptPages.size()));
|
||||
|
||||
|
||||
if(prePageNo <=0){
|
||||
nextChaptPages =currentChaptPages;
|
||||
currentChapter--;
|
||||
|
@ -993,7 +1014,10 @@ public static boolean busy(){
|
|||
mBookUtil.setChapterNo(currentChapter);
|
||||
currentChaptPages = loadCurrentChapt(currentChapter ) ;
|
||||
prePageNo = currentChaptPages.size();
|
||||
}else{
|
||||
preReadChaptCache(currentChapter-1);
|
||||
}
|
||||
|
||||
return currentChaptPages.get(prePageNo-1);
|
||||
|
||||
}
|
||||
|
@ -1292,7 +1316,7 @@ public static boolean busy(){
|
|||
|
||||
public void openBookmark(int chapNum,long position){
|
||||
|
||||
preChaptPages =currentChaptPages;
|
||||
//preChaptPages =currentChaptPages;
|
||||
currentChapter = chapNum;
|
||||
mBookUtil.setChapterNo(currentChapter);
|
||||
currentChaptPages = loadCurrentChapt(currentChapter ) ;
|
||||
|
@ -1402,6 +1426,7 @@ public static boolean busy(){
|
|||
public void clear(){
|
||||
Log.d(TAG, String .format("prepare Book: clearing book info %s" , getNovle().getName()));
|
||||
fileRetryCnt.clear();
|
||||
chaptMap.clear();
|
||||
//mBookUtil=null;
|
||||
currentChapter = 0;
|
||||
bookPath = "";
|
||||
|
@ -1446,6 +1471,11 @@ public static boolean busy(){
|
|||
public Novel getNovle(){
|
||||
return mBookUtil.getNovel();
|
||||
}
|
||||
public boolean isWorking(){
|
||||
return mBookUtil !=null;
|
||||
}
|
||||
|
||||
|
||||
//是否是第一页
|
||||
public boolean isfirstPage() {
|
||||
return m_isfirstPage;
|
||||
|
|
|
@ -192,23 +192,28 @@ public class PageWidget extends View {
|
|||
Log.e(TAG,"isNext:" + isNext);
|
||||
}else{
|
||||
//判断是否取消翻页
|
||||
if (isNext){
|
||||
if (x - moveX > 0){
|
||||
cancelPage = true;
|
||||
mAnimationProvider.setCancel(true);
|
||||
}else {
|
||||
cancelPage = false;
|
||||
mAnimationProvider.setCancel(false);
|
||||
if(mTouchListener.canCancel()) {
|
||||
if (isNext) {
|
||||
if (x - moveX > 0) {
|
||||
cancelPage = true;
|
||||
mAnimationProvider.setCancel(true);
|
||||
} else {
|
||||
cancelPage = false;
|
||||
mAnimationProvider.setCancel(false);
|
||||
}
|
||||
} else {
|
||||
if (x - moveX < 0) {
|
||||
mAnimationProvider.setCancel(true);
|
||||
cancelPage = true;
|
||||
} else {
|
||||
mAnimationProvider.setCancel(false);
|
||||
cancelPage = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (x - moveX < 0){
|
||||
mAnimationProvider.setCancel(true);
|
||||
cancelPage = true;
|
||||
}else {
|
||||
mAnimationProvider.setCancel(false);
|
||||
cancelPage = false;
|
||||
}
|
||||
noNext=true;
|
||||
}
|
||||
if(cancelPage)
|
||||
Log.e(TAG,"cancelPage:" + cancelPage);
|
||||
}
|
||||
|
||||
|
@ -309,6 +314,7 @@ public class PageWidget extends View {
|
|||
Boolean prePage();
|
||||
Boolean nextPage();
|
||||
void cancel();
|
||||
Boolean canCancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
app:collapsedTitleGravity="center"
|
||||
app:collapsedTitleGravity="center_horizontal"
|
||||
app:contentScrim="?attr/colorPrimary"
|
||||
app:expandedTitleGravity="bottom"
|
||||
app:expandedTitleTextAppearance="@style/TitleText"
|
||||
|
@ -142,8 +142,6 @@
|
|||
app:contentInsetLeft="0dp"
|
||||
app:contentInsetStart="0dp"
|
||||
app:layout_collapseMode="pin"
|
||||
|
||||
|
||||
app:popupTheme="@style/ToolBarTheme.PopupOverlay">
|
||||
|
||||
<Button
|
||||
|
@ -151,8 +149,9 @@
|
|||
style="@style/buttonCates"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="right|center_vertical"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:text="首页"
|
||||
android:visibility="invisible"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
android:id="@+id/rgSex"
|
||||
|
||||
style="@style/radioGroup"
|
||||
android:layout_gravity="center_horizontal"
|
||||
>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButtonBoy"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/app_bar_height_250"
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true"
|
||||
|
||||
android:theme="@style/ToolBarTheme.AppBarOverlay">
|
||||
|
@ -25,7 +25,7 @@
|
|||
app:contentScrim="?attr/colorPrimary"
|
||||
app:expandedTitleGravity="bottom"
|
||||
app:expandedTitleTextAppearance="@style/TitleText"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:toolbarId="@+id/toolbar">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -34,7 +34,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/white"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingBottom="0dp"
|
||||
android:layout_marginTop="40dp"
|
||||
app:layout_collapseMode="pin"
|
||||
app:layout_collapseParallaxMultiplier="0.7">
|
||||
|
|
|
@ -33,15 +33,15 @@
|
|||
<TextView
|
||||
android:id="@+id/tvCateName"
|
||||
style="@style/NovelBlockTitle"
|
||||
android:layout_height="15dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
|
||||
android:text=""
|
||||
android:text="原创风云榜"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvNovels"
|
||||
android:text=""
|
||||
android:text="abcd efg hi"
|
||||
style="@style/TextViewNovelDesc.titles"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -188,6 +188,8 @@
|
|||
<string name="title_Activity_ChgSource">换源</string>
|
||||
<string name="_00_00">00.00%</string>
|
||||
<string name="cached">已缓存</string>
|
||||
<string name="noRecordInshelf">书架空空如也</string>
|
||||
<string name="msgLoading">正在加载...</string>
|
||||
|
||||
<string-array name="voicer_cloud_entries">
|
||||
<item>小燕—女青、中英、普通话</item>
|
||||
|
|
|
@ -338,11 +338,13 @@
|
|||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:lines">2</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:gravity">left</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
</style>
|
||||
<style name="TextViewNovelDesc.titles">
|
||||
<item name="android:lines">1</item>
|
||||
<item name="android:gravity">left</item>
|
||||
<item name="android:layout_margin">5dp</item>
|
||||
</style>
|
||||
<style name="TextViewNovelDesc.head">
|
||||
<item name="android:layout_margin">10dp</item>
|
||||
|
|
Loading…
Reference in New Issue