pull/1352/head
gedoor 3 years ago
parent bcf7f71a0f
commit b81ae218a4
  1. 13
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  2. 2
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  3. 8
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  4. 20
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt
  5. 6
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  6. 7
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  8. 6
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  9. 6
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  10. 8
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  11. 2
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  12. 23
      app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt
  13. 18
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  14. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  15. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  16. 11
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  17. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  18. 4
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt
  19. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
  20. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt
  21. 6
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  22. 6
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  23. 8
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  24. 17
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt
  25. 9
      app/src/main/java/io/legado/app/utils/FragmentExtensions.kt
  26. 12
      app/src/main/res/layout/activity_audio_play.xml
  27. 5
      app/src/main/res/menu/audio_play.xml

@ -18,10 +18,7 @@ import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.SimpleExoPlayer import com.google.android.exoplayer2.SimpleExoPlayer
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst import io.legado.app.constant.*
import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
@ -251,14 +248,12 @@ class AudioPlayService : BaseService(),
super.onPlayerError(error) super.onPlayerError(error)
AudioPlay.status = Status.STOP AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP) postEvent(EventBus.AUDIO_STATE, Status.STOP)
val errorMsg = "音频播放出错\n${error.errorCodeName} ${error.errorCode}"
AppLog.put(errorMsg, error)
toastOnUi(errorMsg)
error.printOnDebug() error.printOnDebug()
} }
override fun onPlayerErrorChanged(error: PlaybackException?) {
super.onPlayerErrorChanged(error)
postEvent(EventBus.AUDIO_ERROR, error?.localizedMessage)
}
private fun setTimer(minute: Int) { private fun setTimer(minute: Int) {
timeMinute = minute timeMinute = minute
doDs() doDs()

@ -86,7 +86,7 @@ class AboutFragment : PreferenceFragmentCompat() {
private fun checkUpdate() { private fun checkUpdate() {
AppUpdate.checkFromGitHub(lifecycleScope) { newVersion, updateBody, url, name -> AppUpdate.checkFromGitHub(lifecycleScope) { newVersion, updateBody, url, name ->
childFragmentManager.showDialog( showDialogFragment(
UpdateDialog(newVersion, updateBody, url, name) UpdateDialog(newVersion, updateBody, url, name)
) )
} }

@ -5,7 +5,7 @@ import androidx.activity.viewModels
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.ui.book.read.ReadBookActivity 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.startActivity
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -27,17 +27,17 @@ class FileAssociationActivity :
} }
viewModel.importBookSourceLive.observe(this) { viewModel.importBookSourceLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()
supportFragmentManager.showDialog(ImportBookSourceDialog(it, true)) showDialogFragment(ImportBookSourceDialog(it, true))
} }
viewModel.importRssSourceLive.observe(this) { viewModel.importRssSourceLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()
supportFragmentManager.showDialog( showDialogFragment(
ImportRssSourceDialog(it, true) ImportRssSourceDialog(it, true)
) )
} }
viewModel.importReplaceRuleLive.observe(this) { viewModel.importReplaceRuleLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()
supportFragmentManager.showDialog(ImportReplaceRuleDialog(it, true)) showDialogFragment(ImportReplaceRuleDialog(it, true))
} }
viewModel.errorLiveData.observe(this, { viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide() binding.rotateLoading.hide()

@ -6,7 +6,7 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.lib.dialogs.alert 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.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -23,13 +23,13 @@ class OnLineImportActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.successLive.observe(this) { viewModel.successLive.observe(this) {
when (it.first) { when (it.first) {
"bookSource" -> supportFragmentManager.showDialog( "bookSource" -> showDialogFragment(
ImportBookSourceDialog(it.second, true) ImportBookSourceDialog(it.second, true)
) )
"rssSource" -> supportFragmentManager.showDialog( "rssSource" -> showDialogFragment(
ImportRssSourceDialog(it.second, true) ImportRssSourceDialog(it.second, true)
) )
"replaceRule" -> supportFragmentManager.showDialog( "replaceRule" -> showDialogFragment(
ImportReplaceRuleDialog(it.second, true) ImportReplaceRuleDialog(it.second, true)
) )
} }
@ -44,13 +44,13 @@ class OnLineImportActivity :
return return
} }
when (it.path) { when (it.path) {
"/bookSource" -> supportFragmentManager.showDialog( "/bookSource" -> showDialogFragment(
ImportBookSourceDialog(url, true) ImportBookSourceDialog(url, true)
) )
"/rssSource" -> supportFragmentManager.showDialog( "/rssSource" -> showDialogFragment(
ImportRssSourceDialog(url, true) ImportRssSourceDialog(url, true)
) )
"/replaceRule" -> supportFragmentManager.showDialog( "/replaceRule" -> showDialogFragment(
ImportReplaceRuleDialog(url, true) ImportReplaceRuleDialog(url, true)
) )
"/textTocRule" -> viewModel.getText(url) { json -> "/textTocRule" -> viewModel.getText(url) { json ->
@ -66,13 +66,13 @@ class OnLineImportActivity :
viewModel.importReadConfig(bytes, this::finallyDialog) viewModel.importReadConfig(bytes, this::finallyDialog)
} }
"/importonline" -> when (it.host) { "/importonline" -> when (it.host) {
"booksource" -> supportFragmentManager.showDialog( "booksource" -> showDialogFragment(
ImportBookSourceDialog(url, true) ImportBookSourceDialog(url, true)
) )
"rsssource" -> supportFragmentManager.showDialog( "rsssource" -> showDialogFragment(
ImportRssSourceDialog(url, true) ImportRssSourceDialog(url, true)
) )
"replace" -> supportFragmentManager.showDialog( "replace" -> showDialogFragment(
ImportReplaceRuleDialog(url, true) ImportReplaceRuleDialog(url, true)
) )
else -> { else -> {

@ -26,7 +26,7 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.getPrefInt 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 io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -144,7 +144,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_group_manage -> supportFragmentManager.showDialog<GroupManageDialog>() R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>()
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title binding.titleBar.subtitle = item.title
groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0
@ -180,7 +180,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
} }
override fun selectGroup(requestCode: Int, groupId: Long) { override fun selectGroup(requestCode: Int, groupId: Long) {
supportFragmentManager.showDialog( showDialogFragment(
GroupSelectDialog(groupId, requestCode) GroupSelectDialog(groupId, requestCode)
) )
} }

@ -24,6 +24,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.model.AudioPlay import io.legado.app.model.AudioPlay
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.book.toc.TocActivityResult
@ -93,7 +94,7 @@ class AudioPlayActivity :
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_change_source -> AudioPlay.book?.let { R.id.menu_change_source -> AudioPlay.book?.let {
supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) showDialogFragment(ChangeSourceDialog(it.name, it.author))
} }
R.id.menu_login -> AudioPlay.bookSource?.let { R.id.menu_login -> AudioPlay.bookSource?.let {
startActivity<SourceLoginActivity> { startActivity<SourceLoginActivity> {
@ -106,6 +107,7 @@ class AudioPlayActivity :
putExtra("sourceUrl", it.bookSourceUrl) putExtra("sourceUrl", it.bookSourceUrl)
} }
} }
R.id.menu_log -> showDialogFragment<AppLogDialog>()
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
@ -221,9 +223,6 @@ class AudioPlayActivity :
playButton() playButton()
} }
} }
observeEventSticky<String>(EventBus.AUDIO_ERROR) {
binding.tvErrorMessage.text = it
}
observeEventSticky<Int>(EventBus.AUDIO_STATE) { observeEventSticky<Int>(EventBus.AUDIO_STATE) {
AudioPlay.status = it AudioPlay.status = it
if (it == Status.PLAY) { if (it == Status.PLAY) {

@ -134,7 +134,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
R.id.menu_export_file_name -> alertExportFileName() R.id.menu_export_file_name -> alertExportFileName()
R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_type -> showExportTypeConfig()
R.id.menu_export_charset -> showCharsetConfig() R.id.menu_export_charset -> showCharsetConfig()
R.id.menu_log -> supportFragmentManager.showDialog<AppLogDialog>() R.id.menu_log -> showDialogFragment<AppLogDialog>()
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title binding.titleBar.subtitle = item.title
groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0

@ -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.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint 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.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible import io.legado.app.utils.visible
import io.legado.app.utils.windowSize import io.legado.app.utils.windowSize
@ -90,7 +90,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.menu_add -> childFragmentManager.showDialog(GroupEditDialog()) R.id.menu_add -> showDialogFragment(GroupEditDialog())
} }
return true return true
} }
@ -122,7 +122,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
binding.run { binding.run {
tvEdit.setOnClickListener { tvEdit.setOnClickListener {
getItem(holder.layoutPosition)?.let { bookGroup -> getItem(holder.layoutPosition)?.let { bookGroup ->
childFragmentManager.showDialog( showDialogFragment(
GroupEditDialog(bookGroup) GroupEditDialog(bookGroup)
) )
} }

@ -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.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint 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.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize import io.legado.app.utils.windowSize
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
@ -104,7 +104,7 @@ class GroupSelectDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListene
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.menu_add -> childFragmentManager.showDialog( R.id.menu_add -> showDialogFragment(
GroupEditDialog() GroupEditDialog()
) )
} }
@ -148,7 +148,7 @@ class GroupSelectDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListene
} }
} }
tvEdit.setOnClickListener { tvEdit.setOnClickListener {
childFragmentManager.showDialog( showDialogFragment(
GroupEditDialog(getItem(holder.layoutPosition)) GroupEditDialog(getItem(holder.layoutPosition))
) )
} }

@ -181,7 +181,7 @@ class BookInfoActivity :
} }
} }
R.id.menu_clear_cache -> viewModel.clearCache() R.id.menu_clear_cache -> viewModel.clearCache()
R.id.menu_log -> supportFragmentManager.showDialog<AppLogDialog>() R.id.menu_log -> showDialogFragment<AppLogDialog>()
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
@ -255,7 +255,7 @@ class BookInfoActivity :
private fun initOnClick() = binding.run { private fun initOnClick() = binding.run {
ivCover.setOnClickListener { ivCover.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
supportFragmentManager.showDialog( showDialogFragment(
ChangeCoverDialog(it.name, it.author) ChangeCoverDialog(it.name, it.author)
) )
} }
@ -283,7 +283,7 @@ class BookInfoActivity :
} }
tvChangeSource.setOnClickListener { tvChangeSource.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) showDialogFragment(ChangeSourceDialog(it.name, it.author))
} }
} }
tvTocView.setOnClickListener { tvTocView.setOnClickListener {
@ -299,7 +299,7 @@ class BookInfoActivity :
} }
tvChangeGroup.setOnClickListener { tvChangeGroup.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
supportFragmentManager.showDialog( showDialogFragment(
GroupSelectDialog(it.group) GroupSelectDialog(it.group)
) )
} }

@ -52,7 +52,7 @@ class BookInfoEditActivity :
private fun initEvent() = binding.run { private fun initEvent() = binding.run {
tvChangeCover.setOnClickListener { tvChangeCover.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
supportFragmentManager.showDialog( showDialogFragment(
ChangeCoverDialog(it.name, it.author) ChangeCoverDialog(it.name, it.author)
) )
} }

@ -1,10 +1,9 @@
package io.legado.app.ui.widget.dialog package io.legado.app.ui.book.read
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogPhotoViewBinding 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 import io.legado.app.utils.viewbindingdelegate.viewBinding
class PhotoDialog : BaseDialogFragment() { class PhotoDialog() : BaseDialogFragment() {
companion object { constructor(chapterIndex: Int, src: String) : this() {
arguments = Bundle().apply {
fun show( putInt("chapterIndex", chapterIndex)
fragmentManager: FragmentManager, putString("src", src)
chapterIndex: Int,
src: String,
) {
PhotoDialog().apply {
val bundle = Bundle()
bundle.putInt("chapterIndex", chapterIndex)
bundle.putString("src", src)
arguments = bundle
}.show(fragmentManager, "photoDialog")
} }
} }
private val binding by viewBinding(DialogPhotoViewBinding::bind) private val binding by viewBinding(DialogPhotoViewBinding::bind)

@ -224,7 +224,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
R.id.menu_change_source -> { R.id.menu_change_source -> {
binding.readMenu.runMenuOut() binding.readMenu.runMenuOut()
BookRead.book?.let { BookRead.book?.let {
supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author)) showDialogFragment(ChangeSourceDialog(it.name, it.author))
} }
} }
R.id.menu_refresh -> { R.id.menu_refresh -> {
@ -249,7 +249,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
chapterName = page.title chapterName = page.title
bookText = page.text.trim() bookText = page.text.trim()
} }
supportFragmentManager.showDialog(BookmarkDialog(bookmark)) showDialogFragment(BookmarkDialog(bookmark))
} }
} }
R.id.menu_copy_text -> R.id.menu_copy_text ->
@ -277,7 +277,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
putExtra("author", it.author) putExtra("author", it.author)
} }
} }
R.id.menu_toc_regex -> supportFragmentManager.showDialog( R.id.menu_toc_regex -> showDialogFragment(
TocRegexDialog(BookRead.book?.tocUrl) TocRegexDialog(BookRead.book?.tocUrl)
) )
R.id.menu_reverse_content -> BookRead.book?.let { R.id.menu_reverse_content -> BookRead.book?.let {
@ -511,7 +511,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
if (bookmark == null) { if (bookmark == null) {
toastOnUi(R.string.create_bookmark_error) toastOnUi(R.string.create_bookmark_error)
} else { } else {
supportFragmentManager.showDialog(BookmarkDialog(bookmark)) showDialogFragment(BookmarkDialog(bookmark))
} }
return true return true
} }
@ -538,7 +538,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
return true return true
} }
R.id.menu_dict -> { R.id.menu_dict -> {
supportFragmentManager.showDialog(DictDialog(selectedText)) showDialogFragment(DictDialog(selectedText))
return true return true
} }
} }
@ -646,7 +646,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun showActionMenu() { override fun showActionMenu() {
when { when {
BaseReadAloudService.isRun -> showReadAloudDialog() BaseReadAloudService.isRun -> showReadAloudDialog()
isAutoPage -> supportFragmentManager.showDialog<AutoReadDialog>() isAutoPage -> showDialogFragment<AutoReadDialog>()
else -> binding.readMenu.runMenuIn() else -> binding.readMenu.runMenuIn()
} }
} }
@ -660,7 +660,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 显示朗读菜单 * 显示朗读菜单
*/ */
override fun showReadAloudDialog() { override fun showReadAloudDialog() {
supportFragmentManager.showDialog<ReadAloudDialog>() showDialogFragment<ReadAloudDialog>()
} }
/** /**
@ -761,14 +761,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 显示阅读样式配置 * 显示阅读样式配置
*/ */
override fun showReadStyle() { override fun showReadStyle() {
supportFragmentManager.showDialog<ReadStyleDialog>() showDialogFragment<ReadStyleDialog>()
} }
/** /**
* 显示更多设置 * 显示更多设置
*/ */
override fun showMoreSetting() { override fun showMoreSetting() {
supportFragmentManager.showDialog<MoreConfigDialog>() showDialogFragment<MoreConfigDialog>()
} }
/** /**

@ -95,7 +95,7 @@ class ReadAloudConfigDialog : DialogFragment() {
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
PreferKey.ttsEngine -> childFragmentManager.showDialog(SpeakEngineDialog()) PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog())
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }

@ -110,7 +110,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
tvTextFont.setOnClickListener { tvTextFont.setOnClickListener {
childFragmentManager.showDialog<FontSelectDialog>() showDialogFragment<FontSelectDialog>()
} }
tvTextIndent.setOnClickListener { tvTextIndent.setOnClickListener {
context?.selector( context?.selector(

@ -12,17 +12,14 @@ import io.legado.app.data.entities.Bookmark
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.model.BookRead 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.TextChar
import io.legado.app.ui.book.read.page.entities.TextLine 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.entities.TextPage
import io.legado.app.ui.book.read.page.provider.ChapterProvider 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.ImageProvider
import io.legado.app.ui.book.read.page.provider.TextPageFactory import io.legado.app.ui.book.read.page.provider.TextPageFactory
import io.legado.app.ui.widget.dialog.PhotoDialog import io.legado.app.utils.*
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 kotlin.math.min import kotlin.math.min
/** /**
@ -235,9 +232,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (!selectAble) return if (!selectAble) return
touch(x, y) { relativePos, textPage, _, lineIndex, _, charIndex, textChar -> touch(x, y) { relativePos, textPage, _, lineIndex, _, charIndex, textChar ->
if (textChar.isImage) { if (textChar.isImage) {
activity?.supportFragmentManager?.let { activity?.showDialogFragment(PhotoDialog(textPage.chapterIndex, textChar.charData))
PhotoDialog.show(it, textPage.chapterIndex, textChar.charData)
}
} else { } else {
textChar.selected = true textChar.selected = true
invalidate() invalidate()

@ -62,13 +62,13 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private var snackBar: Snackbar? = null private var snackBar: Snackbar? = null
private val qrResult = registerForActivityResult(QrCodeResult()) { private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
supportFragmentManager.showDialog(ImportBookSourceDialog(it)) showDialogFragment(ImportBookSourceDialog(it))
} }
private val importDoc = registerForActivityResult(HandleFileContract()) { uri -> private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
try { try {
uri.readText(this)?.let { uri.readText(this)?.let {
supportFragmentManager.showDialog(ImportBookSourceDialog(it)) showDialogFragment(ImportBookSourceDialog(it))
} }
} catch (e: Exception) { } catch (e: Exception) {
toastOnUi("readTextError:${e.localizedMessage}") toastOnUi("readTextError:${e.localizedMessage}")
@ -440,7 +440,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
supportFragmentManager.showDialog(ImportBookSourceDialog(it)) showDialogFragment(ImportBookSourceDialog(it))
} }
} }
cancelButton() cancelButton()

@ -13,7 +13,7 @@ import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.FragmentBookmarkBinding import io.legado.app.databinding.FragmentBookmarkBinding
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.showDialog import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
@ -68,6 +68,6 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_bookmark
} }
override fun onLongClick(bookmark: Bookmark) { override fun onLongClick(bookmark: Bookmark) {
childFragmentManager.showDialog(BookmarkDialog(bookmark)) showDialogFragment(BookmarkDialog(bookmark))
} }
} }

@ -69,7 +69,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
R.id.menu_search -> startActivity<SearchActivity>() R.id.menu_search -> startActivity<SearchActivity>()
R.id.menu_update_toc -> activityViewModel.upToc(books) R.id.menu_update_toc -> activityViewModel.upToc(books)
R.id.menu_bookshelf_layout -> configBookshelf() R.id.menu_bookshelf_layout -> configBookshelf()
R.id.menu_group_manage -> childFragmentManager.showDialog<GroupManageDialog>() R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>()
R.id.menu_add_local -> startActivity<ImportBookActivity>() R.id.menu_add_local -> startActivity<ImportBookActivity>()
R.id.menu_add_url -> addBookByUrl() R.id.menu_add_url -> addBookByUrl()
R.id.menu_arrange_bookshelf -> startActivity<ArrangeBookActivity> { R.id.menu_arrange_bookshelf -> startActivity<ArrangeBookActivity> {
@ -89,7 +89,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
} }
} }
R.id.menu_import_bookshelf -> importBookshelfAlert(groupId) R.id.menu_import_bookshelf -> importBookshelfAlert(groupId)
R.id.menu_log -> childFragmentManager.showDialog<AppLogDialog>() R.id.menu_log -> showDialogFragment<AppLogDialog>()
} }
} }

@ -192,7 +192,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
putExtra("name", item.name) putExtra("name", item.name)
putExtra("author", item.author) putExtra("author", item.author)
} }
is BookGroup -> childFragmentManager.showDialog(GroupEditDialog(item)) is BookGroup -> showDialogFragment(GroupEditDialog(item))
} }
} }

@ -61,7 +61,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private var dataInit = false private var dataInit = false
private val qrCodeResult = registerForActivityResult(QrCodeResult()) { private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
supportFragmentManager.showDialog( showDialogFragment(
ImportReplaceRuleDialog(it) ImportReplaceRuleDialog(it)
) )
} }
@ -74,7 +74,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private val importDoc = registerForActivityResult(HandleFileContract()) { uri -> private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
kotlin.runCatching { kotlin.runCatching {
uri?.readText(this)?.let { uri?.readText(this)?.let {
supportFragmentManager.showDialog( showDialogFragment(
ImportReplaceRuleDialog(it) ImportReplaceRuleDialog(it)
) )
} }
@ -283,7 +283,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
supportFragmentManager.showDialog( showDialogFragment(
ImportReplaceRuleDialog(it) ImportReplaceRuleDialog(it)
) )
} }

@ -53,14 +53,14 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
private val qrCodeResult = registerForActivityResult(QrCodeResult()) { private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
supportFragmentManager.showDialog( showDialogFragment(
ImportRssSourceDialog(it) ImportRssSourceDialog(it)
) )
} }
private val importDoc = registerForActivityResult(HandleFileContract()) { uri -> private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
kotlin.runCatching { kotlin.runCatching {
uri?.readText(this)?.let { uri?.readText(this)?.let {
supportFragmentManager.showDialog( showDialogFragment(
ImportRssSourceDialog(it) ImportRssSourceDialog(it)
) )
} }
@ -290,7 +290,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
supportFragmentManager.showDialog( showDialogFragment(
ImportRssSourceDialog(it) ImportRssSourceDialog(it)
) )
} }

@ -16,7 +16,7 @@ import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.association.ImportReplaceRuleDialog import io.legado.app.ui.association.ImportReplaceRuleDialog
import io.legado.app.ui.association.ImportRssSourceDialog import io.legado.app.ui.association.ImportRssSourceDialog
import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.showDialog import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -71,13 +71,13 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun openSubscription(ruleSub: RuleSub) { override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) { when (ruleSub.type) {
0 -> supportFragmentManager.showDialog( 0 -> showDialogFragment(
ImportBookSourceDialog(ruleSub.url) ImportBookSourceDialog(ruleSub.url)
) )
1 -> supportFragmentManager.showDialog( 1 -> showDialogFragment(
ImportRssSourceDialog(ruleSub.url) ImportRssSourceDialog(ruleSub.url)
) )
2 -> supportFragmentManager.showDialog( 2 -> showDialogFragment(
ImportReplaceRuleDialog(ruleSub.url) ImportReplaceRuleDialog(ruleSub.url)
) )
} }

@ -2,11 +2,28 @@ package io.legado.app.utils
import android.app.Activity import android.app.Activity
import android.os.Build import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowInsets import android.view.WindowInsets
import android.view.WindowMetrics import android.view.WindowMetrics
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
inline fun <reified T : DialogFragment> 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 val Activity.windowSize: DisplayMetrics
get() { get() {

@ -12,20 +12,19 @@ import androidx.annotation.DrawableRes
import androidx.core.content.edit import androidx.core.content.edit
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
inline fun <reified T : DialogFragment> FragmentManager.showDialog( inline fun <reified T : DialogFragment> Fragment.showDialogFragment(
arguments: Bundle.() -> Unit = {} arguments: Bundle.() -> Unit = {}
) { ) {
val dialog = T::class.java.newInstance() val dialog = T::class.java.newInstance()
val bundle = Bundle() val bundle = Bundle()
bundle.apply(arguments) bundle.apply(arguments)
dialog.arguments = bundle dialog.arguments = bundle
dialog.show(this, T::class.simpleName) dialog.show(childFragmentManager, T::class.simpleName)
} }
fun FragmentManager.showDialog(dialogFragment: DialogFragment) { fun Fragment.showDialogFragment(dialogFragment: DialogFragment) {
dialogFragment.show(this, dialogFragment::class.simpleName) dialogFragment.show(childFragmentManager, dialogFragment::class.simpleName)
} }
fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) =

@ -54,18 +54,6 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" /> app:layout_constraintTop_toBottomOf="@+id/title_bar" />
<TextView
android:id="@+id/tv_error_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:textColor="@color/md_white_1000"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@+id/tv_sub_title" />
<TextView <TextView
android:id="@+id/tv_sub_title" android:id="@+id/tv_sub_title"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -25,4 +25,9 @@
android:title="@string/edit_book_source" android:title="@string/edit_book_source"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_log"
android:title="@string/log"
app:showAsAction="never" />
</menu> </menu>
Loading…
Cancel
Save