diff --git a/app/src/main/java/io/github/sds100/keymapper/home/HomeFragment.kt b/app/src/main/java/io/github/sds100/keymapper/home/HomeFragment.kt index ea54c30689..ead9950f94 100644 --- a/app/src/main/java/io/github/sds100/keymapper/home/HomeFragment.kt +++ b/app/src/main/java/io/github/sds100/keymapper/home/HomeFragment.kt @@ -33,7 +33,6 @@ import io.github.sds100.keymapper.util.Inject import io.github.sds100.keymapper.util.QuickStartGuideTapTarget import io.github.sds100.keymapper.util.launchRepeatOnLifecycle import io.github.sds100.keymapper.util.str -import io.github.sds100.keymapper.util.strArray import io.github.sds100.keymapper.util.ui.TextListItem import io.github.sds100.keymapper.util.ui.setupNavigation import io.github.sds100.keymapper.util.ui.showPopups @@ -130,7 +129,8 @@ class HomeFragment : Fragment() { binding.viewPager.adapter = pagerAdapter TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position -> - tab.text = strArray(R.array.home_tab_titles)[position] + val tabId = homeViewModel.tabsState.value.tabs[position] + tab.text = str(HomePagerAdapter.TAB_NAMES[tabId]!!) }.apply { attach() } diff --git a/app/src/main/java/io/github/sds100/keymapper/home/HomePagerAdapter.kt b/app/src/main/java/io/github/sds100/keymapper/home/HomePagerAdapter.kt index 75c15ed552..81344e94be 100644 --- a/app/src/main/java/io/github/sds100/keymapper/home/HomePagerAdapter.kt +++ b/app/src/main/java/io/github/sds100/keymapper/home/HomePagerAdapter.kt @@ -2,8 +2,10 @@ package io.github.sds100.keymapper.home import androidx.fragment.app.Fragment import androidx.viewpager2.adapter.FragmentStateAdapter +import io.github.sds100.keymapper.R import io.github.sds100.keymapper.mappings.fingerprintmaps.FingerprintMapListFragment import io.github.sds100.keymapper.mappings.keymaps.KeyMapListFragment +import io.github.sds100.keymapperpro.AssistantTriggerFragment /** * Created by sds100 on 26/01/2020. @@ -13,7 +15,15 @@ class HomePagerAdapter( fragment: Fragment, ) : FragmentStateAdapter(fragment) { - private var tabs: Set = emptySet() + companion object { + val TAB_NAMES: Map = mapOf( + HomeTab.KEY_EVENTS to R.string.tab_keyevents, + HomeTab.FINGERPRINT_MAPS to R.string.tab_fingerprint, + HomeTab.ASSISTANT_TRIGGER to R.string.tab_assistant_trigger + ) + } + + private var tabs: List = emptyList() private val tabFragmentsCreators: List<() -> Fragment> get() = tabs.map { tab -> when (tab) { @@ -32,6 +42,14 @@ class HomePagerAdapter( } } } + + HomeTab.ASSISTANT_TRIGGER -> { + { + AssistantTriggerFragment().apply { + isAppBarVisible = false + } + } + } } } @@ -39,7 +57,7 @@ class HomePagerAdapter( override fun createFragment(position: Int) = tabFragmentsCreators[position].invoke() - fun invalidateFragments(tabs: Set) { + fun invalidateFragments(tabs: List) { if (this.tabs == tabs) return this.tabs = tabs diff --git a/app/src/main/java/io/github/sds100/keymapper/home/HomeTab.kt b/app/src/main/java/io/github/sds100/keymapper/home/HomeTab.kt index 264083953c..bd07456154 100644 --- a/app/src/main/java/io/github/sds100/keymapper/home/HomeTab.kt +++ b/app/src/main/java/io/github/sds100/keymapper/home/HomeTab.kt @@ -6,4 +6,5 @@ package io.github.sds100.keymapper.home enum class HomeTab { KEY_EVENTS, FINGERPRINT_MAPS, + ASSISTANT_TRIGGER } diff --git a/app/src/main/java/io/github/sds100/keymapper/home/HomeViewModel.kt b/app/src/main/java/io/github/sds100/keymapper/home/HomeViewModel.kt index a04c79afd9..22ed21db4e 100644 --- a/app/src/main/java/io/github/sds100/keymapper/home/HomeViewModel.kt +++ b/app/src/main/java/io/github/sds100/keymapper/home/HomeViewModel.kt @@ -144,7 +144,9 @@ class HomeViewModel( if (showFingerprintMaps) { yield(HomeTab.FINGERPRINT_MAPS) } - }.toSet() + + yield(HomeTab.ASSISTANT_TRIGGER) + }.toList() val showTabs = when { tabs.size == 1 -> false @@ -165,7 +167,7 @@ class HomeViewModel( HomeTabsState( enableViewPagerSwiping = false, showTabs = false, - emptySet(), + emptyList(), ), ) @@ -541,7 +543,7 @@ enum class HomeAppBarState { data class HomeTabsState( val enableViewPagerSwiping: Boolean = true, val showTabs: Boolean = false, - val tabs: Set, + val tabs: List, ) data class HomeErrorListState( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3faa26d102..d0dc501da5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -209,11 +209,7 @@ Trigger Key events Fingerprint - - - @string/tab_keyevents - @string/tab_fingerprint - + Assistant trigger