Skip to content

Commit

Permalink
Merge pull request #333 from android/dev_alpha09
Browse files Browse the repository at this point in the history
Update for Jetpack Compose 1.0.0-alpha09
  • Loading branch information
chrisbanes authored Dec 17, 2020
2 parents a09e341 + a5f658f commit de4d7b8
Show file tree
Hide file tree
Showing 72 changed files with 343 additions and 435 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assertLabelEquals
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithLabel
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import dagger.hilt.android.testing.HiltAndroidRule
Expand Down Expand Up @@ -69,16 +69,16 @@ class CalendarTest {

@Test
fun scrollsToTheBottom() {
composeTestRule.onNodeWithLabel("January 1").assertExists()
composeTestRule.onNodeWithLabel("December 31").performScrollTo().performClick()
composeTestRule.onNodeWithContentDescription("January 1").assertExists()
composeTestRule.onNodeWithContentDescription("December 31").performScrollTo().performClick()
assert(datesRepository.datesSelected.toString() == "Dec 31")
}

@Test
fun onDaySelected() {
composeTestRule.onNodeWithLabel("January 1").assertExists()
composeTestRule.onNodeWithLabel("January 2").assertExists().performClick()
composeTestRule.onNodeWithLabel("January 3").assertExists()
composeTestRule.onNodeWithContentDescription("January 1").assertExists()
composeTestRule.onNodeWithContentDescription("January 2").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 3").assertExists()

val datesNoSelected = composeTestRule.onDateNodes(NoSelected)
datesNoSelected[0].assertLabelEquals("January 1")
Expand All @@ -89,13 +89,13 @@ class CalendarTest {

@Test
fun twoDaysSelected() {
composeTestRule.onNodeWithLabel("January 2").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 2").assertExists().performClick()

val datesNoSelectedOneClick = composeTestRule.onDateNodes(NoSelected)
datesNoSelectedOneClick[0].assertLabelEquals("January 1")
datesNoSelectedOneClick[1].assertLabelEquals("January 3")

composeTestRule.onNodeWithLabel("January 4").assertExists().performClick()
composeTestRule.onNodeWithContentDescription("January 4").assertExists().performClick()

composeTestRule.onDateNode(FirstDay).assertLabelEquals("January 2")
composeTestRule.onDateNode(Selected).assertLabelEquals("January 3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import org.junit.Rule
import org.junit.Test
import java.util.concurrent.CountDownLatch
import javax.inject.Inject
import kotlin.math.pow
import kotlin.math.round

@UninstallModules(DispatchersModule::class)
@HiltAndroidTest
Expand Down Expand Up @@ -118,4 +120,5 @@ class DetailsActivityTest {
}
}

private fun Double.round(decimals: Int = 2): Double = "%.${decimals}f".format(this).toDouble()
private fun Double.round(decimals: Int = 2): Double =
round(this * 10f.pow(decimals)) / 10f.pow(decimals)
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private fun CraneBaseUserInput(
showCaption: () -> Boolean = { true },
tintIcon: () -> Boolean,
tint: Color = AmbientContentColor.current,
children: @Composable () -> Unit
content: @Composable () -> Unit
) {
Surface(modifier = modifier, color = MaterialTheme.colors.primaryVariant) {
Row(Modifier.padding(all = 12.dp)) {
Expand All @@ -138,15 +138,15 @@ private fun CraneBaseUserInput(
Spacer(Modifier.preferredWidth(8.dp))
}
Row(Modifier.weight(1f).align(Alignment.CenterVertically)) {
children()
content()
}
}
}
}

@Preview
@Composable
fun previewInput() {
fun PreviewInput() {
CraneScaffold {
CraneBaseUserInput(
tintIcon = { true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
Expand Down Expand Up @@ -62,16 +62,19 @@ fun ExploreSection(
style = MaterialTheme.typography.caption.copy(color = crane_caption)
)
Spacer(Modifier.preferredHeight(8.dp))
LazyColumnFor(
LazyColumn(
modifier = Modifier.weight(1f),
items = exploreList
) { item ->
ExploreItem(
modifier = Modifier.fillParentMaxWidth(),
item = item,
onItemClicked = onItemClicked
)
Divider(color = crane_divider_color)
) {
items(exploreList) { exploreItem ->
Column(Modifier.fillParentMaxWidth()) {
ExploreItem(
modifier = Modifier.fillParentMaxWidth(),
item = exploreItem,
onItemClicked = onItemClicked
)
Divider(color = crane_divider_color)
}
}
}
}
}
Expand Down Expand Up @@ -119,8 +122,8 @@ private fun ExploreItem(
}

@Composable
private fun ExploreImageContainer(children: @Composable () -> Unit) {
private fun ExploreImageContainer(content: @Composable () -> Unit) {
Surface(Modifier.preferredSize(width = 60.dp, height = 60.dp), RoundedCornerShape(4.dp)) {
children()
content()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.samples.crane.ui.CraneTheme

@Composable
fun CraneScaffold(children: @Composable () -> Unit) {
fun CraneScaffold(content: @Composable () -> Unit) {
CraneTheme {
Surface(color = MaterialTheme.colors.primary) {
children()
content()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
import androidx.compose.ui.semantics.accessibilityLabel
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -137,7 +137,7 @@ private fun Week(
day,
onDayClicked,
Modifier.semantics {
accessibilityLabel = "${month.name} ${day.value}"
contentDescription = "${month.name} ${day.value}"
dayStatusProperty = day.status
}
)
Expand Down Expand Up @@ -195,21 +195,21 @@ private fun Day(name: String) {
private fun DayContainer(
modifier: Modifier = Modifier,
backgroundColor: Color = Color.Transparent,
children: @Composable () -> Unit
content: @Composable () -> Unit
) {
// What if this doesn't fit the screen? - LayoutFlexible(1f) + LayoutAspectRatio(1f)
Surface(
modifier = modifier.preferredSize(width = CELL_SIZE, height = CELL_SIZE),
color = backgroundColor
) {
children()
content()
}
}

@Composable
private fun DayStatusContainer(
status: DaySelectedStatus,
children: @Composable () -> Unit
content: @Composable () -> Unit
) {
if (status.isMarked()) {
Box {
Expand All @@ -220,10 +220,10 @@ private fun DayStatusContainer(
} else if (status == DaySelectedStatus.LastDay) {
SemiRect(color = color, lookingLeft = true)
}
children()
content()
}
} else {
children()
content()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class CalendarMonth(
val monthNumber: Int,
val startDayOfWeek: DayOfWeek
) {
val days = mutableListOf<CalendarDay>().apply {
private val days = mutableListOf<CalendarDay>().apply {
// Add offset of the start of the month
for (i in 1..startDayOfWeek.ordinal) {
add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.material.Button
import androidx.compose.material.ButtonConstants
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -186,7 +186,7 @@ private fun ZoomControls(
private fun ZoomButton(text: String, onClick: () -> Unit) {
Button(
modifier = Modifier.padding(8.dp),
colors = ButtonConstants.defaultButtonColors(
colors = ButtonDefaults.buttonColors(
backgroundColor = MaterialTheme.colors.onPrimary,
contentColor = MaterialTheme.colors.primary
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ fun EatSearchContent(datesSelected: String, eatUpdates: EatSearchContentUpdates)
}

@Composable
private fun CraneSearch(searchItems: @Composable () -> Unit) {
private fun CraneSearch(content: @Composable () -> Unit) {
Column(Modifier.padding(start = 24.dp, top = 0.dp, end = 24.dp, bottom = 12.dp)) {
searchItems()
content()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ val BottomSheetShape = RoundedCornerShape(
)

@Composable
fun CraneTheme(children: @Composable () -> Unit) {
fun CraneTheme(content: @Composable () -> Unit) {
MaterialTheme(colors = craneColors, typography = craneTypography) {
children()
content()
}
}
2 changes: 1 addition & 1 deletion Crane/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ buildscript {
}

plugins {
id 'com.diffplug.spotless' version '5.7.0'
id 'com.diffplug.spotless' version '5.8.2'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package com.example.crane.buildsrc

object Versions {
const val ktLint = "0.39.0"
const val ktLint = "0.40.0"
}

object Libs {
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha02"
const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.0-alpha03"
const val ktLint = "com.pinterest:ktlint:${Versions.ktLint}"

object GoogleMaps {
Expand All @@ -30,12 +30,12 @@ object Libs {
}

object Accompanist {
private const val version = "0.4.0"
private const val version = "0.4.1"
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
}

object Kotlin {
private const val version = "1.4.20"
private const val version = "1.4.21"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
const val extensions = "org.jetbrains.kotlin:kotlin-android-extensions:$version"
Expand All @@ -50,7 +50,7 @@ object Libs {
object AndroidX {
object Compose {
const val snapshot = ""
const val version = "1.0.0-alpha08"
private const val version = "1.0.0-alpha09"

const val runtime = "androidx.compose.runtime:runtime:$version"
const val runtimeLivedata = "androidx.compose.runtime:runtime-livedata:$version"
Expand Down
2 changes: 1 addition & 1 deletion Crane/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Oct 23 09:30:32 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-rc-1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading

0 comments on commit de4d7b8

Please sign in to comment.