| @@ -50,7 +50,9 @@ class MainActivity : BaseActivity<ReadPresenter>(),ReadView { | |||
| Config.APP_NAME = "家校互通(测试)" | |||
| Config.BASE_URL = "http://192.168.69.99:9009" | |||
| Config.M_URL = "http://192.168.69.99:8098" | |||
| User.clearUserInfo() | |||
| if (BuildConfig.BUILD_TYPE != "debug") { | |||
| User.clearUserInfo() | |||
| } | |||
| startActivity<HomeActivity>() | |||
| } | |||
| btn3.setOnClickListener { | |||
| @@ -201,5 +203,9 @@ class MainActivity : BaseActivity<ReadPresenter>(),ReadView { | |||
| // startActivity<ReadActivity>("book_id" to "xxjs") | |||
| } | |||
| override fun onProgressSuccess(progress: Float) { | |||
| } | |||
| } | |||
| @@ -28,6 +28,7 @@ class PDFViewActivity : BaseActivity<ReadPresenter>(), ReadView { | |||
| var currPage = 0 | |||
| var total = 0 | |||
| var oldPosition = 0 | |||
| var lastProgress = 0f | |||
| //控制屏幕常亮 | |||
| private var mWakeLock: WakeLock? = null | |||
| @@ -46,6 +47,7 @@ class PDFViewActivity : BaseActivity<ReadPresenter>(), ReadView { | |||
| loadPdf() | |||
| } | |||
| mPresenter?.getReadProgress(mRealBookId, mReadTaskId) | |||
| } | |||
| private fun loadPdf() { | |||
| @@ -86,8 +88,8 @@ class PDFViewActivity : BaseActivity<ReadPresenter>(), ReadView { | |||
| } | |||
| }) | |||
| val pos = mBookRecord?.pagePos?:0; | |||
| pdf.currentItem =pos | |||
| val pos = mBookRecord?.pagePos ?: 0; | |||
| pdf.currentItem = pos | |||
| currPage = pos | |||
| } | |||
| @@ -133,6 +135,7 @@ class PDFViewActivity : BaseActivity<ReadPresenter>(), ReadView { | |||
| super.onResume() | |||
| mWakeLock?.acquire() | |||
| } | |||
| override fun onPause() { | |||
| super.onPause() | |||
| mWakeLock?.release() | |||
| @@ -140,12 +143,14 @@ class PDFViewActivity : BaseActivity<ReadPresenter>(), ReadView { | |||
| if (mBookRecord != null) { | |||
| BookRepository.getInstance() | |||
| .saveBookRecord(mBookRecord) | |||
| if (mBookRecord!!.pagePos > oldPosition) { | |||
| val currProgress = getPercent( | |||
| (mBookRecord!!.pagePos + 1).toFloat(), | |||
| total.toFloat() | |||
| ).toFloat() | |||
| if (mBookRecord!!.pagePos > oldPosition && currProgress > lastProgress) { | |||
| mPresenter?.updateReadProgress( | |||
| mRealBookId, mReadTaskId, getPercent( | |||
| (mBookRecord!!.pagePos + 1).toFloat(), | |||
| total.toFloat() | |||
| ) | |||
| mRealBookId, mReadTaskId, currProgress.toString() | |||
| ) | |||
| } | |||
| } | |||
| @@ -159,4 +164,8 @@ class PDFViewActivity : BaseActivity<ReadPresenter>(), ReadView { | |||
| override fun showCategory(localId: String?) { | |||
| } | |||
| override fun onProgressSuccess(progress: Float) { | |||
| lastProgress = progress | |||
| } | |||
| } | |||
| @@ -33,6 +33,7 @@ import androidx.core.content.ContextCompat; | |||
| import androidx.core.view.GravityCompat; | |||
| import androidx.drawerlayout.widget.DrawerLayout; | |||
| import com.blankj.utilcode.util.NumberUtils; | |||
| import com.google.android.material.appbar.AppBarLayout; | |||
| import com.yzx.webebook.R; | |||
| import com.yzx.webebook.activity.base.BaseActivity; | |||
| @@ -222,8 +223,11 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| mReadTaskId = getIntent().getStringExtra("read_task_id"); | |||
| mRealBookId = getIntent().getStringExtra("real_book_id"); | |||
| loadBookData(id); | |||
| getMPresenter().getReadProgress(mRealBookId, mReadTaskId); | |||
| } | |||
| private void loadBookData(String id) { | |||
| mCollBook = BookRepository.getInstance().getCollBook(id); | |||
| @@ -338,12 +342,6 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| mSbChapterProgress.post( | |||
| () -> { | |||
| mSbChapterProgress.setProgress(pos); | |||
| int max = mSbChapterProgress.getMax() + 1; | |||
| float progress = (pos + 1) * 1.0f / max; | |||
| if (progress > 0 && progress > lastProgress) { | |||
| lastProgress = progress; | |||
| } | |||
| } | |||
| ); | |||
| } | |||
| @@ -666,8 +664,11 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| saveBookInfo(); | |||
| mPageLoader.saveRecord(); | |||
| } | |||
| if(getMPresenter()!=null && mPageLoader!=null){ | |||
| getMPresenter().updateReadProgress(mRealBookId, mReadTaskId, String.valueOf(mPageLoader.getPercent())); | |||
| if (getMPresenter() != null && mPageLoader != null) { | |||
| float currProgress = Float.parseFloat(mPageLoader.getPercent()); | |||
| if (currProgress > lastProgress) { | |||
| getMPresenter().updateReadProgress(mRealBookId, mReadTaskId, String.valueOf(mPageLoader.getPercent())); | |||
| } | |||
| } | |||
| } | |||
| @@ -721,4 +722,9 @@ public class ReadActivity extends BaseActivity<ReadPresenter> implements ReadVie | |||
| } | |||
| } | |||
| @Override | |||
| public void onProgressSuccess(float progress) { | |||
| lastProgress = progress; | |||
| } | |||
| } | |||
| @@ -484,6 +484,10 @@ class YzxJavascriptInterface(var ctx: Activity) { | |||
| } | |||
| override fun onProgressSuccess(progress: Float) { | |||
| } | |||
| override fun errorChapter() { | |||
| } | |||
| @@ -531,6 +535,10 @@ class YzxJavascriptInterface(var ctx: Activity) { | |||
| } | |||
| } | |||
| override fun onProgressSuccess(progress: Float) { | |||
| } | |||
| }) | |||
| presenter.loadCategory(bookTaskId) | |||
| } | |||
| @@ -7,6 +7,7 @@ class Book { | |||
| var book_file_id:String = "" | |||
| var author:String = "" | |||
| var read_requires:String = "" | |||
| var read_progress:Float = 0f | |||
| var volumes:MutableList<Volumes> = mutableListOf() | |||
| } | |||
| @@ -2,7 +2,11 @@ package com.yzx.webebook.presenter; | |||
| import android.util.Log; | |||
| import com.blankj.utilcode.util.FileIOUtils; | |||
| import com.blankj.utilcode.util.FileUtils; | |||
| import com.blankj.utilcode.util.LogUtils; | |||
| import com.blankj.utilcode.util.TimeUtils; | |||
| import com.blankj.utilcode.util.ToastUtils; | |||
| import com.google.gson.Gson; | |||
| import com.google.gson.reflect.TypeToken; | |||
| import com.lzy.okgo.OkGo; | |||
| @@ -19,8 +23,6 @@ import com.yzx.webebook.model.Volumes; | |||
| import com.yzx.webebook.model.bean.CollBookBean; | |||
| import com.yzx.webebook.model.local.BookRepository; | |||
| import com.yzx.webebook.presenter.base.BasePresenter; | |||
| import com.yzx.webebook.utils.FileUtils; | |||
| import com.yzx.webebook.utils.MD5Utils; | |||
| import com.yzx.webebook.widget.page.TxtChapter; | |||
| import org.jetbrains.annotations.NotNull; | |||
| @@ -36,6 +38,34 @@ public class ReadPresenter extends BasePresenter<ReadView> { | |||
| super(view); | |||
| } | |||
| public void getReadProgress(String bookId,String readTaskId){ | |||
| User user = User.Companion.getUser(); | |||
| String url = Config.INSTANCE.getBASE_URL() + "/parent/readTask/getBookWarehouseContent"; | |||
| 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) | |||
| .headers(headers) | |||
| .execute(new StringCallback() { | |||
| @Override | |||
| public void onSuccess(Response<String> response) { | |||
| Gson gson = new Gson(); | |||
| BaseBean<Book> bean = gson.fromJson(response.body(), new TypeToken<BaseBean<Book>>() { | |||
| }.getType()); | |||
| getMView().onProgressSuccess(bean.getData().getRead_progress()); | |||
| } | |||
| @Override | |||
| public void onError(Response<String> response) { | |||
| super.onError(response); | |||
| } | |||
| }); | |||
| } | |||
| public void loadCategory(String bookTaskId) { | |||
| User user = User.Companion.getUser(); | |||
| @@ -64,36 +94,46 @@ public class ReadPresenter extends BasePresenter<ReadView> { | |||
| downloadBook(bean.getData(), bookTaskId); | |||
| } else { | |||
| Book book = bean.getData(); | |||
| StringBuilder builder = new StringBuilder(); | |||
| StringBuffer builder = new StringBuffer() ; | |||
| if (book.getVolumes().size() > 0) { | |||
| for (Volumes volume : book.getVolumes()) { | |||
| builder.append(volume.getTitle()); | |||
| builder.append("----------"); | |||
| builder.append("\r\n"); | |||
| for (Sections section : volume.getSections()) { | |||
| builder.append(section.getTitle()); | |||
| builder.append("\r\n"); | |||
| builder.append(section.getContent()); | |||
| builder.append("\r\n"); | |||
| } | |||
| } | |||
| } | |||
| String filePath = FileUtils.writeTxtToFile(builder.toString(), NOTE_FOLDER_DIR, user.getUser_id() + "_" + bookTaskId + ".txt"); | |||
| CollBookBean bookBean = new CollBookBean(); | |||
| String localId = user.getUser_id() + "_" + bookTaskId; | |||
| bookBean.set_id(localId); | |||
| bookBean.setAuthor(book.getAuthor()); | |||
| bookBean.setTitle(book.getBook_name()); | |||
| bookBean.setShortIntro(book.getRead_requires()); | |||
| bookBean.setLastChapter("开始阅读"); | |||
| bookBean.setUpdate(true); | |||
| bookBean.setIsLocal(true); | |||
| bookBean.setLastRead(TimeUtils.getNowString()); | |||
| bookBean.setUpdated(TimeUtils.getNowString()); | |||
| bookBean.setCover(filePath); | |||
| List<CollBookBean> list = new ArrayList<CollBookBean>(); | |||
| list.add(bookBean); | |||
| BookRepository.getInstance() | |||
| .saveCollBooks(list); | |||
| getMView().showCategory(localId); | |||
| LogUtils.d(builder); | |||
| LogUtils.d(builder.toString()); | |||
| String filePath = NOTE_FOLDER_DIR + user.getUser_id() + "_" + bookTaskId + ".txt"; | |||
| boolean success = FileUtils.createOrExistsFile(filePath); | |||
| boolean whiteSuccess = FileIOUtils.writeFileFromString(new File(filePath),builder.toString()); | |||
| if(success && whiteSuccess){ | |||
| CollBookBean bookBean = new CollBookBean(); | |||
| String localId = user.getUser_id() + "_" + bookTaskId; | |||
| bookBean.set_id(localId); | |||
| bookBean.setAuthor(book.getAuthor()); | |||
| bookBean.setTitle(book.getBook_name()); | |||
| bookBean.setShortIntro(book.getRead_requires()); | |||
| bookBean.setLastChapter("开始阅读"); | |||
| bookBean.setUpdate(true); | |||
| bookBean.setIsLocal(true); | |||
| bookBean.setLastRead(TimeUtils.getNowString()); | |||
| bookBean.setUpdated(TimeUtils.getNowString()); | |||
| bookBean.setCover(filePath); | |||
| List<CollBookBean> list = new ArrayList<CollBookBean>(); | |||
| list.add(bookBean); | |||
| BookRepository.getInstance() | |||
| .saveCollBooks(list); | |||
| getMView().showCategory(localId); | |||
| }else{ | |||
| ToastUtils.showLong("书籍信息读取失败!"); | |||
| } | |||
| } | |||
| } | |||
| @@ -11,4 +11,5 @@ public interface ReadView extends IView { | |||
| void showCategory(String localId); | |||
| void finishChapter(); | |||
| void errorChapter(); | |||
| void onProgressSuccess(float progress); | |||
| } | |||