From 08b0520bd23dd4756fbd094e2225bbe7678e99a5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 2 Dec 2020 21:46:19 +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 --- .../app/ui/book/read/ReadBookBaseActivity.kt | 24 ++++++++----------- .../ui/book/read/config/BgTextConfigDialog.kt | 2 +- .../app/ui/book/read/config/PageKeyDialog.kt | 3 +-- .../ui/book/read/config/ReadStyleDialog.kt | 2 +- .../ui/book/read/config/SpeakEngineDialog.kt | 3 +-- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt index abbb5edd6..9e9f7deab 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt @@ -179,22 +179,18 @@ abstract class ReadBookBaseActivity : fun showDownloadDialog() { ReadBook.book?.let { book -> alert(titleResource = R.string.offline_cache) { - var dialogBinding: DialogDownloadChoiceBinding? = null - customView { - LayoutInflater.from(this@ReadBookBaseActivity) - .inflate(R.layout.dialog_download_choice, null) - .apply { - dialogBinding = DialogDownloadChoiceBinding.bind(this) - setBackgroundColor(context.backgroundColor) - dialogBinding!!.editStart.setText((book.durChapterIndex + 1).toString()) - dialogBinding!!.editEnd.setText(book.totalChapterNum.toString()) - } + val alertBinding = DialogDownloadChoiceBinding.inflate(layoutInflater).apply { + root.setBackgroundColor(root.context.backgroundColor) + editStart.setText((book.durChapterIndex + 1).toString()) + editEnd.setText(book.totalChapterNum.toString()) } + customView = alertBinding.root yesButton { - val start = dialogBinding!!.editStart.text?.toString()?.toInt() ?: 0 - val end = - dialogBinding!!.editEnd.text?.toString()?.toInt() ?: book.totalChapterNum - CacheBook.start(this@ReadBookBaseActivity, book.bookUrl, start - 1, end - 1) + alertBinding.run { + val start = editStart.text?.toString()?.toInt() ?: 0 + val end = editEnd.text?.toString()?.toInt() ?: book.totalChapterNum + CacheBook.start(this@ReadBookBaseActivity, book.bookUrl, start - 1, end - 1) + } } noButton() }.show() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 0f4079d4f..1801c7bf3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -104,7 +104,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { adapter = BgAdapter(requireContext(), secondaryTextColor) binding.recyclerView.adapter = adapter val headerView = ItemBgImageBinding.inflate( - LayoutInflater.from(requireContext()), + layoutInflater, binding.recyclerView, false ) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt index 94db6dda0..85ec5d31a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.book.read.config import android.app.Dialog import android.content.Context import android.view.KeyEvent -import android.view.LayoutInflater import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.databinding.DialogPageKeyBinding @@ -16,7 +15,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class PageKeyDialog(context: Context) : Dialog(context, R.style.AppTheme_AlertDialog) { - private val binding = DialogPageKeyBinding.inflate(LayoutInflater.from(context)) + private val binding = DialogPageKeyBinding.inflate(layoutInflater) init { setContentView(binding.root) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 2f8ab3ca8..43a3c053a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -87,7 +87,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { styleAdapter = StyleAdapter() rvStyle.adapter = styleAdapter val footerBinding = - ItemReadStyleBinding.inflate(LayoutInflater.from(requireContext()), rvStyle, false) + ItemReadStyleBinding.inflate(layoutInflater, rvStyle, false) footerBinding.ivStyle.setPadding(6.dp, 6.dp, 6.dp, 6.dp) footerBinding.ivStyle.setText(null) footerBinding.ivStyle.setColorFilter(textColor) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 9ca22fb3b..2da91bcdf 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -105,8 +105,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private fun editHttpTTS(v: HttpTTS? = null) { val httpTTS = v?.copy() ?: HttpTTS() requireContext().alert(titleResource = R.string.speak_engine) { - val alertBinding = - DialogHttpTtsEditBinding.inflate(LayoutInflater.from(requireContext())) + val alertBinding = DialogHttpTtsEditBinding.inflate(layoutInflater) alertBinding.tvName.setText(httpTTS.name) alertBinding.tvUrl.setText(httpTTS.url) customView = alertBinding.root