From 2a6177e51df7f79bbfcdc2426d6e6bb02ce1d84a Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 30 Sep 2021 15:54:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/about/AboutFragment.kt | 4 +- .../io/legado/app/ui/about/AppLogDialog.kt | 3 +- .../app/ui/book/read/ReadBookActivity.kt | 7 +-- .../ui/book/read/config/SpeakEngineDialog.kt | 2 +- .../source/debug/BookSourceDebugActivity.kt | 15 +++--- .../source/edit/BookSourceEditActivity.kt | 4 +- .../book/source/manage/BookSourceActivity.kt | 2 +- .../app/ui/config/BackupConfigFragment.kt | 2 +- .../io/legado/app/ui/main/MainActivity.kt | 5 +- .../io/legado/app/ui/main/my/MyFragment.kt | 2 +- .../app/ui/replace/ReplaceRuleActivity.kt | 2 +- .../ui/replace/edit/ReplaceEditActivity.kt | 3 +- .../source/debug/RssSourceDebugActivity.kt | 7 ++- .../rss/source/edit/RssSourceEditActivity.kt | 4 +- .../ui/rss/source/manage/RssSourceActivity.kt | 2 +- .../legado/app/ui/widget/dialog/TextDialog.kt | 49 ++++++++++--------- .../app/ui/widget/dialog/TextListDialog.kt | 15 ++---- 17 files changed, 63 insertions(+), 65 deletions(-) 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 9a9550536..a9e529e9a 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 @@ -81,7 +81,7 @@ class AboutFragment : PreferenceFragmentCompat() { private fun showUpdateLog() { val log = String(requireContext().assets.open("updateLog.md").readBytes()) - TextDialog.show(childFragmentManager, log, TextDialog.MD) + showDialogFragment(TextDialog(log, TextDialog.Mode.MD)) } private fun checkUpdate() { @@ -133,7 +133,7 @@ class AboutFragment : PreferenceFragmentCompat() { } context?.selector(R.string.crash_log, crashLogNames) { _, select -> crashLogs?.getOrNull(select)?.let { logFile -> - TextDialog.show(childFragmentManager, logFile.readText()) + showDialogFragment(TextDialog(logFile.readText())) } } } diff --git a/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt index 831f1e740..add61cd9e 100644 --- a/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt +++ b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt @@ -16,6 +16,7 @@ import io.legado.app.databinding.ItemAppLogBinding import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.LogUtils +import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.windowSize import splitties.views.onClick @@ -76,7 +77,7 @@ class AppLogDialog : BaseDialogFragment() { binding.root.onClick { getItem(holder.layoutPosition)?.let { item -> item.third?.let { - TextDialog.show(childFragmentManager, it.stackTraceToString()) + showDialogFragment(TextDialog(it.stackTraceToString())) } } } 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 c94c9b11e..2b9a5600f 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 @@ -252,8 +252,9 @@ class ReadBookActivity : ReadBookBaseActivity(), showDialogFragment(BookmarkDialog(bookmark)) } } - R.id.menu_copy_text -> - TextDialog.show(supportFragmentManager, BookRead.curTextChapter?.getContent()) + R.id.menu_copy_text -> showDialogFragment( + TextDialog(BookRead.curTextChapter?.getContent()) + ) R.id.menu_update_toc -> BookRead.book?.let { loadChapterList(it) } @@ -653,7 +654,7 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun showReadMenuHelp() { val text = String(assets.open("help/readMenuHelp.md").readBytes()) - TextDialog.show(supportFragmentManager, text, TextDialog.MD) + showDialogFragment(TextDialog(text, TextDialog.Mode.MD)) } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index ebc44b1e0..0b5b74236 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -205,7 +205,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener val helpStr = String( requireContext().assets.open("help/httpTTSHelp.md").readBytes() ) - TextDialog.show(childFragmentManager, helpStr, TextDialog.MD) + showDialogFragment(TextDialog(helpStr, TextDialog.Mode.MD)) } }.show() } diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index 3b5fe0b2c..998bb81c8 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -14,6 +14,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.widget.dialog.TextDialog +import io.legado.app.utils.showDialogFragment import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.launch @@ -129,14 +130,10 @@ class BookSourceDebugActivity : VMBaseActivity qrCodeResult.launch(null) - R.id.menu_search_src -> - TextDialog.show(supportFragmentManager, viewModel.searchSrc) - R.id.menu_book_src -> - TextDialog.show(supportFragmentManager, viewModel.bookSrc) - R.id.menu_toc_src -> - TextDialog.show(supportFragmentManager, viewModel.tocSrc) - R.id.menu_content_src -> - TextDialog.show(supportFragmentManager, viewModel.contentSrc) + R.id.menu_search_src -> showDialogFragment(TextDialog(viewModel.searchSrc)) + R.id.menu_book_src -> showDialogFragment(TextDialog(viewModel.bookSrc)) + R.id.menu_toc_src -> showDialogFragment(TextDialog(viewModel.tocSrc)) + R.id.menu_content_src -> showDialogFragment(TextDialog(viewModel.contentSrc)) R.id.menu_help -> showHelp() } return super.onCompatOptionsItemSelected(item) @@ -144,7 +141,7 @@ class BookSourceDebugActivity : VMBaseActivity(), LocalConfig.versionCode = appInfo.versionCode if (LocalConfig.isFirstOpenApp) { val text = String(assets.open("help/appHelp.md").readBytes()) - TextDialog.show(supportFragmentManager, text, TextDialog.MD) + showDialogFragment(TextDialog(text, TextDialog.Mode.MD)) } else if (!BuildConfig.DEBUG) { val log = String(assets.open("updateLog.md").readBytes()) - TextDialog.show(supportFragmentManager, log, TextDialog.MD) + showDialogFragment(TextDialog(log, TextDialog.Mode.MD)) } viewModel.upVersion() } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 8261fa726..f92e3fa40 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -51,7 +51,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { when (item.itemId) { R.id.menu_help -> { val text = String(requireContext().assets.open("help/appHelp.md").readBytes()) - TextDialog.show(childFragmentManager, text, TextDialog.MD) + showDialogFragment(TextDialog(text, TextDialog.Mode.MD)) } } } 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 5ce76fbcb..659f6afe3 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 @@ -294,7 +294,7 @@ class ReplaceRuleActivity : VMBaseActivity - TextDialog.show(supportFragmentManager, viewModel.listSrc) - R.id.menu_content_src -> - TextDialog.show(supportFragmentManager, viewModel.contentSrc) + R.id.menu_list_src -> showDialogFragment(TextDialog(viewModel.listSrc)) + R.id.menu_content_src -> showDialogFragment(TextDialog(viewModel.contentSrc)) } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index b3f165a50..e5fe77b04 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -237,12 +237,12 @@ class RssSourceEditActivity : private fun showRuleHelp() { val mdText = String(assets.open("help/ruleHelp.md").readBytes()) - TextDialog.show(supportFragmentManager, mdText, TextDialog.MD) + showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD)) } private fun showRegexHelp() { val mdText = String(assets.open("help/regexHelp.md").readBytes()) - TextDialog.show(supportFragmentManager, mdText, TextDialog.MD) + showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD)) } private fun showKeyboardTopPopupWindow() { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 9e99bd1d6..cbc9146dc 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -256,7 +256,7 @@ class RssSourceActivity : VMBaseActivity binding.textView.post { + when (it.getString("mode")) { + Mode.MD.name -> binding.textView.post { Markwon.builder(requireContext()) .usePlugin(GlideImagesPlugin.create(requireContext())) .usePlugin(HtmlPlugin.create()) @@ -73,6 +70,12 @@ class TextDialog : BaseDialogFragment() { .build() .setMarkdown(binding.textView, content) } + Mode.HTML.name -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + binding.textView.text = Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY) + } else { + @Suppress("DEPRECATION") + binding.textView.text = Html.fromHtml(content) + } else -> binding.textView.text = content } time = it.getLong("time", 0L) diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt index 690cc6413..a6f2b01cb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -16,16 +15,12 @@ import io.legado.app.databinding.ItemLogBinding import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.windowSize -class TextListDialog : BaseDialogFragment() { +class TextListDialog() : BaseDialogFragment() { - companion object { - fun show(fragmentManager: FragmentManager, title: String, values: ArrayList) { - TextListDialog().apply { - val bundle = Bundle() - bundle.putString("title", title) - bundle.putStringArrayList("values", values) - arguments = bundle - }.show(fragmentManager, "textListDialog") + constructor(title: String, values: ArrayList) : this() { + arguments = Bundle().apply { + putString("title", title) + putStringArrayList("values", values) } }