-
-
Save ntngel1/0b852f557979e225d19eb626899eebad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
something |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LaunchDetailsFragmentAdapter( | |
private val flightNumber: Int, | |
fm: FragmentManager, | |
lifecycle: Lifecycle | |
) : FragmentStateAdapter(fm, lifecycle) { | |
override fun createFragment(position: Int): Fragment = when (position) { | |
RESOURCES_POSITION -> LaunchDetailsResourcesFragment.newInstance(flightNumber) | |
IMAGES_POSITION -> LaunchDetailsImagesFragment.newInstance(flightNumber) | |
else -> throw IllegalStateException("No such fragment for position = $position") | |
} | |
override fun getItemCount() = 2 | |
companion object { | |
const val RESOURCES_POSITION = 0 | |
const val IMAGES_POSITION = 1 | |
fun getTabLayoutMediator(tabLayout: TabLayout, pager: ViewPager2) = | |
TabLayoutMediator(tabLayout, pager) { tab, position -> | |
val titleIdRes = when (position) { | |
RESOURCES_POSITION -> R.string.resources | |
IMAGES_POSITION -> R.string.images | |
else -> throw IllegalStateException("No such title for position = $position") | |
} | |
pager.setCurrentItem(tab.position, true) | |
tab.text = tabLayout.context.str(titleIdRes) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment