Repository: android/compose-samples
File: Reply/app/src/main/java/com/example/reply/ui/ReplyApp.kt (Kotlin)

Code before:
    /**
     * This will help us select type of navigation and content type depending on window size and
     * fold state of the device.
     *
     * In the state of folding device If it's half fold in BookPosture we want to avoid content
     * at the crease/hinge
     */
    val (navigationType, contentType) = when (windowSize) {
        WindowSize.Compact -> {
            Pair(ReplyNavigationType.BOTTOM_NAVIGATION, ReplyContentType.LIST_ONLY)
        }
        WindowSize.Medium -> {
            if (foldingDevicePosture != DevicePosture.NormalPosture) {
                Pair(ReplyNavigationType.NAVIGATION_RAIL, ReplyContentType.LIST_AND_DETAIL)
            } else {
                Pair(ReplyNavigationType.NAVIGATION_RAIL, ReplyContentType.LIST_ONLY)
            }
        }
        WindowSize.Expanded -> {
            if (foldingDevicePosture is DevicePosture.BookPosture) {
                Pair(ReplyNavigationType.NAVIGATION_RAIL, ReplyContentType.LIST_AND_DETAIL)
            } else {
                Pair(ReplyNavigationType.FIXED_NAVIGATION_DRAWER, ReplyContentType.LIST_AND_DETAIL)
            }
        }
    }

    if (navigationType == ReplyNavigationType.FIXED_NAVIGATION_DRAWER) {
        PermanentNavigationDrawer(drawerContent = {}) {
            ReplyAppContent(navigationType, contentType)
        }
    } else {
        ModalNavigationDrawer(drawerContent = {}) {
            ReplyAppContent(navigationType, contentType)
        }
    }
}

@Composable
fun ReplyAppContent(navigationType: ReplyNavigationType, contentType: ReplyContentType) {
    Row(modifier = Modifier
        .fillMaxSize()) {
        if (navigationType == ReplyNavigationType.NAVIGATION_RAIL) {
            //ReplyNavigationRail()
        }
        Column(modifier = Modifier.fillMaxSize()) {
            if (contentType == ReplyContentType.LIST_AND_DETAIL) {
                // ReplyListAndDetailContent()
            } else {
                // ReplyListContent()
            }

Review comment (suggestion):
Optional Kotlin trick:

You can separate the declaration from the initialization, and Kotlin will be smart enough to verify that in all cases it was initialized once and exactly once. That might be clearer than the `Pair` approach:

```suggestion
    val navigationType: ReplyNavigationType
    val contentType: ReplyContentType
    when (windowSize) {
        WindowSize.Compact -> {
            replyNavigationType = ReplyNavigationType.BOTTOM_NAVIGATION
            replyContentType = ReplyContentType.LIST_ONLY
        }
        WindowSize.Medium -> {
            replyNavigationType = ReplyNavigationType.NAVIGATION_RAIL
            replyContentType = if (foldingDevicePosture != DevicePosture.NormalPosture) {
                ReplyContentType.LIST_AND_DETAIL
            } else {
                ReplyContentType.LIST_ONLY
            }
        }
        WindowSize.Expanded -> {
            replyNavigationType = if (foldingDevicePosture is DevicePosture.BookPosture) {
               ReplyNavigationType.NAVIGATION_RAIL
            } else {
               ReplyNavigationType.FIXED_NAVIGATION_DRAWER
            }
            replyContentType = ReplyContentType.LIST_AND_DETAIL
        }
    }
```

Code after:
     * fold state of the device.
     *
     * In the state of folding device If it's half fold in BookPosture we want to avoid content
     * at the crease/hinge
     */
    val navigationType: ReplyNavigationType
    val contentType: ReplyContentType
    when (windowSize) {
        WindowSize.COMPACT -> {
            navigationType = ReplyNavigationType.BOTTOM_NAVIGATION
            contentType = ReplyContentType.LIST_ONLY
        }
        WindowSize.MEDIUM -> {
            navigationType = ReplyNavigationType.NAVIGATION_RAIL
            contentType = if (foldingDevicePosture != DevicePosture.NormalPosture) {
                ReplyContentType.LIST_AND_DETAIL
            } else {
                ReplyContentType.LIST_ONLY
            }
        }
        WindowSize.EXPANDED -> {
            navigationType = if (foldingDevicePosture is DevicePosture.BookPosture) {
                ReplyNavigationType.NAVIGATION_RAIL
            } else {
                ReplyNavigationType.PERMANENT_NAVIGATION_DRAWER
            }
            contentType = ReplyContentType.LIST_AND_DETAIL
        }
    }

    if (navigationType == ReplyNavigationType.PERMANENT_NAVIGATION_DRAWER) {
        PermanentNavigationDrawer(drawerContent = {}) {
            ReplyAppContent(navigationType, contentType)
        }
    } else {
        ModalNavigationDrawer(drawerContent = {}) {
            ReplyAppContent(navigationType, contentType)
        }
    }
}

@Composable
fun ReplyAppContent(navigationType: ReplyNavigationType, contentType: ReplyContentType) {
    Row(modifier = Modifier
        .fillMaxSize()) {
        if (navigationType == ReplyNavigationType.NAVIGATION_RAIL) {
            // TODO ReplyNavigationRail()
        }
        Column(modifier = Modifier.fillMaxSize()) {
            if (contentType == ReplyContentType.LIST_AND_DETAIL) {
                // TODO ReplyListAndDetailContent()