From 82a218947e4366e6a02a4822f08d9ce24f099107 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 15 Sep 2021 14:26:11 +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 --- .../ui/association/ImportBookSourceDialog.kt | 15 +++++---------- .../ui/association/ImportReplaceRuleDialog.kt | 17 +++++++---------- .../app/ui/association/ImportRssSourceDialog.kt | 17 +++++++---------- .../ui/book/changecover/ChangeCoverDialog.kt | 16 +++++++--------- .../ui/book/changesource/ChangeSourceDialog.kt | 9 +++------ .../legado/app/ui/book/group/GroupEditDialog.kt | 8 +++----- .../app/ui/book/group/GroupSelectDialog.kt | 11 +++++------ .../legado/app/ui/book/read/ReadBookActivity.kt | 2 +- .../io/legado/app/ui/book/toc/BookmarkDialog.kt | 9 ++++----- .../java/io/legado/app/ui/dict/DictDialog.kt | 11 +++++------ .../legado/app/ui/document/FilePickerDialog.kt | 7 +++---- .../main/bookshelf/style1/BookshelfFragment1.kt | 2 +- .../bookshelf/style1/books/BooksFragment.kt | 16 ++++++---------- .../app/ui/rss/article/RssArticlesFragment.kt | 16 ++++++---------- .../app/ui/rss/article/RssSortActivity.kt | 2 +- 15 files changed, 64 insertions(+), 94 deletions(-) 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 dce1044e9..1b919e439 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 @@ -27,11 +27,8 @@ import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.dialog.WaitDialog -import io.legado.app.utils.dp -import io.legado.app.utils.putPrefBoolean -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import io.legado.app.utils.visible /** @@ -46,12 +43,10 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList source: String, finishOnDismiss: Boolean = false ) { - ImportBookSourceDialog().apply { - arguments = Bundle().apply { - putString("source", source) - putBoolean("finishOnDismiss", finishOnDismiss) - } - }.show(fragmentManager, "importBookSource") + fragmentManager.showDialog { + putString("source", source) + putBoolean("finishOnDismiss", finishOnDismiss) + } } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt index 70e7f3e53..d684c9d9c 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt @@ -26,27 +26,24 @@ import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.dialog.WaitDialog -import io.legado.app.utils.dp -import io.legado.app.utils.putPrefBoolean -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import io.legado.app.utils.visible class ImportReplaceRuleDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { companion object { + fun start( fragmentManager: FragmentManager, source: String, finishOnDismiss: Boolean = false ) { - ImportReplaceRuleDialog().apply { - arguments = Bundle().apply { - putString("source", source) - putBoolean("finishOnDismiss", finishOnDismiss) - } - }.show(fragmentManager, "importReplaceRule") + fragmentManager.showDialog { + putString("source", source) + putBoolean("finishOnDismiss", finishOnDismiss) + } } + } private val binding by viewBinding(DialogRecyclerViewBinding::bind) 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 d4be8117b..5143322d4 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 @@ -27,11 +27,8 @@ import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.dialog.WaitDialog -import io.legado.app.utils.dp -import io.legado.app.utils.putPrefBoolean -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import io.legado.app.utils.visible /** * 导入rss源弹出窗口 @@ -39,18 +36,18 @@ import io.legado.app.utils.visible class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { companion object { + fun start( fragmentManager: FragmentManager, source: String, finishOnDismiss: Boolean = false ) { - ImportRssSourceDialog().apply { - arguments = Bundle().apply { - putString("source", source) - putBoolean("finishOnDismiss", finishOnDismiss) - } - }.show(fragmentManager, "importRssSource") + fragmentManager.showDialog { + putString("source", source) + putBoolean("finishOnDismiss", finishOnDismiss) + } } + } private val binding by viewBinding(DialogRecyclerViewBinding::bind) diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt index 88a4ddc2b..fce5fa26c 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt @@ -14,6 +14,7 @@ import io.legado.app.base.BaseDialogFragment import io.legado.app.databinding.DialogChangeCoverBinding import io.legado.app.lib.theme.primaryColor import io.legado.app.utils.applyTint +import io.legado.app.utils.showDialog import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.windowSize @@ -23,17 +24,14 @@ class ChangeCoverDialog : BaseDialogFragment(), CoverAdapter.CallBack { companion object { - const val tag = "changeCoverDialog" - - fun show(manager: FragmentManager, name: String, author: String) { - val fragment = ChangeCoverDialog().apply { - val bundle = Bundle() - bundle.putString("name", name) - bundle.putString("author", author) - arguments = bundle + + fun show(fragmentManager: FragmentManager, name: String, author: String) { + fragmentManager.showDialog { + putString("name", name) + putString("author", author) } - fragment.show(manager, tag) } + } private val binding by viewBinding(DialogChangeCoverBinding::bind) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 7981e893d..ee19680da 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -37,13 +37,10 @@ class ChangeSourceDialog : BaseDialogFragment(), const val tag = "changeSourceDialog" fun show(manager: FragmentManager, name: String, author: String) { - val fragment = ChangeSourceDialog().apply { - val bundle = Bundle() - bundle.putString("name", name) - bundle.putString("author", author) - arguments = bundle + manager.showDialog { + putString("name", name) + putString("author", author) } - fragment.show(manager, tag) } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt index 4994df880..32e27fffa 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt @@ -21,11 +21,9 @@ class GroupEditDialog : BaseDialogFragment() { companion object { fun start(fragmentManager: FragmentManager, bookGroup: BookGroup? = null) { - GroupEditDialog().apply { - arguments = Bundle().apply { - putParcelable("group", bookGroup) - } - }.show(fragmentManager, "bookGroupEdit") + fragmentManager.showDialog { + putParcelable("group", bookGroup) + } } } 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 51f67d8df..1cf2ea092 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 @@ -26,6 +26,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint +import io.legado.app.utils.showDialog import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.windowSize import kotlinx.coroutines.flow.collect @@ -38,14 +39,12 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener const val tag = "groupSelectDialog" fun show(manager: FragmentManager, groupId: Long, requestCode: Int = -1) { - val fragment = GroupSelectDialog().apply { - val bundle = Bundle() - bundle.putLong("groupId", groupId) - bundle.putInt("requestCode", requestCode) - arguments = bundle + manager.showDialog { + putLong("groupId", groupId) + putInt("requestCode", requestCode) } - fragment.show(manager, tag) } + } private val binding by viewBinding(DialogBookGroupPickerBinding::bind) 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 39b8ae10c..06b29f925 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 @@ -539,7 +539,7 @@ class ReadBookActivity : ReadBookBaseActivity(), return true } R.id.menu_dict -> { - DictDialog.dict(supportFragmentManager, selectedText) + DictDialog.show(supportFragmentManager, selectedText) return true } } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkDialog.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkDialog.kt index 6602986ce..f71bbb168 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkDialog.kt @@ -11,6 +11,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Bookmark import io.legado.app.databinding.DialogBookmarkBinding import io.legado.app.lib.theme.primaryColor +import io.legado.app.utils.showDialog import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -21,11 +22,9 @@ class BookmarkDialog : BaseDialogFragment() { companion object { fun start(fragmentManager: FragmentManager, bookmark: Bookmark) { - BookmarkDialog().apply { - arguments = Bundle().apply { - putParcelable("bookmark", bookmark) - } - }.show(fragmentManager, "bookMarkDialog") + fragmentManager.showDialog { + putParcelable("bookmark", bookmark) + } } } diff --git a/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt b/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt index 68993a416..8d3019dbe 100644 --- a/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt +++ b/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt @@ -13,6 +13,7 @@ import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.databinding.DialogDictBinding import io.legado.app.utils.invisible +import io.legado.app.utils.showDialog import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -23,12 +24,10 @@ class DictDialog : BaseDialogFragment() { companion object { - fun dict(manager: FragmentManager, word: String) { - DictDialog().apply { - val bundle = Bundle() - bundle.putString("word", word) - arguments = bundle - }.show(manager, word) + fun show(manager: FragmentManager, word: String) { + manager.showDialog { + putString("word", word) + } } } diff --git a/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt b/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt index 1bf1aac41..8e01b8fc3 100644 --- a/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/document/FilePickerDialog.kt @@ -9,11 +9,11 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar -import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +import io.legado.app.base.BaseDialogFragment import io.legado.app.databinding.DialogFileChooserBinding import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.document.HandleFileContract.Companion.DIR @@ -26,7 +26,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import java.io.File -class FilePickerDialog : DialogFragment(), +class FilePickerDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener, FileAdapter.CallBack, PathAdapter.CallBack { @@ -88,8 +88,7 @@ class FilePickerDialog : DialogFragment(), return inflater.inflate(R.layout.dialog_file_chooser, container, true) } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { binding.toolBar.setBackgroundColor(primaryColor) view.setBackgroundResource(R.color.background_card) arguments?.let { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt index 96b2f85d7..b5aa82e91 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt @@ -138,7 +138,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf), override fun getItem(position: Int): Fragment { val group = bookGroups[position] - return BooksFragment.newInstance(position, group.groupId) + return BooksFragment(position, group.groupId) } override fun getCount(): Int { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt index 47f3fa92e..f1ed5656e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt @@ -37,18 +37,14 @@ import kotlin.math.max /** * 书架界面 */ -class BooksFragment : BaseFragment(R.layout.fragment_books), +class BooksFragment() : BaseFragment(R.layout.fragment_books), BaseBooksAdapter.CallBack { - companion object { - fun newInstance(position: Int, groupId: Long): BooksFragment { - return BooksFragment().apply { - val bundle = Bundle() - bundle.putInt("position", position) - bundle.putLong("groupId", groupId) - arguments = bundle - } - } + constructor(position: Int, groupId: Long) : this() { + val bundle = Bundle() + bundle.putInt("position", position) + bundle.putLong("groupId", groupId) + arguments = bundle } private val binding by viewBinding(FragmentBooksBinding::bind) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index d3a577781..a8bad2493 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -26,18 +26,14 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -class RssArticlesFragment : VMBaseFragment(R.layout.fragment_rss_articles), +class RssArticlesFragment() : VMBaseFragment(R.layout.fragment_rss_articles), BaseRssArticlesAdapter.CallBack { - companion object { - fun create(sortName: String, sortUrl: String): RssArticlesFragment { - return RssArticlesFragment().apply { - val bundle = Bundle() - bundle.putString("sortName", sortName) - bundle.putString("sortUrl", sortUrl) - arguments = bundle - } - } + constructor(sortName: String, sortUrl: String) : this() { + val bundle = Bundle() + bundle.putString("sortName", sortName) + bundle.putString("sortUrl", sortUrl) + arguments = bundle } private val binding by viewBinding(FragmentRssArticlesBinding::bind) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index f92e98f1f..f3c22e7a5 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -135,7 +135,7 @@ class RssSortActivity : VMBaseActivity