From b87a4c14e61fd7c570c52031d036019ddffdffd1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 16 Feb 2021 20:39:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presenter/BookDetailPresenter.java | 11 ++++ .../contract/BookDetailContract.java | 2 + .../view/activity/BookDetailActivity.java | 55 ++++++++++--------- app/src/main/res/layout/view_file_picker.xml | 1 + 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/kunfei/bookshelf/presenter/BookDetailPresenter.java b/app/src/main/java/com/kunfei/bookshelf/presenter/BookDetailPresenter.java index 33a9d4fa6f..7b92d4a298 100644 --- a/app/src/main/java/com/kunfei/bookshelf/presenter/BookDetailPresenter.java +++ b/app/src/main/java/com/kunfei/bookshelf/presenter/BookDetailPresenter.java @@ -17,6 +17,7 @@ import com.kunfei.bookshelf.bean.BookChapterBean; import com.kunfei.bookshelf.bean.BookShelfBean; import com.kunfei.bookshelf.bean.BookSourceBean; +import com.kunfei.bookshelf.bean.OpenChapterBean; import com.kunfei.bookshelf.bean.SearchBookBean; import com.kunfei.bookshelf.bean.TwoDataBean; import com.kunfei.bookshelf.constant.RxBusTag; @@ -287,4 +288,14 @@ public void hadAddOrRemoveBook(BookShelfBean bookShelfBean) { bookShelf = bookShelfBean; mView.updateView(); } + + @Subscribe(thread = EventThread.MAIN_THREAD, tags = {@Tag(RxBusTag.SKIP_TO_CHAPTER)}) + public void skipToChapter(OpenChapterBean openChapterBean) { + bookShelf.setDurChapter(openChapterBean.getChapterIndex()); + bookShelf.setDurChapterPage(openChapterBean.getPageIndex()); + if (inBookShelf) { + BookshelfHelp.saveBookToShelf(bookShelf); + } + mView.readBook(); + } } diff --git a/app/src/main/java/com/kunfei/bookshelf/presenter/contract/BookDetailContract.java b/app/src/main/java/com/kunfei/bookshelf/presenter/contract/BookDetailContract.java index fb8b6be78f..c690e7eac0 100644 --- a/app/src/main/java/com/kunfei/bookshelf/presenter/contract/BookDetailContract.java +++ b/app/src/main/java/com/kunfei/bookshelf/presenter/contract/BookDetailContract.java @@ -46,6 +46,8 @@ interface View extends IView { */ void getBookShelfError(); + void readBook(); + void finish(); void toast(String msg); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java index 81abea145b..950c52a4dc 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java @@ -266,31 +266,7 @@ protected void bindEvent() { }).show()); binding.tvRead.setOnClickListener(v -> { - if (!mPresenter.getInBookShelf()) { - BookshelfHelp.saveBookToShelf(mPresenter.getBookShelf()); - if (mPresenter.getChapterList() != null) - DbHelper.getDaoSession().getBookChapterBeanDao().insertOrReplaceInTx(mPresenter.getChapterList()); - } - Intent intent = new Intent(BookDetailActivity.this, ReadBookActivity.class); - intent.putExtra("openFrom", ReadBookPresenter.OPEN_FROM_APP); - intent.putExtra("inBookshelf", mPresenter.getInBookShelf()); - String key = String.valueOf(System.currentTimeMillis()); - String bookKey = "book" + key; - intent.putExtra("bookKey", bookKey); - BitIntentDataManager.getInstance().putData(bookKey, mPresenter.getBookShelf().clone()); - startActivityByAnim(intent, android.R.anim.fade_in, android.R.anim.fade_out); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (getStart_share_ele()) { - finishAfterTransition(); - } else { - finish(); - overridePendingTransition(0, android.R.anim.fade_out); - } - } else { - finish(); - overridePendingTransition(0, android.R.anim.fade_out); - } + readBook(); }); binding.ivMenu.setOnClickListener(view -> { @@ -386,6 +362,35 @@ protected void firstRequest() { } } + @Override + public void readBook() { + if (!mPresenter.getInBookShelf()) { + BookshelfHelp.saveBookToShelf(mPresenter.getBookShelf()); + if (mPresenter.getChapterList() != null) + DbHelper.getDaoSession().getBookChapterBeanDao().insertOrReplaceInTx(mPresenter.getChapterList()); + } + Intent intent = new Intent(BookDetailActivity.this, ReadBookActivity.class); + intent.putExtra("openFrom", ReadBookPresenter.OPEN_FROM_APP); + intent.putExtra("inBookshelf", mPresenter.getInBookShelf()); + String key = String.valueOf(System.currentTimeMillis()); + String bookKey = "book" + key; + intent.putExtra("bookKey", bookKey); + BitIntentDataManager.getInstance().putData(bookKey, mPresenter.getBookShelf().clone()); + startActivityByAnim(intent, android.R.anim.fade_in, android.R.anim.fade_out); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (getStart_share_ele()) { + finishAfterTransition(); + } else { + finish(); + overridePendingTransition(0, android.R.anim.fade_out); + } + } else { + finish(); + overridePendingTransition(0, android.R.anim.fade_out); + } + } + @SuppressLint("DefaultLocale") private void upChapterSizeTv() { String chapterSize = ""; diff --git a/app/src/main/res/layout/view_file_picker.xml b/app/src/main/res/layout/view_file_picker.xml index 341ae2f726..4ef9049aab 100644 --- a/app/src/main/res/layout/view_file_picker.xml +++ b/app/src/main/res/layout/view_file_picker.xml @@ -28,6 +28,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" + android:textColor="@color/tv_text_secondary" android:visibility="gone" />