Skip to content

Commit 8adf820

Browse files
authored
Merge pull request #452 from android/jdk/adaptive-codelab-end
[AdaptiveUiCodelab] use window size class from material3.adaptive:ada…
2 parents cd27d70 + 2dfe81f commit 8adf820

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

AdaptiveUiCodelab/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dependencies {
7272
androidTestImplementation(composeBom)
7373

7474
implementation(libs.androidx.material3)
75-
implementation(libs.androidx.material3.windowSizeClass)
75+
implementation(libs.androidx.material3.adaptive)
7676
implementation(libs.androidx.material.icons.extended)
7777
implementation(libs.androidx.ui.tooling.preview)
7878
androidTestImplementation(libs.androidx.ui.test.junit4)

AdaptiveUiCodelab/app/src/main/java/com/example/reply/ui/MainActivity.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
2222
import androidx.activity.viewModels
23-
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
24-
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
25-
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
23+
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
2624
import androidx.compose.runtime.Composable
2725
import androidx.compose.runtime.collectAsState
2826
import androidx.compose.ui.tooling.preview.Preview
2927
import androidx.lifecycle.flowWithLifecycle
3028
import androidx.lifecycle.lifecycleScope
29+
import androidx.window.core.layout.WindowWidthSizeClass
3130
import androidx.window.layout.FoldingFeature
3231
import androidx.window.layout.WindowInfoTracker
3332
import com.example.reply.data.local.LocalEmailsDataProvider
@@ -43,7 +42,6 @@ class MainActivity : ComponentActivity() {
4342

4443
private val viewModel: ReplyHomeViewModel by viewModels()
4544

46-
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
4745
override fun onCreate(savedInstanceState: Bundle?) {
4846
super.onCreate(savedInstanceState)
4947

@@ -75,10 +73,10 @@ class MainActivity : ComponentActivity() {
7573

7674
setContent {
7775
ReplyTheme {
78-
val windowSize = calculateWindowSizeClass(this)
76+
val windowAdaptiveInfo = currentWindowAdaptiveInfo()
7977
val devicePosture = devicePostureFlow.collectAsState().value
8078
val uiState = viewModel.uiState.collectAsState().value
81-
ReplyApp(windowSize.widthSizeClass, devicePosture, uiState)
79+
ReplyApp(windowAdaptiveInfo.windowSizeClass.windowWidthSizeClass, devicePosture, uiState)
8280
}
8381
}
8482
}
@@ -90,7 +88,7 @@ fun ReplyAppPreview() {
9088
ReplyTheme {
9189
ReplyApp(
9290
replyHomeUIState = ReplyHomeUIState(emails = LocalEmailsDataProvider.allEmails),
93-
windowSize = WindowWidthSizeClass.Compact,
91+
windowSize = WindowWidthSizeClass.COMPACT,
9492
foldingDevicePosture = DevicePosture.NormalPosture
9593
)
9694
}
@@ -102,7 +100,7 @@ fun ReplyAppPreviewTablet() {
102100
ReplyTheme {
103101
ReplyApp(
104102
replyHomeUIState = ReplyHomeUIState(emails = LocalEmailsDataProvider.allEmails),
105-
windowSize = WindowWidthSizeClass.Medium,
103+
windowSize = WindowWidthSizeClass.MEDIUM,
106104
foldingDevicePosture = DevicePosture.NormalPosture
107105
)
108106
}
@@ -114,8 +112,8 @@ fun ReplyAppPreviewDesktop() {
114112
ReplyTheme {
115113
ReplyApp(
116114
replyHomeUIState = ReplyHomeUIState(emails = LocalEmailsDataProvider.allEmails),
117-
windowSize = WindowWidthSizeClass.Expanded,
115+
windowSize = WindowWidthSizeClass.EXPANDED,
118116
foldingDevicePosture = DevicePosture.NormalPosture
119117
)
120118
}
121-
}
119+
}

AdaptiveUiCodelab/app/src/main/java/com/example/reply/ui/ReplyApp.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import androidx.compose.material3.PermanentDrawerSheet
5252
import androidx.compose.material3.PermanentNavigationDrawer
5353
import androidx.compose.material3.Text
5454
import androidx.compose.material3.rememberDrawerState
55-
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
5655
import androidx.compose.runtime.Composable
5756
import androidx.compose.runtime.rememberCoroutineScope
5857
import androidx.compose.ui.Alignment
@@ -61,6 +60,7 @@ import androidx.compose.ui.graphics.Color
6160
import androidx.compose.ui.res.stringResource
6261
import androidx.compose.ui.tooling.preview.Preview
6362
import androidx.compose.ui.unit.dp
63+
import androidx.window.core.layout.WindowWidthSizeClass
6464
import com.example.reply.R
6565
import com.example.reply.ui.utils.DevicePosture
6666
import com.example.reply.ui.utils.ReplyContentType
@@ -85,19 +85,19 @@ fun ReplyApp(
8585
val contentType: ReplyContentType
8686

8787
when (windowSize) {
88-
WindowWidthSizeClass.Compact -> {
88+
WindowWidthSizeClass.COMPACT -> {
8989
navigationType = ReplyNavigationType.BOTTOM_NAVIGATION
9090
contentType = ReplyContentType.LIST_ONLY
9191
}
92-
WindowWidthSizeClass.Medium -> {
92+
WindowWidthSizeClass.MEDIUM -> {
9393
navigationType = ReplyNavigationType.NAVIGATION_RAIL
9494
contentType = if (foldingDevicePosture != DevicePosture.NormalPosture) {
9595
ReplyContentType.LIST_AND_DETAIL
9696
} else {
9797
ReplyContentType.LIST_ONLY
9898
}
9999
}
100-
WindowWidthSizeClass.Expanded -> {
100+
WindowWidthSizeClass.EXPANDED -> {
101101
navigationType = if (foldingDevicePosture is DevicePosture.BookPosture) {
102102
ReplyNavigationType.NAVIGATION_RAIL
103103
} else {
@@ -320,4 +320,4 @@ fun NavigationDrawerContent(
320320
onClick = { /*TODO*/ }
321321
)
322322
}
323-
}
323+
}

AdaptiveUiCodelab/gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ kotlin = "1.9.23"
1010
kotlinxCoroutinesAndroid = "1.8.0"
1111
lifecycleViewmodelCompose = "2.7.0"
1212
lifecycleRuntimeKtx = "2.7.0"
13-
material3WindowSizeClass = "1.2.1"
13+
material3Adaptive = "1.0.0-alpha12"
1414
window = "1.2.0"
1515

1616
[libraries]
@@ -23,7 +23,7 @@ androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtim
2323
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" }
2424
androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
2525
androidx-material3 = { module = "androidx.compose.material3:material3" }
26-
androidx-material3-windowSizeClass = { module = "androidx.compose.material3:material3-window-size-class", version.ref = "material3WindowSizeClass" }
26+
androidx-material3-adaptive = { module = "androidx.compose.material3.adaptive:adaptive", version.ref = "material3Adaptive" }
2727
androidx-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
2828
androidx-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
2929
androidx-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" }

0 commit comments

Comments
 (0)