AdaptiveFragmentHelper

class AdaptiveFragmentHelper<T : Enum<T>>(    fragment: Fragment,     viewVariantSelector: (widthDp: Int, heightDp: Int) -> T,     viewFactoryProvider: (T) -> IviFragment.ViewFactory<*>)

A helper class for fragments that change their view depending on the size that it's given, offering an adaptive UI.

A 'view variant' of type T defines the different possible variations of the fragment's view. For example the view could have different orientations (HORIZONTAL, VERTICAL), different sizes (SMALL, MEDIUM, LARGE), or any combination of those variations.

Each time the fragment's root view size change, a different view variant can be selected via viewVariantSelector. If a different view variant is selected, the fragment's view is recreated with the corresponding ViewFactory provided by the viewFactoryProvider.

Parameters

T

The enum type of view variant.

fragment

The adaptive fragment.

viewVariantSelector

Called when the fragment's root view updates its size in order to determine which view variant to use. If the returned value differs from the previous one the fragment will be reattached in order to recreate the view. In case the value to which the size is compared is stored in the dimen xml, one can use the Context.getDimensionByAttrInDp function.

viewFactoryProvider

Called when the size of the fragment's root view changes and a different view variant is returned by viewVariantSelector. This function should return the new value for viewFactory, which can be returned from IviFragment.viewFactory to apply the new view variant when the fragment recreates its view.

Constructors

Link copied to clipboard
fun <T : Enum<T>> AdaptiveFragmentHelper(    fragment: Fragment,     viewVariantSelector: (widthDp: Int, heightDp: Int) -> T,     viewFactoryProvider: (T) -> IviFragment.ViewFactory<*>)

Properties

Link copied to clipboard
var viewFactory: IviFragment.ViewFactory<*>

The IviFragment.ViewFactory that the fragment should use to create views. Can be used easily from the fragment with: