kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
rodzic
3713d371fa
commit
6e83870295
|
@ -39,6 +39,7 @@ import com.geeksville.mesh.model.toChannelSet
|
||||||
import com.geeksville.mesh.repository.radio.BluetoothInterface
|
import com.geeksville.mesh.repository.radio.BluetoothInterface
|
||||||
import com.geeksville.mesh.service.*
|
import com.geeksville.mesh.service.*
|
||||||
import com.geeksville.mesh.ui.*
|
import com.geeksville.mesh.ui.*
|
||||||
|
import com.geeksville.mesh.ui.map.MapFragment
|
||||||
import com.geeksville.mesh.util.Exceptions
|
import com.geeksville.mesh.util.Exceptions
|
||||||
import com.geeksville.mesh.util.LanguageUtils
|
import com.geeksville.mesh.util.LanguageUtils
|
||||||
import com.geeksville.mesh.util.getPackageInfoCompat
|
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) {
|
private val tabsAdapter = object : FragmentStateAdapter(supportFragmentManager, lifecycle) {
|
||||||
override fun getItemCount(): Int = MainTab.entries.size
|
override fun getItemCount(): Int = tabInfos.size
|
||||||
override fun createFragment(position: Int): Fragment = MainTab.entries[position].content
|
override fun createFragment(position: Int): Fragment = tabInfos[position].content
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
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
|
// 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 ->
|
TabLayoutMediator(binding.tabLayout, binding.pager, false, false) { tab, position ->
|
||||||
// tab.text = tabInfos[position].text // I think it looks better with icons only
|
// 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()
|
}.attach()
|
||||||
|
|
||||||
binding.tabLayout.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
|
binding.tabLayout.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
|
||||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||||
val mainTab = MainTab.entries[tab?.position ?: 0]
|
val mainTab = tab?.position ?: 0
|
||||||
model.setCurrentTab(mainTab)
|
model.setCurrentTab(mainTab)
|
||||||
}
|
}
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab?) { }
|
override fun onTabUnselected(tab: TabLayout.Tab?) { }
|
||||||
|
@ -537,7 +568,7 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
model.currentTab.observe(this) {
|
model.currentTab.observe(this) {
|
||||||
binding.tabLayout.getTabAt(it.ordinal)?.select()
|
binding.tabLayout.getTabAt(it)?.select()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -27,7 +27,6 @@ import com.geeksville.mesh.database.PacketRepository
|
||||||
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
||||||
import com.geeksville.mesh.repository.radio.RadioInterfaceService
|
import com.geeksville.mesh.repository.radio.RadioInterfaceService
|
||||||
import com.geeksville.mesh.service.MeshService
|
import com.geeksville.mesh.service.MeshService
|
||||||
import com.geeksville.mesh.ui.MainTab
|
|
||||||
import com.geeksville.mesh.util.positionToMeter
|
import com.geeksville.mesh.util.positionToMeter
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -588,15 +587,15 @@ class UIViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _currentTab = MutableLiveData(MainTab.MESSAGES)
|
private val _currentTab = MutableLiveData(0)
|
||||||
val currentTab: LiveData<MainTab> get() = _currentTab
|
val currentTab: LiveData<Int> get() = _currentTab
|
||||||
|
|
||||||
fun setCurrentTab(tab: MainTab) {
|
fun setCurrentTab(tab: Int) {
|
||||||
_currentTab.value = tab
|
_currentTab.value = tab
|
||||||
}
|
}
|
||||||
|
|
||||||
fun focusUserNode(node: NodeInfo?) {
|
fun focusUserNode(node: NodeInfo?) {
|
||||||
_currentTab.value = MainTab.USERS
|
_currentTab.value = 1
|
||||||
_focusedNode.value = node
|
_focusedNode.value = node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
package com.geeksville.mesh.ui
|
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import com.geeksville.mesh.R
|
|
||||||
import com.geeksville.mesh.ui.map.MapFragment
|
|
||||||
|
|
||||||
enum class MainTab(
|
|
||||||
@StringRes
|
|
||||||
val text: Int,
|
|
||||||
@DrawableRes
|
|
||||||
val icon: Int,
|
|
||||||
val content: Fragment
|
|
||||||
) {
|
|
||||||
MESSAGES(
|
|
||||||
R.string.main_tab_lbl_messages,
|
|
||||||
R.drawable.ic_twotone_message_24,
|
|
||||||
ContactsFragment()
|
|
||||||
),
|
|
||||||
USERS(
|
|
||||||
R.string.main_tab_lbl_users,
|
|
||||||
R.drawable.ic_twotone_people_24,
|
|
||||||
UsersFragment()
|
|
||||||
),
|
|
||||||
MAP(
|
|
||||||
R.string.main_tab_lbl_map,
|
|
||||||
R.drawable.ic_twotone_map_24,
|
|
||||||
MapFragment()
|
|
||||||
),
|
|
||||||
CHANNEL(
|
|
||||||
R.string.main_tab_lbl_channel,
|
|
||||||
R.drawable.ic_twotone_contactless_24,
|
|
||||||
ChannelFragment()
|
|
||||||
),
|
|
||||||
SETTINGS(
|
|
||||||
R.string.main_tab_lbl_settings,
|
|
||||||
R.drawable.ic_twotone_settings_applications_24,
|
|
||||||
SettingsFragment()
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -11,13 +11,6 @@
|
||||||
<string name="sample_coords" translatable="false">55.332244 34.442211</string>
|
<string name="sample_coords" translatable="false">55.332244 34.442211</string>
|
||||||
<string name="sample_message" translatable="false">hey I found the cache, it is over here next to the big tiger. I\'m kinda scared.</string>
|
<string name="sample_message" translatable="false">hey I found the cache, it is over here next to the big tiger. I\'m kinda scared.</string>
|
||||||
|
|
||||||
<!-- Main Tabs -->
|
|
||||||
<string name="main_tab_lbl_messages" translatable="false">Messages</string>
|
|
||||||
<string name="main_tab_lbl_users" translatable="false">Users</string>
|
|
||||||
<string name="main_tab_lbl_map" translatable="false">Map</string>
|
|
||||||
<string name="main_tab_lbl_channel" translatable="false">Channel</string>
|
|
||||||
<string name="main_tab_lbl_settings" translatable="false">Settings</string>
|
|
||||||
|
|
||||||
<string name="channel_name">Channel Name</string>
|
<string name="channel_name">Channel Name</string>
|
||||||
<string name="channel_options">Channel options</string>
|
<string name="channel_options">Channel options</string>
|
||||||
<string name="qr_code">QR code</string>
|
<string name="qr_code">QR code</string>
|
||||||
|
|
Ładowanie…
Reference in New Issue