Skip to content

Commit

Permalink
A11y TagList: Ensure minimum touch target size. The close icon does n…
Browse files Browse the repository at this point in the history
…ot get focused by Talback in Recycler view

We make the context commands available through custom actions
  • Loading branch information
mtotschnig committed Nov 24, 2024
1 parent 86d0765 commit 2c9a2fc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
Expand Down Expand Up @@ -57,7 +58,7 @@ class TagList : Fragment(), OnDialogResultListener {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View {
_binding = TagListBinding.inflate(inflater, container, false)
return binding.root
Expand All @@ -75,7 +76,7 @@ class TagList : Fragment(), OnDialogResultListener {
override fun onCreateContextMenu(
menu: ContextMenu,
v: View,
menuInfo: ContextMenu.ContextMenuInfo?
menuInfo: ContextMenu.ContextMenuInfo?,
) {
requireActivity().menuInflater.inflate(R.menu.tags, menu)
menu.findItem(R.id.EDIT_COMMAND).title =
Expand All @@ -88,44 +89,53 @@ class TagList : Fragment(), OnDialogResultListener {
val tag = adapter.getItem(info.position)
return when (item.itemId) {
R.id.DELETE_COMMAND -> {
SimpleDialog.build()
.title(R.string.dialog_title_warning_delete_tag)
.extra(Bundle().apply {
putParcelable(KEY_TAG, tag)
})
.msg(
resources.getQuantityString(
R.plurals.warning_delete_tag,
tag.count,
tag.label,
tag.count
)
)
.pos(R.string.menu_delete)
.neg(android.R.string.cancel)
.show(this, DELETE_TAG_DIALOG)
onDelete(tag)
true
}

R.id.EDIT_COMMAND -> {
SimpleFormDialog.build()
.title(R.string.menu_edit_tag)
.cancelable(false)
.fields(
Input.plain(KEY_LABEL).text(tag.label),
ColorField.picker(KEY_COLOR).color(tag.color ?: ColorField.NONE).label(R.string.color)
)
.pos(R.string.menu_save)
.neut()
.extra(Bundle().apply { putParcelable(KEY_TAG, tag) })
.show(this, EDIT_TAG_DIALOG)
onEdit(tag)
true
}

else -> false
}
}

private fun onEdit(tag: Tag) {
SimpleFormDialog.build()
.title(R.string.menu_edit_tag)
.cancelable(false)
.fields(
Input.plain(KEY_LABEL).text(tag.label),
ColorField.picker(KEY_COLOR).color(tag.color ?: ColorField.NONE)
.label(R.string.color)
)
.pos(R.string.menu_save)
.neut()
.extra(Bundle().apply { putParcelable(KEY_TAG, tag) })
.show(this, EDIT_TAG_DIALOG)
}

private fun onDelete(tag: Tag) {
SimpleDialog.build()
.title(R.string.dialog_title_warning_delete_tag)
.extra(Bundle().apply {
putParcelable(KEY_TAG, tag)
})
.msg(
resources.getQuantityString(
R.plurals.warning_delete_tag,
tag.count,
tag.label,
tag.count
)
)
.pos(R.string.menu_delete)
.neg(android.R.string.cancel)
.show(this, DELETE_TAG_DIALOG)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val selected = activity?.intent?.getLongArrayExtra(KEY_SELECTION)
Expand Down Expand Up @@ -244,7 +254,13 @@ class TagList : Fragment(), OnDialogResultListener {
private inner class Adapter : ListAdapter<Tag, ViewHolder>(DIFF_CALLBACK) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
ViewHolder(LayoutInflater.from(parent.context).inflate(if (allowSelection) R.layout.tag_select else R.layout.tag_manage, parent, false))
ViewHolder(
LayoutInflater.from(parent.context).inflate(
if (allowSelection) R.layout.tag_select else R.layout.tag_manage,
parent,
false
)
)

fun getPosition(label: String) = currentList.indexOfFirst { it.label == label }

Expand All @@ -269,6 +285,20 @@ class TagList : Fragment(), OnDialogResultListener {
isCloseIconVisible = allowModifications
if (allowModifications) {
setOnCloseIconClickListener(View::showContextMenu)
ViewCompat.addAccessibilityAction(
holder.itemView,
context.getString(R.string.menu_edit)
) { _, _ ->
onEdit(tag)
true
}
ViewCompat.addAccessibilityAction(
holder.itemView,
context.getString(R.string.menu_delete)
) { _, _ ->
onDelete(tag)
true
}
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions myExpenses/src/main/res/layout/tag_manage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:checkable="false"
android:clickable="false"
android:layout_marginHorizontal="4dp"
app:closeIcon="@drawable/more"
android:gravity="center_horizontal"
android:textAlignment="center"
app:ensureMinTouchTargetSize="false" />
android:textAlignment="center" />
5 changes: 2 additions & 3 deletions myExpenses/src/main/res/layout/tag_select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
style="@style/Widget.Material3.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:closeIcon="@drawable/more"
android:layout_marginHorizontal="4dp"
android:gravity="center_horizontal"
android:textAlignment="center"
app:ensureMinTouchTargetSize="false" />
app:closeIcon="@drawable/more" />

0 comments on commit 2c9a2fc

Please sign in to comment.