From 593e66f145d7c32145a6c8f9bac2df6dd5a42dbf Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 18 Dec 2019 20:38:33 +0800 Subject: [PATCH 1/2] up --- .../app/ui/book/read/ReadBookActivity.kt | 29 ++++++- .../res/layout/dialog_download_choice.xml | 78 +++++++++++++++++++ 2 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/layout/dialog_download_choice.xml diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7b9daf6d2..23bec9842 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read +import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.net.Uri @@ -8,6 +9,7 @@ import android.text.SpannableStringBuilder import android.view.KeyEvent import android.view.Menu import android.view.MenuItem +import android.view.View import androidx.core.view.isVisible import androidx.lifecycle.Observer import com.jaredrummler.android.colorpicker.ColorPickerDialogListener @@ -18,11 +20,10 @@ import io.legado.app.constant.Status import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.ReadBookConfig -import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.okButton +import io.legado.app.lib.dialogs.* import io.legado.app.receiver.TimeElectricityReceiver import io.legado.app.service.BaseReadAloudService +import io.legado.app.service.help.Download import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.config.* @@ -38,6 +39,7 @@ import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.delegate.PageDelegate import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_read.* +import kotlinx.android.synthetic.main.dialog_download_choice.view.* import kotlinx.android.synthetic.main.view_book_page.* import kotlinx.android.synthetic.main.view_read_menu.* import kotlinx.coroutines.Dispatchers.IO @@ -131,6 +133,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 菜单 */ + @SuppressLint("InflateParams") override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_change_source -> { @@ -146,6 +149,26 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo viewModel.refreshContent(it) } } + R.id.menu_download -> ReadBook.book?.let { book -> + alert(titleResource = R.string.download_offline) { + var view: View? = null + customView { + layoutInflater.inflate(R.layout.dialog_download_choice, null).apply { + view = this + edit_start.setText(book.durChapterIndex.toString()) + edit_end.setText(book.totalChapterNum.toString()) + } + } + yesButton { + view?.apply { + val start = edit_start?.text?.toString()?.toInt() ?: 0 + val end = edit_end?.text?.toString()?.toInt() ?: book.totalChapterNum + Download.start(this@ReadBookActivity, book.bookUrl, start, end) + } + } + noButton() + }.show().applyTint() + } } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/res/layout/dialog_download_choice.xml b/app/src/main/res/layout/dialog_download_choice.xml new file mode 100644 index 000000000..9eabee75b --- /dev/null +++ b/app/src/main/res/layout/dialog_download_choice.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + From 86fdd1b2dc8d3b4ef7eafa2e8705791c53924085 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 18 Dec 2019 21:31:12 +0800 Subject: [PATCH 2/2] up --- .../legado/app/ui/widget/page/ChapterProvider.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt index 80c21103a..25b68e6c3 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt @@ -4,6 +4,8 @@ import android.text.Spannable import android.text.SpannableStringBuilder import android.text.style.ForegroundColorSpan import android.text.style.RelativeSizeSpan +import androidx.core.text.HtmlCompat +import androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT import io.legado.app.App import io.legado.app.data.entities.BookChapter import io.legado.app.lib.theme.accentColor @@ -17,7 +19,9 @@ object ChapterProvider { fun getTextChapter( bookChapter: BookChapter, - content: String, chapterSize: Int + content: String, + chapterSize: Int, + isHtml: Boolean = false ): TextChapter { textView?.let { val textPages = arrayListOf() @@ -26,7 +30,15 @@ object ChapterProvider { var surplusText = content var pageIndex = 0 while (surplusText.isNotEmpty()) { - val spannableStringBuilder = SpannableStringBuilder(surplusText) + val spannableStringBuilder = + if (isHtml) { + HtmlCompat.fromHtml( + surplusText, + FROM_HTML_MODE_COMPACT + ) as SpannableStringBuilder + } else { + SpannableStringBuilder(surplusText) + } if (pageIndex == 0) { val end = surplusText.indexOf("\n") if (end > 0) {