From 593e66f145d7c32145a6c8f9bac2df6dd5a42dbf Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 18 Dec 2019 20:38:33 +0800 Subject: [PATCH] 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 @@ + + + + + + + + + + + + + + + +