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
@Composable | |
private fun FabContainer( | |
modifier: Modifier = Modifier, | |
) { | |
var containerState by remember { mutableStateOf(ContainerState.Fab) } | |
val transition = updateTransition(targetState = containerState) | |
val backgroundColor by transition.animateColor { state -> | |
when (state) { | |
ContainerState.Fab -> Colors.fabContainerColor | |
ContainerState.Fullscreen -> Colors.surface |
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
@Composable | |
private fun FabContent( | |
modifier: Modifier = Modifier, | |
) { | |
var containerState by remember { mutableStateOf(ContainerState.Fab) } | |
AnimatedContent( | |
modifier = modifier, | |
targetState = containerState, | |
label = "container transform", | |
) { state -> |
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
Box( | |
modifier = Modifier | |
.fillMaxSize() | |
) { | |
var containerState by remember { mutableStateOf(ContainerState.Fab) } | |
HotTakesContent() | |
when (containerState) { | |
ContainerState.Fab -> Fab( | |
modifier = Modifier | |
.align(Aligment.BottomEnd) |
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
override fun onBindViewHolder( | |
holder: FragmentViewHolder, | |
position: Int, | |
payloads: MutableList<Any> | |
) { | |
if (payloads.isNotEmpty()) { | |
val tag = "f" + holder.itemId | |
val fragment = activity.supportFragmentManager.findFragmentByTag(tag) | |
// safe check, but fragment should not be null here | |
if (fragment != null) { |
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 PagerDiffUtil(private val oldList: List<PagerItem>, private val newList: List<PagerItem>) : DiffUtil.Callback() { | |
enum class PayloadKey { | |
VALUE | |
} | |
override fun getOldListSize() = oldList.size | |
override fun getNewListSize() = newList.size |
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 PagerAdapter(private val activity: FragmentActivity) : FragmentStateAdapter(activity) { | |
private val items: ArrayList<PagerItem> = arrayListOf() | |
override fun createFragment(position: Int): Fragment = | |
PagerFragment.newInstance(items[position]) | |
override fun getItemCount() = items.size | |
override fun getItemId(position: Int): Long { |
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 MainActivity : AppCompatActivity(R.layout.activity_main) { | |
private lateinit var pagerAdapter: PagerAdapter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
pagerAdapter = PagerAdapter(this) | |
viewPager.adapter = pagerAdapter | |
pagerAdapter.setItems(generatePagerItems()) |
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 PagerAdapter(private val activity: FragmentActivity) : FragmentStateAdapter(activity) { | |
private val items: ArrayList<PagerItem> = arrayListOf() | |
override fun createFragment(position: Int): Fragment = | |
PagerFragment.newInstance(items[position]) | |
override fun getItemCount() = items.size | |
fun setItems(newItems: List<PagerItem>) { |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
setupKoinFragmentFactory() | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
} |
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 KoinFragmentFactory : FragmentFactory() { | |
override fun instantiate(classLoader: ClassLoader, className: String): Fragment { | |
val clazz = Class.forName(className).kotlin | |
val instance = getKoin().getOrNull<Fragment>(clazz) | |
return instance ?: super.instantiate(classLoader, className) | |
} | |
} |
NewerOlder