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