Skip to content

Commit

Permalink
#1274 add empty assistant trigger fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Aug 13, 2024
1 parent c7445f8 commit 09bd3c1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -13,7 +15,15 @@ class HomePagerAdapter(
fragment: Fragment,
) : FragmentStateAdapter(fragment) {

private var tabs: Set<HomeTab> = emptySet()
companion object {
val TAB_NAMES: Map<HomeTab, Int> = 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<HomeTab> = emptyList()
private val tabFragmentsCreators: List<() -> Fragment>
get() = tabs.map { tab ->
when (tab) {
Expand All @@ -32,14 +42,22 @@ class HomePagerAdapter(
}
}
}

HomeTab.ASSISTANT_TRIGGER -> {
{
AssistantTriggerFragment().apply {
isAppBarVisible = false
}
}
}
}
}

override fun getItemCount() = tabFragmentsCreators.size

override fun createFragment(position: Int) = tabFragmentsCreators[position].invoke()

fun invalidateFragments(tabs: Set<HomeTab>) {
fun invalidateFragments(tabs: List<HomeTab>) {
if (this.tabs == tabs) return

this.tabs = tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ package io.github.sds100.keymapper.home
enum class HomeTab {
KEY_EVENTS,
FINGERPRINT_MAPS,
ASSISTANT_TRIGGER
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -165,7 +167,7 @@ class HomeViewModel(
HomeTabsState(
enableViewPagerSwiping = false,
showTabs = false,
emptySet(),
emptyList(),
),
)

Expand Down Expand Up @@ -541,7 +543,7 @@ enum class HomeAppBarState {
data class HomeTabsState(
val enableViewPagerSwiping: Boolean = true,
val showTabs: Boolean = false,
val tabs: Set<HomeTab>,
val tabs: List<HomeTab>,
)

data class HomeErrorListState(
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@
<string name="tab_trigger">Trigger</string>
<string name="tab_keyevents" translatable="false">Key events</string>
<string name="tab_fingerprint">Fingerprint</string>

<string-array name="home_tab_titles">
<item>@string/tab_keyevents</item>
<item>@string/tab_fingerprint</item>
</string-array>
<string name="tab_assistant_trigger">Assistant trigger</string>
<!-- Tabs -->

<!-- Navigation argument ids -->
Expand Down

0 comments on commit 09bd3c1

Please sign in to comment.