Skip to content

Commit 5a6895e

Browse files
authoredNov 6, 2020
Merge pull request android#270 from android/nb/owl_alpha07
[Owl] Update to snapshot 6953474 & Accompanist Insets.
2 parents cc48218 + c87772e commit 5a6895e

File tree

14 files changed

+69
-680
lines changed

14 files changed

+69
-680
lines changed
 

‎Owl/app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ dependencies {
9191
implementation Libs.AndroidX.Compose.tooling
9292

9393
implementation Libs.Accompanist.coil
94+
implementation Libs.Accompanist.insets
9495
}

‎Owl/app/src/main/java/com/example/owl/ui/OwlApp.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import com.example.owl.ui.courses.Courses
2727
import com.example.owl.ui.onboarding.Onboarding
2828
import com.example.owl.ui.utils.AmbientBackDispatcher
2929
import com.example.owl.ui.utils.Navigator
30-
import com.example.owl.ui.utils.ProvideDisplayInsets
3130
import com.example.owl.ui.utils.ProvideImageLoader
31+
import dev.chrisbanes.accompanist.insets.ProvideWindowInsets
3232

3333
@Composable
3434
fun OwlApp(backDispatcher: OnBackPressedDispatcher) {
@@ -41,7 +41,7 @@ fun OwlApp(backDispatcher: OnBackPressedDispatcher) {
4141
val actions = remember(navigator) { Actions(navigator) }
4242

4343
Providers(AmbientBackDispatcher provides backDispatcher) {
44-
ProvideDisplayInsets {
44+
ProvideWindowInsets {
4545
ProvideImageLoader {
4646
Crossfade(navigator.current) { destination ->
4747
when (destination) {

‎Owl/app/src/main/java/com/example/owl/ui/common/CourseListItem.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.example.owl.ui.common
1818

19-
import androidx.compose.foundation.Text
2019
import androidx.compose.foundation.clickable
2120
import androidx.compose.foundation.layout.Column
2221
import androidx.compose.foundation.layout.Row
@@ -30,6 +29,7 @@ import androidx.compose.foundation.shape.CircleShape
3029
import androidx.compose.material.Icon
3130
import androidx.compose.material.MaterialTheme
3231
import androidx.compose.material.Surface
32+
import androidx.compose.material.Text
3333
import androidx.compose.material.icons.Icons
3434
import androidx.compose.material.icons.rounded.OndemandVideo
3535
import androidx.compose.runtime.Composable

‎Owl/app/src/main/java/com/example/owl/ui/course/CourseDetails.kt

+14-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import androidx.compose.animation.animate
2020
import androidx.compose.foundation.Image
2121
import androidx.compose.foundation.ScrollableColumn
2222
import androidx.compose.foundation.ScrollableRow
23-
import androidx.compose.foundation.Text
2423
import androidx.compose.foundation.clickable
2524
import androidx.compose.foundation.layout.Box
2625
import androidx.compose.foundation.layout.Column
@@ -36,15 +35,16 @@ import androidx.compose.foundation.layout.preferredHeight
3635
import androidx.compose.foundation.layout.preferredSize
3736
import androidx.compose.foundation.rememberScrollState
3837
import androidx.compose.foundation.shape.RoundedCornerShape
39-
import androidx.compose.material.AmbientEmphasisLevels
38+
import androidx.compose.material.AmbientContentAlpha
39+
import androidx.compose.material.ContentAlpha
4040
import androidx.compose.material.Divider
4141
import androidx.compose.material.ExperimentalMaterialApi
4242
import androidx.compose.material.FractionalThreshold
4343
import androidx.compose.material.Icon
4444
import androidx.compose.material.IconButton
4545
import androidx.compose.material.MaterialTheme
46-
import androidx.compose.material.ProvideEmphasis
4746
import androidx.compose.material.Surface
47+
import androidx.compose.material.Text
4848
import androidx.compose.material.TopAppBar
4949
import androidx.compose.material.contentColorFor
5050
import androidx.compose.material.icons.Icons
@@ -56,13 +56,14 @@ import androidx.compose.material.primarySurface
5656
import androidx.compose.material.rememberSwipeableState
5757
import androidx.compose.material.swipeable
5858
import androidx.compose.runtime.Composable
59+
import androidx.compose.runtime.Providers
5960
import androidx.compose.runtime.remember
6061
import androidx.compose.ui.Alignment
6162
import androidx.compose.ui.Modifier
62-
import androidx.compose.ui.WithConstraints
6363
import androidx.compose.ui.drawLayer
6464
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
6565
import androidx.compose.ui.graphics.Color
66+
import androidx.compose.ui.layout.WithConstraints
6667
import androidx.compose.ui.platform.DensityAmbient
6768
import androidx.compose.ui.res.stringResource
6869
import androidx.compose.ui.res.vectorResource
@@ -81,14 +82,14 @@ import com.example.owl.ui.common.OutlinedAvatar
8182
import com.example.owl.ui.theme.BlueTheme
8283
import com.example.owl.ui.theme.PinkTheme
8384
import com.example.owl.ui.theme.pink500
84-
import com.example.owl.ui.utils.AmbientInsets
8585
import com.example.owl.ui.utils.NetworkImage
8686
import com.example.owl.ui.utils.backHandler
8787
import com.example.owl.ui.utils.lerp
88-
import com.example.owl.ui.utils.navigationBarsPadding
8988
import com.example.owl.ui.utils.scrim
90-
import com.example.owl.ui.utils.statusBarsPadding
91-
import com.example.owl.ui.utils.toPaddingValues
89+
import dev.chrisbanes.accompanist.insets.AmbientWindowInsets
90+
import dev.chrisbanes.accompanist.insets.navigationBarsPadding
91+
import dev.chrisbanes.accompanist.insets.statusBarsPadding
92+
import dev.chrisbanes.accompanist.insets.toPaddingValues
9293

9394
private val FabSize = 56.dp
9495
private const val ExpandedSheetAlpha = 0.96f
@@ -227,7 +228,7 @@ private fun CourseDescriptionBody(course: Course) {
227228
.padding(horizontal = 16.dp)
228229
)
229230
Spacer(modifier = Modifier.preferredHeight(16.dp))
230-
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
231+
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
231232
Text(
232233
text = stringResource(id = R.string.course_desc),
233234
style = MaterialTheme.typography.body1,
@@ -246,7 +247,7 @@ private fun CourseDescriptionBody(course: Course) {
246247
.fillMaxWidth()
247248
.padding(16.dp)
248249
)
249-
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
250+
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
250251
Text(
251252
text = stringResource(id = R.string.needs),
252253
style = MaterialTheme.typography.body1,
@@ -320,7 +321,7 @@ private fun LessonsSheet(
320321
) {
321322
// Use the fraction that the sheet is open to drive the transformation from FAB -> Sheet
322323
val fabSize = with(DensityAmbient.current) { FabSize.toPx() }
323-
val fabSheetHeight = fabSize + AmbientInsets.current.systemBars.bottom
324+
val fabSheetHeight = fabSize + AmbientWindowInsets.current.systemBars.bottom
324325
val offsetX = lerp(width - fabSize, 0f, 0f, 0.15f, openFraction)
325326
val offsetY = lerp(height - fabSheetHeight, 0f, openFraction)
326327
val tlCorner = lerp(fabSize, 0f, 0f, 0.15f, openFraction)
@@ -388,7 +389,7 @@ private fun Lessons(
388389
}
389390
ScrollableColumn(
390391
scrollState = scroll,
391-
contentPadding = AmbientInsets.current.systemBars.toPaddingValues(
392+
contentPadding = AmbientWindowInsets.current.systemBars.toPaddingValues(
392393
top = false
393394
)
394395
) {
@@ -442,7 +443,7 @@ private fun Lesson(lesson: Lesson) {
442443
maxLines = 2,
443444
overflow = TextOverflow.Ellipsis
444445
)
445-
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
446+
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
446447
Row(
447448
modifier = Modifier.padding(top = 4.dp),
448449
verticalAlignment = Alignment.CenterVertically

‎Owl/app/src/main/java/com/example/owl/ui/courses/Courses.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ package com.example.owl.ui.courses
1818

1919
import androidx.annotation.DrawableRes
2020
import androidx.annotation.StringRes
21-
import androidx.compose.foundation.AmbientContentColor
2221
import androidx.compose.foundation.Image
23-
import androidx.compose.foundation.Text
2422
import androidx.compose.foundation.layout.padding
2523
import androidx.compose.foundation.layout.preferredHeight
24+
import androidx.compose.material.AmbientContentColor
2625
import androidx.compose.material.BottomNavigation
2726
import androidx.compose.material.BottomNavigationItem
2827
import androidx.compose.material.Icon
2928
import androidx.compose.material.IconButton
3029
import androidx.compose.material.MaterialTheme
3130
import androidx.compose.material.Scaffold
31+
import androidx.compose.material.Text
3232
import androidx.compose.material.TopAppBar
3333
import androidx.compose.material.icons.Icons
3434
import androidx.compose.material.icons.filled.AccountCircle
@@ -45,8 +45,8 @@ import com.example.owl.R
4545
import com.example.owl.model.courses
4646
import com.example.owl.model.topics
4747
import com.example.owl.ui.theme.BlueTheme
48-
import com.example.owl.ui.utils.navigationBarsHeightPlus
49-
import com.example.owl.ui.utils.navigationBarsPadding
48+
import dev.chrisbanes.accompanist.insets.navigationBarsHeight
49+
import dev.chrisbanes.accompanist.insets.navigationBarsPadding
5050

5151
@Composable
5252
fun Courses(selectCourse: (Long) -> Unit) {
@@ -57,7 +57,7 @@ fun Courses(selectCourse: (Long) -> Unit) {
5757
backgroundColor = MaterialTheme.colors.primarySurface,
5858
bottomBar = {
5959
BottomNavigation(
60-
Modifier.navigationBarsHeightPlus(56.dp)
60+
Modifier.navigationBarsHeight(additional = 56.dp)
6161
) {
6262
tabs.forEach { tab ->
6363
BottomNavigationItem(

‎Owl/app/src/main/java/com/example/owl/ui/courses/FeaturedCourses.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.example.owl.ui.courses
1818

1919
import androidx.compose.foundation.ScrollableColumn
20-
import androidx.compose.foundation.Text
2120
import androidx.compose.foundation.clickable
2221
import androidx.compose.foundation.layout.ConstraintLayout
2322
import androidx.compose.foundation.layout.ExperimentalLayout
@@ -28,11 +27,12 @@ import androidx.compose.material.AmbientElevationOverlay
2827
import androidx.compose.material.Icon
2928
import androidx.compose.material.MaterialTheme
3029
import androidx.compose.material.Surface
30+
import androidx.compose.material.Text
3131
import androidx.compose.material.icons.Icons
3232
import androidx.compose.material.icons.rounded.OndemandVideo
3333
import androidx.compose.runtime.Composable
34-
import androidx.compose.ui.Layout
3534
import androidx.compose.ui.Modifier
35+
import androidx.compose.ui.layout.Layout
3636
import androidx.compose.ui.text.style.TextAlign
3737
import androidx.compose.ui.unit.Dp
3838
import androidx.compose.ui.unit.dp
@@ -43,7 +43,7 @@ import com.example.owl.ui.common.OutlinedAvatar
4343
import com.example.owl.ui.theme.BlueTheme
4444
import com.example.owl.ui.theme.OwlTheme
4545
import com.example.owl.ui.utils.NetworkImage
46-
import com.example.owl.ui.utils.statusBarsPadding
46+
import dev.chrisbanes.accompanist.insets.statusBarsPadding
4747
import kotlin.math.ceil
4848

4949
@Composable

‎Owl/app/src/main/java/com/example/owl/ui/courses/MyCourses.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import androidx.compose.foundation.layout.Spacer
2121
import androidx.compose.foundation.layout.padding
2222
import androidx.compose.foundation.layout.preferredHeight
2323
import androidx.compose.foundation.layout.preferredWidth
24-
import androidx.compose.foundation.lazy.ExperimentalLazyDsl
2524
import androidx.compose.foundation.lazy.LazyColumn
2625
import androidx.compose.foundation.shape.RoundedCornerShape
2726
import androidx.compose.runtime.Composable
@@ -32,9 +31,8 @@ import com.example.owl.model.Course
3231
import com.example.owl.model.courses
3332
import com.example.owl.ui.common.CourseListItem
3433
import com.example.owl.ui.theme.BlueTheme
35-
import com.example.owl.ui.utils.statusBarsHeight
34+
import dev.chrisbanes.accompanist.insets.statusBarsHeight
3635

37-
@OptIn(ExperimentalLazyDsl::class)
3836
@Composable
3937
fun MyCourses(
4038
courses: List<Course>,

‎Owl/app/src/main/java/com/example/owl/ui/courses/SearchCourses.kt

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616

1717
package com.example.owl.ui.courses
1818

19-
import androidx.compose.foundation.BaseTextField
2019
import androidx.compose.foundation.ExperimentalFoundationApi
2120
import androidx.compose.foundation.Image
2221
import androidx.compose.foundation.ScrollableColumn
23-
import androidx.compose.foundation.Text
2422
import androidx.compose.foundation.clickable
2523
import androidx.compose.foundation.layout.fillMaxWidth
2624
import androidx.compose.foundation.layout.padding
2725
import androidx.compose.foundation.layout.wrapContentWidth
26+
import androidx.compose.foundation.text.BasicTextField
27+
import androidx.compose.material.AmbientContentColor
2828
import androidx.compose.material.Icon
2929
import androidx.compose.material.IconButton
3030
import androidx.compose.material.MaterialTheme
31+
import androidx.compose.material.Text
3132
import androidx.compose.material.TopAppBar
3233
import androidx.compose.material.icons.Icons
3334
import androidx.compose.material.icons.filled.AccountCircle
@@ -44,7 +45,7 @@ import com.example.owl.R
4445
import com.example.owl.model.Topic
4546
import com.example.owl.model.topics
4647
import com.example.owl.ui.theme.BlueTheme
47-
import com.example.owl.ui.utils.statusBarsPadding
48+
import dev.chrisbanes.accompanist.insets.statusBarsPadding
4849

4950
@Composable
5051
fun SearchCourses(
@@ -102,10 +103,14 @@ private fun AppBar(
102103
.align(Alignment.CenterVertically)
103104
)
104105
// TODO hint
105-
BaseTextField(
106+
BasicTextField(
106107
value = searchTerm,
107108
onValueChange = updateSearchTerm,
108-
textStyle = MaterialTheme.typography.subtitle1,
109+
textStyle = MaterialTheme.typography.subtitle1.copy(
110+
color = AmbientContentColor.current
111+
),
112+
maxLines = 1,
113+
cursorColor = AmbientContentColor.current,
109114
modifier = Modifier
110115
.weight(1f)
111116
.align(Alignment.CenterVertically)

‎Owl/app/src/main/java/com/example/owl/ui/onboarding/Onboarding.kt

+21-24
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import androidx.compose.animation.core.FloatPropKey
2121
import androidx.compose.animation.core.transitionDefinition
2222
import androidx.compose.animation.transition
2323
import androidx.compose.foundation.Image
24-
import androidx.compose.foundation.Text
2524
import androidx.compose.foundation.horizontalScroll
2625
import androidx.compose.foundation.layout.Arrangement
2726
import androidx.compose.foundation.layout.Box
@@ -37,26 +36,28 @@ import androidx.compose.foundation.layout.wrapContentHeight
3736
import androidx.compose.foundation.rememberScrollState
3837
import androidx.compose.foundation.selection.toggleable
3938
import androidx.compose.foundation.shape.CornerSize
40-
import androidx.compose.material.AmbientEmphasisLevels
39+
import androidx.compose.material.AmbientContentAlpha
40+
import androidx.compose.material.ContentAlpha
4141
import androidx.compose.material.FloatingActionButton
4242
import androidx.compose.material.Icon
4343
import androidx.compose.material.IconButton
4444
import androidx.compose.material.MaterialTheme
45-
import androidx.compose.material.ProvideEmphasis
4645
import androidx.compose.material.Scaffold
4746
import androidx.compose.material.Surface
47+
import androidx.compose.material.Text
4848
import androidx.compose.material.icons.Icons
4949
import androidx.compose.material.icons.filled.Done
5050
import androidx.compose.material.icons.filled.Settings
5151
import androidx.compose.material.icons.rounded.Explore
5252
import androidx.compose.material.primarySurface
5353
import androidx.compose.runtime.Composable
54+
import androidx.compose.runtime.Providers
5455
import androidx.compose.runtime.mutableStateOf
5556
import androidx.compose.runtime.remember
5657
import androidx.compose.ui.Alignment
57-
import androidx.compose.ui.Layout
5858
import androidx.compose.ui.Modifier
5959
import androidx.compose.ui.drawLayer
60+
import androidx.compose.ui.layout.Layout
6061
import androidx.compose.ui.res.stringResource
6162
import androidx.compose.ui.res.vectorResource
6263
import androidx.compose.ui.text.style.TextAlign
@@ -69,8 +70,8 @@ import com.example.owl.ui.theme.OwlTheme
6970
import com.example.owl.ui.theme.YellowTheme
7071
import com.example.owl.ui.theme.pink500
7172
import com.example.owl.ui.utils.NetworkImage
72-
import com.example.owl.ui.utils.navigationBarsPadding
73-
import com.example.owl.ui.utils.statusBarsPadding
73+
import dev.chrisbanes.accompanist.insets.navigationBarsPadding
74+
import dev.chrisbanes.accompanist.insets.statusBarsPadding
7475
import kotlin.math.max
7576

7677
@Composable
@@ -94,17 +95,15 @@ fun Onboarding(onboardingComplete: () -> Unit) {
9495
.navigationBarsPadding()
9596
.padding(innerPadding)
9697
) {
97-
ProvideEmphasis(AmbientEmphasisLevels.current.high) {
98-
Text(
99-
text = stringResource(R.string.choose_topics_that_interest_you),
100-
style = MaterialTheme.typography.h4,
101-
textAlign = TextAlign.End,
102-
modifier = Modifier.padding(
103-
horizontal = 16.dp,
104-
vertical = 32.dp
105-
)
98+
Text(
99+
text = stringResource(R.string.choose_topics_that_interest_you),
100+
style = MaterialTheme.typography.h4,
101+
textAlign = TextAlign.End,
102+
modifier = Modifier.padding(
103+
horizontal = 16.dp,
104+
vertical = 32.dp
106105
)
107-
}
106+
)
108107
TopicsGrid(
109108
modifier = Modifier
110109
.weight(1f)
@@ -129,13 +128,11 @@ private fun AppBar() {
129128
asset = vectorResource(id = OwlTheme.images.lockupLogo),
130129
modifier = Modifier.padding(16.dp)
131130
)
132-
ProvideEmphasis(emphasis = AmbientEmphasisLevels.current.high) {
133-
IconButton(
134-
modifier = Modifier.padding(16.dp),
135-
onClick = { /* todo */ }
136-
) {
137-
Icon(Icons.Filled.Settings)
138-
}
131+
IconButton(
132+
modifier = Modifier.padding(16.dp),
133+
onClick = { /* todo */ }
134+
) {
135+
Icon(Icons.Filled.Settings)
139136
}
140137
}
141138
}
@@ -221,7 +218,7 @@ private fun TopicChip(topic: Topic) {
221218
)
222219
)
223220
Row(verticalAlignment = Alignment.CenterVertically) {
224-
ProvideEmphasis(emphasis = AmbientEmphasisLevels.current.medium) {
221+
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
225222
Icon(
226223
asset = vectorResource(R.drawable.ic_grain),
227224
modifier = Modifier

0 commit comments

Comments
 (0)