Added accessibility actions for the contact menu

This commit is contained in:
ottoptj 2024-09-09 09:50:14 +03:00
commit fdc8fad134
4 changed files with 58 additions and 26 deletions

View file

@ -188,6 +188,13 @@ class AppMenuAdapter(
activity.backToHome() activity.backToHome()
true true
} }
if (sharedPreferenceManager.areContactsEnabled()) {
ViewCompat.addAccessibilityAction(holder.textView, activity.getString(R.string.switch_to_contacts)) { _, _ ->
activity.switchMenus()
true
}
}
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {

View file

@ -1,26 +1,26 @@
package eu.ottop.yamlauncher package eu.ottop.yamlauncher
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
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 android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.TextView import android.widget.TextView
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import eu.ottop.yamlauncher.settings.SharedPreferenceManager import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import eu.ottop.yamlauncher.utils.UIUtils import eu.ottop.yamlauncher.utils.UIUtils
class ContactsAdapter( class ContactsAdapter(
private val context: Context, private val activity: MainActivity,
private var contacts: MutableList<Pair<String, Int>>, private var contacts: MutableList<Pair<String, Int>>,
private val contactClickListener: OnContactClickListener private val contactClickListener: OnContactClickListener
) : ) :
RecyclerView.Adapter<ContactsAdapter.AppViewHolder>() { RecyclerView.Adapter<ContactsAdapter.AppViewHolder>() {
private val uiUtils = UIUtils(context) private val uiUtils = UIUtils(activity)
private val sharedPreferenceManager = SharedPreferenceManager(context) private val sharedPreferenceManager = SharedPreferenceManager(activity)
interface OnContactClickListener { interface OnContactClickListener {
fun onContactClick(contactId: Int) fun onContactClick(contactId: Int)
@ -49,7 +49,7 @@ class ContactsAdapter(
override fun onBindViewHolder(holder: AppViewHolder, position: Int) { override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
val contact = contacts[position] val contact = contacts[position]
holder.textView.setCompoundDrawablesWithIntrinsicBounds( holder.textView.setCompoundDrawablesWithIntrinsicBounds(
ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null, ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null) ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null)
uiUtils.setAppAlignment(holder.textView) uiUtils.setAppAlignment(holder.textView)
@ -63,6 +63,18 @@ class ContactsAdapter(
holder.textView.text = contact.first holder.textView.text = contact.first
holder.textView.visibility = View.VISIBLE holder.textView.visibility = View.VISIBLE
ViewCompat.addAccessibilityAction(holder.textView, "Close App Menu") { _, _ ->
activity.backToHome()
true
}
if (sharedPreferenceManager.areContactsEnabled()) {
ViewCompat.addAccessibilityAction(holder.textView, activity.getString(R.string.switch_to_apps)) { _, _ ->
activity.switchMenus()
true
}
}
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {

View file

@ -742,9 +742,23 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
setupRecyclerListener(contactRecycler, contactMenuLinearLayoutManager) setupRecyclerListener(contactRecycler, contactMenuLinearLayoutManager)
searchSwitcher.setOnClickListener { searchSwitcher.setOnClickListener {
switchMenus()
}
}
fun switchMenus() {
menuView.showNext() menuView.showNext()
when (menuView.displayedChild) { when (menuView.displayedChild) {
0 -> { 0 -> {
setAppViewDetails()
}
1 -> {
setContactViewDetails()
}
}
}
private fun setAppViewDetails() {
searchSwitcher.setImageDrawable( searchSwitcher.setImageDrawable(
ResourcesCompat.getDrawable( ResourcesCompat.getDrawable(
resources, resources,
@ -754,16 +768,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
) )
searchSwitcher.contentDescription = getString(R.string.switch_to_contacts) searchSwitcher.contentDescription = getString(R.string.switch_to_contacts)
} }
1 -> {
private fun setContactViewDetails() {
lifecycleScope.launch(Dispatchers.Default) { lifecycleScope.launch(Dispatchers.Default) {
filterItems(searchView.text.toString()) filterItems(searchView.text.toString())
} }
searchSwitcher.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.apps_24px, null)) searchSwitcher.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.apps_24px, null))
searchSwitcher.contentDescription = getString(R.string.switch_to_apps) searchSwitcher.contentDescription = getString(R.string.switch_to_apps)
} }
}
}
}
private fun getContacts(filterString: String): MutableList<Pair<String, Int>> { private fun getContacts(filterString: String): MutableList<Pair<String, Int>> {
val contacts = mutableListOf<Pair<String, Int>>() val contacts = mutableListOf<Pair<String, Int>>()

View file

@ -12,6 +12,9 @@
<string name="search">Search…</string> <string name="search">Search…</string>
<string name="switch_to_contacts">Switch to Contacts</string>
<string name="switch_to_apps">Switch to Apps</string>
<!--Action Menu Items--> <!--Action Menu Items-->
<string name="reset">Reset</string> <string name="reset">Reset</string>
<string name="info">Info</string> <string name="info">Info</string>
@ -44,6 +47,4 @@
<string name="region_text">%1$s%2$s</string> <string name="region_text">%1$s%2$s</string>
<string name="accessibility_service_description">The permission is required for double tap to work for locking the screen.\n\nIt is only needed if you want to use the double tap to lock screen feature in YAM Launcher.</string> <string name="accessibility_service_description">The permission is required for double tap to work for locking the screen.\n\nIt is only needed if you want to use the double tap to lock screen feature in YAM Launcher.</string>
<string name="switch_to_contacts">Switch to Contacts</string>
<string name="switch_to_apps">Switch to Apps</string>
</resources> </resources>