Notes and checklist item link fixes

Allow edittext to be clickable for Notes and task checklist items (And prevent link from opening when clicking on open spaces)
This commit is contained in:
Hafiz 2022-10-11 13:06:13 -04:00
parent ee20b4740f
commit 2b033f6d1b
2 changed files with 25 additions and 3 deletions

View file

@ -8,6 +8,11 @@ import android.graphics.Typeface
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.Handler
import android.text.Spannable
import android.text.SpannableString
import android.text.TextUtils
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.view.Menu
import android.view.MenuItem
import android.view.MotionEvent
@ -185,6 +190,7 @@ class TaskFormActivity : BaseActivity() {
binding.notesEditText.onFocusChangeListener = View.OnFocusChangeListener { _, isFocused ->
binding.notesInputLayout.alpha = if (isFocused) 0.8f else 0.6f
}
binding.notesEditText.movementMethod = LinkMovementMethod.getInstance()
binding.statStrengthButton.setOnClickListener { selectedStat = Attribute.STRENGTH }
binding.statIntelligenceButton.setOnClickListener { selectedStat = Attribute.INTELLIGENCE }
binding.statConstitutionButton.setOnClickListener { selectedStat = Attribute.CONSTITUTION }
@ -404,7 +410,12 @@ class TaskFormActivity : BaseActivity() {
}
canSave = true
binding.textEditText.setText(task.text)
binding.notesEditText.setText(task.notes)
val spannable: Spannable = SpannableString(task.notes)
Linkify.addLinks(spannable, Linkify.WEB_URLS)
//Append a zero-width space to the Spannable to allow clicking
//on the open spaces (and prevent links from opening)
val text: CharSequence = TextUtils.concat(spannable, "\u200B")
binding.notesEditText.setText(text)
binding.taskDifficultyButtons.selectedDifficulty = task.priority
when (taskType) {
TaskType.HABIT -> {

View file

@ -1,6 +1,11 @@
package com.habitrpg.android.habitica.ui.views.tasks.form
import android.content.Context
import android.text.Spannable
import android.text.SpannableString
import android.text.TextUtils
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.util.AttributeSet
import android.view.Gravity
import android.view.View
@ -13,10 +18,10 @@ import androidx.core.content.ContextCompat
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.databinding.TaskFormChecklistItemBinding
import com.habitrpg.android.habitica.extensions.OnChangeTextWatcher
import com.habitrpg.android.habitica.models.tasks.ChecklistItem
import com.habitrpg.common.habitica.extensions.dpToPx
import com.habitrpg.common.habitica.extensions.getThemeColor
import com.habitrpg.common.habitica.extensions.layoutInflater
import com.habitrpg.android.habitica.models.tasks.ChecklistItem
class ChecklistItemFormView @JvmOverloads constructor(
context: Context,
@ -30,7 +35,12 @@ class ChecklistItemFormView @JvmOverloads constructor(
var item: ChecklistItem = ChecklistItem()
set(value) {
field = value
binding.editText.setText(item.text)
val spannable: Spannable = SpannableString(item.text)
Linkify.addLinks(spannable, Linkify.WEB_URLS)
//Append a zero-width space to the Spannable to allow clicking
//on the open spaces (and prevent the link from opening)
val text: CharSequence = TextUtils.concat(spannable, "\u200B")
binding.editText.setText(text)
}
var tintColor: Int = context.getThemeColor(R.attr.taskFormTint)
@ -89,6 +99,7 @@ class ChecklistItemFormView @JvmOverloads constructor(
// a plus button we set it as 'unimportant for accessibility' so it can't be focused.
binding.button.contentDescription = context.getString(R.string.delete_checklist_entry)
binding.button.drawable.mutate().setTint(tintColor)
binding.editText.movementMethod = LinkMovementMethod.getInstance()
binding.editText.addTextChangedListener(
OnChangeTextWatcher { s, _, _, _ ->