Created
March 23, 2020 22:22
-
-
Save fo2rist/84a33a18bc3b050de40b82d424f4008a to your computer and use it in GitHub Desktop.
Java To Kotlin Conversion. Step 6. Polish After
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 NonLazyDemoAdapter internal constructor( | |
fm: FragmentManager | |
) : FragmentStatePagerAdapter(fm) { | |
internal data class FragmentBundle( | |
@SerializedName("id") // caller side now can be refactored to use property, not JvmField | |
var id: Int, | |
@SerializedName("name") | |
var name: String | |
) : Serializable | |
companion object { | |
@JvmStatic | |
fun createAdapter(fm: FragmentManager): NonLazyDemoAdapter = NonLazyDemoAdapter(fm) | |
} | |
private val pages = arrayOf(SomePage.FIRST, SomePage.SECOND) | |
private val cachedFragments by lazy { | |
pages.mapIndexed { i, page -> PageFragment.newInstance(page, FragmentBundle(i, pages.toString())) } | |
} | |
override fun getItem(position: Int): Fragment = cachedFragments[position] | |
override fun getCount(): Int = cachedFragments.size | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment