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 1a4322da6..5ac8c49f6 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 @@ -42,7 +42,7 @@ import kotlin.collections.ArrayList class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: GroupViewModel private lateinit var adapter: GroupAdapter - private var callBack: CallBack? = null + private val callBack: CallBack? get() = parentFragment as? CallBack override fun onStart() { super.onStart() @@ -62,19 +62,12 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - callBack = parentFragment as? CallBack + tool_bar.title = getString(R.string.group_manage) initData() + initMenu() } private fun initData() { - tool_bar.title = getString(R.string.group_manage) - tool_bar.inflateMenu(R.menu.book_group_manage) - tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) - tool_bar.setOnMenuItemClickListener(this) - tool_bar.menu.findItem(R.id.menu_group_local) - .isChecked = AppConst.bookGroupLocalShow - tool_bar.menu.findItem(R.id.menu_group_audio) - .isChecked = AppConst.bookGroupAudioShow adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration(VerticalDivider(requireContext())) @@ -90,6 +83,16 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) } + private fun initMenu() { + tool_bar.inflateMenu(R.menu.book_group_manage) + tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) + tool_bar.setOnMenuItemClickListener(this) + tool_bar.menu.findItem(R.id.menu_group_local) + .isChecked = AppConst.bookGroupLocalShow + tool_bar.menu.findItem(R.id.menu_group_audio) + .isChecked = AppConst.bookGroupAudioShow + } + override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_add -> addGroup() diff --git a/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt b/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt index 5978ab32b..f46195b1b 100644 --- a/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt +++ b/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt @@ -45,15 +45,16 @@ class BookshelfController { if (book == null || chapter == null) { returnData.setErrorMsg("未找到") } else { - var content = BookHelp.getContent(book, chapter) + val content: String? = BookHelp.getContent(book, chapter) if (content != null) { returnData.setData(content) } else { App.db.bookSourceDao().getBookSource(book.origin)?.let { source -> - content = runBlocking { + runBlocking { WebBook(source).getContentSuspend(book, chapter) + }.let { + returnData.setData(it) } - returnData.setErrorMsg(content) } ?: returnData.setErrorMsg("未找到书源") } }