diff --git a/zhuike/build.gradle b/zhuike/build.gradle index 8c33394..b3a754d 100644 --- a/zhuike/build.gradle +++ b/zhuike/build.gradle @@ -31,15 +31,15 @@ android { multiDexEnabled true //突破65535 manifestPlaceholders = [UMENG_CHANNEL_CALUE: "umeng"] //默认为uMeng - flavorDimensions "default" //debug时注销 + // flavorDimensions "default" //debug时注销 } buildTypes { debug { // 显示Log buildConfigField "boolean", "LOG_DEBUG", "true" buildConfigField "String", "MAIN_HOST", '"http://xiaoshuofenxiang.com/api/"' - buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' - // buildConfigField "String", "API_HOST", '""' + buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' + // buildConfigField "String", "API_HOST", '""' versionNameSuffix "-debug" minifyEnabled false zipAlignEnabled false @@ -56,7 +56,7 @@ android { // 移除无用的resource文件 shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - applicationVariants.all { variant -> +/* applicationVariants.all { variant -> variant.outputs.all { output -> def outFile = output.outputFile if (outFile != null && outFile.name.endsWith(".apk")) { @@ -66,12 +66,12 @@ android { } } - } + }*/ signingConfig signingConfigs.releaseConfig } } //渠道 - productFlavors { + /*productFlavors { // googleplay {} qxs { applicationId "com.novelbook.android.qxs" @@ -107,7 +107,7 @@ android { flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } - } + }*/ android { lintOptions { abortOnError false @@ -124,6 +124,7 @@ android { } } + def releaseTime() { return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC")) } diff --git a/zhuike/src/main/AndroidManifest.xml b/zhuike/src/main/AndroidManifest.xml index 1c1bf3e..94c9376 100644 --- a/zhuike/src/main/AndroidManifest.xml +++ b/zhuike/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ - + + + android:theme="@style/ToolBarTheme.NoActionBar" /> + android:theme="@style/ToolBarTheme.NoActionBar" /> + android:theme="@style/ToolBarTheme.NoActionBar" /> + android:theme="@style/ToolBarTheme.NoActionBar" /> + android:theme="@style/ToolBarTheme.NoActionBar" /> + android:theme="@style/ToolBarTheme.NoActionBar" /> - + android:theme="@style/ToolBarTheme.NoActionBar" /> + @@ -94,16 +97,14 @@ android:grantUriPermissions="true"> - - - - - - - + android:resource="@xml/provider_paths" /> + + + - \ No newline at end of file diff --git a/zhuike/src/main/java/com/novelbook/android/ActivitySetup.java b/zhuike/src/main/java/com/novelbook/android/ActivitySetup.java new file mode 100644 index 0000000..9de6363 --- /dev/null +++ b/zhuike/src/main/java/com/novelbook/android/ActivitySetup.java @@ -0,0 +1,158 @@ +package com.novelbook.android; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +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.Constants; +import com.novelbook.android.utils.FileUtils; +import com.novelbook.android.utils.Fileutil; + +import org.litepal.LitePal; + +import butterknife.BindView; +import butterknife.OnClick; + +import static com.novelbook.android.utils.Constants.lstNt; + +public class ActivitySetup extends Activity_base { +static final String TAG = ActivitySetup.class.getSimpleName(); +@BindView(R.id.tvCache) + TextView tvCache; + @BindView(R.id.tvVersion) + TextView tvVersion; + + + + + @Override + public int getLayoutRes() { + return R.layout.activity_setup; + } + + @Override + protected void initViews() { + tvVersion.setText(CommonUtil.getVersion(this)); + tvCache.setText(FileUtils.getCachedSize()); + } + + + @Override + protected void setTitle() { + + } + + @Override + protected void initData() { + + } + + @Override + public void fillData() { + + + + + + } + + @OnClick({R.id.llAnouncement,R.id.llCache,R.id.llVersion}) + void onSetupclick(View view){ + + switch (view.getId()) { + case R.id.llAnouncement: + + break; + case R.id.llCache: + final AlertDialog.Builder normalDialog = + new AlertDialog.Builder(ActivitySetup.this); + + normalDialog.setTitle("提示"); + normalDialog.setMessage("是否清除所有缓存内容及下载任务?"); + normalDialog.setPositiveButton("确定", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(ActivitySetup.this, ServiceDownload.class); + stopService(intent); + FileUtils.clearCache(); + LitePal.deleteAll(DownloadTask.class); + tvCache.setText(FileUtils.getCachedSize()); + + } + }); + normalDialog.setNegativeButton("取消", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) + { + + } + }); + + normalDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + + } + }); + // 显示 + normalDialog.show(); + + break; + case R.id.llVersion: + Constants.serverVersion =-1; + + NetUtil.checkUpdate(false); + showProgressDialog(false,"正在检查版本..."); + new Thread(){ + @Override + public void run() { + Log.d(TAG, "prepare book to load options for search" ); + int slept =0; + while( slept <100 && Constants.serverVersion ==-1){ + try { + Thread.sleep(100); + slept++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + if( Constants.serverVersion <= Constants.version ){ + handler.sendEmptyMessage(MSG_VERSION_LATEST); + }else if(Constants.serverVersion==-1){ + handler.sendEmptyMessage(MSG_VERSION_LATEST); + } + + + } + }.start(); + + + + + + + + break; + } + + + + + + + } + +} diff --git a/zhuike/src/main/java/com/novelbook/android/Activity_base.java b/zhuike/src/main/java/com/novelbook/android/Activity_base.java index fad8ed6..74ead72 100644 --- a/zhuike/src/main/java/com/novelbook/android/Activity_base.java +++ b/zhuike/src/main/java/com/novelbook/android/Activity_base.java @@ -166,7 +166,8 @@ public abstract class Activity_base extends AppCompatActivity { } public abstract void fillData(); - + protected static final int MSG_VERSION_LATEST =4; + protected static final int MSG_VERSION_FAILE =5; Handler handler = new Handler() { @Override public void handleMessage(Message msg) { @@ -183,6 +184,12 @@ public abstract class Activity_base extends AppCompatActivity { } else if (msg.what == 3) { Toast.makeText(Activity_base.this, " ", Toast.LENGTH_LONG).show(); + } else if (msg.what == MSG_VERSION_LATEST) { + + Toast.makeText(Activity_base.this, "已是最新版本", Toast.LENGTH_LONG).show(); + }else if (msg.what == MSG_VERSION_FAILE) { + + Toast.makeText(Activity_base.this, "版本检查失败", Toast.LENGTH_LONG).show(); } hideProgress(); diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java b/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java index c9a409e..2448dfc 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/BasicFragment.java @@ -251,6 +251,7 @@ void initTabs(){ //失败 Toast.makeText(getActivity(),"Novel 请求失败:"+errorMsg,Toast.LENGTH_SHORT).show(); // PageFactory.getInstance(activity ).prepareBook(novel ); //打开本地小说内容 + pageFactory.prepareBook(novel ); // ReadActivity.openBook(novel ,activity); handler.sendEmptyMessage(99); } diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java b/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java index c7c2749..944ddc4 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java @@ -54,17 +54,24 @@ public class BookMarkFragment extends BasicFragment implements MarkActivity.Sor novelId = bundle.getInt(ARGUMENT); } bookMarksList = new ArrayList<>(); - String domain =pageFactory.getSite().getDomain(); - if(TextUtils.isEmpty(domain)){ - Novel nv = LitePal.find(Novel.class,novelId); - if(nv!=null) { - domain = nv.getDomain(); - } - } - if(null!=domain || !TextUtils.isEmpty(domain)){ - bookMarksList = LitePal.where("novelId = ? and domain= ?", novelId+"",domain).order(String.format("id %s",isAsc ?"asc" :"desc")). find(BookMarks.class); + + if(pageFactory.getNovle().isLocalBook()){ + bookMarksList = LitePal.where("novelId =?", novelId + "").order(String.format("id %s", isAsc ? "asc" : "desc")).find(BookMarks.class); + }else { + + String domain = pageFactory.getSite().getDomain(); + if (TextUtils.isEmpty(domain)) { + Novel nv = LitePal.find(Novel.class, novelId); + if (nv != null) { + domain = nv.getDomain(); + } + } + if (null != domain || !TextUtils.isEmpty(domain)) { + bookMarksList = LitePal.where("novelId = ? and domain= ?", novelId + "", domain).order(String.format("id %s", isAsc ? "asc" : "desc")).find(BookMarks.class); + } } + Log.d(TAG, "initData: bookmark size " +bookMarksList.size()); markAdapter = new MarkAdapter(getActivity(), bookMarksList); lv_bookmark.setAdapter(markAdapter); diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java index cfe0c07..e0e9943 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/Fragment_Shelf.java @@ -26,6 +26,7 @@ import android.widget.Toast; import com.novelbook.android.Main2Activity; import com.novelbook.android.R; +import com.novelbook.android.db.Chapter; import com.novelbook.android.db.Novel; import com.novelbook.android.filechooser.FileChooserActivity; @@ -37,6 +38,7 @@ import com.novelbook.android.netutils.OnSuccessAndFaultSub; import com.novelbook.android.utils.CommonUtil; import com.novelbook.android.utils.Constants; import com.novelbook.android.utils.FileUtils; +import com.novelbook.android.utils.Fileutil; import com.novelbook.android.utils.GsonUtil; import com.novelbook.android.utils.ImageUtil; import com.novelbook.android.utils.MyImageLoader; @@ -208,13 +210,27 @@ void test(int maxAge){ mAdapter = new BookListAdapter(activity,bookLists,R.layout.recycle_list_item,new OnItemClickListener() { + private long lastTimeMillis; + private static final long MIN_CLICK_INTERVAL =1000; + + protected boolean isTimeEnabled() { + long currentTimeMillis = System.currentTimeMillis(); + if ((currentTimeMillis - lastTimeMillis) > MIN_CLICK_INTERVAL) { + lastTimeMillis = currentTimeMillis; + return true; + } + return false; + } @Override public void onItemClick(View view, int position) { - Novel book = bookLists.get(position); - - openBook(book,mAdapter); + if(isTimeEnabled()) { + Novel book = bookLists.get(position); + openBook(book, mAdapter); + }else{ + Log.d(TAG, "onclickInterval: bad click"); + } } @@ -296,7 +312,7 @@ void test(int maxAge){ initZhengliDialog(); } }); - Button btnImport = bottomSheetDialog.findViewById(R.id.btnImport); + Button btnImport = bottomSheetDialog.findViewById(R.id.btnImport); btnImport.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -327,26 +343,33 @@ void test(int maxAge){ private void initDialog(int position) { - bottomSheetDialog = new BottomSheetDialog(this.activity); + bottomSheetDialog = new BottomSheetDialog(this.activity); bottomSheetDialog.setContentView(R.layout.fragment_shelf_botoomsheetdialog); //给布局设置透明背景色 bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); - TextView tvTitle =(TextView) bottomSheetDialog.findViewById(R.id.bdTitle); - + TextView tvTitle = (TextView) bottomSheetDialog.findViewById(R.id.bdTitle); + TextView tvLatestChapt = (TextView) bottomSheetDialog.findViewById(R.id.txtLatestCate); + TextView tvAuthor = (TextView) bottomSheetDialog.findViewById(R.id.tvAuthor); tvTitle.setText(bookLists.get(position).getName()); - TextView tvAuthor =(TextView) bottomSheetDialog.findViewById(R.id.tvAuthor); - tvAuthor.setText(bookLists.get(position).getAuthor()); - TextView tvLatest =(TextView) bottomSheetDialog.findViewById(R.id.txtLatestUpdate); - TextView tvLatestChapt =(TextView) bottomSheetDialog.findViewById(R.id.txtLatestCate); - tvLatestChapt.setText(bookLists.get(position).getChapterName()); - tvLatest.setText(CommonUtil.getDateString( bookLists.get(position).getLastUpdateTime()) ); + if (!bookLists.get(position).isLocalBook()) { + + tvAuthor.setText(bookLists.get(position).getAuthor()); + TextView tvLatest = (TextView) bottomSheetDialog.findViewById(R.id.txtLatestUpdate); + + tvLatestChapt.setText(bookLists.get(position).getChapterName()); + tvLatest.setText(CommonUtil.getDateString( bookLists.get(position).getLastUpdateTime()) ); + }else{ + tvLatestChapt.setText("本地导入"); + tvAuthor.setText(""); + } ImageView imageView = (ImageView) bottomSheetDialog.findViewById(R.id.imageG1); ImageUtil.loadImage(activity,bookLists.get(position).getCover(),imageView); LinearLayout lldetail=(LinearLayout) bottomSheetDialog.findViewById(R.id.llBookdetail); + if(!bookLists.get(position).isLocalBook()) lldetail.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showBookDetail(bookLists.get(position)); @@ -355,16 +378,24 @@ void test(int maxAge){ TextView tvCache =(TextView) bottomSheetDialog.findViewById(R.id.tvCache); tvCache.setText(FileUtils.getCacheSizeK(bookLists.get(position).getId())); - LinearLayout llClearCache =(LinearLayout) bottomSheetDialog.findViewById(R.id.llClearCache); - llClearCache.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - FileUtils.clearChapterCache(bookLists.get(position).getId()); - long size = FileUtils.getCacheSize(bookLists.get(position).getId()); - size = size/1024; - tvCache.setText(String.format("%sK",size)); - Toast.makeText(activity,"缓存清除成功",Toast.LENGTH_SHORT); - } - }); + + if(!bookLists.get(position).isLocalBook()) { + LinearLayout llClearCache = (LinearLayout) bottomSheetDialog.findViewById(R.id.llClearCache); + + llClearCache.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + FileUtils.clearChapterCache(bookLists.get(position).getId()); + long size = FileUtils.getCacheSize(bookLists.get(position).getId()); + size = size / 1024; + tvCache.setText(String.format("%sK", size)); + Toast.makeText(activity, "缓存清除成功", Toast.LENGTH_SHORT); + + } + }); + }else{ + TextView tvClearCache = (TextView) bottomSheetDialog.findViewById(R.id.tvClearCache); + tvClearCache.setText("导入文本"); + } LinearLayout lltop =(LinearLayout) bottomSheetDialog.findViewById(R.id.llTop); TextView tvTop =(TextView) bottomSheetDialog.findViewById(R.id.tvTop); @@ -397,7 +428,7 @@ void test(int maxAge){ loadNovelsOnShelf(); mAdapter.setData(bookLists); - Toast.makeText(activity,"缓存清除成功",Toast.LENGTH_SHORT); + //Toast.makeText(activity,"缓存清除成功",Toast.LENGTH_SHORT); } }); @@ -439,9 +470,9 @@ void test(int maxAge){ { nv.delete(); - + LitePal.deleteAllAsync(Chapter.class,"novelId=?",nv.getId()+""); //TODO: remove cache on a new thread - //Fileutil.deleteDir(file) + FileUtils.clearChapterCache(nv.getId()); }else{ Log.d(TAG, "shelfZhengliSubmit: to delete novel " + nv.getName()); nv.setToDefault("isOnShelf"); diff --git a/zhuike/src/main/java/com/novelbook/android/Main2Activity.java b/zhuike/src/main/java/com/novelbook/android/Main2Activity.java index 7716665..151670f 100644 --- a/zhuike/src/main/java/com/novelbook/android/Main2Activity.java +++ b/zhuike/src/main/java/com/novelbook/android/Main2Activity.java @@ -65,6 +65,8 @@ public class Main2Activity extends Activity_base NavigationView navigationView; @BindView(R.id.navigation ) BottomNavigationView botoomNavigation; + @BindView(R.id.drawer_layout) + DrawerLayout drawerLayout; @BindView(R.id.rgSex) RadioGroup rgSex; // @BindView(R.id.tvUser) @@ -247,7 +249,7 @@ public class Main2Activity extends Activity_base } - @Override +/* @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { @@ -255,7 +257,7 @@ public class Main2Activity extends Activity_base } else { super.onBackPressed(); } - } + }*/ @@ -302,6 +304,9 @@ public class Main2Activity extends Activity_base intent.putExtra(Intent.EXTRA_SUBJECT, "意见建议"); // 主题 intent.putExtra(Intent.EXTRA_TEXT, "请输入内容"); // 正文 startActivity(Intent.createChooser(intent, "请选择邮件应用")); + } else if (id == R.id.nav_setup) { + Intent intent = new Intent(Main2Activity.this,ActivitySetup.class); + startActivity(intent); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); @@ -435,20 +440,17 @@ private int bottomSelectedIndex; swithToolbarItems( ); } - - - - long firstTime =0; + long firstTime =0; @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { - if( navigationView.isShown()){ + if (drawerLayout.isDrawerOpen(navigationView)) { + drawerLayout.closeDrawers(); + return true; + } - } int cnt=0; - - long secondTime = System.currentTimeMillis(); if (secondTime - firstTime > 800) {//如果两次按键时间间隔大于800毫秒,则不退出 String msg= "再按一次将退出" ; diff --git a/zhuike/src/main/java/com/novelbook/android/MarkActivity.java b/zhuike/src/main/java/com/novelbook/android/MarkActivity.java index a1db955..804cc1f 100644 --- a/zhuike/src/main/java/com/novelbook/android/MarkActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/MarkActivity.java @@ -52,7 +52,7 @@ public class MarkActivity extends Activity_base { private ArrayList catalogueList = new ArrayList<>();*/ private DisplayMetrics dm; - private String EXTR_BOOK ="book"; + // private String EXTR_BOOK ="book"; @Override public int getLayoutRes() { return R.layout.zactivity_mark; @@ -60,7 +60,10 @@ public class MarkActivity extends Activity_base { @Override protected void initViews() { - + if(getFactory().getNovle().isLocalBook()) { + // btnRefresh.setEnabled(false); + btnRefresh.setVisibility(View.GONE); + } } @Override @@ -70,7 +73,7 @@ public class MarkActivity extends Activity_base { @Override protected void initData() { - pageFactory = PageFactory.getInstance(getApplicationContext()); + pageFactory = getFactory();//PageFactory.getInstance(getApplicationContext()); Log.d(TAG, "prepareBook: pagefactory.mbook is ?" + (pageFactory.getNovle() .getName()) ); //config = Config.getInstance(); @@ -152,6 +155,9 @@ public class MarkActivity extends Activity_base { public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.catalogemark, menu); + if(getFactory().getNovle().isLocalBook()) { + menu.findItem(R.id.action_change_source).setEnabled(false); + } return true; } @@ -173,4 +179,10 @@ public class MarkActivity extends Activity_base { } return super.onOptionsItemSelected(item); } + PageFactory getFactory(){ + if(pageFactory==null) { + pageFactory = PageFactory.getInstance(getApplicationContext()); + } + return pageFactory; + } } diff --git a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java index 3d5ff19..9e4f669 100644 --- a/zhuike/src/main/java/com/novelbook/android/ReadActivity.java +++ b/zhuike/src/main/java/com/novelbook/android/ReadActivity.java @@ -472,6 +472,25 @@ public class ReadActivity extends Activity_base implements AdInterface { mSpeechSynthesizer.resume(); }*/ startTime = (int) new Date().getTime(); + if (book != null) { + Intent intent = getIntent(); + if (intent.hasExtra(EXTRA_BOOK)) { + Novel novel = (Novel) intent.getSerializableExtra(EXTRA_BOOK); + if (!pageFactory.isWorking() || novel.getId() != book.getId()) { + initData(); + }else{ + if( novel.getLastReadChapt()!=pageFactory.getCurrentChapter()){ + pageFactory.changeChapter(novel.getLastReadChapt()); + // hideReadSetting(); + } + } + hideReadSetting(); + } + } + + + + } @Override @@ -580,6 +599,13 @@ public class ReadActivity extends Activity_base implements AdInterface { public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.read, menu); + + if(book!=null && book.isLocalBook()){ + menu.findItem(R.id.action_change_source).setEnabled(false); + menu.findItem(R.id.action_refresh).setEnabled(false); + menu.findItem(R.id.action_bookdetail).setEnabled(false); + } + return true; } @@ -614,7 +640,9 @@ public class ReadActivity extends Activity_base implements AdInterface { bookMarks.setNovelId(pageFactory.getNovle().getId()); bookMarks.setChapt(pageFactory.getCurrentChapter()); bookMarks.setChaptName(((pageFactory.getChapters().get(bookMarks.getChapt()-1).getChapterName()))); - bookMarks.setDomain(pageFactory.getSite().getDomain()); + if(!book.isLocalBook()) { + bookMarks.setDomain(pageFactory.getSite().getDomain()); + } bookMarks.save(); Toast.makeText(ReadActivity.this, "书签添加成功", Toast.LENGTH_SHORT).show(); @@ -677,6 +705,13 @@ public class ReadActivity extends Activity_base implements AdInterface { } + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + Log.e("tag", "onNewINtent执行了"); + setIntent(intent); + + } public static boolean openBook(final Novel book, Activity context) { if (book == null){ @@ -758,7 +793,7 @@ public class ReadActivity extends Activity_base implements AdInterface { sb_progress.setProgress((int) (progress * 10000)); } - private void showReadSetting(){ + public void showReadSetting(){ isShow = true; // rl_progress.setVisibility(View.GONE); @@ -832,7 +867,7 @@ public class ReadActivity extends Activity_base implements AdInterface { ); pageFactory.setBusy(true); } - private void hideReadSetting() { + public void hideReadSetting() { isShow = false; Animation bottomAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_exit); Animation topAnim = AnimationUtils.loadAnimation(this, R.anim.dialog_top_exit); @@ -881,7 +916,7 @@ public class ReadActivity extends Activity_base implements AdInterface { case R.id.tv_directory: Intent intent = new Intent(ReadActivity.this, MarkActivity.class); startActivity(intent); - finish(); + // finish(); break; case R.id.tv_dayornight: changeDayOrNight(); diff --git a/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java b/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java index 90395f1..0b1e14f 100644 --- a/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java +++ b/zhuike/src/main/java/com/novelbook/android/adapter/BookListAdapter.java @@ -28,6 +28,8 @@ import butterknife.BindView; import butterknife.ButterKnife; import okhttp3.internal.Util; +import static com.novelbook.android.utils.ImageUtil.loader; + public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHolder> { private final int EMPTY_VIEW = 1; private final int PROGRESS_VIEW = 2; @@ -221,8 +223,9 @@ public class BookListAdapter extends RecyclerView.Adapter< RecyclerView.ViewHol if (holder.tvStatus != null) holder.tvStatus.setText(mDatas.get(position).getProgress()); - if (holder.imageView != null && !TextUtils.isEmpty(mDatas.get(position).getCover())) { - ImageUtil.loadImage(context, mDatas.get(position).getCover(), holder.imageView); + if (holder.imageView != null/* && !TextUtils.isEmpty(mDatas.get(position).getCover())*/) { + // ImageUtil.loadImage(context, mDatas.get(position).getCover(), holder.imageView); + loader.displayImage(context, NetUtil.getCoverUrl(mDatas.get(position).getCover()) ,holder.imageView); } if (holder.imageTop != null) { if( mDatas.get(position).isTop()){ diff --git a/zhuike/src/main/java/com/novelbook/android/netutils/HttpMethods.java b/zhuike/src/main/java/com/novelbook/android/netutils/HttpMethods.java index 273eddc..c2e5ebc 100644 --- a/zhuike/src/main/java/com/novelbook/android/netutils/HttpMethods.java +++ b/zhuike/src/main/java/com/novelbook/android/netutils/HttpMethods.java @@ -222,7 +222,7 @@ public class HttpMethods { }); - loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); + loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); //设置 Debug Log 模式 okHttpBuilder.addInterceptor(loggingInterceptor); // okHttpBuilder.addInterceptor(new RetryInterceptor()); diff --git a/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java b/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java index 23f13e8..a966aba 100644 --- a/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java @@ -372,7 +372,7 @@ public class NetUtil { // Log.e(TAG, "initHostConstants: update error ",er ); // } } - static void checkUpdate(boolean isSilence){ + public static void checkUpdate(boolean isSilence){ UpdateManager manager = new UpdateManager(Main2Activity.activityContext); if(isSilence) diff --git a/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java b/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java index 93dda05..f66bad5 100644 --- a/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java +++ b/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java @@ -200,6 +200,7 @@ public class UpdateManager { mHashMap = multiHashMap.get(packgename); if (mHashMap != null) { serviceCode = Integer.valueOf(mHashMap.get("version")); + Constants.serverVersion = serviceCode; if(mHashMap.containsKey("minVersion")) Constants.minVersion = Integer.valueOf(mHashMap.get("minVersion")); // need update or not diff --git a/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java b/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java index cdc9c5c..4b4b853 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/AdInterface.java @@ -12,5 +12,6 @@ public interface AdInterface { public void showProgressbar(boolean dismissAble,String msg); public void hideProgressbar(); public void showLoading(boolean isShow); - + public void hideReadSetting(); + public void showReadSetting(); } diff --git a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java index 3552217..d419571 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/BookUtil.java @@ -101,6 +101,9 @@ public class BookUtil { public void setChapters(List chapters) { this.mChapters = chapters; } + private final int MSG_FILLCONTENTDONE=1; + private final int MSG_READCHAPTER_FAIL=2; + private final int MSG_READCHAPTER_SUCCESS=3; @@ -134,8 +137,11 @@ public class BookUtil { private Map chaptDownStatus = new HashMap(); DownloadStatus downloadStatus = DownloadStatus.notStart; + public Chapter getChapter(int chapId){ chapId = chapId >0 ?chapId : 1; + + Log.d(TAG, String.format("prepare book getChapter: chaptId %s,mChapters.size() %s ",chapId,mChapters.size())); if(chapId > mChapters.size() || mChapters.size() ==0){ return Chapter.getChapter(mNovel.getId(), mNovel.getDomain()==null?"":mNovel.getDomain(),chapId); }else{ @@ -358,7 +364,7 @@ public class BookUtil { readChaptersAsync(); }else { - handler.sendEmptyMessage(3); + handler.sendEmptyMessage(MSG_READCHAPTER_SUCCESS); Log.d(TAG,String.format("prepare book loadChapts----end download %s 目录, 目录数量 %s, cost %s", mNovel.getName() , mChapters.size(), new Date().getTime() -startTime )); mMuluStatus = MuluStatus.isDone; Log.d(TAG, String.format("prepare book %s 章节信息完成.",mNovel.getName()) ); @@ -848,7 +854,7 @@ int muluRetryCount =0; //try next site Message msg =Message.obtain(); - msg.what =99; + msg.what =MSG_READCHAPTER_FAIL; msg.arg1 =chapterNo; Bundle bundleData = new Bundle(); @@ -870,7 +876,7 @@ int muluRetryCount =0; handler.sendMessage(msg); - // handler.sendEmptyMessage(99); + // handler.sendEmptyMessage(MSG_READCHAPTER_FAIL); // readChaptersAsync(); @@ -908,7 +914,7 @@ int muluRetryCount =0; Log.d(TAG,String.format("prepare book loadChapts----end download %s 目录, 目录数量 %s, cost %s", mNovel.getName() , mChapters.size(), new Date().getTime() -startTime )); mMuluStatus = MuluStatus.isDone; Log.d(TAG, String.format("prepare book %s 章节信息完成.",mNovel.getName()) ); - handler.sendEmptyMessage(3); //通知换源过程已读到目录 + handler.sendEmptyMessage(MSG_READCHAPTER_SUCCESS); //通知换源过程已读到目录 } catch (IOException e) { e.printStackTrace(); }finally { @@ -1218,6 +1224,7 @@ int muluRetryCount =0; bookChapter.setNovelChapterStartPos(start); bookChapter.setChapterName(str.replaceAll("###","")); bookChapter.setNovelPath(bookPath); + bookChapter.setIndex(chaptId+1); bookChapter.save(); int id= bookChapter.getId(); Log.d(TAG,str + " chaptId is " + id); @@ -1373,10 +1380,10 @@ int muluRetryCount =0; void handlerMsg(Message msg){ - if (msg.what == 123) { + if (msg.what == MSG_FILLCONTENTDONE) { // isDownloadChapt =true; Log.d(TAG,String.format("handler msg, download %s",true) ); - }else if(msg.what==99){ + }else if(msg.what==MSG_READCHAPTER_FAIL){ try { Toast.makeText(mContext, "网络拥堵,已帮您切换其它源", Toast.LENGTH_LONG).show(); }catch (Exception e){ @@ -1395,9 +1402,9 @@ int muluRetryCount =0; // isDownloadChapt =true; // Toast.makeText(mContext,"网络错误",Toast.LENGTH_LONG).show(); - }else if(msg.what==3){ //change source + }else if(msg.what==MSG_READCHAPTER_SUCCESS){ //change source isChangeSource =false; - Log.d(TAG, "changing Source:successed get chapters for " + mSite.getDomain() ); + Log.d(TAG, "prepare book changing Source:successed get chapters for " + mSite.getDomain() ); /*if(isChangeSource){ Log.d(TAG, "changing Source:successed get chapters for " + mSite.getDomain() ); isChangeSource =false; @@ -1712,7 +1719,7 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte // return; }*/ - // handler.sendEmptyMessage(123); + // handler.sendEmptyMessage(MSG_FILLCONTENTDONE); // handler.sendEmptyMessage(1); @@ -1765,7 +1772,7 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte 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(123); + handler.sendEmptyMessage(MSG_FILLCONTENTDONE); // setDownloadFlag(true); } catch (IOException | JSONException e) { e.printStackTrace(); @@ -1777,7 +1784,7 @@ private void loadChaptContent(final int chapterIndex) throws JSONException, Inte finally { body.close(); - handler.sendEmptyMessage(123); + handler.sendEmptyMessage(MSG_FILLCONTENTDONE); // setDownloadFlag(true); } chapter.setNovelId(mNovel.getId()); diff --git a/zhuike/src/main/java/com/novelbook/android/utils/Constants.java b/zhuike/src/main/java/com/novelbook/android/utils/Constants.java index f8af054..b9c9f72 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/Constants.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/Constants.java @@ -33,5 +33,6 @@ public class Constants { public static String email =""; public static int minVersion =0; public static int version =0; + public static int serverVersion =0; public static String updateUrl="http://xiaoshuofenxiang.com/version.xml";; } diff --git a/zhuike/src/main/java/com/novelbook/android/utils/FileUtils.java b/zhuike/src/main/java/com/novelbook/android/utils/FileUtils.java index 7a9fb58..2c0dcdc 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/FileUtils.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/FileUtils.java @@ -122,4 +122,12 @@ public class FileUtils { public static long getCacheSize(int noveId) { return Fileutil.getDirSize(getNovelDir(noveId)); } + public static String getCachedSize(){ + File f = new File(BookUtil.chapterPath); + return Fileutil.formatFileSize(Fileutil.getDirSize(f)); + } + public static void clearCache(){ + File f = new File(BookUtil.chapterPath); + Fileutil.deleteDir(f); + } } diff --git a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java index 44040ac..b6a32c3 100644 --- a/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java +++ b/zhuike/src/main/java/com/novelbook/android/utils/PageFactory.java @@ -182,9 +182,10 @@ public class PageFactory implements ChangeSource{ private AdInterface mAd; private BookTask bookTask; - private int MSG_NEXTPAGE=2; - private int MSG_HIDEPROGRESS=3; - private int MSG_NEXTPAGE_FAIL=4; + private final int MSG_CHANGECHAPTER =1; + private final int MSG_NEXTPAGE=2; + private final int MSG_HIDEPROGRESS=3; + private final int MSG_NEXTPAGE_FAIL=4; public AdInterface getmAd() { return mAd; } @@ -196,7 +197,7 @@ public class PageFactory implements ChangeSource{ @Override public void handleMessage(Message msg) { - Log.d(TAG, "prepare book get handler msg:" +msg); + // Log.d(TAG, "prepare book get handler msg:" +msg); handlerMsg(msg); @@ -240,6 +241,13 @@ public class PageFactory implements ChangeSource{ private List loadCurrentChapt(int chaptId){ Log.d(TAG, String.format("prepare book, loadCurrentChapt chaptId %s, getChapters().size() %s ,currentChapter %s",chaptId,getChapters().size() ,currentChapter) ); + if ( getChapters().size()>0) { //待下载 + chaptId = chaptId > getChapters().size() ? getChapters().size() : chaptId; + + chaptId = chaptId > 0 ? chaptId : 1; + + } + List chaptPages = new ArrayList(); chaptPages.add(new TRPage()); @@ -319,7 +327,7 @@ public class PageFactory implements ChangeSource{ @Override public void run() { Log.d(TAG, String.format("prepare book to download chapter %s ,thread.name %s",chid,Thread.currentThread().getName() ) ); - mBookUtil.chaptChars(chid); //TODO: 读取到上一章block后,file还是不存在的,现在就死循环了 + mBookUtil.chaptChars(chid); //TODO: 读取到上一章block后,file还是不存在的,现在就死循环了 fixed super.run(); }}.start(); @@ -345,7 +353,7 @@ public class PageFactory implements ChangeSource{ } Log.d(TAG, String.format("prepare book to download chapter %s ,handler notice changeChapter %s",chid, currentChapter ) ); //notice file done - handler.sendEmptyMessage(1); + handler.sendEmptyMessage(MSG_CHANGECHAPTER); super.run(); @@ -433,9 +441,9 @@ public class PageFactory implements ChangeSource{ page.setPageNo(pageNo); chaptPages.add(page); length= page.getEnd(); - Log.d(TAG, String.format("prepare book build page %s ready for chapter %s,cost %s",pageNo, chaptId,new Date().getTime()-starttime1)); + // Log.d(TAG, String.format("prepare book build page %s ready for chapter %s,cost %s",pageNo, chaptId,new Date().getTime()-starttime1)); } - Log.d(TAG, String.format(" prepare book build pages ready for chapter %s,cost %s", chaptId,new Date().getTime()-starttime)); + // Log.d(TAG, String.format(" prepare book build pages ready for chapter %s,cost %s", chaptId,new Date().getTime()-starttime)); return chaptPages; } @@ -709,6 +717,7 @@ private void hideSysUI(){ case FAIL: status = "读取错误,请稍后重试"; mAd.showRefresh(View.VISIBLE); + mAd.showReadSetting(); try { throw new Exception("error on reading"); } catch (Exception e) { @@ -853,7 +862,7 @@ private void hideSysUI(){ // Log.d(TAG, strLine); // Log.d(TAG,"最后字符 。。。" +strLine.charAt(strLine.length()-1) + ""); lastLine =strLine; - if(( strLine.charAt(strLine.length()-1) + "" ).equals("\n")){ + if(strLine.length()>0 && ( strLine.charAt(strLine.length()-1) + "" ).equals("\n")){ strLine =strLine.replace("\n",""); y += space; space =m_fontSize + paragraphSpace; @@ -1018,6 +1027,7 @@ private void hideSysUI(){ return; } + Log.d(TAG, "prepare book nextPage:chaptid " +mBookUtil.getChapterNo()); if (currentPage.getEnd() >= mBookUtil.getChapterLen()) { Log.d(TAG,"已经是本章最后一页了"); File file =new File( mBookUtil.fileChapterName(currentChapter+1)); @@ -1030,7 +1040,7 @@ private void hideSysUI(){ @Override public void run() { int slepttime = 0; mBookUtil.muluRetryCount=0; - while (slepttime<50 && mBookUtil.getChapters().size()==0 && (mBookUtil.mMuluStatus == BookUtil.MuluStatus.isDownloading || mBookUtil.muluRetryCount < Constants.retryCnt)) { + while (slepttime<80 && mBookUtil.getChapters().size()==0 && (mBookUtil.mMuluStatus == BookUtil.MuluStatus.isDownloading || mBookUtil.muluRetryCount < Constants.retryCnt)) { try { sleep(50); slepttime++; @@ -1040,9 +1050,14 @@ private void hideSysUI(){ } } - Log.d(TAG, String.format("prepare book waiting for chapters slept %s, chapt size %s " , slepttime *50,mBookUtil.getChapters().size())); + Log.d(TAG, String.format("prepare book waiting for chapters slept %s, chapt size %s, MuluStatus %s, muluRetryCount %s " , + slepttime *50,mBookUtil.getChapters().size(),mBookUtil.mMuluStatus,mBookUtil.muluRetryCount)); if(mBookUtil.getChapters().size()>0){ + if( mBookUtil.getChapterNo() == mBookUtil.getChapters().size()+1){ + mBookUtil.setChapterNo(mBookUtil.getChapterNo()-1); + } + currentChapter=mBookUtil.getChapterNo(); handler.sendEmptyMessage(MSG_NEXTPAGE) ; }else{ handler.sendEmptyMessage(MSG_NEXTPAGE_FAIL) ; @@ -1130,7 +1145,10 @@ private void hideSysUI(){ if(book==null){ return; } - if(book.isLocalBook() || mBookUtil==null){ //离线书籍重新初始化加载mBookUtil + if(book.isLocalBook()){ //离线书籍重新初始化加载mBookUtil + mBookUtil = new BookUtil(); + mBookUtil.setNovel(book); + }else if(mBookUtil==null){ mBookUtil = new BookUtil(); } mBookUtil.setContext(context); @@ -1157,7 +1175,7 @@ private void hideSysUI(){ } bookTask = new BookTask(); - Log.d(TAG, String.format("prepare book 1 to open chapter %s ",book.getLastReadChapt() ) ); + Log.d(TAG, String.format("prepare book 1 to open chapter %s ,position %s,source %s",book.getLastReadChapt() ,book.getLastReadPos(),book.getDomain()+book.getDomainName() ) ); bookTask.execute((long)book.getLastReadChapt(),book .getLastReadPos()); } @@ -1174,6 +1192,7 @@ private void hideSysUI(){ if (result) { Log.d(TAG, String.format("prepare book ready, to open chapter %s ",chapter ) ); // m_mbBufLen = mBookUtil.getChapterLen(); + currentChapter =(int)chapter; mBookUtil.setChapterNo((int)chapter); Log.d(TAG, String.format("prepare book ready, to open chapter, loadCurrentChapt %s ",chapter ) ); currentChaptPages = loadCurrentChapt((int)chapter); @@ -1212,6 +1231,7 @@ private void hideSysUI(){ try { int slept=0; while(getNovel() ==null){ + // Log.d(TAG, "prepare book:waiting for bookutil book:" + getNovel()); Thread.sleep(10); slept++; } @@ -1290,7 +1310,7 @@ private void hideSysUI(){ trPage.setEnd(mBookUtil.getPosition()); return trPage; */ - Log.d(TAG, String.format("prepare book getPageForBegin: chaptid %s, begin %s ",currentChapter,begin)); + Log.d(TAG, String.format("prepare book getPageForBegin: currentChaptPages count %s, chaptid %s, begin %s ",currentChaptPages.size(),currentChapter,begin)); for(TRPage page : currentChaptPages) { if(page.getEnd() >begin){ @@ -1531,7 +1551,7 @@ private void hideSysUI(){ */ currentChapter = mBookUtil.getChapterNo(); - // Log.d(TAG, String.format(" prepare book onDraw chapter after mBookUtil.getChapterNo(),currentChapter %s ",currentChapter ) ); + Log.d(TAG, String.format(" prepare book onDraw chapter after mBookUtil.getChapterNo(),currentChapter %s ",currentChapter ) ); return currentChapter ; } @@ -1581,13 +1601,21 @@ private void hideSysUI(){ if (getNovel() == null) { return; } + long position =0; + if(currentChapter == chapNum){ + if( currentPage!=null){ + position =currentPage.getBegin(); + Log.d(TAG, "prepare book changeChapter: to position " + position); + } + } preChaptPages =currentChaptPages; currentChapter = chapNum; mBookUtil.setChapterNo(currentChapter); currentChaptPages = loadCurrentChapt(currentChapter ) ; - currentPage = getPageForBegin(0); + currentPage = getPageForBegin(position); currentPage(true); hideSysUI(); + } public void retryChapt(int chapNum){ fileRetryCnt.clear(); diff --git a/zhuike/src/main/res/drawable/side_nav_bar.xml b/zhuike/src/main/res/drawable/side_nav_bar.xml index 9ad7c08..8ad6e43 100644 --- a/zhuike/src/main/res/drawable/side_nav_bar.xml +++ b/zhuike/src/main/res/drawable/side_nav_bar.xml @@ -4,6 +4,7 @@ android:angle="135" android:endColor="@color/colorPrimaryDark" + android:startColor="@color/colorPrimary" android:type="linear" /> @@ -11,7 +12,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/zhuike/src/main/res/layout/fragment_shelf_botoomsheetdialog.xml b/zhuike/src/main/res/layout/fragment_shelf_botoomsheetdialog.xml index 6ca1f76..c133d28 100644 --- a/zhuike/src/main/res/layout/fragment_shelf_botoomsheetdialog.xml +++ b/zhuike/src/main/res/layout/fragment_shelf_botoomsheetdialog.xml @@ -147,6 +147,7 @@ android:textColor="#212121" /> - -