diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index 2b1e612c5..e4ba2f0c5 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -16,11 +16,11 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookSource +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert -import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.putPrefBoolean import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -85,14 +85,10 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList when (item.itemId) { R.id.menu_new_group -> { alert(R.string.diy_edit_source_group) { - var editText: AutoCompleteTextView? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - } - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater) + customView = alertBinding.root okButton { - editText?.text?.toString()?.let { group -> + alertBinding.editView.text?.toString()?.let { group -> viewModel.groupName = group item.title = getString(R.string.diy_edit_source_group_title, group) } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index c2985fc4b..9753ac7f0 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -16,11 +16,11 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.PreferKey import io.legado.app.data.entities.RssSource +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert -import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.putPrefBoolean import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -85,14 +85,10 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe when (item.itemId) { R.id.menu_new_group -> { alert(R.string.diy_edit_source_group) { - var editText: AutoCompleteTextView? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - } - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater) + customView = alertBinding.root okButton { - editText?.text?.toString()?.let { group -> + alertBinding.editView.text?.toString()?.let { group -> viewModel.groupName = group item.title = getString(R.string.diy_edit_source_group_title, group) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 2c9ab0c3a..2a9539f82 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup -import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.core.view.isGone import androidx.recyclerview.widget.DiffUtil @@ -20,6 +19,7 @@ import io.legado.app.base.BaseDialogFragment import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookGroup +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemGroupManageBinding import io.legado.app.lib.dialogs.alert @@ -99,15 +99,12 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener @SuppressLint("InflateParams") private fun addGroup() { alert(title = getString(R.string.add_group)) { - var editText: EditText? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - editText?.setHint(R.string.group_name) - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setHint(R.string.group_name) } + customView = alertBinding.root yesButton { - editText?.text?.toString()?.let { + alertBinding.editView.text?.toString()?.let { if (it.isNotBlank()) { viewModel.addGroup(it) } @@ -120,16 +117,15 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener @SuppressLint("InflateParams") private fun editGroup(bookGroup: BookGroup) { alert(title = getString(R.string.group_edit)) { - var editText: EditText? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - editText!!.setHint(R.string.group_name) - editText!!.setText(bookGroup.groupName) - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setHint(R.string.group_name) + editView.setText(bookGroup.groupName) } + customView = alertBinding.root yesButton { - viewModel.upGroup(bookGroup.copy(groupName = editText?.text?.toString() ?: "")) + alertBinding.editView.text?.toString()?.let { + viewModel.upGroup(bookGroup.copy(groupName = it)) + } } noButton() }.show().requestInputMethod() diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index ffa5d76fc..6f496dc18 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup -import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.ItemTouchHelper @@ -20,6 +19,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookGroup import io.legado.app.databinding.DialogBookGroupPickerBinding +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.ItemGroupSelectBinding import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.accentColor @@ -120,15 +120,12 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener @SuppressLint("InflateParams") private fun addGroup() { alert(title = getString(R.string.add_group)) { - var editText: EditText? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - editText!!.setHint(R.string.group_name) - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setHint(R.string.group_name) } + customView = alertBinding.root yesButton { - editText?.text?.toString()?.let { + alertBinding.editView.text?.toString()?.let { if (it.isNotBlank()) { viewModel.addGroup(it) } @@ -141,16 +138,15 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener @SuppressLint("InflateParams") private fun editGroup(bookGroup: BookGroup) { alert(title = getString(R.string.group_edit)) { - var editText: EditText? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - editText!!.setHint(R.string.group_name) - editText!!.setText(bookGroup.groupName) - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setHint(R.string.group_name) + editView.setText(bookGroup.groupName) } + customView = alertBinding.root yesButton { - viewModel.upGroup(bookGroup.copy(groupName = editText?.text?.toString() ?: "")) + alertBinding.editView.text?.toString()?.let { + viewModel.upGroup(bookGroup.copy(groupName = it)) + } } noButton() }.show().requestInputMethod() 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 3147a8858..abbb5edd6 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 @@ -6,7 +6,6 @@ import android.graphics.Color import android.os.Build import android.os.Bundle import android.view.* -import android.widget.EditText import androidx.core.view.isVisible import io.legado.app.App import io.legado.app.R @@ -15,6 +14,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Bookmark import io.legado.app.databinding.ActivityBookReadBinding import io.legado.app.databinding.DialogDownloadChoiceBinding +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.AppConfig import io.legado.app.help.LocalConfig import io.legado.app.help.ReadBookConfig @@ -30,7 +30,6 @@ import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.config.BgTextConfigDialog import io.legado.app.ui.book.read.config.ClickActionConfigDialog import io.legado.app.ui.book.read.config.PaddingConfigDialog -import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.getPrefString import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod @@ -207,16 +206,13 @@ abstract class ReadBookBaseActivity : val book = ReadBook.book ?: return val textChapter = ReadBook.curTextChapter ?: return alert(title = getString(R.string.bookmark_add)) { - var editText: EditText? = null - message = book.name + " • " + textChapter.title - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - editText!!.setHint(R.string.note_content) - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setHint(R.string.note_content) } + message = book.name + " • " + textChapter.title + customView = alertBinding.root yesButton { - editText?.text?.toString()?.let { editContent -> + alertBinding.editView.text?.toString()?.let { editContent -> Coroutine.async { val bookmark = Bookmark( bookUrl = book.bookUrl, @@ -239,17 +235,13 @@ abstract class ReadBookBaseActivity : val charsets = arrayListOf("UTF-8", "GB2312", "GBK", "Unicode", "UTF-16", "UTF-16LE", "ASCII") alert(R.string.set_charset) { - var editText: AutoCompleteTextView? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - editText?.setFilterValues(charsets) - editText?.setText(ReadBook.book?.charset) - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setFilterValues(charsets) + editView.setText(ReadBook.book?.charset) } + customView = alertBinding.root okButton { - val text = editText?.text?.toString() - text?.let { + alertBinding.editView.text?.toString()?.let { ReadBook.setCharset(it) } } 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 d75045e1d..0f4079d4f 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 @@ -13,6 +13,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialog import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.constant.EventBus +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogReadBgTextBinding import io.legado.app.databinding.ItemBgImageBinding import io.legado.app.help.ReadBookConfig @@ -26,7 +27,6 @@ import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.filepicker.FilePicker import io.legado.app.ui.filepicker.FilePickerDialog -import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import org.jetbrains.anko.sdk27.listeners.onCheckedChange @@ -123,15 +123,12 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { private fun initEvent() = with(ReadBookConfig.durConfig) { binding.ivEdit.onClick { alert(R.string.style_name) { - var editText: AutoCompleteTextView? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - editText!!.setText(ReadBookConfig.durConfig.name) - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.setText(ReadBookConfig.durConfig.name) } + customView = alertBinding.root okButton { - editText?.text?.toString()?.let { + alertBinding.editView.text?.toString()?.let { binding.tvName.text = it ReadBookConfig.durConfig.name = it } @@ -278,14 +275,10 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { @SuppressLint("InflateParams") private fun importNetConfigAlert() { alert("输入地址") { - var editText: AutoCompleteTextView? = null - customView { - layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { - editText = findViewById(R.id.edit_view) - } - } + val alertBinding = DialogEditTextBinding.inflate(layoutInflater) + customView = alertBinding.root okButton { - editText?.text?.toString()?.let { url -> + alertBinding.editView.text?.toString()?.let { url -> importNetConfig(url) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index e33d4f916..cad3128db 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -22,6 +22,7 @@ import io.legado.app.constant.AppPattern import io.legado.app.constant.EventBus import io.legado.app.data.entities.BookSource import io.legado.app.databinding.ActivityBookSourceBinding +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.IntentDataHelp import io.legado.app.help.LocalConfig import io.legado.app.lib.dialogs.alert @@ -38,7 +39,6 @@ import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider -import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult @@ -279,15 +279,12 @@ class BookSourceActivity : VMBaseActivity(R.layout.fragment_b val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout) val bookshelfSort = getPrefInt(PreferKey.bookshelfSort) val alertBinding = - DialogBookshelfConfigBinding.inflate(LayoutInflater.from(requireContext())) + DialogBookshelfConfigBinding.inflate(layoutInflater) .apply { rgLayout.checkByIndex(bookshelfLayout) rgSort.checkByIndex(bookshelfSort) @@ -175,7 +178,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b @SuppressLint("InflateParams") private fun addBookByUrl() { alert(titleResource = R.string.add_book_url) { - val alertBinding = DialogEditTextBinding.inflate(LayoutInflater.from(requireContext())) + val alertBinding = DialogEditTextBinding.inflate(layoutInflater) customView = alertBinding.root okButton { alertBinding.editView.text?.toString()?.let { diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index ed2f5e932..d935f5204 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -20,6 +20,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern import io.legado.app.data.entities.ReplaceRule import io.legado.app.databinding.ActivityReplaceRuleBinding +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.IntentDataHelp import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.alert @@ -34,7 +35,6 @@ import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider -import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.toast @@ -214,19 +214,16 @@ class ReplaceRuleActivity : VMBaseActivity