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

@ -1,14 +1,13 @@
package io.legado.app.ui.widget.dialog
import android.os.Build
import android.os.Bundle
import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogTextViewBinding
import io.legado.app.utils.setHtml
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
import io.noties.markwon.Markwon
@ -70,12 +69,7 @@ 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)
}
Mode.HTML.name -> binding.textView.setHtml(content)
else -> binding.textView.text = content
}
time = it.getLong("time", 0L)

@ -5,11 +5,13 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import android.text.Html
import android.view.View
import android.view.View.*
import android.view.inputmethod.InputMethodManager
import android.widget.RadioGroup
import android.widget.SeekBar
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuPopupHelper
import androidx.appcompat.widget.PopupMenu
@ -103,6 +105,15 @@ fun RadioGroup.checkByIndex(index: Int) {
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")
fun PopupMenu.show(x: Int, y: Int) {
kotlin.runCatching {

Loading…
Cancel
Save