Skip to content

Commit 46a9ebf

Browse files
[All] Update to alpha11
[All] Update to alpha11
2 parents 87f862e + 0d0e390 commit 46a9ebf

File tree

127 files changed

+1381
-987
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1381
-987
lines changed

Crane/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ interact with the `MapView` seamlessly.
3434

3535
## Hilt
3636

37-
Crane uses [Hilt][hilt] to manage its dependencies. The Hilt's ViewModel extension (with the
38-
`@ViewModelInject` annotation) works perfectly with Compose's ViewModel integration (`viewModel()`
37+
Crane uses [Hilt][hilt] to manage its dependencies. Hilt's ViewModel (with the
38+
`@HiltViewModel` annotation) works perfectly with Compose's ViewModel integration (`viewModel()`
3939
composable function) as you can see in the following snippet of code. `viewModel()` will
4040
automatically use the factory that Hilt creates for the ViewModel:
4141

4242
```
43-
class MainViewModel @ViewModelInject constructor(
43+
@HiltViewModel
44+
class MainViewModel @Inject constructor(
4445
private val destinationsRepository: DestinationsRepository,
4546
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher,
4647
datesRepository: DatesRepository

Crane/app/build.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ android {
9191
}
9292

9393
composeOptions {
94-
kotlinCompilerVersion Libs.Kotlin.version
9594
kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version
9695
}
9796

@@ -120,11 +119,7 @@ dependencies {
120119

121120
implementation Libs.AndroidX.Lifecycle.viewModelKtx
122121
implementation Libs.Hilt.android
123-
implementation Libs.Hilt.AndroidX.viewModel
124-
compileOnly Libs.AssistedInjection.dagger
125122
kapt Libs.Hilt.compiler
126-
kapt Libs.Hilt.AndroidX.compiler
127-
kapt Libs.AssistedInjection.processor
128123

129124
androidTestImplementation Libs.JUnit.junit
130125
androidTestImplementation Libs.AndroidX.Test.runner
@@ -134,9 +129,6 @@ dependencies {
134129
androidTestImplementation Libs.Kotlin.Coroutines.test
135130
androidTestImplementation Libs.AndroidX.Compose.uiTest
136131
androidTestImplementation Libs.Hilt.android
137-
androidTestImplementation Libs.Hilt.AndroidX.viewModel
138132
androidTestImplementation Libs.Hilt.testing
139133
kaptAndroidTest Libs.Hilt.compiler
140-
kaptAndroidTest Libs.Hilt.AndroidX.compiler
141-
kaptAndroidTest Libs.AssistedInjection.processor
142134
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.compose.samples.crane
18+
19+
import kotlinx.coroutines.Dispatchers
20+
import kotlinx.coroutines.ExperimentalCoroutinesApi
21+
import kotlinx.coroutines.test.TestCoroutineDispatcher
22+
import kotlinx.coroutines.test.resetMain
23+
import kotlinx.coroutines.test.setMain
24+
import org.junit.rules.TestWatcher
25+
import org.junit.runner.Description
26+
27+
@OptIn(ExperimentalCoroutinesApi::class)
28+
class CoroutinesTestRule constructor(
29+
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()
30+
) : TestWatcher() {
31+
32+
override fun starting(description: Description?) {
33+
super.starting(description)
34+
Dispatchers.setMain(testDispatcher)
35+
}
36+
37+
override fun finished(description: Description?) {
38+
super.finished(description)
39+
Dispatchers.resetMain()
40+
testDispatcher.cleanupTestCoroutines()
41+
}
42+
}

Crane/app/src/androidTest/java/androidx/compose/samples/crane/calendar/CalendarTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.LastDay
2424
import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.NoSelected
2525
import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.Selected
2626
import androidx.compose.samples.crane.data.DatesRepository
27-
import androidx.compose.samples.crane.di.DispatchersModule
2827
import androidx.compose.samples.crane.ui.CraneTheme
2928
import androidx.compose.ui.test.SemanticsMatcher
3029
import androidx.compose.ui.test.assertLabelEquals
@@ -35,13 +34,12 @@ import androidx.compose.ui.test.performClick
3534
import androidx.compose.ui.test.performScrollTo
3635
import dagger.hilt.android.testing.HiltAndroidRule
3736
import dagger.hilt.android.testing.HiltAndroidTest
38-
import dagger.hilt.android.testing.UninstallModules
3937
import org.junit.Before
38+
import org.junit.Ignore
4039
import org.junit.Rule
4140
import org.junit.Test
4241
import javax.inject.Inject
4342

44-
@UninstallModules(DispatchersModule::class)
4543
@HiltAndroidTest
4644
class CalendarTest {
4745

@@ -67,6 +65,7 @@ class CalendarTest {
6765
}
6866
}
6967

68+
@Ignore("performScrollTo doesn't work with LazyLists: issuetracker.google.com/178483889")
7069
@Test
7170
fun scrollsToTheBottom() {
7271
composeTestRule.onNodeWithContentDescription("January 1").assertExists()

Crane/app/src/androidTest/java/androidx/compose/samples/crane/details/DetailsActivityTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import androidx.compose.samples.crane.R
2020
import androidx.compose.samples.crane.data.DestinationsRepository
2121
import androidx.compose.samples.crane.data.ExploreModel
2222
import androidx.compose.samples.crane.data.MADRID
23-
import androidx.compose.samples.crane.di.DispatchersModule
2423
import androidx.compose.ui.test.assertIsDisplayed
2524
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
2625
import androidx.compose.ui.test.onNodeWithText
@@ -35,7 +34,6 @@ import com.google.android.libraries.maps.model.CameraPosition
3534
import com.google.android.libraries.maps.model.LatLng
3635
import dagger.hilt.android.testing.HiltAndroidRule
3736
import dagger.hilt.android.testing.HiltAndroidTest
38-
import dagger.hilt.android.testing.UninstallModules
3937
import org.junit.Before
4038
import org.junit.Rule
4139
import org.junit.Test
@@ -44,7 +42,6 @@ import javax.inject.Inject
4442
import kotlin.math.pow
4543
import kotlin.math.round
4644

47-
@UninstallModules(DispatchersModule::class)
4845
@HiltAndroidTest
4946
class DetailsActivityTest {
5047

Crane/app/src/androidTest/java/androidx/compose/samples/crane/di/TestDispatchersModule.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ package androidx.compose.samples.crane.di
2020

2121
import dagger.Module
2222
import dagger.Provides
23-
import dagger.hilt.InstallIn
2423
import dagger.hilt.components.SingletonComponent
24+
import dagger.hilt.testing.TestInstallIn
2525
import kotlinx.coroutines.CoroutineDispatcher
2626
import kotlinx.coroutines.Dispatchers
2727
import kotlinx.coroutines.ExperimentalCoroutinesApi
2828

2929
@OptIn(ExperimentalCoroutinesApi::class)
3030
@Module
31-
@InstallIn(SingletonComponent::class)
31+
@TestInstallIn(
32+
components = [SingletonComponent::class],
33+
replaces = [DispatchersModule::class]
34+
)
3235
class TestDispatchersModule {
3336

3437
@Provides

Crane/app/src/androidTest/java/androidx/compose/samples/crane/home/HomeTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@
1616

1717
package androidx.compose.samples.crane.home
1818

19-
import androidx.compose.samples.crane.di.DispatchersModule
2019
import androidx.compose.ui.test.junit4.createAndroidComposeRule
2120
import androidx.compose.ui.test.onNodeWithText
2221
import androidx.compose.ui.test.performClick
2322
import dagger.hilt.android.testing.HiltAndroidRule
2423
import dagger.hilt.android.testing.HiltAndroidTest
25-
import dagger.hilt.android.testing.UninstallModules
2624
import org.junit.Before
2725
import org.junit.Rule
2826
import org.junit.Test
2927

30-
@UninstallModules(DispatchersModule::class)
3128
@HiltAndroidTest
3229
class HomeTest {
3330

Crane/app/src/main/java/androidx/compose/samples/crane/base/BaseUserInput.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fun CraneEditableUserInput(
102102
textStyle = if (isHint()) {
103103
captionTextStyle.copy(color = AmbientContentColor.current)
104104
} else {
105-
MaterialTheme.typography.body1
105+
MaterialTheme.typography.body1.copy(color = AmbientContentColor.current)
106106
},
107107
cursorColor = AmbientContentColor.current
108108
)
@@ -125,7 +125,8 @@ private fun CraneBaseUserInput(
125125
Icon(
126126
modifier = Modifier.preferredSize(24.dp, 24.dp),
127127
imageVector = vectorResource(id = vectorImageId),
128-
tint = if (tintIcon()) tint else Color(0x80FFFFFF)
128+
tint = if (tintIcon()) tint else Color(0x80FFFFFF),
129+
contentDescription = null
129130
)
130131
Spacer(Modifier.preferredWidth(8.dp))
131132
}

Crane/app/src/main/java/androidx/compose/samples/crane/base/CraneDrawer.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.compose.runtime.Composable
2828
import androidx.compose.samples.crane.R
2929
import androidx.compose.samples.crane.ui.CraneTheme
3030
import androidx.compose.ui.Modifier
31+
import androidx.compose.ui.res.stringResource
3132
import androidx.compose.ui.res.vectorResource
3233
import androidx.compose.ui.tooling.preview.Preview
3334
import androidx.compose.ui.unit.dp
@@ -36,8 +37,15 @@ private val screens = listOf("Find Trips", "My Trips", "Saved Trips", "Price Ale
3637

3738
@Composable
3839
fun CraneDrawer(modifier: Modifier = Modifier) {
39-
Column(modifier.fillMaxSize().padding(start = 24.dp, top = 48.dp)) {
40-
Image(imageVector = vectorResource(id = R.drawable.ic_crane_drawer))
40+
Column(
41+
modifier
42+
.fillMaxSize()
43+
.padding(start = 24.dp, top = 48.dp)
44+
) {
45+
Image(
46+
imageVector = vectorResource(R.drawable.ic_crane_drawer),
47+
contentDescription = stringResource(R.string.cd_drawer)
48+
)
4149
for (screen in screens) {
4250
Spacer(Modifier.preferredHeight(24.dp))
4351
Text(text = screen, style = MaterialTheme.typography.h4)

Crane/app/src/main/java/androidx/compose/samples/crane/base/CraneTabs.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import androidx.compose.ui.Alignment
3737
import androidx.compose.ui.Modifier
3838
import androidx.compose.ui.graphics.Color
3939
import androidx.compose.ui.platform.AmbientConfiguration
40+
import androidx.compose.ui.res.stringResource
4041
import androidx.compose.ui.res.vectorResource
4142
import androidx.compose.ui.unit.dp
4243
import androidx.core.os.ConfigurationCompat
@@ -51,13 +52,23 @@ fun CraneTabBar(
5152
// Separate Row as the children shouldn't have the padding
5253
Row(Modifier.padding(top = 8.dp)) {
5354
Image(
54-
modifier = Modifier.padding(top = 8.dp).clickable(onClick = onMenuClicked),
55-
imageVector = vectorResource(id = R.drawable.ic_menu)
55+
modifier = Modifier
56+
.padding(top = 8.dp)
57+
.clickable(onClick = onMenuClicked),
58+
imageVector = vectorResource(id = R.drawable.ic_menu),
59+
contentDescription = stringResource(id = R.string.cd_menu)
5660
)
5761
Spacer(Modifier.preferredWidth(8.dp))
58-
Image(imageVector = vectorResource(id = R.drawable.ic_crane_logo))
62+
Image(
63+
imageVector = vectorResource(id = R.drawable.ic_crane_logo),
64+
contentDescription = null
65+
)
5966
}
60-
children(Modifier.weight(1f).align(Alignment.CenterVertically))
67+
children(
68+
Modifier
69+
.weight(1f)
70+
.align(Alignment.CenterVertically)
71+
)
6172
}
6273
}
6374

@@ -82,7 +93,8 @@ fun CraneTabs(
8293
var textModifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp)
8394
if (selected) {
8495
textModifier =
85-
Modifier.border(BorderStroke(2.dp, Color.White), RoundedCornerShape(16.dp))
96+
Modifier
97+
.border(BorderStroke(2.dp, Color.White), RoundedCornerShape(16.dp))
8698
.then(textModifier)
8799
}
88100

Crane/app/src/main/java/androidx/compose/samples/crane/base/ExploreSection.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.preferredHeight
2828
import androidx.compose.foundation.layout.preferredSize
2929
import androidx.compose.foundation.layout.preferredWidth
3030
import androidx.compose.foundation.lazy.LazyColumn
31+
import androidx.compose.foundation.lazy.items
3132
import androidx.compose.foundation.shape.RoundedCornerShape
3233
import androidx.compose.material.Divider
3334
import androidx.compose.material.MaterialTheme
@@ -96,11 +97,13 @@ private fun ExploreItem(
9697
data = item.imageUrl,
9798
fadeIn = true,
9899
contentScale = ContentScale.Crop,
100+
contentDescription = null,
99101
loading = {
100102
Box(Modifier.fillMaxSize()) {
101103
Image(
102104
modifier = Modifier.preferredSize(36.dp).align(Alignment.Center),
103-
imageVector = vectorResource(id = R.drawable.ic_crane_logo)
105+
imageVector = vectorResource(id = R.drawable.ic_crane_logo),
106+
contentDescription = null
104107
)
105108
}
106109
}

0 commit comments

Comments
 (0)