| @@ -116,7 +116,7 @@ android { | |||
| greendao{ | |||
| schemaVersion 3 | |||
| schemaVersion 4 | |||
| daoPackage 'com.yzx.webebook.model.gen' | |||
| targetGenDir 'src/main/java' | |||
| } | |||
| @@ -168,4 +168,6 @@ dependencies { | |||
| //RxJava | |||
| implementation deps.reactivex.rxandroid | |||
| implementation deps.reactivex.rxjava2 | |||
| implementation 'es.voghdev.pdfviewpager:library:1.1.2' | |||
| } | |||
| @@ -12,8 +12,8 @@ | |||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |||
| <uses-permission android:name="android.permission.READ_MEDIA_STORAGE" /> | |||
| <uses-permission android:name="android.permission.WAKE_LOCK" /> | |||
| <uses-permission android:name="android.permission.WRITE_SETTINGS"/> | |||
| <uses-permission android:name="android.permission.BATTERY_STATS"/> | |||
| <uses-permission android:name="android.permission.WRITE_SETTINGS" /> | |||
| <uses-permission android:name="android.permission.BATTERY_STATS" /> | |||
| <uses-permission android:name="android.permission.WAKE_LOCK" /> | |||
| <application | |||
| @@ -22,12 +22,13 @@ | |||
| android:icon="@mipmap/ic_launcher" | |||
| android:label="@string/app_name" | |||
| android:networkSecurityConfig="@xml/network_security_config" | |||
| android:requestLegacyExternalStorage="true" | |||
| android:roundIcon="@mipmap/ic_launcher_round" | |||
| android:supportsRtl="true" | |||
| android:theme="@style/AppTheme" | |||
| android:requestLegacyExternalStorage="true" | |||
| android:usesCleartextTraffic="true"> | |||
| <activity android:name=".activity.ReadActivity"></activity> | |||
| <activity android:name=".activity.PDFViewActivity"></activity> | |||
| <activity android:name=".activity.ReadActivity" /> | |||
| <activity android:name=".activity.WeexTestActivity" /> | |||
| <activity | |||
| android:name=".activity.HomeActivity" | |||
| @@ -67,7 +67,9 @@ class MainActivity : BaseActivity<ReadPresenter>(),ReadView { | |||
| Config.APP_NAME = "家校互通(本地)" | |||
| Config.BASE_URL = mBaseUrl | |||
| Config.M_URL = mUrl | |||
| // User.clearUserInfo() | |||
| if (BuildConfig.BUILD_TYPE != "debug") { | |||
| User.clearUserInfo() | |||
| } | |||
| startActivity<HomeActivity>() | |||
| } | |||
| btn4.setOnClickListener { | |||
| @@ -88,9 +90,9 @@ class MainActivity : BaseActivity<ReadPresenter>(),ReadView { | |||
| } | |||
| btn7.setOnClickListener { | |||
| startActivity<PDFViewActivity>() | |||
| mPresenter?.loadCategory("17") | |||
| // mPresenter?.loadCategory("17") | |||
| } | |||
| /*OkGo.post<String>("https://fileupload.oa.qbjjyyun.net/edufile/fileUpload") | |||
| @@ -15,10 +15,8 @@ import androidx.recyclerview.widget.GridLayoutManager | |||
| import com.allenliu.versionchecklib.v2.AllenVersionChecker | |||
| import com.allenliu.versionchecklib.v2.builder.UIData | |||
| import com.allenliu.versionchecklib.v2.callback.CustomDownloadingDialogListener | |||
| import com.blankj.utilcode.util.AppUtils | |||
| import com.blankj.utilcode.util.NetworkUtils | |||
| import com.blankj.utilcode.util.SPUtils | |||
| import com.blankj.utilcode.util.StringUtils | |||
| import com.blankj.utilcode.constant.PermissionConstants | |||
| import com.blankj.utilcode.util.* | |||
| import com.google.gson.Gson | |||
| import com.google.gson.reflect.TypeToken | |||
| import com.lzy.okgo.OkGo | |||
| @@ -107,11 +105,29 @@ class HomeActivity : BaseActivity<BasePresenter<*>>() { | |||
| //请求权限 | |||
| ActivityCompat.requestPermissions( | |||
| this, | |||
| PERMISSIONS, | |||
| PERMISSIONS_REQUEST_STORAGE | |||
| ) | |||
| // ActivityCompat.requestPermissions( | |||
| // this, | |||
| // PERMISSIONS, | |||
| // PERMISSIONS_REQUEST_STORAGE | |||
| // ) | |||
| PermissionUtils.permissionGroup(PermissionConstants.STORAGE) | |||
| .rationale { activity, shouldRequest -> | |||
| }.callback(object :PermissionUtils.FullCallback{ | |||
| override fun onGranted(granted: MutableList<String>) { | |||
| LogUtils.d("权限通过",granted) | |||
| } | |||
| override fun onDenied( | |||
| deniedForever: MutableList<String>, | |||
| denied: MutableList<String> | |||
| ) { | |||
| LogUtils.d("权限拒绝",denied) | |||
| } | |||
| }).theme { activity -> ScreenUtils.setFullScreen(activity) } | |||
| .request() | |||
| } | |||
| private val PERMISSIONS_REQUEST_STORAGE = 1 | |||
| @@ -0,0 +1,162 @@ | |||
| package com.yzx.webebook.activity | |||
| import android.content.Context | |||
| import android.os.PowerManager | |||
| import android.os.PowerManager.WakeLock | |||
| import androidx.viewpager.widget.ViewPager | |||
| import com.blankj.utilcode.util.NumberUtils | |||
| import com.yzx.webebook.R | |||
| import com.yzx.webebook.activity.base.BaseActivity | |||
| import com.yzx.webebook.model.bean.BookRecordBean | |||
| import com.yzx.webebook.model.bean.CollBookBean | |||
| import com.yzx.webebook.model.local.BookRepository | |||
| import com.yzx.webebook.presenter.ReadPresenter | |||
| import com.yzx.webebook.presenter.ReadView | |||
| import com.yzx.webebook.widget.YzxPDFViewPager | |||
| import kotlinx.android.synthetic.main.activity_pdf_view.* | |||
| /** | |||
| * pdf 预览页面 | |||
| */ | |||
| class PDFViewActivity : BaseActivity<ReadPresenter>(), ReadView { | |||
| private var mBookRecord: BookRecordBean? = null | |||
| private var mCollBook: CollBookBean? = null | |||
| private var mRealBookId: String = "" | |||
| private var mReadTaskId: String = "" | |||
| private var mBookId: String = "" | |||
| var currPage = 0 | |||
| var total = 0 | |||
| var oldPosition = 0 | |||
| //控制屏幕常亮 | |||
| private var mWakeLock: WakeLock? = null | |||
| override val inflateId: Int | |||
| get() = R.layout.activity_pdf_view | |||
| override fun initView() { | |||
| mBookId = intent.getStringExtra("book_id") ?: "" | |||
| mReadTaskId = intent.getStringExtra("read_task_id") ?: "" | |||
| mRealBookId = intent.getStringExtra("real_book_id") ?: "" | |||
| mCollBook = BookRepository.getInstance().getCollBook(mBookId) | |||
| mCollBook.apply { | |||
| loadPdf() | |||
| } | |||
| } | |||
| private fun loadPdf() { | |||
| val pdf = YzxPDFViewPager(this, mCollBook?.cover ?: "") | |||
| pdfView.addView(pdf) | |||
| total = pdf.adapter?.count ?: 0 | |||
| btnLeft.setOnClickListener { | |||
| if (currPage > 0) { | |||
| pdf.currentItem = --currPage | |||
| } | |||
| } | |||
| btnRight.setOnClickListener { | |||
| if (currPage < total - 1) { | |||
| pdf.currentItem = ++currPage | |||
| } | |||
| } | |||
| prepareBook() | |||
| pdf.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { | |||
| override fun onPageScrollStateChanged(state: Int) { | |||
| } | |||
| override fun onPageScrolled( | |||
| position: Int, | |||
| positionOffset: Float, | |||
| positionOffsetPixels: Int | |||
| ) { | |||
| } | |||
| override fun onPageSelected(position: Int) { | |||
| currPageTv.text = "${position + 1}" | |||
| percentTv.text = "${getPercent(position.toFloat(), total.toFloat())}%" | |||
| mBookRecord?.pagePos = position | |||
| } | |||
| }) | |||
| val pos = mBookRecord?.pagePos?:0; | |||
| pdf.currentItem =pos | |||
| currPage = pos | |||
| } | |||
| /** | |||
| * 初始化书籍 | |||
| */ | |||
| private fun prepareBook() { | |||
| mBookRecord = BookRepository.getInstance() | |||
| .getBookRecord(mCollBook!!._id) | |||
| if (mBookRecord == null) { | |||
| mBookRecord = BookRecordBean() | |||
| mBookRecord?.bookId = mBookId | |||
| totalPageTv.text = "$total" | |||
| currPageTv.text = "${currPage + 1}" | |||
| percentTv.text = "${getPercent(1f, total.toFloat())}%" | |||
| oldPosition = 0 | |||
| } else { | |||
| oldPosition = mBookRecord!!.pagePos | |||
| totalPageTv.text = "$total" | |||
| currPageTv.text = "${mBookRecord!!.pagePos + 1}" | |||
| percentTv.text = | |||
| "${getPercent((mBookRecord!!.pagePos + 1).toFloat(), total.toFloat())}%" | |||
| } | |||
| } | |||
| override fun initData() { | |||
| //初始化屏幕常亮类 | |||
| //初始化屏幕常亮类 | |||
| val pm = | |||
| getSystemService(Context.POWER_SERVICE) as PowerManager | |||
| mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "ireader:keep bright") | |||
| } | |||
| private fun getPercent(curr: Float, total: Float): String { | |||
| val percent = NumberUtils.format(curr * 100f / total, 2) | |||
| return "$percent" | |||
| } | |||
| override fun initPresenter(): ReadPresenter = ReadPresenter(this) | |||
| override fun onResume() { | |||
| super.onResume() | |||
| mWakeLock?.acquire() | |||
| } | |||
| override fun onPause() { | |||
| super.onPause() | |||
| mWakeLock?.release() | |||
| //存储到数据库 | |||
| if (mBookRecord != null) { | |||
| BookRepository.getInstance() | |||
| .saveBookRecord(mBookRecord) | |||
| if (mBookRecord!!.pagePos > oldPosition) { | |||
| mPresenter?.updateReadProgress( | |||
| mRealBookId, mReadTaskId, getPercent( | |||
| (mBookRecord!!.pagePos + 1).toFloat(), | |||
| total.toFloat() | |||
| ) | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| override fun finishChapter() { | |||
| } | |||
| override fun errorChapter() { | |||
| } | |||
| override fun showCategory(localId: String?) { | |||
| } | |||
| } | |||
| @@ -120,6 +120,9 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| private boolean isRegistered = false; | |||
| private String mBookId; | |||
| private String mRealBookId; | |||
| private String mReadTaskId; | |||
| private float lastProgress = 0f; | |||
| private Handler mHandler = new Handler() { | |||
| @@ -216,6 +219,8 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| @Override | |||
| public void initData() { | |||
| String id = getIntent().getStringExtra("book_id"); | |||
| mReadTaskId = getIntent().getStringExtra("read_task_id"); | |||
| mRealBookId = getIntent().getStringExtra("real_book_id"); | |||
| loadBookData(id); | |||
| } | |||
| @@ -280,7 +285,7 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| } | |||
| private void saveBookInfo() { | |||
| if(mCollBook!=null){ | |||
| if (mCollBook != null) { | |||
| mCollBook.setLastRead(StringUtils. | |||
| dateConvert(System.currentTimeMillis(), Constant.FORMAT_BOOK_DATE)); | |||
| @@ -331,7 +336,15 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| @Override | |||
| public void onPageChange(int pos) { | |||
| mSbChapterProgress.post( | |||
| () -> mSbChapterProgress.setProgress(pos) | |||
| () -> { | |||
| mSbChapterProgress.setProgress(pos); | |||
| int max = mSbChapterProgress.getMax() + 1; | |||
| float progress = (pos + 1) * 1.0f / max; | |||
| if (progress > 0 && progress > lastProgress) { | |||
| lastProgress = progress; | |||
| } | |||
| } | |||
| ); | |||
| } | |||
| } | |||
| @@ -653,6 +666,9 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| saveBookInfo(); | |||
| mPageLoader.saveRecord(); | |||
| } | |||
| if(getMPresenter()!=null && mPageLoader!=null){ | |||
| getMPresenter().updateReadProgress(mRealBookId, mReadTaskId, String.valueOf(mPageLoader.getPercent())); | |||
| } | |||
| } | |||
| @Override | |||
| @@ -440,7 +440,7 @@ class YzxJavascriptInterface(var ctx: Activity) { | |||
| * 保存用户信息 | |||
| */ | |||
| @JavascriptInterface | |||
| fun saveUserInfo(json:String){ | |||
| fun saveUserInfo(json: String) { | |||
| val resultType = object : TypeToken<User>() {}.type | |||
| val gson = Gson() | |||
| val user = gson.fromJson<User>(json, resultType) | |||
| @@ -448,17 +448,17 @@ class YzxJavascriptInterface(var ctx: Activity) { | |||
| } | |||
| @JavascriptInterface | |||
| fun saveUnitCount(count:Int){ | |||
| fun saveUnitCount(count: Int) { | |||
| User.saveUnitCount(count) | |||
| } | |||
| @JavascriptInterface | |||
| fun toHome(){ | |||
| fun toHome() { | |||
| ctx.startActivity<HomeActivity>() | |||
| } | |||
| @JavascriptInterface | |||
| fun logout(){ | |||
| fun logout() { | |||
| val sp = SPUtils.getInstance() | |||
| sp.remove("user_name") | |||
| sp.remove("user_id") | |||
| @@ -478,8 +478,8 @@ class YzxJavascriptInterface(var ctx: Activity) { | |||
| } | |||
| @JavascriptInterface | |||
| fun readPage(bookTaskId:String){ | |||
| val presenter = ReadPresenter(object :ReadView{ | |||
| fun readPage(bookTaskId: String) { | |||
| val presenter = ReadPresenter(object : ReadView { | |||
| override fun finishChapter() { | |||
| } | |||
| @@ -490,9 +490,43 @@ class YzxJavascriptInterface(var ctx: Activity) { | |||
| override fun showCategory(localId: String?) { | |||
| val collBook = BookRepository.getInstance().getCollBook(localId) | |||
| if(collBook.cover.endsWith(".txt")){ | |||
| if (collBook.cover.endsWith(".txt")) { | |||
| ctx.startActivity<ReadActivity>("book_id" to localId) | |||
| }else{ | |||
| } else { | |||
| ToastUtils.showLong("暂不支持该格式预览!") | |||
| } | |||
| } | |||
| }) | |||
| presenter.loadCategory(bookTaskId) | |||
| } | |||
| @JavascriptInterface | |||
| fun readPage(bookTaskId: String, readTaskId: String) { | |||
| val presenter = ReadPresenter(object : ReadView { | |||
| override fun finishChapter() { | |||
| } | |||
| override fun errorChapter() { | |||
| } | |||
| override fun showCategory(localId: String?) { | |||
| val collBook = BookRepository.getInstance().getCollBook(localId) | |||
| if (collBook.cover.endsWith(".txt")) { | |||
| ctx.startActivity<ReadActivity>( | |||
| "book_id" to localId, | |||
| "read_task_id" to readTaskId, | |||
| "real_book_id" to bookTaskId | |||
| ) | |||
| } else if (collBook.cover.endsWith(".pdf")) { | |||
| ctx.startActivity<PDFViewActivity>( | |||
| "book_id" to localId, | |||
| "read_task_id" to readTaskId, | |||
| "real_book_id" to bookTaskId | |||
| ) | |||
| } else { | |||
| ToastUtils.showLong("暂不支持该格式预览!") | |||
| } | |||
| } | |||
| @@ -0,0 +1,38 @@ | |||
| package com.yzx.webebook.model.bean; | |||
| import org.greenrobot.greendao.annotation.Entity; | |||
| import org.greenrobot.greendao.annotation.Id; | |||
| import org.greenrobot.greendao.annotation.Generated; | |||
| @Entity | |||
| public class BookCount { | |||
| @Id | |||
| private String _id; // 本地书籍中,path 的 md5 值作为本地书籍的 id | |||
| private int total; | |||
| @Generated(hash = 433479827) | |||
| public BookCount(String _id, int total) { | |||
| this._id = _id; | |||
| this.total = total; | |||
| } | |||
| @Generated(hash = 2056164259) | |||
| public BookCount() { | |||
| } | |||
| public int getTotal() { | |||
| return total; | |||
| } | |||
| public String get_id() { | |||
| return _id; | |||
| } | |||
| public void set_id(String _id) { | |||
| this._id = _id; | |||
| } | |||
| public void setTotal(int total) { | |||
| this.total = total; | |||
| } | |||
| } | |||
| @@ -0,0 +1,52 @@ | |||
| package com.yzx.webebook.model.bean; | |||
| import org.greenrobot.greendao.annotation.Entity; | |||
| import org.greenrobot.greendao.annotation.Id; | |||
| import org.greenrobot.greendao.annotation.Generated; | |||
| import org.greenrobot.greendao.annotation.Index; | |||
| @Entity | |||
| public class ChapterPageCount { | |||
| @Id | |||
| private String _id; // 本地书籍中,path 的 md5 值作为本地书籍的 id | |||
| private int total; | |||
| @Index | |||
| private String book_id; | |||
| @Generated(hash = 774780221) | |||
| public ChapterPageCount(String _id, int total, String book_id) { | |||
| this._id = _id; | |||
| this.total = total; | |||
| this.book_id = book_id; | |||
| } | |||
| @Generated(hash = 876465118) | |||
| public ChapterPageCount() { | |||
| } | |||
| public void setTotal(int total) { | |||
| this.total = total; | |||
| } | |||
| public void set_id(String _id) { | |||
| this._id = _id; | |||
| } | |||
| public void setBook_id(String book_id) { | |||
| this.book_id = book_id; | |||
| } | |||
| public int getTotal() { | |||
| return total; | |||
| } | |||
| public String get_id() { | |||
| return _id; | |||
| } | |||
| public String getBook_id() { | |||
| return book_id; | |||
| } | |||
| } | |||
| @@ -3,7 +3,11 @@ package com.yzx.webebook.model.local; | |||
| import com.google.gson.Gson; | |||
| import com.yzx.webebook.model.bean.AuthorBean; | |||
| import com.yzx.webebook.model.bean.BookCount; | |||
| import com.yzx.webebook.model.bean.ChapterPageCount; | |||
| import com.yzx.webebook.model.bean.DownloadTaskBean; | |||
| import com.yzx.webebook.model.gen.BookCountDao; | |||
| import com.yzx.webebook.model.gen.ChapterPageCountDao; | |||
| import com.yzx.webebook.model.gen.DaoSession; | |||
| import org.greenrobot.greendao.Property; | |||
| @@ -74,4 +78,39 @@ public class LocalRepository implements SaveDbHelper,GetDbHelper,DeleteDbHelper{ | |||
| public void saveDownloadTask(DownloadTaskBean bean) { | |||
| } | |||
| @Override | |||
| public void saveBookCount(BookCount bookCount) { | |||
| mSession.getBookCountDao().insertOrReplaceInTx(bookCount); | |||
| } | |||
| @Override | |||
| public int getBookCount(String id) { | |||
| BookCount list = mSession.getBookCountDao() | |||
| .queryBuilder() | |||
| .where(BookCountDao.Properties._id.eq(id)) | |||
| .unique(); | |||
| if(list!=null){ | |||
| return list.getTotal(); | |||
| } | |||
| return 0; | |||
| } | |||
| @Override | |||
| public void saveChapterCount(List<ChapterPageCount> list) { | |||
| mSession.getChapterPageCountDao().insertOrReplaceInTx(list); | |||
| } | |||
| @Override | |||
| public List<ChapterPageCount> getChapterCount(String book_id) { | |||
| List<ChapterPageCount> list = mSession.getChapterPageCountDao() | |||
| .queryBuilder() | |||
| .where(ChapterPageCountDao.Properties.Book_id.eq(book_id)) | |||
| .list(); | |||
| if(list!=null && list.size()>0){ | |||
| return list; | |||
| } | |||
| return new ArrayList<ChapterPageCount>(); | |||
| } | |||
| } | |||
| @@ -3,6 +3,8 @@ package com.yzx.webebook.model.local; | |||
| import com.yzx.webebook.model.bean.AuthorBean; | |||
| import com.yzx.webebook.model.bean.BookCount; | |||
| import com.yzx.webebook.model.bean.ChapterPageCount; | |||
| import com.yzx.webebook.model.bean.DownloadTaskBean; | |||
| import java.util.List; | |||
| @@ -15,4 +17,12 @@ public interface SaveDbHelper { | |||
| void saveAuthors(List<AuthorBean> beans); | |||
| /*************DownloadTask*********************/ | |||
| void saveDownloadTask(DownloadTaskBean bean); | |||
| void saveBookCount(BookCount bookCount); | |||
| int getBookCount(String id); | |||
| void saveChapterCount(List<ChapterPageCount> list); | |||
| List<ChapterPageCount> getChapterCount(String book_id); | |||
| } | |||
| @@ -60,7 +60,7 @@ public class ReadPresenter extends BasePresenter<ReadView> { | |||
| Gson gson = new Gson(); | |||
| BaseBean<Book> bean = gson.fromJson(response.body(), new TypeToken<BaseBean<Book>>() { | |||
| }.getType()); | |||
| if ("txt".equals(bean.getData().getFile_type())) { | |||
| if ("txt".equals(bean.getData().getFile_type()) || "pdf".equals(bean.getData().getFile_type().toLowerCase())) { | |||
| downloadBook(bean.getData(), bookTaskId); | |||
| } else { | |||
| Book book = bean.getData(); | |||
| @@ -142,4 +142,30 @@ public class ReadPresenter extends BasePresenter<ReadView> { | |||
| public void loadChapter(String bookId, List<TxtChapter> bookChapterList) { | |||
| } | |||
| public void updateReadProgress(String bookId,String readTaskId,String progress){ | |||
| User user = User.Companion.getUser(); | |||
| String url = Config.INSTANCE.getBASE_URL() + "/parent/readTask/updateReadProgress"; | |||
| HttpHeaders headers = new HttpHeaders(); | |||
| headers.put("phone", user.getPhone()); | |||
| headers.put("token", user.getToken()); | |||
| OkGo.<String>post(url) | |||
| .tag(this) | |||
| .params("id", bookId) | |||
| .params("read_task_id", readTaskId) | |||
| .params("read_progress", progress) | |||
| .headers(headers) | |||
| .execute(new StringCallback() { | |||
| @Override | |||
| public void onSuccess(Response<String> response) { | |||
| } | |||
| @Override | |||
| public void onError(Response<String> response) { | |||
| super.onError(response); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,26 @@ | |||
| package com.yzx.webebook.widget | |||
| import android.content.Context | |||
| import android.view.MotionEvent | |||
| import es.voghdev.pdfviewpager.library.PDFViewPager | |||
| class YzxPDFViewPager(context:Context,path:String):PDFViewPager(context,path){ | |||
| override fun setCurrentItem(item: Int, smoothScroll: Boolean) { | |||
| super.setCurrentItem(item, false) | |||
| } | |||
| override fun setCurrentItem(item: Int) { | |||
| super.setCurrentItem(item,false) | |||
| } | |||
| override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean { | |||
| return false | |||
| } | |||
| override fun onTouchEvent(ev: MotionEvent?): Boolean { | |||
| return false | |||
| } | |||
| } | |||
| @@ -41,7 +41,7 @@ import io.reactivex.disposables.Disposable; | |||
| public class LocalPageLoader extends PageLoader { | |||
| private static final String TAG = "LocalPageLoader"; | |||
| //默认从文件中获取数据的长度 | |||
| private final static int BUFFER_SIZE = 10 * 1024; | |||
| private final static int BUFFER_SIZE = 50 * 1024; | |||
| //没有标题的时候,每个章节的最大长度 | |||
| private final static int MAX_LENGTH_WITH_NO_CHAPTER = 10 * 1024; | |||
| @@ -9,16 +9,22 @@ import android.graphics.Rect; | |||
| import android.graphics.RectF; | |||
| import android.graphics.Typeface; | |||
| import android.text.TextPaint; | |||
| import android.util.Log; | |||
| import androidx.core.content.ContextCompat; | |||
| import com.blankj.utilcode.util.NumberUtils; | |||
| import com.yzx.webebook.model.bean.BookCount; | |||
| import com.yzx.webebook.model.bean.BookRecordBean; | |||
| import com.yzx.webebook.model.bean.ChapterPageCount; | |||
| import com.yzx.webebook.model.bean.CollBookBean; | |||
| import com.yzx.webebook.model.local.BookRepository; | |||
| import com.yzx.webebook.model.local.LocalRepository; | |||
| import com.yzx.webebook.model.local.ReadSettingManager; | |||
| import com.yzx.webebook.utils.Constant; | |||
| import com.yzx.webebook.utils.IOUtils; | |||
| import com.yzx.webebook.utils.MD5Utils; | |||
| import com.yzx.webebook.utils.RxUtils; | |||
| import com.yzx.webebook.utils.ScreenUtils; | |||
| import com.yzx.webebook.utils.StringUtils; | |||
| @@ -391,6 +397,8 @@ public abstract class PageLoader { | |||
| // 重新获取指定页面 | |||
| mCurPage = mCurPageList.get(mCurPage.position); | |||
| // getTotalPage(true); | |||
| } | |||
| mPageView.drawCurPage(false); | |||
| @@ -724,6 +732,44 @@ public abstract class PageLoader { | |||
| mPageView.invalidate(); | |||
| } | |||
| private int getTotalPage() { | |||
| return getTotalPage(false); | |||
| } | |||
| private int getTotalPage(boolean update) { | |||
| // int total = LocalRepository.getInstance().getBookCount(mCollBook.get_id()); | |||
| // if (total > 0 && !update) { | |||
| // return total; | |||
| // } | |||
| int size = 0; | |||
| List<ChapterPageCount> chapterPageCountsList = new ArrayList<>(); | |||
| for (TxtChapter txtChapter : mChapterList) { | |||
| int index = mChapterList.indexOf(txtChapter); | |||
| try { | |||
| List<TxtPage> list = loadPageList(index); | |||
| size += list.size(); | |||
| chapterPageCountsList.add(new ChapterPageCount(MD5Utils.strToMd5By16(txtChapter.title), list.size(), mCollBook.get_id())); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| // LocalRepository.getInstance().saveChapterCount(chapterPageCountsList); | |||
| // LocalRepository.getInstance().saveBookCount(new BookCount(mCollBook.get_id(), size)); | |||
| return size; | |||
| } | |||
| public String getPercent(){ | |||
| float currPercent = (mCurPage.position + 1.0f) / mCurPageList.size(); | |||
| float step = 1.0f / mChapterList.size(); | |||
| float currChapPercent = 1.0f * mCurChapterPos * step; | |||
| // String percent = (mCurPage.position + 1) + "/" + mCurPageList.size(); | |||
| String percent = NumberUtils.format((currChapPercent + (currPercent * step))*100f, 2); | |||
| return percent; | |||
| } | |||
| private void drawBackground(Bitmap bitmap, boolean isUpdate) { | |||
| Canvas canvas = new Canvas(bitmap); | |||
| int tipMarginHeight = ScreenUtils.dpToPx(3); | |||
| @@ -750,8 +796,7 @@ public abstract class PageLoader { | |||
| float y = mDisplayHeight - mTipPaint.getFontMetrics().bottom - tipMarginHeight; | |||
| // 只有finish的时候采用页码 | |||
| if (mStatus == STATUS_FINISH) { | |||
| String percent = (mCurPage.position + 1) + "/" + mCurPageList.size(); | |||
| canvas.drawText(percent, mMarginWidth, y, mTipPaint); | |||
| canvas.drawText(getPercent() + "%", mMarginWidth, y, mTipPaint); | |||
| } | |||
| } | |||
| } else { | |||
| @@ -0,0 +1,57 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
| xmlns:app="http://schemas.android.com/apk/res-auto" | |||
| xmlns:tools="http://schemas.android.com/tools" | |||
| android:layout_width="match_parent" | |||
| android:layout_height="match_parent" | |||
| tools:context=".activity.PDFViewActivity"> | |||
| <FrameLayout | |||
| android:id="@+id/pdfView" | |||
| android:layout_width="match_parent" | |||
| android:layout_height="match_parent"/> | |||
| <LinearLayout | |||
| android:layout_width="match_parent" | |||
| android:layout_height="match_parent"> | |||
| <View | |||
| android:id="@+id/btnLeft" | |||
| android:layout_width="0dp" | |||
| android:layout_height="match_parent" | |||
| android:layout_weight="1"/> | |||
| <View | |||
| android:id="@+id/btnRight" | |||
| android:layout_width="0dp" | |||
| android:layout_height="match_parent" | |||
| android:layout_weight="1"/> | |||
| </LinearLayout> | |||
| <LinearLayout | |||
| android:layout_width="wrap_content" | |||
| android:orientation="horizontal" | |||
| android:layout_alignParentStart="true" | |||
| android:layout_alignParentBottom="true" | |||
| android:paddingBottom="@dimen/d_5" | |||
| android:layout_height="wrap_content"> | |||
| <TextView | |||
| android:id="@+id/currPageTv" | |||
| android:text="1" | |||
| style="@style/pdf_page_count" /> | |||
| <TextView | |||
| android:layout_width="wrap_content" | |||
| android:layout_height="wrap_content" | |||
| android:text="/" | |||
| android:textColor="@color/black"/> | |||
| <TextView | |||
| android:id="@+id/totalPageTv" | |||
| android:text="100" | |||
| style="@style/pdf_page_count"/> | |||
| <TextView | |||
| android:id="@+id/percentTv" | |||
| android:text="50%" | |||
| android:layout_marginLeft="@dimen/d_10" | |||
| style="@style/pdf_page_count"/> | |||
| </LinearLayout> | |||
| </RelativeLayout> | |||
| @@ -35,7 +35,7 @@ | |||
| android:paddingRight="12dp" | |||
| android:paddingTop="8dp" | |||
| android:text="1/12" | |||
| android:textColor="@color/white" | |||
| android:textColor="@color/black" | |||
| android:visibility="gone" /> | |||
| @@ -129,4 +129,13 @@ | |||
| <!-- TextAppearance:修改 --> | |||
| <style name="NB.Theme.TextAppearance"/> | |||
| <style name="pdf_page_count"> | |||
| <item name="android:layout_width">wrap_content</item> | |||
| <item name="android:layout_height">wrap_content</item> | |||
| <item name="android:textSize">@dimen/sp18</item> | |||
| <item name="android:textColor">@color/black</item> | |||
| <item name="android:paddingStart">5dp</item> | |||
| <item name="android:paddingEnd">5dp</item> | |||
| </style> | |||
| </resources> | |||