Fix linkify preference when Markdown enabled

pull/1462/head
Alex Baker 3 years ago
parent bc5e08ec14
commit 1a04be6afd

@ -79,6 +79,9 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
@Inject lateinit var timerPlugin: TimerPlugin
@Inject lateinit var linkify: Linkify
private val linkifyEnabled: Boolean
get() = preferences.getBoolean(R.string.p_linkify_task_edit, false)
val editViewModel: TaskEditViewModel by viewModels()
lateinit var binding: FragmentTaskEditBinding
private var showKeyboard = false
@ -144,7 +147,7 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
val title = binding.title
val markdown = if (preferences.markdown) {
MarkwonEditorTextWatcher.withPreRender(
MarkwonEditor.create(requireContext().markwon),
MarkwonEditor.create(requireContext().markwon(linkifyEnabled)),
Executors.newCachedThreadPool(),
title
)
@ -200,7 +203,7 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
lifecycleScope.launch {
notificationManager.cancel(model.id)
}
if (preferences.getBoolean(R.string.p_linkify_task_edit, false)) {
if (linkifyEnabled) {
linkify.linkify(title)
}
}

@ -38,7 +38,7 @@ class WhatsNewDialog : DialogFragment() {
val textStream = requireContext().assets.open("CHANGELOG.md")
val text = BufferedReader(textStream.reader()).readText()
binding.changelog.movementMethod = LinkMovementMethod.getInstance()
requireContext().markwon.setMarkdown(binding.changelog, text)
requireContext().markwon(true).setMarkdown(binding.changelog, text)
val begForSubscription = !inventory.hasPro
val begForRating = !preferences.getBoolean(R.string.p_clicked_rate, false)

@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.net.Uri
import android.text.util.Linkify
import android.text.util.Linkify.*
import android.widget.Toast
import androidx.browser.customtabs.CustomTabsIntent
import io.noties.markwon.Markwon
@ -53,20 +53,21 @@ object Context {
fun Context.toast(text: String?, duration: Int = Toast.LENGTH_LONG) =
text?.let { Toast.makeText(this, it, duration).show() }
val Context.markwon: Markwon
get() =
Markwon
.builder(this)
.usePlugins(
listOf(
TaskListPlugin.create(this),
TablePlugin.create(this),
LinkifyPlugin.create(
Linkify.WEB_URLS or Linkify.EMAIL_ADDRESSES or Linkify.PHONE_NUMBERS,
true
),
StrikethroughPlugin.create()
)
fun Context.markwon(linkify: Boolean = false): Markwon {
val builder = Markwon
.builder(this)
.usePlugins(
listOf(
TaskListPlugin.create(this),
TablePlugin.create(this),
StrikethroughPlugin.create()
)
.build()
)
if (linkify) {
builder.usePlugin(
LinkifyPlugin.create(WEB_URLS or EMAIL_ADDRESSES or PHONE_NUMBERS, true)
)
}
return builder.build()
}
}

@ -46,7 +46,7 @@ class TaskViewHolder internal constructor(
private val linkify: Linkify,
private val locale: Locale
) : RecyclerView.ViewHolder(binding.root) {
private val markwon = if (preferences.markdown) context.markwon else null
private val markwon = if (preferences.markdown) context.markwon(linkifyEnabled) else null
private val row: ViewGroup = binding.row
private val dueDate: TextView = binding.dueDate.apply {
setOnClickListener { changeDueDate() }
@ -63,7 +63,10 @@ class TaskViewHolder internal constructor(
private val chipGroup: ChipGroup = binding.chipGroup
lateinit var task: TaskContainer
private val linkifyEnabled: Boolean
get() = preferences.getBoolean(R.string.p_linkify_task_list, false)
var indent = 0
set(value) {
field = value
@ -146,7 +149,7 @@ class TaskViewHolder internal constructor(
}
description.visibility = if (task.hasNotes()) View.VISIBLE else View.GONE
}
if (preferences.getBoolean(R.string.p_linkify_task_list, false)) {
if (markwon != null || preferences.getBoolean(R.string.p_linkify_task_list, false)) {
linkify.setMovementMethod(nameView) { onRowBodyClick() }
linkify.setMovementMethod(description) { onRowBodyClick() }
if (markwon == null) {

@ -21,10 +21,13 @@ class DescriptionControlSet : TaskEditControlFragment() {
@Inject lateinit var preferences: Preferences
private lateinit var editText: EditText
private val linkifyEnabled: Boolean
get() = preferences.getBoolean(R.string.p_linkify_task_edit, false)
override fun createView(savedInstanceState: Bundle?) {
viewModel.description?.let(editText::setTextKeepState)
if (preferences.getBoolean(R.string.p_linkify_task_edit, false)) {
if (linkifyEnabled) {
linkify.linkify(editText)
}
}
@ -34,7 +37,7 @@ class DescriptionControlSet : TaskEditControlFragment() {
editText = it.notes
val markdown = if (preferences.markdown) {
MarkwonEditorTextWatcher.withPreRender(
MarkwonEditor.create(requireContext().markwon),
MarkwonEditor.create(requireContext().markwon(linkifyEnabled)),
Executors.newCachedThreadPool(),
editText
)

Loading…
Cancel
Save