@@ -5,6 +5,8 @@ import android.view.LayoutInflater
55import android.view.View
66import android.view.ViewGroup
77import android.widget.FrameLayout
8+ import android.widget.ImageView
9+ import android.widget.TextView
810import androidx.fragment.app.Fragment
911import com.google.android.material.tabs.TabLayout
1012import com.io7m.jmulticlose.core.CloseableCollection
@@ -39,10 +41,10 @@ class MainTabsFragment : Fragment(), MainBackButtonConsumerType {
3941 private const val TAB_INDEX_SETTINGS = 3
4042 }
4143
42- private lateinit var tabSettingsView: View
43- private lateinit var tabReservationsView: View
44- private lateinit var tabBooksView: View
45- private lateinit var tabCatalogView: View
44+ private lateinit var tabSettingsView: TabLayout . TabView
45+ private lateinit var tabReservationsView: TabLayout . TabView
46+ private lateinit var tabBooksView: TabLayout . TabView
47+ private lateinit var tabCatalogView: TabLayout . TabView
4648 private lateinit var root: ViewGroup
4749 private lateinit var tabBooks: TabLayout .Tab
4850 private lateinit var tabCatalog: TabLayout .Tab
@@ -77,14 +79,39 @@ class MainTabsFragment : Fragment(), MainBackButtonConsumerType {
7779 */
7880
7981 val tabStrip = (this .tabLayout.getChildAt(0 ) as ViewGroup )
80- this .tabCatalog = this .tabLayout.getTabAt(TAB_INDEX_CATALOG )!!
81- this .tabCatalogView = tabStrip.getChildAt(TAB_INDEX_CATALOG )!!
82- this .tabBooks = this .tabLayout.getTabAt(TAB_INDEX_BOOKS )!!
83- this .tabBooksView = tabStrip.getChildAt(TAB_INDEX_BOOKS )!!
84- this .tabReservations = this .tabLayout.getTabAt(TAB_INDEX_RESERVATIONS )!!
85- this .tabReservationsView = tabStrip.getChildAt(TAB_INDEX_RESERVATIONS )!!
86- this .tabSettings = this .tabLayout.getTabAt(TAB_INDEX_SETTINGS )!!
87- this .tabSettingsView = tabStrip.getChildAt(TAB_INDEX_SETTINGS )!!
82+ this .tabCatalog =
83+ this .tabLayout.getTabAt(TAB_INDEX_CATALOG )!!
84+ this .tabBooks =
85+ this .tabLayout.getTabAt(TAB_INDEX_BOOKS )!!
86+ this .tabReservations =
87+ this .tabLayout.getTabAt(TAB_INDEX_RESERVATIONS )!!
88+ this .tabSettings =
89+ this .tabLayout.getTabAt(TAB_INDEX_SETTINGS )!!
90+
91+ /*
92+ * We're forced to use custom views for tab items to comply with accessibility regulations:
93+ * Android tab items will ellipsize text when the device font size is set to the largest
94+ * values, and there's no way to stop it ellipsizing.
95+ */
96+
97+ this .tabCatalog.setCustomView(R .layout.tab_item)
98+ this .tabBooks.setCustomView(R .layout.tab_item)
99+ this .tabReservations.setCustomView(R .layout.tab_item)
100+ this .tabSettings.setCustomView(R .layout.tab_item)
101+
102+ this .tabCatalogView =
103+ tabStrip.getChildAt(TAB_INDEX_CATALOG )!! as TabLayout .TabView
104+ this .tabBooksView =
105+ tabStrip.getChildAt(TAB_INDEX_BOOKS )!! as TabLayout .TabView
106+ this .tabReservationsView =
107+ tabStrip.getChildAt(TAB_INDEX_RESERVATIONS )!! as TabLayout .TabView
108+ this .tabSettingsView =
109+ tabStrip.getChildAt(TAB_INDEX_SETTINGS )!! as TabLayout .TabView
110+
111+ this .setIconAndText(TAB_CATALOG , this .tabCatalogView)
112+ this .setIconAndText(TAB_BOOKS , this .tabBooksView)
113+ this .setIconAndText(TAB_RESERVATIONS , this .tabReservationsView)
114+ this .setIconAndText(TAB_SETTINGS , this .tabSettingsView)
88115
89116 /*
90117 * Naturally, because even the simplest things on Android are completely broken, it's
@@ -141,6 +168,35 @@ class MainTabsFragment : Fragment(), MainBackButtonConsumerType {
141168 return this .root
142169 }
143170
171+ private fun setIconAndText (
172+ category : MainTabCategory ,
173+ view : TabLayout .TabView
174+ ) {
175+ val textView =
176+ view.findViewById<TextView >(R .id.customTabText)
177+ val imageView =
178+ view.findViewById<ImageView >(R .id.customTabIcon)
179+
180+ when (category) {
181+ TAB_CATALOG -> {
182+ textView.text = resources.getString(R .string.tabCatalog)
183+ imageView.setImageResource(R .drawable.tab_catalog)
184+ }
185+ TAB_BOOKS -> {
186+ textView.text = resources.getString(R .string.tabBooks)
187+ imageView.setImageResource(R .drawable.tab_books)
188+ }
189+ TAB_RESERVATIONS -> {
190+ textView.text = resources.getString(R .string.tabHolds)
191+ imageView.setImageResource(R .drawable.tab_holds)
192+ }
193+ TAB_SETTINGS -> {
194+ textView.text = resources.getString(R .string.tabSettings)
195+ imageView.setImageResource(R .drawable.tab_settings)
196+ }
197+ }
198+ }
199+
144200 override fun onStart () {
145201 super .onStart()
146202
0 commit comments