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 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()

@ -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)
)
}

@ -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()

@ -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 -> {

@ -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<ActivityArrangeBookBinding, ArrangeBo
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
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) {
binding.titleBar.subtitle = item.title
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) {
supportFragmentManager.showDialog(
showDialogFragment(
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.BookCover
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.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult
@ -93,7 +94,7 @@ class AudioPlayActivity :
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
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 {
startActivity<SourceLoginActivity> {
@ -106,6 +107,7 @@ class AudioPlayActivity :
putExtra("sourceUrl", it.bookSourceUrl)
}
}
R.id.menu_log -> showDialogFragment<AppLogDialog>()
}
return super.onCompatOptionsItemSelected(item)
}
@ -221,9 +223,6 @@ class AudioPlayActivity :
playButton()
}
}
observeEventSticky<String>(EventBus.AUDIO_ERROR) {
binding.tvErrorMessage.text = it
}
observeEventSticky<Int>(EventBus.AUDIO_STATE) {
AudioPlay.status = it
if (it == Status.PLAY) {

@ -134,7 +134,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
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<AppLogDialog>()
R.id.menu_log -> showDialogFragment<AppLogDialog>()
else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title
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.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)
)
}

@ -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))
)
}

@ -181,7 +181,7 @@ class BookInfoActivity :
}
}
R.id.menu_clear_cache -> viewModel.clearCache()
R.id.menu_log -> supportFragmentManager.showDialog<AppLogDialog>()
R.id.menu_log -> showDialogFragment<AppLogDialog>()
}
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)
)
}

@ -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)
)
}

@ -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)

@ -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<AutoReadDialog>()
isAutoPage -> showDialogFragment<AutoReadDialog>()
else -> binding.readMenu.runMenuIn()
}
}
@ -660,7 +660,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 显示朗读菜单
*/
override fun showReadAloudDialog() {
supportFragmentManager.showDialog<ReadAloudDialog>()
showDialogFragment<ReadAloudDialog>()
}
/**
@ -761,14 +761,14 @@ class ReadBookActivity : ReadBookBaseActivity(),
* 显示阅读样式配置
*/
override fun showReadStyle() {
supportFragmentManager.showDialog<ReadStyleDialog>()
showDialogFragment<ReadStyleDialog>()
}
/**
* 显示更多设置
*/
override fun showMoreSetting() {
supportFragmentManager.showDialog<MoreConfigDialog>()
showDialogFragment<MoreConfigDialog>()
}
/**

@ -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)
}

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

@ -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()

@ -62,13 +62,13 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private var snackBar: Snackbar? = null
private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
supportFragmentManager.showDialog(ImportBookSourceDialog(it))
showDialogFragment(ImportBookSourceDialog(it))
}
private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
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<ActivityBookSourceBinding, BookSourceV
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
supportFragmentManager.showDialog(ImportBookSourceDialog(it))
showDialogFragment(ImportBookSourceDialog(it))
}
}
cancelButton()

@ -13,7 +13,7 @@ import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.FragmentBookmarkBinding
import io.legado.app.lib.theme.ATH
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 kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
@ -68,6 +68,6 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_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_update_toc -> activityViewModel.upToc(books)
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_url -> addBookByUrl()
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_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("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 val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
supportFragmentManager.showDialog(
showDialogFragment(
ImportReplaceRuleDialog(it)
)
}
@ -74,7 +74,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
kotlin.runCatching {
uri?.readText(this)?.let {
supportFragmentManager.showDialog(
showDialogFragment(
ImportReplaceRuleDialog(it)
)
}
@ -283,7 +283,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
supportFragmentManager.showDialog(
showDialogFragment(
ImportReplaceRuleDialog(it)
)
}

@ -53,14 +53,14 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private var groupMenu: SubMenu? = null
private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
supportFragmentManager.showDialog(
showDialogFragment(
ImportRssSourceDialog(it)
)
}
private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
kotlin.runCatching {
uri?.readText(this)?.let {
supportFragmentManager.showDialog(
showDialogFragment(
ImportRssSourceDialog(it)
)
}
@ -290,7 +290,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
supportFragmentManager.showDialog(
showDialogFragment(
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.ImportRssSourceDialog
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.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
@ -71,13 +71,13 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
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)
)
}

@ -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 <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
get() {

@ -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 <reified T : DialogFragment> FragmentManager.showDialog(
inline fun <reified T : DialogFragment> 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) =

@ -54,18 +54,6 @@
app:layout_constraintRight_toRightOf="parent"
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
android:id="@+id/tv_sub_title"
android:layout_width="match_parent"

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