mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: revert main tab reference change
reverts https://github.com/meshtastic/Meshtastic-Android/pull/844/commits/4add8f97da5cc24455fff5ed7c7a7e3064e3d534
This commit is contained in:
parent
3713d371fa
commit
6e83870295
4 changed files with 40 additions and 58 deletions
|
|
@ -39,6 +39,7 @@ import com.geeksville.mesh.model.toChannelSet
|
|||
import com.geeksville.mesh.repository.radio.BluetoothInterface
|
||||
import com.geeksville.mesh.service.*
|
||||
import com.geeksville.mesh.ui.*
|
||||
import com.geeksville.mesh.ui.map.MapFragment
|
||||
import com.geeksville.mesh.util.Exceptions
|
||||
import com.geeksville.mesh.util.LanguageUtils
|
||||
import com.geeksville.mesh.util.getPackageInfoCompat
|
||||
|
|
@ -140,9 +141,39 @@ class MainActivity : AppCompatActivity(), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
data class TabInfo(val text: String, val icon: Int, val content: Fragment)
|
||||
|
||||
private val tabInfos = arrayOf(
|
||||
TabInfo(
|
||||
"Messages",
|
||||
R.drawable.ic_twotone_message_24,
|
||||
ContactsFragment()
|
||||
),
|
||||
TabInfo(
|
||||
"Users",
|
||||
R.drawable.ic_twotone_people_24,
|
||||
UsersFragment()
|
||||
),
|
||||
TabInfo(
|
||||
"Map",
|
||||
R.drawable.ic_twotone_map_24,
|
||||
MapFragment()
|
||||
),
|
||||
TabInfo(
|
||||
"Channel",
|
||||
R.drawable.ic_twotone_contactless_24,
|
||||
ChannelFragment()
|
||||
),
|
||||
TabInfo(
|
||||
"Settings",
|
||||
R.drawable.ic_twotone_settings_applications_24,
|
||||
SettingsFragment()
|
||||
)
|
||||
)
|
||||
|
||||
private val tabsAdapter = object : FragmentStateAdapter(supportFragmentManager, lifecycle) {
|
||||
override fun getItemCount(): Int = MainTab.entries.size
|
||||
override fun createFragment(position: Int): Fragment = MainTab.entries[position].content
|
||||
override fun getItemCount(): Int = tabInfos.size
|
||||
override fun createFragment(position: Int): Fragment = tabInfos[position].content
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -178,12 +209,12 @@ class MainActivity : AppCompatActivity(), Logging {
|
|||
// pager.offscreenPageLimit = 0 // Don't keep any offscreen pages around, because we want to make sure our bluetooth scanning stops
|
||||
TabLayoutMediator(binding.tabLayout, binding.pager, false, false) { tab, position ->
|
||||
// tab.text = tabInfos[position].text // I think it looks better with icons only
|
||||
tab.icon = ContextCompat.getDrawable(this, MainTab.entries[position].icon)
|
||||
tab.icon = ContextCompat.getDrawable(this, tabInfos[position].icon)
|
||||
}.attach()
|
||||
|
||||
binding.tabLayout.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
|
||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||
val mainTab = MainTab.entries[tab?.position ?: 0]
|
||||
val mainTab = tab?.position ?: 0
|
||||
model.setCurrentTab(mainTab)
|
||||
}
|
||||
override fun onTabUnselected(tab: TabLayout.Tab?) { }
|
||||
|
|
@ -537,7 +568,7 @@ class MainActivity : AppCompatActivity(), Logging {
|
|||
}
|
||||
|
||||
model.currentTab.observe(this) {
|
||||
binding.tabLayout.getTabAt(it.ordinal)?.select()
|
||||
binding.tabLayout.getTabAt(it)?.select()
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue