Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Owl] Update to snapshot 6901934.
Change-Id: I15c92c5252e61b8918bbb9c80cbdc679e3809555
  • Loading branch information
nickbutcher committed Oct 13, 2020
commit 0e3edfc10d215d2ad2264d273c739cc267951e9d
4 changes: 2 additions & 2 deletions Owl/app/src/main/java/com/example/owl/ui/OwlApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.compose.runtime.savedinstancestate.rememberSavedInstanceState
import com.example.owl.ui.course.CourseDetails
import com.example.owl.ui.courses.Courses
import com.example.owl.ui.onboarding.Onboarding
import com.example.owl.ui.utils.BackDispatcherAmbient
import com.example.owl.ui.utils.AmbientBackDispatcher
import com.example.owl.ui.utils.Navigator
import com.example.owl.ui.utils.ProvideDisplayInsets
import com.example.owl.ui.utils.ProvideImageLoader
Expand All @@ -40,7 +40,7 @@ fun OwlApp(backDispatcher: OnBackPressedDispatcher) {
}
val actions = remember(navigator) { Actions(navigator) }

Providers(BackDispatcherAmbient provides backDispatcher) {
Providers(AmbientBackDispatcher provides backDispatcher) {
ProvideDisplayInsets {
ProvideImageLoader {
Crossfade(navigator.current) { destination ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
Expand Down Expand Up @@ -104,6 +105,7 @@ fun CourseListItem(
modifier = Modifier
.padding(start = 8.dp)
.weight(1f)
.wrapContentWidth(Alignment.Start)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a note to remember to re-visit this in alpha06? Seems like the Text change is reverted

)
NetworkImage(
url = course.instructor,
Expand Down
14 changes: 7 additions & 7 deletions Owl/app/src/main/java/com/example/owl/ui/course/CourseDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.AmbientEmphasisLevels
import androidx.compose.material.Divider
import androidx.compose.material.EmphasisAmbient
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.FractionalThreshold
import androidx.compose.material.IconButton
Expand Down Expand Up @@ -81,7 +81,7 @@ import com.example.owl.ui.common.OutlinedAvatar
import com.example.owl.ui.theme.BlueTheme
import com.example.owl.ui.theme.PinkTheme
import com.example.owl.ui.theme.pink500
import com.example.owl.ui.utils.InsetsAmbient
import com.example.owl.ui.utils.AmbientInsets
import com.example.owl.ui.utils.NetworkImage
import com.example.owl.ui.utils.backHandler
import com.example.owl.ui.utils.lerp
Expand Down Expand Up @@ -227,7 +227,7 @@ private fun CourseDescriptionBody(course: Course) {
.padding(horizontal = 16.dp)
)
Spacer(modifier = Modifier.preferredHeight(16.dp))
ProvideEmphasis(EmphasisAmbient.current.medium) {
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
Text(
text = stringResource(id = R.string.course_desc),
style = MaterialTheme.typography.body1,
Expand All @@ -246,7 +246,7 @@ private fun CourseDescriptionBody(course: Course) {
.fillMaxWidth()
.padding(16.dp)
)
ProvideEmphasis(EmphasisAmbient.current.medium) {
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
Text(
text = stringResource(id = R.string.needs),
style = MaterialTheme.typography.body1,
Expand Down Expand Up @@ -320,7 +320,7 @@ private fun LessonsSheet(
) {
// Use the fraction that the sheet is open to drive the transformation from FAB -> Sheet
val fabSize = with(DensityAmbient.current) { FabSize.toPx() }
val fabSheetHeight = fabSize + InsetsAmbient.current.systemBars.bottom
val fabSheetHeight = fabSize + AmbientInsets.current.systemBars.bottom
val offsetX = lerp(width - fabSize, 0f, 0f, 0.15f, openFraction)
val offsetY = lerp(height - fabSheetHeight, 0f, openFraction)
val tlCorner = lerp(fabSize, 0f, 0f, 0.15f, openFraction)
Expand Down Expand Up @@ -388,7 +388,7 @@ private fun Lessons(
}
ScrollableColumn(
scrollState = scroll,
contentPadding = InsetsAmbient.current.systemBars.toPaddingValues(
contentPadding = AmbientInsets.current.systemBars.toPaddingValues(
top = false
)
) {
Expand Down Expand Up @@ -442,7 +442,7 @@ private fun Lesson(lesson: Lesson) {
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
ProvideEmphasis(EmphasisAmbient.current.medium) {
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
Row(
modifier = Modifier.padding(top = 4.dp),
verticalAlignment = Alignment.CenterVertically
Expand Down
4 changes: 2 additions & 2 deletions Owl/app/src/main/java/com/example/owl/ui/courses/Courses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package com.example.owl.ui.courses

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.AmbientContentColor
import androidx.compose.foundation.Icon
import androidx.compose.foundation.Image
import androidx.compose.foundation.Text
import androidx.compose.foundation.contentColor
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.material.BottomNavigation
Expand Down Expand Up @@ -67,7 +67,7 @@ fun Courses(selectCourse: (Long) -> Unit) {
onClick = { setSelectedTab(tab) },
alwaysShowLabels = false,
selectedContentColor = MaterialTheme.colors.secondary,
unselectedContentColor = contentColor(),
unselectedContentColor = AmbientContentColor.current,
modifier = Modifier.navigationBarsPadding()
)
}
Expand Down
24 changes: 15 additions & 9 deletions Owl/app/src/main/java/com/example/owl/ui/courses/MyCourses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package com.example.owl.ui.courses

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.lazy.ExperimentalLazyDsl
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -32,30 +32,36 @@ import com.example.owl.model.Course
import com.example.owl.model.courses
import com.example.owl.ui.common.CourseListItem
import com.example.owl.ui.theme.BlueTheme
import com.example.owl.ui.utils.statusBarsPadding
import com.example.owl.ui.utils.statusBarsHeight

@OptIn(ExperimentalLazyDsl::class)
@Composable
fun MyCourses(
courses: List<Course>,
selectCourse: (Long) -> Unit,
modifier: Modifier = Modifier
) {
Column(modifier = modifier.statusBarsPadding()) {
// TODO appbar should scroll out
CoursesAppBar()
LazyColumnFor(courses) { course ->
MyCourse(course, selectCourse)
LazyColumn(modifier) {
item {
Spacer(Modifier.statusBarsHeight())
}
item {
CoursesAppBar()
}
itemsIndexed(courses) { index, course ->
MyCourse(course, index, selectCourse)
}
}
}

@Composable
fun MyCourse(
course: Course,
index: Int,
selectCourse: (Long) -> Unit
) {
Row(modifier = Modifier.padding(bottom = 8.dp)) {
val stagger = if (course.id % 2L == 0L) 72.dp else 16.dp
val stagger = if (index % 2 == 0) 72.dp else 16.dp
Spacer(modifier = Modifier.preferredWidth(stagger))
CourseListItem(
course = course,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.foundation.Text
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.TopAppBar
Expand Down Expand Up @@ -67,6 +68,7 @@ fun SearchCourses(
end = 16.dp,
bottom = 8.dp
)
.wrapContentWidth(Alignment.Start)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.material.EmphasisAmbient
import androidx.compose.material.AmbientEmphasisLevels
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
Expand Down Expand Up @@ -94,7 +94,7 @@ fun Onboarding(onboardingComplete: () -> Unit) {
.navigationBarsPadding()
.padding(innerPadding)
) {
ProvideEmphasis(EmphasisAmbient.current.high) {
ProvideEmphasis(AmbientEmphasisLevels.current.high) {
Text(
text = stringResource(R.string.choose_topics_that_interest_you),
style = MaterialTheme.typography.h4,
Expand Down Expand Up @@ -129,7 +129,7 @@ private fun AppBar() {
asset = vectorResource(id = OwlTheme.images.lockupLogo),
modifier = Modifier.padding(16.dp)
)
ProvideEmphasis(emphasis = EmphasisAmbient.current.high) {
ProvideEmphasis(emphasis = AmbientEmphasisLevels.current.high) {
IconButton(
modifier = Modifier.padding(16.dp),
onClick = { /* todo */ }
Expand Down Expand Up @@ -221,7 +221,7 @@ private fun TopicChip(topic: Topic) {
)
)
Row(verticalAlignment = Alignment.CenterVertically) {
ProvideEmphasis(emphasis = EmphasisAmbient.current.medium) {
ProvideEmphasis(emphasis = AmbientEmphasisLevels.current.medium) {
Icon(
asset = vectorResource(R.drawable.ic_grain),
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ import androidx.compose.ui.unit.dp
* Elevation values that can be themed.
*/
@Immutable
data class Elevation(val card: Dp = 0.dp)
data class Elevations(val card: Dp = 0.dp)

internal val ElevationAmbient = staticAmbientOf { Elevation() }
internal val AmbientElevations = staticAmbientOf { Elevations() }
2 changes: 1 addition & 1 deletion Owl/app/src/main/java/com/example/owl/ui/theme/Images.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ import androidx.compose.runtime.staticAmbientOf
@Immutable
data class Images(@DrawableRes val lockupLogo: Int)

internal val ImageAmbient = staticAmbientOf<Images>()
internal val AmbientImages = staticAmbientOf<Images>()
18 changes: 9 additions & 9 deletions Owl/app/src/main/java/com/example/owl/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ fun PinkTheme(
OwlTheme(darkTheme, colors, content)
}

private val LightElevation = Elevation()
private val LightElevation = Elevations()

private val DarkElevation = Elevation(card = 1.dp)
private val DarkElevation = Elevations(card = 1.dp)

private val LightImages = Images(lockupLogo = R.drawable.ic_lockup_blue)

Expand All @@ -127,8 +127,8 @@ private fun OwlTheme(
val elevation = if (darkTheme) DarkElevation else LightElevation
val images = if (darkTheme) DarkImages else LightImages
Providers(
ElevationAmbient provides elevation,
ImageAmbient provides images
AmbientElevations provides elevation,
AmbientImages provides images
) {
MaterialTheme(
colors = colors,
Expand All @@ -140,7 +140,7 @@ private fun OwlTheme(
}

/**
* Alternate to [MaterialTheme] allowing us to add our own theme systems (e.g. [Elevation]) or to
* Alternate to [MaterialTheme] allowing us to add our own theme systems (e.g. [Elevations]) or to
* extend [MaterialTheme]'s types e.g. return our own [Colors] extension
*/
object OwlTheme {
Expand All @@ -167,16 +167,16 @@ object OwlTheme {
get() = MaterialTheme.shapes

/**
* Retrieves the current [Elevation] at the call site's position in the hierarchy.
* Retrieves the current [Elevations] at the call site's position in the hierarchy.
*/
@Composable
val elevations: Elevation
get() = ElevationAmbient.current
val elevations: Elevations
get() = AmbientElevations.current

/**
* Retrieves the current [Images] at the call site's position in the hierarchy.
*/
@Composable
val images: Images
get() = ImageAmbient.current
get() = AmbientImages.current
}
20 changes: 10 additions & 10 deletions Owl/app/src/main/java/com/example/owl/ui/utils/Insets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class Insets {
internal set
}

val InsetsAmbient = staticAmbientOf { DisplayInsets() }
val AmbientInsets = staticAmbientOf { DisplayInsets() }

/**
* Applies any [WindowInsetsCompat] values to [InsetsAmbient], which are then available
* Applies any [WindowInsetsCompat] values to [AmbientInsets], which are then available
* within [content].
*
* @param consumeWindowInsets Whether to consume any [WindowInsetsCompat]s which are dispatched to
Expand Down Expand Up @@ -165,7 +165,7 @@ fun ProvideDisplayInsets(
}
}

Providers(InsetsAmbient provides displayInsets) {
Providers(AmbientInsets provides displayInsets) {
content()
}
}
Expand All @@ -192,7 +192,7 @@ private fun Insets.updateFrom(windowInsets: WindowInsetsCompat, type: Int) {
*/
fun Modifier.systemBarsPadding(enabled: Boolean = true) = composed {
insetsPadding(
insets = InsetsAmbient.current.systemBars,
insets = AmbientInsets.current.systemBars,
left = enabled,
top = enabled,
right = enabled,
Expand All @@ -205,7 +205,7 @@ fun Modifier.systemBarsPadding(enabled: Boolean = true) = composed {
* of the content.
*/
fun Modifier.statusBarsPadding() = composed {
insetsPadding(insets = InsetsAmbient.current.statusBars, top = true)
insetsPadding(insets = AmbientInsets.current.statusBars, top = true)
}

/**
Expand All @@ -226,7 +226,7 @@ fun Modifier.navigationBarsPadding(
right: Boolean = true
) = composed {
insetsPadding(
insets = InsetsAmbient.current.navigationBars,
insets = AmbientInsets.current.navigationBars,
left = left,
right = right,
bottom = bottom
Expand Down Expand Up @@ -260,7 +260,7 @@ fun Modifier.navigationBarsPadding(
*/
fun Modifier.statusBarsHeight(additional: Dp = 0.dp) = composed {
InsetsSizeModifier(
insets = InsetsAmbient.current.statusBars,
insets = AmbientInsets.current.statusBars,
heightSide = VerticalSide.Top,
additionalHeight = additional
)
Expand Down Expand Up @@ -312,7 +312,7 @@ inline fun Modifier.statusBarsHeight() = statusBarsHeightPlus(0.dp)
*/
fun Modifier.statusBarsHeightPlus(additional: Dp) = composed {
InsetsSizeModifier(
insets = InsetsAmbient.current.statusBars,
insets = AmbientInsets.current.statusBars,
heightSide = VerticalSide.Top,
additionalHeight = additional
)
Expand Down Expand Up @@ -364,7 +364,7 @@ inline fun Modifier.navigationBarsHeight() = navigationBarsHeightPlus(0.dp)
*/
fun Modifier.navigationBarsHeightPlus(additional: Dp) = composed {
InsetsSizeModifier(
insets = InsetsAmbient.current.navigationBars,
insets = AmbientInsets.current.navigationBars,
heightSide = VerticalSide.Bottom,
additionalHeight = additional
)
Expand Down Expand Up @@ -418,7 +418,7 @@ fun Modifier.navigationBarsWidthPlus(
additional: Dp
) = composed {
InsetsSizeModifier(
insets = InsetsAmbient.current.navigationBars,
insets = AmbientInsets.current.navigationBars,
widthSide = side,
additionalWidth = additional
)
Expand Down
Loading