diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index d3a6ecc0a..6a0a919db 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -18,10 +18,7 @@ import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.SimpleExoPlayer import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.AppConst -import io.legado.app.constant.EventBus -import io.legado.app.constant.IntentAction -import io.legado.app.constant.Status +import io.legado.app.constant.* import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter @@ -251,14 +248,12 @@ class AudioPlayService : BaseService(), super.onPlayerError(error) AudioPlay.status = Status.STOP postEvent(EventBus.AUDIO_STATE, Status.STOP) + val errorMsg = "音频播放出错\n${error.errorCodeName} ${error.errorCode}" + AppLog.put(errorMsg, error) + toastOnUi(errorMsg) error.printOnDebug() } - override fun onPlayerErrorChanged(error: PlaybackException?) { - super.onPlayerErrorChanged(error) - postEvent(EventBus.AUDIO_ERROR, error?.localizedMessage) - } - private fun setTimer(minute: Int) { timeMinute = minute doDs() diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index e88b8900e..9a9550536 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -86,7 +86,7 @@ class AboutFragment : PreferenceFragmentCompat() { private fun checkUpdate() { AppUpdate.checkFromGitHub(lifecycleScope) { newVersion, updateBody, url, name -> - childFragmentManager.showDialog( + showDialogFragment( UpdateDialog(newVersion, updateBody, url, name) ) } diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index ae92e78f6..75fd0c9af 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -5,7 +5,7 @@ import androidx.activity.viewModels import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.ui.book.read.ReadBookActivity -import io.legado.app.utils.showDialog +import io.legado.app.utils.showDialogFragment import io.legado.app.utils.startActivity import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -27,17 +27,17 @@ class FileAssociationActivity : } viewModel.importBookSourceLive.observe(this) { binding.rotateLoading.hide() - supportFragmentManager.showDialog(ImportBookSourceDialog(it, true)) + showDialogFragment(ImportBookSourceDialog(it, true)) } viewModel.importRssSourceLive.observe(this) { binding.rotateLoading.hide() - supportFragmentManager.showDialog( + showDialogFragment( ImportRssSourceDialog(it, true) ) } viewModel.importReplaceRuleLive.observe(this) { binding.rotateLoading.hide() - supportFragmentManager.showDialog(ImportReplaceRuleDialog(it, true)) + showDialogFragment(ImportReplaceRuleDialog(it, true)) } viewModel.errorLiveData.observe(this, { binding.rotateLoading.hide() diff --git a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt index 8e485b8ca..e9edcfaae 100644 --- a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt @@ -6,7 +6,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.lib.dialogs.alert -import io.legado.app.utils.showDialog +import io.legado.app.utils.showDialogFragment import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -23,13 +23,13 @@ class OnLineImportActivity : override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.successLive.observe(this) { when (it.first) { - "bookSource" -> supportFragmentManager.showDialog( + "bookSource" -> showDialogFragment( ImportBookSourceDialog(it.second, true) ) - "rssSource" -> supportFragmentManager.showDialog( + "rssSource" -> showDialogFragment( ImportRssSourceDialog(it.second, true) ) - "replaceRule" -> supportFragmentManager.showDialog( + "replaceRule" -> showDialogFragment( ImportReplaceRuleDialog(it.second, true) ) } @@ -44,13 +44,13 @@ class OnLineImportActivity : return } when (it.path) { - "/bookSource" -> supportFragmentManager.showDialog( + "/bookSource" -> showDialogFragment( ImportBookSourceDialog(url, true) ) - "/rssSource" -> supportFragmentManager.showDialog( + "/rssSource" -> showDialogFragment( ImportRssSourceDialog(url, true) ) - "/replaceRule" -> supportFragmentManager.showDialog( + "/replaceRule" -> showDialogFragment( ImportReplaceRuleDialog(url, true) ) "/textTocRule" -> viewModel.getText(url) { json -> @@ -66,13 +66,13 @@ class OnLineImportActivity : viewModel.importReadConfig(bytes, this::finallyDialog) } "/importonline" -> when (it.host) { - "booksource" -> supportFragmentManager.showDialog( + "booksource" -> showDialogFragment( ImportBookSourceDialog(url, true) ) - "rsssource" -> supportFragmentManager.showDialog( + "rsssource" -> showDialogFragment( ImportRssSourceDialog(url, true) ) - "replace" -> supportFragmentManager.showDialog( + "replace" -> showDialogFragment( ImportReplaceRuleDialog(url, true) ) else -> { diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 758424c32..377f77834 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -26,7 +26,7 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.cnCompare import io.legado.app.utils.getPrefInt -import io.legado.app.utils.showDialog +import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job @@ -144,7 +144,7 @@ class ArrangeBookActivity : VMBaseActivity supportFragmentManager.showDialog() + R.id.menu_group_manage -> showDialogFragment() else -> if (item.groupId == R.id.menu_group) { binding.titleBar.subtitle = item.title groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 @@ -180,7 +180,7 @@ class ArrangeBookActivity : VMBaseActivity AudioPlay.book?.let { - supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) + showDialogFragment(ChangeSourceDialog(it.name, it.author)) } R.id.menu_login -> AudioPlay.bookSource?.let { startActivity { @@ -106,6 +107,7 @@ class AudioPlayActivity : putExtra("sourceUrl", it.bookSourceUrl) } } + R.id.menu_log -> showDialogFragment() } return super.onCompatOptionsItemSelected(item) } @@ -221,9 +223,6 @@ class AudioPlayActivity : playButton() } } - observeEventSticky(EventBus.AUDIO_ERROR) { - binding.tvErrorMessage.text = it - } observeEventSticky(EventBus.AUDIO_STATE) { AudioPlay.status = it if (it == Status.PLAY) { diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 8790f19e1..5b4a72ed4 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -134,7 +134,7 @@ class CacheActivity : VMBaseActivity() R.id.menu_export_file_name -> alertExportFileName() R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_charset -> showCharsetConfig() - R.id.menu_log -> supportFragmentManager.showDialog() + R.id.menu_log -> showDialogFragment() else -> if (item.groupId == R.id.menu_group) { binding.titleBar.subtitle = item.title groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 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 764814918..b33cdd4f5 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 @@ -25,7 +25,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.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.visible import io.legado.app.utils.windowSize @@ -90,7 +90,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { - R.id.menu_add -> childFragmentManager.showDialog(GroupEditDialog()) + R.id.menu_add -> showDialogFragment(GroupEditDialog()) } return true } @@ -122,7 +122,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener binding.run { tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { bookGroup -> - childFragmentManager.showDialog( + showDialogFragment( GroupEditDialog(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 ffe3a3836..8267f4eee 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 @@ -25,7 +25,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.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.windowSize import kotlinx.coroutines.flow.collect @@ -104,7 +104,7 @@ class GroupSelectDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListene override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { - R.id.menu_add -> childFragmentManager.showDialog( + R.id.menu_add -> showDialogFragment( GroupEditDialog() ) } @@ -148,7 +148,7 @@ class GroupSelectDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListene } } tvEdit.setOnClickListener { - childFragmentManager.showDialog( + showDialogFragment( GroupEditDialog(getItem(holder.layoutPosition)) ) } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 91ef166cb..1f015fa9c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -181,7 +181,7 @@ class BookInfoActivity : } } R.id.menu_clear_cache -> viewModel.clearCache() - R.id.menu_log -> supportFragmentManager.showDialog() + R.id.menu_log -> showDialogFragment() } return super.onCompatOptionsItemSelected(item) } @@ -255,7 +255,7 @@ class BookInfoActivity : private fun initOnClick() = binding.run { ivCover.setOnClickListener { viewModel.bookData.value?.let { - supportFragmentManager.showDialog( + showDialogFragment( ChangeCoverDialog(it.name, it.author) ) } @@ -283,7 +283,7 @@ class BookInfoActivity : } tvChangeSource.setOnClickListener { viewModel.bookData.value?.let { - supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) + showDialogFragment(ChangeSourceDialog(it.name, it.author)) } } tvTocView.setOnClickListener { @@ -299,7 +299,7 @@ class BookInfoActivity : } tvChangeGroup.setOnClickListener { viewModel.bookData.value?.let { - supportFragmentManager.showDialog( + showDialogFragment( GroupSelectDialog(it.group) ) } diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index ea36d9c4f..9a7ebc192 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -52,7 +52,7 @@ class BookInfoEditActivity : private fun initEvent() = binding.run { tvChangeCover.setOnClickListener { viewModel.bookData.value?.let { - supportFragmentManager.showDialog( + showDialogFragment( ChangeCoverDialog(it.name, it.author) ) } diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt similarity index 74% rename from app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt rename to app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt index c332fb72e..6e5ba715b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt @@ -1,10 +1,9 @@ -package io.legado.app.ui.widget.dialog +package io.legado.app.ui.book.read import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.databinding.DialogPhotoViewBinding @@ -13,23 +12,13 @@ import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.utils.viewbindingdelegate.viewBinding -class PhotoDialog : BaseDialogFragment() { +class PhotoDialog() : BaseDialogFragment() { - companion object { - - fun show( - fragmentManager: FragmentManager, - chapterIndex: Int, - src: String, - ) { - PhotoDialog().apply { - val bundle = Bundle() - bundle.putInt("chapterIndex", chapterIndex) - bundle.putString("src", src) - arguments = bundle - }.show(fragmentManager, "photoDialog") + constructor(chapterIndex: Int, src: String) : this() { + arguments = Bundle().apply { + putInt("chapterIndex", chapterIndex) + putString("src", src) } - } private val binding by viewBinding(DialogPhotoViewBinding::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 c1010244e..c94c9b11e 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 @@ -224,7 +224,7 @@ class ReadBookActivity : ReadBookBaseActivity(), R.id.menu_change_source -> { binding.readMenu.runMenuOut() BookRead.book?.let { - supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) + showDialogFragment(ChangeSourceDialog(it.name, it.author)) } } R.id.menu_refresh -> { @@ -249,7 +249,7 @@ class ReadBookActivity : ReadBookBaseActivity(), chapterName = page.title bookText = page.text.trim() } - supportFragmentManager.showDialog(BookmarkDialog(bookmark)) + showDialogFragment(BookmarkDialog(bookmark)) } } R.id.menu_copy_text -> @@ -277,7 +277,7 @@ class ReadBookActivity : ReadBookBaseActivity(), putExtra("author", it.author) } } - R.id.menu_toc_regex -> supportFragmentManager.showDialog( + R.id.menu_toc_regex -> showDialogFragment( TocRegexDialog(BookRead.book?.tocUrl) ) R.id.menu_reverse_content -> BookRead.book?.let { @@ -511,7 +511,7 @@ class ReadBookActivity : ReadBookBaseActivity(), if (bookmark == null) { toastOnUi(R.string.create_bookmark_error) } else { - supportFragmentManager.showDialog(BookmarkDialog(bookmark)) + showDialogFragment(BookmarkDialog(bookmark)) } return true } @@ -538,7 +538,7 @@ class ReadBookActivity : ReadBookBaseActivity(), return true } R.id.menu_dict -> { - supportFragmentManager.showDialog(DictDialog(selectedText)) + showDialogFragment(DictDialog(selectedText)) return true } } @@ -646,7 +646,7 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun showActionMenu() { when { BaseReadAloudService.isRun -> showReadAloudDialog() - isAutoPage -> supportFragmentManager.showDialog() + isAutoPage -> showDialogFragment() else -> binding.readMenu.runMenuIn() } } @@ -660,7 +660,7 @@ class ReadBookActivity : ReadBookBaseActivity(), * 显示朗读菜单 */ override fun showReadAloudDialog() { - supportFragmentManager.showDialog() + showDialogFragment() } /** @@ -761,14 +761,14 @@ class ReadBookActivity : ReadBookBaseActivity(), * 显示阅读样式配置 */ override fun showReadStyle() { - supportFragmentManager.showDialog() + showDialogFragment() } /** * 显示更多设置 */ override fun showMoreSetting() { - supportFragmentManager.showDialog() + showDialogFragment() } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index db7a661b7..0e078f1b9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -95,7 +95,7 @@ class ReadAloudConfigDialog : DialogFragment() { override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - PreferKey.ttsEngine -> childFragmentManager.showDialog(SpeakEngineDialog()) + PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog()) } return super.onPreferenceTreeClick(preference) } 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 24944c641..dd4212382 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 @@ -110,7 +110,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { postEvent(EventBus.UP_CONFIG, true) } tvTextFont.setOnClickListener { - childFragmentManager.showDialog() + showDialogFragment() } tvTextIndent.setOnClickListener { context?.selector( diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index ce6ea8b27..68e049930 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -12,17 +12,14 @@ import io.legado.app.data.entities.Bookmark import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.model.BookRead +import io.legado.app.ui.book.read.PhotoDialog import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.ui.book.read.page.provider.TextPageFactory -import io.legado.app.ui.widget.dialog.PhotoDialog -import io.legado.app.utils.activity -import io.legado.app.utils.getCompatColor -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.toastOnUi +import io.legado.app.utils.* import kotlin.math.min /** @@ -235,9 +232,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (!selectAble) return touch(x, y) { relativePos, textPage, _, lineIndex, _, charIndex, textChar -> if (textChar.isImage) { - activity?.supportFragmentManager?.let { - PhotoDialog.show(it, textPage.chapterIndex, textChar.charData) - } + activity?.showDialogFragment(PhotoDialog(textPage.chapterIndex, textChar.charData)) } else { textChar.selected = true invalidate() 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 0f70d4902..13d946c82 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 @@ -62,13 +62,13 @@ class BookSourceActivity : VMBaseActivity uri ?: return@registerForActivityResult try { uri.readText(this)?.let { - supportFragmentManager.showDialog(ImportBookSourceDialog(it)) + showDialogFragment(ImportBookSourceDialog(it)) } } catch (e: Exception) { toastOnUi("readTextError:${e.localizedMessage}") @@ -440,7 +440,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.fragment_bookmark } override fun onLongClick(bookmark: Bookmark) { - childFragmentManager.showDialog(BookmarkDialog(bookmark)) + showDialogFragment(BookmarkDialog(bookmark)) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt index b300c8093..80778423e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt @@ -69,7 +69,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment startActivity() R.id.menu_update_toc -> activityViewModel.upToc(books) R.id.menu_bookshelf_layout -> configBookshelf() - R.id.menu_group_manage -> childFragmentManager.showDialog() + R.id.menu_group_manage -> showDialogFragment() R.id.menu_add_local -> startActivity() R.id.menu_add_url -> addBookByUrl() R.id.menu_arrange_bookshelf -> startActivity { @@ -89,7 +89,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment importBookshelfAlert(groupId) - R.id.menu_log -> childFragmentManager.showDialog() + R.id.menu_log -> showDialogFragment() } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index 99a08e7bc..f7dcb8d12 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -192,7 +192,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), putExtra("name", item.name) putExtra("author", item.author) } - is BookGroup -> childFragmentManager.showDialog(GroupEditDialog(item)) + is BookGroup -> showDialogFragment(GroupEditDialog(item)) } } 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 f1661993e..5ce76fbcb 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 @@ -61,7 +61,7 @@ class ReplaceRuleActivity : VMBaseActivity kotlin.runCatching { uri?.readText(this)?.let { - supportFragmentManager.showDialog( + showDialogFragment( ImportReplaceRuleDialog(it) ) } @@ -283,7 +283,7 @@ class ReplaceRuleActivity : VMBaseActivity kotlin.runCatching { uri?.readText(this)?.let { - supportFragmentManager.showDialog( + showDialogFragment( ImportRssSourceDialog(it) ) } @@ -290,7 +290,7 @@ class RssSourceActivity : VMBaseActivity(), override fun openSubscription(ruleSub: RuleSub) { when (ruleSub.type) { - 0 -> supportFragmentManager.showDialog( + 0 -> showDialogFragment( ImportBookSourceDialog(ruleSub.url) ) - 1 -> supportFragmentManager.showDialog( + 1 -> showDialogFragment( ImportRssSourceDialog(ruleSub.url) ) - 2 -> supportFragmentManager.showDialog( + 2 -> showDialogFragment( ImportReplaceRuleDialog(ruleSub.url) ) } diff --git a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt index 2fe4b5425..9546c7705 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -2,11 +2,28 @@ package io.legado.app.utils import android.app.Activity import android.os.Build +import android.os.Bundle import android.util.DisplayMetrics import android.view.View import android.view.ViewGroup import android.view.WindowInsets import android.view.WindowMetrics +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.DialogFragment + +inline fun AppCompatActivity.showDialogFragment( + arguments: Bundle.() -> Unit = {} +) { + val dialog = T::class.java.newInstance() + val bundle = Bundle() + bundle.apply(arguments) + dialog.arguments = bundle + dialog.show(supportFragmentManager, T::class.simpleName) +} + +fun AppCompatActivity.showDialogFragment(dialogFragment: DialogFragment) { + dialogFragment.show(supportFragmentManager, dialogFragment::class.simpleName) +} val Activity.windowSize: DisplayMetrics get() { diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index 195903cf9..691fa833d 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -12,20 +12,19 @@ import androidx.annotation.DrawableRes import androidx.core.content.edit import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentManager -inline fun FragmentManager.showDialog( +inline fun Fragment.showDialogFragment( arguments: Bundle.() -> Unit = {} ) { val dialog = T::class.java.newInstance() val bundle = Bundle() bundle.apply(arguments) dialog.arguments = bundle - dialog.show(this, T::class.simpleName) + dialog.show(childFragmentManager, T::class.simpleName) } -fun FragmentManager.showDialog(dialogFragment: DialogFragment) { - dialogFragment.show(this, dialogFragment::class.simpleName) +fun Fragment.showDialogFragment(dialogFragment: DialogFragment) { + dialogFragment.show(childFragmentManager, dialogFragment::class.simpleName) } fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = diff --git a/app/src/main/res/layout/activity_audio_play.xml b/app/src/main/res/layout/activity_audio_play.xml index b7e232627..20c64aba6 100644 --- a/app/src/main/res/layout/activity_audio_play.xml +++ b/app/src/main/res/layout/activity_audio_play.xml @@ -54,18 +54,6 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/title_bar" /> - - + + \ No newline at end of file