This commit is contained in:
mwang 2019-04-18 23:34:19 +08:00
parent 02df9f1114
commit 181bba2a4b
11 changed files with 133 additions and 23 deletions

View File

@ -145,10 +145,10 @@ public abstract class BasicFragment extends Fragment {
{
Toast.makeText(getActivity(), "数据请求失败 ", Toast.LENGTH_LONG).show();
// Toast.makeText(getActivity(), "数据请求失败 ", Toast.LENGTH_LONG).show();
} else if (msg.what == 3) {
Toast.makeText(getActivity(), " ", Toast.LENGTH_LONG).show();
// Toast.makeText(getActivity(), " ", Toast.LENGTH_LONG).show();
}
hideProgress();
@ -237,12 +237,19 @@ public abstract class BasicFragment extends Fragment {
}
void showProgressDialog(boolean flag,String msg){
if(mSwipeRefresh!=null && !mSwipeRefresh.isRefreshing()) {
if(getActivity()==null){
return;
}
if(mSwipeRefresh ==null || !mSwipeRefresh.isRefreshing()) {
((Activity_base) getActivity()).showProgressDialog(flag,msg);
}
}
void hideProgress(){
if(getActivity()==null){
return;
}
if(mSwipeRefresh!=null && mSwipeRefresh.isRefreshing()) {
mSwipeRefresh.setRefreshing(false);
}

View File

@ -63,24 +63,26 @@ public class CatalogFragment extends BasicFragment {
@Override
protected void initData() {
showProgressDialog(true,"请稍等");
showProgressDialog(false,"请稍等");
pageFactory = PageFactory.getInstance();
Log.d(TAG, String .format("prepareBook: start to open book cate of %s" , pageFactory.getNovle().getName()));
new Thread() {
new Thread() {
@Override
public void run() {
int slepttime = 0;
while (slepttime < 100 && pageFactory.isReadingCatalogs() && pageFactory.getChapters().size() == 0) {
while (slepttime < 1000 && ( pageFactory.isReadingCatalogs() || pageFactory.getChapters().size() == 0)) {
try {
Log.d(TAG, String .format("prepareBook: to open book cate to sleep %s" , 50));
sleep(50);
slepttime++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Log.d(TAG, String .format("prepareBook:to open book cate slept %s" , slepttime*50));
if ( !pageFactory.isReadingCatalogs() && pageFactory.getChapters().size() == 0) {
handler.sendEmptyMessage(2);
@ -112,10 +114,44 @@ public class CatalogFragment extends BasicFragment {
ReadActivity.openBook(novel,getActivity());
}
}else
pageFactory.changeChapter(position+1);
hideProgress();
}else {
pageFactory.changeChapter(position+1);
new Thread() {
@Override
public void run() {
super.run();
int slepttime =0;
int chapid = position+1;
while( pageFactory.getChapters().size() ==0 || pageFactory.getChapters().get(chapid-1).getId() ==0 ){
try {
sleep(50);
slepttime+=1;
if(pageFactory.getChapters().size()>0){
Log.d(TAG, String .format("prepare Book: slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
}else{
Log.d(TAG, String .format("prepare Book: slept %s for loading pageFactory.getChapters().size() %s " , slepttime*50, pageFactory.getChapters().size()));
}
} catch (InterruptedException e) {
e.printStackTrace();
}
if(slepttime>100)
{
break;
}
}
Log.d(TAG, String .format("prepare Book: total slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
handler.sendEmptyMessage(2);
}
}.start();
}
getActivity().finish();
}
});
}

View File

@ -153,7 +153,7 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
showProgressDialog(true, "正在加载");
BookSubscribe.getFirstPage(Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
BookSubscribe.getFirstPage(Constants.SEX,new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
@Override
public void onSuccess(String result) {

View File

@ -47,6 +47,7 @@ import com.novelbook.android.view.PageWidget;
import org.litepal.LitePal;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
@ -220,10 +221,46 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
try {
hideSystemUI();
pageFactory.openBook(book,this);
pageFactory.openBook(book, this);
showProgressDialog(true, "正在加载");
new Thread() {
@Override
public void run() {
super.run();
int slepttime =0;
int chapid = book.getLastReadChapt();
while( pageFactory.getChapters().size() ==0 || pageFactory.getChapters().get(chapid-1).getId() ==0 ){
try {
sleep(50);
slepttime+=1;
if(pageFactory.getChapters().size()>0){
Log.d(TAG, String .format("prepare Book: slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
}else{
Log.d(TAG, String .format("prepare Book: slept %s for loading pageFactory.getChapters().size() %s " , slepttime*50, pageFactory.getChapters().size()));
}
} catch (InterruptedException e) {
e.printStackTrace();
}
if(slepttime>200)
{
break;
}
}
// Log.d(TAG, String .format("prepare Book: total slept %s for loading chapter content %s,chapter.getid %s " , slepttime*50, chapid,pageFactory.getChapters().get(chapid-1).getId()));
mHandler.sendEmptyMessage(1);
}
}.start();
hideSystemUI();
} catch (IOException e) {
}catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "打开电子书失败", Toast.LENGTH_SHORT).show();
}
@ -387,12 +424,13 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
/*switch (msg.what) {
case MESSAGE_CHANGEPROGRESS:
float progress = (float) msg.obj;
setSeekBarProgress(progress);
break;
}
}*/
hideProgress();
}
};
@ -612,16 +650,18 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
private void showSystemUI() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);

View File

@ -53,7 +53,7 @@ public interface HttpApi {
@GET("page/index")
Observable<ResponseBody> getFirstPage(@Query("sex") int Sex);
//分类的总榜显示每个小说分类有多少本书
//分类的总榜显示每个小说分类有多少本书http://xiaoshuofenxiang.com/api/page/noveltype
@GET("page/noveltype")
Observable<ResponseBody> getCates(@Query("sex") int sex);

View File

@ -245,7 +245,7 @@ public class HttpMethods {
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
String cacheControl = originalResponse.header("Cache-Control");
int maxAge =0;//60*60; //一小时
int maxAge =60*60; //一小时
if (cacheControl == null || cacheControl.contains("no-store") || cacheControl.contains("no-cache") ||
cacheControl.contains("must-revalidate") || cacheControl.contains("max-age=0")) { //目标网站禁用cache则设置为1小时
return originalResponse.newBuilder()

View File

@ -535,6 +535,10 @@ public class BookUtil {
handler.sendEmptyMessage(3);
//TODO 如果是取消了访问则返回
if(e.getMessage().contains("Canceled")){
return;
}
if( mNovelSites.getSites().length ==1){ //仅有一个rule,且失败了
mMuluStatus = MuluStatus.failed;
return;
@ -952,7 +956,7 @@ public class BookUtil {
protected String fileName(int index) {
return cachedPath + mNovel.getName() + index ;
}
protected String fileChapterName(int chaptId ) {
public String fileChapterName(int chaptId ) {
if(!TextUtils.isEmpty(mNovel.getDomain())){
return getChapterPath() +mNovel.getDomain()+"/"+ chaptId ;

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 实心 -->
<solid android:color="@color/colorPrimary"/>
<!-- 渐变 -->
<!--<gradient-->
<!--android:startColor="#ff8c00"-->
<!--android:endColor="#FFFFFF"-->
<!--android:angle="270" />-->
<!-- 描边 -->
<stroke
android:width="1dp"
android:color="@color/white" />
<!-- 圆角 -->
<corners
android:radius="6dp" />
<padding
android:left="15dp"
android:top="5dp"
android:right="15dp"
android:bottom="5dp" />
</shape>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 实心 -->
<solid android:color="@color/colorPrimaryDark"/>
<solid android:color="@color/read_dialog_bg"/>
<!-- 渐变 -->
<!--<gradient-->
<!--android:startColor="#ff8c00"-->

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_select_bg" android:state_checked="true"></item>
<item android:drawable="@drawable/button_chk_bg" android:state_checked="true"></item>
<item android:drawable="@drawable/button_bg" android:state_checked="false"></item>
</selector>

View File

@ -256,8 +256,8 @@
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:gravity">center</item>
<item name="android:background">@drawable/button_bg</item>
<item name="android:textColor">@color/white</item>
<item name="android:background">@drawable/rb_nobtn_selector</item>
<item name="android:textColor">@color/darkcyan</item>
<item name="android:textSize">16sp</item>
</style>
<style name="text_style">