Provide content container layout id

This commit is contained in:
Daniil Borisovskii 2019-08-15 11:57:06 +03:00
parent 3247f44bc0
commit bf604d87ef
3 changed files with 12 additions and 2 deletions

View File

@ -22,6 +22,8 @@ abstract class BaseNavigationFragment : Fragment() {
abstract fun getContentContainerId(): Int
abstract fun getContentContainerLayoutId(): Int
abstract fun getTopLevelViewControllerId(): Int
abstract fun wrapWithNavigationContainer(): Boolean
@ -37,6 +39,7 @@ abstract class BaseNavigationFragment : Fragment() {
fragmentManager = childFragmentManager,
viewControllers = getNavigationViewControllers(),
contentContainerViewId = getContentContainerId(),
contentContainerLayoutId = getContentContainerLayoutId(),
topLevelViewControllerId = getTopLevelViewControllerId(),
wrapWithNavigationContainer = wrapWithNavigationContainer(),
onReselectListener = getReselectListener()

View File

@ -20,6 +20,7 @@ class BottomNavigationController(
private val fragmentManager: FragmentManager,
private val viewControllers: SparseArray<Pair<Class<out ViewController<*, *>>, Parcelable>>,
private val contentContainerViewId: Int,
private val contentContainerLayoutId: Int,
private val wrapWithNavigationContainer: Boolean = false,
@IdRes private val topLevelViewControllerId: Int = 0, // If it zero back press with empty fragment back stack would close the app
private val onReselectListener: (() -> Unit)? = null
@ -86,7 +87,7 @@ class BottomNavigationController(
Fragment.instantiate(
context,
NavigationContainerFragment::class.java.name,
NavigationContainerFragment.args(viewControllerClass, viewControllerState, contentContainerViewId)
NavigationContainerFragment.args(viewControllerClass, viewControllerState, contentContainerViewId, contentContainerLayoutId)
)
} else {
Fragment.instantiate(

View File

@ -16,17 +16,20 @@ class NavigationContainerFragment : Fragment() {
private const val VIEW_CONTROLLER_CLASS_ARG = "VIEW_CONTROLLER_CLASS_ARG"
private const val VIEW_CONTROLLER_STATE_ARG = "VIEW_CONTROLLER_STATE_ARG"
private const val CONTAINER_VIEW_ID_ARG = "CONTAINER_VIEW_ID_ARG"
private const val CONTAINER_LAYOUT_ID_ARG = "CONTAINER_LAYOUT_ID_ARG"
private const val TRANSITION_ARG = "TRANSITION_ARG"
fun args(
cls: Class<out ViewController<*, *>>,
state: Parcelable,
containerViewId: Int,
containerLayoutId: Int,
transition: Int = FragmentTransaction.TRANSIT_NONE
) = Bundle().apply {
putSerializable(VIEW_CONTROLLER_CLASS_ARG, cls)
putParcelable(VIEW_CONTROLLER_STATE_ARG, state)
putInt(CONTAINER_VIEW_ID_ARG, containerViewId)
putInt(CONTAINER_LAYOUT_ID_ARG, containerLayoutId)
putInt(TRANSITION_ARG, transition)
}
}
@ -42,6 +45,8 @@ class NavigationContainerFragment : Fragment() {
private var containerViewId = 0
private var containerLayoutId = 0
private var transition = 0
@Suppress("UNCHECKED_CAST")
@ -54,6 +59,7 @@ class NavigationContainerFragment : Fragment() {
val args = arguments ?: return
with(args) {
containerViewId = getInt(CONTAINER_VIEW_ID_ARG)
containerLayoutId = getInt(CONTAINER_LAYOUT_ID_ARG)
transition = getInt(TRANSITION_ARG)
}
navigation.setInitialViewController(getViewControllerClass(), args.getParcelable(VIEW_CONTROLLER_STATE_ARG))
@ -61,6 +67,6 @@ class NavigationContainerFragment : Fragment() {
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
inflater.inflate(containerViewId, container, false)
inflater.inflate(containerLayoutId, container, false)
}