Merge pull request #8 from gedoor/master

up
pull/61/head^2
口口吕 5 years ago committed by GitHub
commit 64ac9b59c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 16
      app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt
  3. 78
      app/src/main/res/layout/dialog_download_choice.xml

@ -1,5 +1,6 @@
package io.legado.app.ui.book.read package io.legado.app.ui.book.read
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
@ -8,6 +9,7 @@ import android.text.SpannableStringBuilder
import android.view.KeyEvent import android.view.KeyEvent
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener 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.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.*
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton
import io.legado.app.receiver.TimeElectricityReceiver import io.legado.app.receiver.TimeElectricityReceiver
import io.legado.app.service.BaseReadAloudService 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.ReadAloud
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.config.* 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.ui.widget.page.delegate.PageDelegate
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_read.* 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_book_page.*
import kotlinx.android.synthetic.main.view_read_menu.* import kotlinx.android.synthetic.main.view_read_menu.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -131,6 +133,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
/** /**
* 菜单 * 菜单
*/ */
@SuppressLint("InflateParams")
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_change_source -> { R.id.menu_change_source -> {
@ -146,6 +149,26 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
viewModel.refreshContent(it) 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) return super.onCompatOptionsItemSelected(item)
} }

@ -4,6 +4,8 @@ import android.text.Spannable
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan 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.App
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
@ -17,7 +19,9 @@ object ChapterProvider {
fun getTextChapter( fun getTextChapter(
bookChapter: BookChapter, bookChapter: BookChapter,
content: String, chapterSize: Int content: String,
chapterSize: Int,
isHtml: Boolean = false
): TextChapter { ): TextChapter {
textView?.let { textView?.let {
val textPages = arrayListOf<TextPage>() val textPages = arrayListOf<TextPage>()
@ -26,7 +30,15 @@ object ChapterProvider {
var surplusText = content var surplusText = content
var pageIndex = 0 var pageIndex = 0
while (surplusText.isNotEmpty()) { 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) { if (pageIndex == 0) {
val end = surplusText.indexOf("\n") val end = surplusText.indexOf("\n")
if (end > 0) { if (end > 0) {

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="@color/background"
android:gravity="center"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:text="@string/chapter"
android:textColor="@color/tv_text_default"
android:textSize="16sp"
tools:ignore="RtlHardcoded" />
<EditText
android:id="@+id/edit_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_edit"
android:inputType="number"
android:lines="1"
android:maxLength="5"
android:minWidth="60dp"
android:paddingLeft="5dp"
android:paddingTop="4dp"
android:paddingRight="5dp"
android:paddingBottom="4dp"
android:textColor="@color/tv_text_default"
android:textCursorDrawable="@drawable/shape_text_cursor"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="@string/to"
android:textColor="@color/tv_text_default"
android:textSize="16sp" />
<EditText
android:id="@+id/edit_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_edit"
android:inputType="number"
android:lines="1"
android:maxLength="5"
android:minWidth="60dp"
android:paddingLeft="5dp"
android:paddingTop="4dp"
android:paddingRight="5dp"
android:paddingBottom="4dp"
android:textColor="@color/tv_text_default"
android:textCursorDrawable="@drawable/shape_text_cursor"
android:textSize="14sp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Loading…
Cancel
Save