pull/1395/head
gedoor 3 years ago
parent 0c670fdbca
commit bd02f5ef5d
  1. 10
      app/src/main/java/io/legado/app/ui/dict/DictDialog.kt
  2. 10
      app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt
  3. 11
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt

@ -1,8 +1,6 @@
package io.legado.app.ui.dict package io.legado.app.ui.dict
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.Html
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -12,6 +10,7 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogDictBinding import io.legado.app.databinding.DialogDictBinding
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.setHtml
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
@ -53,12 +52,7 @@ class DictDialog() : BaseDialogFragment() {
} }
viewModel.dictHtmlData.observe(viewLifecycleOwner) { viewModel.dictHtmlData.observe(viewLifecycleOwner) {
binding.rotateLoading.invisible() binding.rotateLoading.invisible()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { binding.tvDict.setHtml(it)
binding.tvDict.text = Html.fromHtml(it, Html.FROM_HTML_MODE_LEGACY)
} else {
@Suppress("DEPRECATION")
binding.tvDict.text = Html.fromHtml(it)
}
} }
viewModel.dict(word) viewModel.dict(word)

@ -1,14 +1,13 @@
package io.legado.app.ui.widget.dialog package io.legado.app.ui.widget.dialog
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.Html
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 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.DialogTextViewBinding import io.legado.app.databinding.DialogTextViewBinding
import io.legado.app.utils.setHtml
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 io.noties.markwon.Markwon import io.noties.markwon.Markwon
@ -70,12 +69,7 @@ class TextDialog() : BaseDialogFragment() {
.build() .build()
.setMarkdown(binding.textView, content) .setMarkdown(binding.textView, content)
} }
Mode.HTML.name -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Mode.HTML.name -> binding.textView.setHtml(content)
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 else -> binding.textView.text = content
} }
time = it.getLong("time", 0L) time = it.getLong("time", 0L)

@ -5,11 +5,13 @@ import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.os.Build import android.os.Build
import android.text.Html
import android.view.View import android.view.View
import android.view.View.* import android.view.View.*
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.RadioGroup import android.widget.RadioGroup
import android.widget.SeekBar import android.widget.SeekBar
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuPopupHelper import androidx.appcompat.view.menu.MenuPopupHelper
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
@ -103,6 +105,15 @@ fun RadioGroup.checkByIndex(index: Int) {
check(get(index).id) check(get(index).id)
} }
fun TextView.setHtml(html: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
text = Html.fromHtml(html, Html.FROM_HTML_MODE_COMPACT)
} else {
@Suppress("DEPRECATION")
text = Html.fromHtml(html)
}
}
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
fun PopupMenu.show(x: Int, y: Int) { fun PopupMenu.show(x: Int, y: Int) {
kotlin.runCatching { kotlin.runCatching {

Loading…
Cancel
Save