调整内容下载设置
This commit is contained in:
parent
da8acff50b
commit
27e08bb384
|
@ -9,12 +9,16 @@ import android.os.Bundle;
|
|||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.novelbook.android.AD.toutiao.TTAdManagerHolder;
|
||||
import com.novelbook.android.db.DownloadTask;
|
||||
import com.novelbook.android.netutils.NetUtil;
|
||||
import com.novelbook.android.service.ServiceDownload;
|
||||
import com.novelbook.android.utils.CommonUtil;
|
||||
import com.novelbook.android.utils.Config;
|
||||
import com.novelbook.android.utils.Constants;
|
||||
import com.novelbook.android.utils.FileUtils;
|
||||
import com.novelbook.android.utils.Fileutil;
|
||||
|
@ -32,11 +36,12 @@ static final String TAG = ActivitySetup.class.getSimpleName();
|
|||
TextView tvCache;
|
||||
@BindView(R.id.tvVersion)
|
||||
TextView tvVersion;
|
||||
|
||||
@BindView(R.id.rgShelfOrder)
|
||||
RadioGroup rgShelfOrder;
|
||||
|
||||
String mVersion ="";
|
||||
String mCacheSize ="";
|
||||
|
||||
private Config config ;
|
||||
@Override
|
||||
public int getLayoutRes() {
|
||||
return R.layout.activity_setup;
|
||||
|
@ -44,6 +49,8 @@ static final String TAG = ActivitySetup.class.getSimpleName();
|
|||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
config =Config.getInstance();
|
||||
initialShelfOrderOption();
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -80,7 +87,7 @@ static final String TAG = ActivitySetup.class.getSimpleName();
|
|||
|
||||
}
|
||||
|
||||
@OnClick({R.id.llAnouncement,R.id.llCache,R.id.llVersion})
|
||||
@OnClick({R.id.llAnouncement,R.id.llCache,R.id.llVersion,R.id.radioButton1,R.id.radioButton2,R.id.radioButton3})
|
||||
void onSetupclick(View view){
|
||||
|
||||
switch (view.getId()) {
|
||||
|
@ -160,20 +167,52 @@ static final String TAG = ActivitySetup.class.getSimpleName();
|
|||
}
|
||||
}.start();
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case R.id.radioButton1:
|
||||
setShelfOrder();
|
||||
break;
|
||||
case R.id.radioButton2:
|
||||
setShelfOrder();
|
||||
break;
|
||||
case R.id.radioButton3:
|
||||
setShelfOrder();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setShelfOrder() {
|
||||
int s = 1;
|
||||
|
||||
switch (rgShelfOrder.getCheckedRadioButtonId()){
|
||||
case R.id.radioButton1:
|
||||
s=1;
|
||||
break;
|
||||
case R.id.radioButton2:
|
||||
s=2;
|
||||
break;
|
||||
case R.id.radioButton3:
|
||||
s=3;
|
||||
break;
|
||||
}
|
||||
|
||||
Log.d(TAG, "setSexOption: new sex option:" +s);
|
||||
if(s!= Constants.SHELF_ORDER) {
|
||||
Constants.SHELF_ORDER = s;
|
||||
config.setShelfOrderOption(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void initialShelfOrderOption(){
|
||||
|
||||
|
||||
Constants.SHELF_ORDER = config.getShelfOrderOption();
|
||||
rgShelfOrder.clearCheck();
|
||||
((RadioButton) rgShelfOrder.getChildAt(Constants.SHELF_ORDER-1)).setChecked(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.widget.CompoundButton;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -43,6 +45,7 @@ import com.novelbook.android.netutils.NetUtil;
|
|||
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
||||
import com.novelbook.android.utils.CommonUtil;
|
||||
import com.novelbook.android.utils.Config;
|
||||
import com.novelbook.android.utils.Constants;
|
||||
import com.novelbook.android.utils.FileUtils;
|
||||
import com.novelbook.android.utils.Fileutil;
|
||||
|
@ -92,6 +95,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
@BindView(R.id.banner_container)
|
||||
FrameLayout mBannerContainer;
|
||||
|
||||
private Config config ;
|
||||
public Fragment_Shelf() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
@ -123,7 +127,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
int i=0;
|
||||
for (Novel novel : bookLists) {
|
||||
if (novel.isFinished() || novel.isLocalBook() || novel.isUpdated() && (new Date().getTime() - novel.getLastVisit() > 1*3600*1000 ) ) {
|
||||
// if(!novel.getName().equals("暗月纪元"))
|
||||
//if(!novel.getName().equals("剑来"))
|
||||
continue;
|
||||
}
|
||||
if(i>Constants.MAX_SHELF_CNT){
|
||||
|
@ -366,9 +370,68 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
}
|
||||
});
|
||||
|
||||
if(config==null){
|
||||
config =Config.getInstance();
|
||||
}
|
||||
|
||||
RadioGroup rgShelfOrder = bottomSheetDialog.findViewById(R.id.rgShelfOrder);
|
||||
Constants.SHELF_ORDER = config.getShelfOrderOption();
|
||||
rgShelfOrder.clearCheck();
|
||||
((RadioButton) rgShelfOrder.getChildAt(Constants.SHELF_ORDER-1)).setChecked(true);
|
||||
|
||||
|
||||
|
||||
RadioButton radioButton1 = bottomSheetDialog.findViewById(R.id.radioButton1);
|
||||
RadioButton radioButton2 = bottomSheetDialog.findViewById(R.id.radioButton2);
|
||||
RadioButton radioButton3 = bottomSheetDialog.findViewById(R.id.radioButton3);
|
||||
RadioButton radioButton4 = bottomSheetDialog.findViewById(R.id.radioButton4);
|
||||
radioButton1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
setShelfOrder(1);
|
||||
}
|
||||
});
|
||||
|
||||
radioButton2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
setShelfOrder(2);
|
||||
}
|
||||
});
|
||||
radioButton3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
setShelfOrder(3);
|
||||
}
|
||||
});
|
||||
|
||||
radioButton4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
setShelfOrder(4);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
bottomSheetDialog.show();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
private void setShelfOrder(int option) {
|
||||
|
||||
Log.d(TAG, "setShelfOrder: new sex option:" +option);
|
||||
if(option!= Constants.SHELF_ORDER) {
|
||||
Constants.SHELF_ORDER = option;
|
||||
config.setShelfOrderOption(option);
|
||||
getUpdatedData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
|
|
@ -51,6 +51,7 @@ public class MyApp extends Application {
|
|||
private void initialConstants(){
|
||||
Config config= Config.createConfig(this);
|
||||
Constants.SEX = config.getSexOption();
|
||||
Constants.SHELF_ORDER = config.getShelfOrderOption();
|
||||
Constants.PRE_LOAD_CHAPT =config.isPreLoadChapter();
|
||||
Gson gson = new Gson();
|
||||
Constants.AD_SETTING = gson.fromJson(config.getAdSetting(), AdSetting.class);
|
||||
|
|
|
@ -996,15 +996,18 @@ public class ReadActivity extends Activity_base implements AdInterface {
|
|||
/* tvUrl.setVisibility(View.VISIBLE);
|
||||
tvUrl.setText("abcd+" + pageFactory.getChapter().getChapterUrl());*/
|
||||
|
||||
showChaptUrl();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
void showChaptUrl(){
|
||||
if(Constants.SHOW_NOVEL_CHAPTER_URL) {
|
||||
if(pageFactory.getChapter()!=null && !TextUtils.isEmpty(pageFactory.getChapter().getChapterUrl())) {
|
||||
tvUrl.setVisibility(View.VISIBLE);
|
||||
tvUrl.setText(pageFactory.getChapter().getChapterUrl());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 隐藏菜单。沉浸式阅读
|
||||
|
@ -1114,12 +1117,15 @@ public class ReadActivity extends Activity_base implements AdInterface {
|
|||
case R.id.rl_progress:
|
||||
break;
|
||||
case R.id.tv_pre:
|
||||
showChaptUrl();
|
||||
pageFactory.preChapter();
|
||||
break;
|
||||
case R.id.sb_progress:
|
||||
break;
|
||||
case R.id.tv_next:
|
||||
showChaptUrl();
|
||||
pageFactory.nextChapter();
|
||||
|
||||
break;
|
||||
case R.id.tv_directory:
|
||||
Intent intent = new Intent(ReadActivity.this, MarkActivity.class);
|
||||
|
|
|
@ -16,8 +16,8 @@ public class AdSetting {
|
|||
private slot fixBanner = new slot();
|
||||
private slot bigBanner = new slot();
|
||||
public boolean isShowAdsense() {
|
||||
// return true;
|
||||
return showAdsense && NetUtil.isNetworkConnected();
|
||||
return false;
|
||||
// return showAdsense && NetUtil.isNetworkConnected();
|
||||
}
|
||||
|
||||
public void setShowAdsense(boolean showAdsense) {
|
||||
|
|
|
@ -275,7 +275,24 @@ public class Novel extends LitePalSupport implements Serializable{
|
|||
public static List<Novel> getNovelsOnShelf(){
|
||||
|
||||
// return LitePal.where("isOnShelf=?","1").order("isTop desc,isUpdated desc,lastVisit desc,lastUpdateTime desc" ).find(Novel.class);
|
||||
return LitePal.where("isOnShelf=?","1").order("isTop desc,lastUpdateTime desc" ).find(Novel.class);
|
||||
String order = "isTop desc,lastUpdateTime desc";
|
||||
switch (Constants.SHELF_ORDER){
|
||||
case 1://更新时间
|
||||
order = "isTop desc,lastUpdateTime desc";
|
||||
break;
|
||||
case 2: //最近阅读
|
||||
order = "isTop desc,lastVisit desc";
|
||||
break;
|
||||
case 3: //有更新 + 最近阅读 + 更新时间
|
||||
order = " isTop desc,isUpdated desc";
|
||||
break;
|
||||
case 4: //有更新 + 最近阅读 + 更新时间
|
||||
order = " isTop desc,isUpdated desc,lastVisit desc,lastUpdateTime desc";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return LitePal.where("isOnShelf=?","1").order(order ).find(Novel.class);
|
||||
|
||||
|
||||
}
|
||||
|
@ -347,21 +364,21 @@ public void testUpdate(){
|
|||
) );
|
||||
|
||||
|
||||
boolean isLastReadchaptUpdated = TextUtils.isEmpty(nv.lastReadChaptName) || !(chapterName.equals(nv.lastReadChaptName)); //没看过最新章节
|
||||
boolean isLastChaptUpdated = !TextUtils.isEmpty(chapterName) && !TextUtils.isEmpty(nv.chapterName) && !(chapterName.equals(nv.chapterName));
|
||||
Log.d("Novel", String.format( " server lastUpdateTime ,server chaptername %s,chaptername %s,lastreadchapt %s" , chapterName,nv.chapterName,nv.lastReadChaptName ) );
|
||||
boolean isLastChaptNotRead = TextUtils.isEmpty(nv.lastReadChaptName) || !( !TextUtils.isEmpty(chapterName) && (chapterName.trim()).equals(nv.lastReadChaptName.trim())); //没看过最新章节
|
||||
boolean isLastChaptUpdated = !TextUtils.isEmpty(chapterName) && !TextUtils.isEmpty(nv.chapterName) && !(chapterName.trim().equals(nv.chapterName.trim()));
|
||||
Log.d("Novel", String.format( " server lastUpdateTime ,server chaptername '%s',chaptername %s,lastreadchapt '%s'" , chapterName,nv.chapterName,nv.lastReadChaptName ) );
|
||||
/*
|
||||
isUpdated = isUpdated && isLastReadchaptUpdated || isLastChaptUpdated ;
|
||||
|
||||
boolean isLastChaptUpdated = !TextUtils.isEmpty(chapterName) && !TextUtils.isEmpty(nv.chapterName) && !(chapterName.equals(nv.chapterName));
|
||||
*/
|
||||
Log.d("Novel", String.format( " isupdated %s, server lastUpdateTime isLastReadchaptUpdated %s,isLastChaptUpdated %s" ,isUpdated,isLastReadchaptUpdated,isLastChaptUpdated ) );
|
||||
Log.d("Novel", String.format( " is updated %s, server lastUpdateTime isLastChaptNotRead %s,isLastChaptUpdated %s" ,isUpdated,isLastChaptNotRead,isLastChaptUpdated ) );
|
||||
|
||||
Log.d("Novel", String.format( " server lastUpdateTime ,server chaptername %s,chaptername %s,lastreadchapt %s" , chapterName,nv.chapterName,nv.lastReadChaptName ) );
|
||||
// Log.d("Novel", String.format( " server lastUpdateTime ,server chaptername '%s',chaptername '%s',lastreadchapt '%s'" , chapterName,nv.chapterName,nv.lastReadChaptName ) );
|
||||
|
||||
isUpdated = isUpdated && isLastChaptUpdated || lastUpdateTime > nv.lastVisit;
|
||||
|
||||
isUpdated = isUpdated && isLastReadchaptUpdated;
|
||||
isUpdated = isUpdated && isLastChaptNotRead;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ public class HttpMethods {
|
|||
public String TAG = "HttpMethods";
|
||||
public static final String CACHE_NAME = "ZHUIKE";
|
||||
//public static String BASE_URL = getBaseUrl();
|
||||
private static final int DEFAULT_CONNECT_TIMEOUT = 5;
|
||||
private static final int DEFAULT_WRITE_TIMEOUT = 5;
|
||||
private static final int DEFAULT_READ_TIMEOUT = 5;
|
||||
private static final int DEFAULT_CONNECT_TIMEOUT = 10;
|
||||
private static final int DEFAULT_WRITE_TIMEOUT = 10;
|
||||
private static final int DEFAULT_READ_TIMEOUT = 10;
|
||||
public static String USERAGENT="";
|
||||
public static String LOCALUSERAGENT="";
|
||||
private Retrofit retrofit;
|
||||
|
@ -62,7 +62,7 @@ public class HttpMethods {
|
|||
/**
|
||||
* 请求失败重连次数
|
||||
*/
|
||||
private int RETRY_COUNT = 0;
|
||||
private int RETRY_COUNT = 3;
|
||||
private OkHttpClient.Builder okHttpBuilder;
|
||||
private OkHttpClient okHttpClient;
|
||||
//构造方法私有
|
||||
|
@ -222,7 +222,7 @@ public class HttpMethods {
|
|||
|
||||
|
||||
});
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||
//设置 Debug Log 模式
|
||||
okHttpBuilder.addInterceptor(loggingInterceptor);
|
||||
// okHttpBuilder.addInterceptor(new RetryInterceptor());
|
||||
|
|
|
@ -1030,7 +1030,7 @@ int muluRetryCount =0;
|
|||
}
|
||||
void buildChapters( String content ,String url){
|
||||
|
||||
Log.d(TAG, "buildChapters: " +content);
|
||||
// Log.d(TAG, "buildChapters: " +content);
|
||||
if(mSite==null ||mSiteRule ==null){
|
||||
Log.d(TAG,String.format("prepare book buildChapters failed---- %s ,mSite is null? %s ,mSiteRule ==null ? %s", mNovel.getName() ,mSite==null,mSiteRule ==null ));
|
||||
return;
|
||||
|
@ -1658,9 +1658,9 @@ int muluRetryCount =0;
|
|||
slepttime += 50;
|
||||
Log.d(TAG, String.format(" prepare book loadChaptContent slept %s for downloading,isDownload %s ,thread %s ", slepttime, getDownloadStatus(), Thread.currentThread().getName()));
|
||||
}*/
|
||||
while (!file.exists() && NetUtil.isNetworkConnected() && chaptDownStatus.get(Integer.valueOf(index)) == DownloadStatus.downloading && slepttime < maxSleep) {
|
||||
Thread.sleep(50);
|
||||
slepttime += 50;
|
||||
while (!file.exists() && NetUtil.isNetworkConnected() && chaptDownStatus.get(Integer.valueOf(index)) == DownloadStatus.downloading && slepttime < maxSleep ) {
|
||||
Thread.sleep(500);
|
||||
slepttime += 500;
|
||||
Log.d(TAG, String.format(" prepare book loadChaptContent %s , slept %s for downloading, thread %s ",index, slepttime, Thread.currentThread().getName()));
|
||||
}
|
||||
Log.d(TAG, String.format("prepare book loadChaptContent slept %s for downloading ", slepttime));
|
||||
|
@ -1833,32 +1833,12 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
|
|||
|
||||
Request request = getTagRequest(url, refUrl,-1);
|
||||
|
||||
|
||||
|
||||
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(MSG_FILLCONTENTDONE);
|
||||
// handler.sendEmptyMessage(1);
|
||||
|
||||
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
// setDownloadFlag(true);
|
||||
Log.d( TAG,String.format("prepare book loadChaptContent %s fail, isDownloadChapt: %s",index,false));
|
||||
// e.printStackTrace();
|
||||
// throw new RuntimeException("Error during writing " + fileChapterName( index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response){
|
||||
|
||||
/*try {
|
||||
Response response = HttpMethods.getOkClient().newCall(request).execute();
|
||||
Log.d( TAG,String.format("prepare book loadChaptContent get response, thread %s", Thread.currentThread().getName()));
|
||||
ResponseBody body = response.body();
|
||||
if (body != null ) {
|
||||
|
||||
if(response.code()!=200){
|
||||
Log.d(TAG, "prepare book loadChaptContent----network failure returnCode " + response.code());
|
||||
// setDownloadFlag(true);
|
||||
|
@ -1873,10 +1853,10 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
|
|||
if(mSiteRule==null){
|
||||
return;
|
||||
}
|
||||
/* Charset charset = body.contentType().charset();
|
||||
*//* Charset charset = body.contentType().charset();
|
||||
if(charset!=null){
|
||||
String name = charset.displayName();
|
||||
}*/
|
||||
}*//*
|
||||
// String bodyStr = body.string();
|
||||
// bodyStr =NovelParseUtil.enconding(bodyStr,mSiteRule.getEncoding());
|
||||
|
||||
|
@ -1885,7 +1865,125 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
|
|||
|
||||
String bodyStr =NovelParseUtil.enconding(body,mSiteRule.getEncoding());
|
||||
if(TextUtils.isEmpty(bodyStr)){
|
||||
Log.d( TAG,String.format("prepare book loadChaptContent %s isEmpty,retry....", index, Thread.currentThread().getName()));
|
||||
Log.e( TAG,String.format("prepare book loadChaptContent %s isEmpty,retry....", index, Thread.currentThread().getName()));
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
return;
|
||||
}
|
||||
// Log.d( TAG,String.format("prepare book encoded content %s", bodyStr ));
|
||||
bodyStr = NovelParseUtil.getChapterContent(bodyStr, siteJson);
|
||||
*//* if(BuildConfig.LOG_DEBUG) {
|
||||
reportMsg(Constants.REPORT_REX_CHAPTER_CONTENT_ERROR, url,"",getRequestHeader(request),200+"");//TODO: remove
|
||||
}*//*
|
||||
if(TextUtils.isEmpty(bodyStr) || bodyStr.trim().length()<10 ){
|
||||
Log.e( TAG,String.format("prepare book loadChaptContent %s isEmpty,reporting empty ....", index ));
|
||||
|
||||
reportMsg(Constants.REPORT_REX_CHAPTER_CONTENT_ERROR, url,bodyStr,getRequestHeader(request),200+"");
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
// bodyStr += Constants.BAD_CHAR +Constants.BAD_CHAR +"内容正在搜索中,请稍后刷新内容";
|
||||
return;
|
||||
}
|
||||
|
||||
String title = chapter.getChapterName();
|
||||
String chapterContent = title+ "\n" + bodyStr;
|
||||
char[] buf = chapterContent.toCharArray();
|
||||
File file = new File(fileChapterName(index));
|
||||
file.createNewFile();
|
||||
|
||||
final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileChapterName(index)), charachterType);//"UTF-16LE"); // UTF-16LE 比 utf-8 文件小
|
||||
// final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileChapterName(index)), mSiteRule.getEncoding() );//charachterType);//"UTF-16LE"); // UTF-16LE 比 utf-8 文件小
|
||||
writer.write(buf);
|
||||
writer.close();
|
||||
Log.d( TAG,String.format("prepare book loadChaptContent file created: %s, thread %s", file.getPath(), Thread.currentThread().getName()));
|
||||
handler.sendEmptyMessage(MSG_FILLCONTENTDONE);
|
||||
// setDownloadFlag(true);
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "onResponse: prepare book error ",e );
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
return;
|
||||
// throw new RuntimeException("Error during writing " + fileChapterName( index));
|
||||
}
|
||||
finally {
|
||||
body.close();
|
||||
|
||||
handler.sendEmptyMessage(MSG_FILLCONTENTDONE);
|
||||
// setDownloadFlag(true);
|
||||
}
|
||||
chapter.setNovelId(mNovel.getId());
|
||||
chapter.setChapterPath(fileChapterName(index));
|
||||
chapter.setDomain(mSite.getDomain());
|
||||
if(chapter.getId()>0) {
|
||||
chapter.update(chapter.getId());
|
||||
}else{
|
||||
chapter.save();
|
||||
}
|
||||
//setDownloadFlag(true);
|
||||
chaptDownStatus.put(index,DownloadStatus.success);
|
||||
Log.d(TAG,String.format(" prepare book loadChaptContent---- finished download %s, cost time %s ,content path %s ,thread %s", chapter.getChapterName(), new Date().getTime() -startTime ,chapter.getChapterPath() , Thread.currentThread().getName() ));
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
Log.e(TAG, "onResponse: prepare book error ",e );
|
||||
}*/
|
||||
|
||||
HttpMethods.getOkClient().newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
if(e!=null &&
|
||||
(e.toString().contains("closed")
|
||||
||e.getMessage().contains("Canceled")))
|
||||
{
|
||||
Log.d(TAG, "onFailure: prepare book cancled request ,return, " + request.url());
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// handler.sendEmptyMessage(MSG_FILLCONTENTDONE);
|
||||
// handler.sendEmptyMessage(1);
|
||||
|
||||
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
// setDownloadFlag(true);
|
||||
Log.e( TAG,String.format("prepare book loadChaptContent %s fail, isDownloadChapt: %s",index,false),e);
|
||||
// e.printStackTrace();
|
||||
// throw new RuntimeException("Error during writing " + fileChapterName( index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response){
|
||||
Log.d( TAG,String.format("prepare book loadChaptContent get response, thread %s", Thread.currentThread().getName()));
|
||||
ResponseBody body = response.body();
|
||||
if (body != null ) {
|
||||
|
||||
if(response.code()!=200){
|
||||
Log.d(TAG, "prepare book loadChaptContent----network failure returnCode " + response.code());
|
||||
// setDownloadFlag(true);
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
Log.d( TAG,String.format("prepare book loadChaptContent error %s ,isDownloadChapt: %s", response.code(),false));
|
||||
handler.sendEmptyMessage(1);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if(mSiteRule==null){
|
||||
return;
|
||||
}
|
||||
Charset charset = body.contentType().charset();
|
||||
if(charset!=null){
|
||||
String name = charset.displayName();
|
||||
}
|
||||
// String bodyStr = body.string();
|
||||
// bodyStr =NovelParseUtil.enconding(bodyStr,mSiteRule.getEncoding());
|
||||
|
||||
// Log.d( TAG,String.format("prepare book content %s", body ));
|
||||
|
||||
|
||||
String bodyStr =NovelParseUtil.enconding(body,mSiteRule.getEncoding());
|
||||
if(TextUtils.isEmpty(bodyStr)){
|
||||
Log.e( TAG,String.format("prepare book loadChaptContent %s isEmpty,retry....", index, Thread.currentThread().getName()));
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
return;
|
||||
}
|
||||
|
@ -1895,9 +1993,10 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
|
|||
reportMsg(Constants.REPORT_REX_CHAPTER_CONTENT_ERROR, url,"",getRequestHeader(request),200+"");//TODO: remove
|
||||
}*/
|
||||
if(TextUtils.isEmpty(bodyStr) || bodyStr.trim().length()<10 ){
|
||||
Log.d( TAG,String.format("prepare book loadChaptContent %s isEmpty,reporting empty ....", index ));
|
||||
Log.e( TAG,String.format("prepare book loadChaptContent %s isEmpty,reporting empty ....", index ));
|
||||
|
||||
reportMsg(Constants.REPORT_REX_CHAPTER_CONTENT_ERROR, url,bodyStr,getRequestHeader(request),200+"");
|
||||
chaptDownStatus.put(index,DownloadStatus.failure);
|
||||
// bodyStr += Constants.BAD_CHAR +Constants.BAD_CHAR +"内容正在搜索中,请稍后刷新内容";
|
||||
return;
|
||||
}
|
||||
|
@ -1947,6 +2046,8 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* @param url
|
||||
|
|
|
@ -47,6 +47,12 @@ public class Config {
|
|||
|
||||
private final static String AD_KEY = "adkey";
|
||||
|
||||
//sexoption
|
||||
private final static String SEX_OPTION_KEY="sexoption";
|
||||
private int sexOption =1;
|
||||
|
||||
private final static String SHELF_ORDER_OPTION_KEY="shelforderoption";
|
||||
private int shelfOrderOption =1;
|
||||
|
||||
private Context mContext;
|
||||
private static Config config;
|
||||
|
@ -70,9 +76,7 @@ public class Config {
|
|||
sp.edit().putInt(SEX_OPTION_KEY,sexOption).commit();
|
||||
}
|
||||
|
||||
//sexoption
|
||||
public final static String SEX_OPTION_KEY="sexoption";
|
||||
private int sexOption =1;
|
||||
|
||||
|
||||
private Config(Context mContext){
|
||||
this.mContext = mContext.getApplicationContext();
|
||||
|
@ -302,6 +306,12 @@ public Boolean isShowAd(){
|
|||
}
|
||||
|
||||
|
||||
public int getShelfOrderOption() {
|
||||
return sp.getInt(SHELF_ORDER_OPTION_KEY,shelfOrderOption );
|
||||
}
|
||||
|
||||
public void setShelfOrderOption(int option) {
|
||||
sp.edit().putInt(SHELF_ORDER_OPTION_KEY,option).commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public class Constants {
|
|||
public static final int MAXAGE_MAX =60*60*24*28; //28 天 ;
|
||||
public static final int MAXAGE_MULU = 60*60*24*7*2; //2周;;
|
||||
public static final String VERSION_ADDRESS ="version.xml";
|
||||
public static int SHELF_ORDER =0 ;
|
||||
|
||||
public static AdSetting AD_SETTING;
|
||||
public static final int AD_TENCENT_QQ =1;
|
||||
|
@ -73,7 +74,7 @@ public class Constants {
|
|||
public static final String BAD_CHAR =" ";//not blank,don't edit
|
||||
|
||||
public final static int MAX_PAGE_CNT =10;//最多加载的页数
|
||||
public final static int MAX_SLEEP_4_CHAPT_DOWNLOAD =10000;//最多等待时间10s
|
||||
public final static int MAX_SLEEP_4_CHAPT_DOWNLOAD =15000;//最多等待时间10s
|
||||
public final static int MAX_SHELF_CNT =100;
|
||||
|
||||
public static final String REPORT_NEW_UPDATE ="HasNewUpdate"; //其它源有新章节
|
||||
|
|
|
@ -391,7 +391,7 @@ public class PageFactory implements ChangeSource{
|
|||
" mBookUtil.muluRetryCount %s,thread.name %s",chid,slepttime , getChapters().size(),mBookUtil.muluRetryCount,Thread.currentThread().getName() ) );
|
||||
slepttime=0;
|
||||
while( !file.exists() && slepttime <maxSleep && ( !mBookUtil.fileRetryCnt.containsKey(chid) || mBookUtil.fileRetryCnt.get(chid)< Constants.retryCnt)
|
||||
||showingStatusAd &&(new Date().getTime() - showStatusAdTime <2200) ){
|
||||
/*||showingStatusAd &&(new Date().getTime() - showStatusAdTime <2200)*/ ){
|
||||
try {
|
||||
sleep(50);
|
||||
slepttime+=50;
|
||||
|
|
|
@ -107,6 +107,49 @@
|
|||
</LinearLayout>
|
||||
|
||||
<View style="@style/llGraySplit.2dp.gray" />
|
||||
<LinearLayout
|
||||
style="@style/llSetup"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView
|
||||
style="@style/NovelBlockTitle"
|
||||
android:layout_width ="wrap_content"
|
||||
android:text="@string/title_shelforder"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<RadioGroup
|
||||
android:id="@+id/rgShelfOrder"
|
||||
android:layout_weight="1"
|
||||
style="@style/radioGroup"
|
||||
android:layout_width ="wrap_content"
|
||||
android:orientation ="vertical"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center_horizontal"
|
||||
>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton1"
|
||||
android:text="按更新时间"
|
||||
style="@style/radioButtonNormal"
|
||||
|
||||
android:checked="true"
|
||||
/>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton2"
|
||||
android:text="按最近阅读"
|
||||
style="@style/radioButtonNormal"
|
||||
|
||||
/>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton3"
|
||||
android:text="按有更新+最近阅读+更新时间"
|
||||
style="@style/radioButtonNormal"
|
||||
|
||||
/>
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -50,12 +50,63 @@
|
|||
|
||||
/>
|
||||
-->
|
||||
<LinearLayout
|
||||
style="@style/llSetup"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/_10dp"
|
||||
>
|
||||
<TextView
|
||||
style="@style/buttonCates"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:text="@string/title_shelforder"
|
||||
|
||||
/>
|
||||
<RadioGroup
|
||||
android:id="@+id/rgShelfOrder"
|
||||
android:layout_weight="1"
|
||||
style="@style/radioGroup"
|
||||
android:layout_width ="wrap_content"
|
||||
android:orientation ="vertical"
|
||||
android:layout_gravity="right"
|
||||
android:gravity="center_horizontal"
|
||||
>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton1"
|
||||
android:text="按更新时间"
|
||||
style="@style/radioButtonNormal"
|
||||
|
||||
android:checked="true"
|
||||
/>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton2"
|
||||
android:text="按最近阅读"
|
||||
style="@style/radioButtonNormal"
|
||||
|
||||
/>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton3"
|
||||
android:text="按有更新"
|
||||
style="@style/radioButtonNormal"
|
||||
|
||||
/>
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton4"
|
||||
android:text="按有更新+最近阅读+更新时间"
|
||||
style="@style/radioButtonNormal"
|
||||
|
||||
/>
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout style="@style/llGraySplit.2dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCancel"
|
||||
style="@style/buttonCates"
|
||||
android:text="取消"
|
||||
android:textColor="@color/colorAccent"
|
||||
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -164,4 +164,5 @@
|
|||
<string name="cancel">取消</string>
|
||||
<string name="message_permission_always_failed">Please give us permission in the settings:\n\n%1$s</string>
|
||||
<string name="message_setting_comeback">The user comes back from the settings page.</string>
|
||||
<string name="title_shelforder">书架排序</string>
|
||||
</resources>
|
||||
|
|
|
@ -459,5 +459,11 @@
|
|||
<item name="android:visibility">visible</item>
|
||||
</style>
|
||||
|
||||
<style name="radioButtonNormal">
|
||||
<item name="android:orientation">horizontal</item>
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue