|
|
|
@ -1,10 +1,11 @@ |
|
|
|
|
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 androidx.fragment.app.FragmentManager |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
|
import io.legado.app.databinding.DialogTextViewBinding |
|
|
|
@ -18,29 +19,25 @@ import kotlinx.coroutines.delay |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TextDialog : BaseDialogFragment() { |
|
|
|
|
class TextDialog() : BaseDialogFragment() { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
const val MD = 1 |
|
|
|
|
enum class Mode { |
|
|
|
|
MD, HTML, TEXT |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun show( |
|
|
|
|
fragmentManager: FragmentManager, |
|
|
|
|
content: String?, |
|
|
|
|
mode: Int = 0, |
|
|
|
|
time: Long = 0, |
|
|
|
|
autoClose: Boolean = false |
|
|
|
|
) { |
|
|
|
|
TextDialog().apply { |
|
|
|
|
val bundle = Bundle() |
|
|
|
|
bundle.putString("content", content) |
|
|
|
|
bundle.putInt("mode", mode) |
|
|
|
|
bundle.putLong("time", time) |
|
|
|
|
arguments = bundle |
|
|
|
|
isCancelable = false |
|
|
|
|
this.autoClose = autoClose |
|
|
|
|
}.show(fragmentManager, "textDialog") |
|
|
|
|
constructor( |
|
|
|
|
content: String?, |
|
|
|
|
mode: Mode = Mode.TEXT, |
|
|
|
|
time: Long = 0, |
|
|
|
|
autoClose: Boolean = false |
|
|
|
|
) : this() { |
|
|
|
|
arguments = Bundle().apply { |
|
|
|
|
putString("content", content) |
|
|
|
|
putString("mode", mode.name) |
|
|
|
|
putLong("time", time) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
isCancelable = false |
|
|
|
|
this.autoClose = autoClose |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val binding by viewBinding(DialogTextViewBinding::bind) |
|
|
|
@ -64,8 +61,8 @@ class TextDialog : BaseDialogFragment() { |
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
arguments?.let { |
|
|
|
|
val content = it.getString("content") ?: "" |
|
|
|
|
when (it.getInt("mode")) { |
|
|
|
|
MD -> 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) |
|
|
|
|