From 4cbfc02dabcff2038f357bc58c2584fb1a15a3e0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 16 Aug 2019 21:01:51 +0800 Subject: [PATCH] up --- .../legado/app/ui/readbook/ReadBookActivity.kt | 12 +++++++++++- .../legado/app/ui/readbook/ReadBookViewModel.kt | 16 +++++++++++----- app/src/main/res/layout/view_book_page.xml | 10 ++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index be1a968ab..f8945670c 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -14,18 +14,22 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.Status import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookChapter import io.legado.app.receiver.TimeElectricityReceiver import io.legado.app.service.ReadAloudService import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity +import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_read_book.* +import kotlinx.android.synthetic.main.view_book_page.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity -class ReadBookActivity : VMBaseActivity(R.layout.activity_read_book), ChangeSourceDialog.CallBack { +class ReadBookActivity : VMBaseActivity(R.layout.activity_read_book), ChangeSourceDialog.CallBack, + ReadBookViewModel.CallBack { override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) @@ -42,6 +46,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea setSupportActionBar(toolbar) initAnimation() initView() + viewModel.callBack = this viewModel.chapterMaxIndex.observe(this, Observer { bookLoadFinish() }) viewModel.initData(intent) savedInstanceState?.let { @@ -228,6 +233,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } + override fun loadContentFinish(bookChapter: BookChapter, content: String) { + val textChapter = ChapterProvider().getTextChapter(content_text_view, bookChapter, content) + print(textChapter.pages.size) + } + override fun changeTo(book: Book) { } diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index 65af68269..4bc182165 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -18,6 +18,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { var bookSource: BookSource? = null var chapterMaxIndex = MediatorLiveData() var webBook: WebBook? = null + var callBack: CallBack? = null fun initData(intent: Intent) { val bookUrl = intent.getStringExtra("bookUrl") @@ -48,23 +49,28 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } - fun loadContent(book: Book, index: Int, success: ((content: String) -> Unit)) { + fun loadContent(book: Book, index: Int) { execute { App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> BookHelp.getContent(book, chapter)?.let { - success(it) - } ?: download(book, chapter, success) + callBack?.loadContentFinish(chapter, it) + } ?: download(book, chapter) } } } - fun download(book: Book, chapter: BookChapter, success: ((content: String) -> Unit)? = null) { + fun download(book: Book, chapter: BookChapter) { webBook?.getContent(book, chapter) ?.onSuccess(IO) { content -> content?.let { BookHelp.saveContent(book, chapter, it) - success?.invoke(it) + callBack?.loadContentFinish(chapter, it) } } } + + + interface CallBack { + fun loadContentFinish(bookChapter: BookChapter, content: String) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index ec9423495..9ed52c863 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -21,12 +21,10 @@ android:layout_height="0dp" android:layout_weight="1"> - - +