Skip to content

Commit

Permalink
[All] Update to alpha11
Browse files Browse the repository at this point in the history
[All] Update to alpha11
  • Loading branch information
JoseAlcerreca authored Feb 1, 2021
2 parents 87f862e + 0d0e390 commit 46a9ebf
Show file tree
Hide file tree
Showing 127 changed files with 1,381 additions and 987 deletions.
7 changes: 4 additions & 3 deletions Crane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ interact with the `MapView` seamlessly.

## Hilt

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

```
class MainViewModel @ViewModelInject constructor(
@HiltViewModel
class MainViewModel @Inject constructor(
private val destinationsRepository: DestinationsRepository,
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher,
datesRepository: DatesRepository
Expand Down
8 changes: 0 additions & 8 deletions Crane/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ android {
}

composeOptions {
kotlinCompilerVersion Libs.Kotlin.version
kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version
}

Expand Down Expand Up @@ -120,11 +119,7 @@ dependencies {

implementation Libs.AndroidX.Lifecycle.viewModelKtx
implementation Libs.Hilt.android
implementation Libs.Hilt.AndroidX.viewModel
compileOnly Libs.AssistedInjection.dagger
kapt Libs.Hilt.compiler
kapt Libs.Hilt.AndroidX.compiler
kapt Libs.AssistedInjection.processor

androidTestImplementation Libs.JUnit.junit
androidTestImplementation Libs.AndroidX.Test.runner
Expand All @@ -134,9 +129,6 @@ dependencies {
androidTestImplementation Libs.Kotlin.Coroutines.test
androidTestImplementation Libs.AndroidX.Compose.uiTest
androidTestImplementation Libs.Hilt.android
androidTestImplementation Libs.Hilt.AndroidX.viewModel
androidTestImplementation Libs.Hilt.testing
kaptAndroidTest Libs.Hilt.compiler
kaptAndroidTest Libs.Hilt.AndroidX.compiler
kaptAndroidTest Libs.AssistedInjection.processor
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.samples.crane

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.rules.TestWatcher
import org.junit.runner.Description

@OptIn(ExperimentalCoroutinesApi::class)
class CoroutinesTestRule constructor(
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()
) : TestWatcher() {

override fun starting(description: Description?) {
super.starting(description)
Dispatchers.setMain(testDispatcher)
}

override fun finished(description: Description?) {
super.finished(description)
Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.LastDay
import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.NoSelected
import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.Selected
import androidx.compose.samples.crane.data.DatesRepository
import androidx.compose.samples.crane.di.DispatchersModule
import androidx.compose.samples.crane.ui.CraneTheme
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assertLabelEquals
Expand All @@ -35,13 +34,12 @@ import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import javax.inject.Inject

@UninstallModules(DispatchersModule::class)
@HiltAndroidTest
class CalendarTest {

Expand All @@ -67,6 +65,7 @@ class CalendarTest {
}
}

@Ignore("performScrollTo doesn't work with LazyLists: issuetracker.google.com/178483889")
@Test
fun scrollsToTheBottom() {
composeTestRule.onNodeWithContentDescription("January 1").assertExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.compose.samples.crane.R
import androidx.compose.samples.crane.data.DestinationsRepository
import androidx.compose.samples.crane.data.ExploreModel
import androidx.compose.samples.crane.data.MADRID
import androidx.compose.samples.crane.di.DispatchersModule
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithText
Expand All @@ -35,7 +34,6 @@ import com.google.android.libraries.maps.model.CameraPosition
import com.google.android.libraries.maps.model.LatLng
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -44,7 +42,6 @@ import javax.inject.Inject
import kotlin.math.pow
import kotlin.math.round

@UninstallModules(DispatchersModule::class)
@HiltAndroidTest
class DetailsActivityTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ package androidx.compose.samples.crane.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dagger.hilt.testing.TestInstallIn
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi

@OptIn(ExperimentalCoroutinesApi::class)
@Module
@InstallIn(SingletonComponent::class)
@TestInstallIn(
components = [SingletonComponent::class],
replaces = [DispatchersModule::class]
)
class TestDispatchersModule {

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@

package androidx.compose.samples.crane.home

import androidx.compose.samples.crane.di.DispatchersModule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@UninstallModules(DispatchersModule::class)
@HiltAndroidTest
class HomeTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fun CraneEditableUserInput(
textStyle = if (isHint()) {
captionTextStyle.copy(color = AmbientContentColor.current)
} else {
MaterialTheme.typography.body1
MaterialTheme.typography.body1.copy(color = AmbientContentColor.current)
},
cursorColor = AmbientContentColor.current
)
Expand All @@ -125,7 +125,8 @@ private fun CraneBaseUserInput(
Icon(
modifier = Modifier.preferredSize(24.dp, 24.dp),
imageVector = vectorResource(id = vectorImageId),
tint = if (tintIcon()) tint else Color(0x80FFFFFF)
tint = if (tintIcon()) tint else Color(0x80FFFFFF),
contentDescription = null
)
Spacer(Modifier.preferredWidth(8.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.samples.crane.R
import androidx.compose.samples.crane.ui.CraneTheme
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -36,8 +37,15 @@ private val screens = listOf("Find Trips", "My Trips", "Saved Trips", "Price Ale

@Composable
fun CraneDrawer(modifier: Modifier = Modifier) {
Column(modifier.fillMaxSize().padding(start = 24.dp, top = 48.dp)) {
Image(imageVector = vectorResource(id = R.drawable.ic_crane_drawer))
Column(
modifier
.fillMaxSize()
.padding(start = 24.dp, top = 48.dp)
) {
Image(
imageVector = vectorResource(R.drawable.ic_crane_drawer),
contentDescription = stringResource(R.string.cd_drawer)
)
for (screen in screens) {
Spacer(Modifier.preferredHeight(24.dp))
Text(text = screen, style = MaterialTheme.typography.h4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.AmbientConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.core.os.ConfigurationCompat
Expand All @@ -51,13 +52,23 @@ fun CraneTabBar(
// Separate Row as the children shouldn't have the padding
Row(Modifier.padding(top = 8.dp)) {
Image(
modifier = Modifier.padding(top = 8.dp).clickable(onClick = onMenuClicked),
imageVector = vectorResource(id = R.drawable.ic_menu)
modifier = Modifier
.padding(top = 8.dp)
.clickable(onClick = onMenuClicked),
imageVector = vectorResource(id = R.drawable.ic_menu),
contentDescription = stringResource(id = R.string.cd_menu)
)
Spacer(Modifier.preferredWidth(8.dp))
Image(imageVector = vectorResource(id = R.drawable.ic_crane_logo))
Image(
imageVector = vectorResource(id = R.drawable.ic_crane_logo),
contentDescription = null
)
}
children(Modifier.weight(1f).align(Alignment.CenterVertically))
children(
Modifier
.weight(1f)
.align(Alignment.CenterVertically)
)
}
}

Expand All @@ -82,7 +93,8 @@ fun CraneTabs(
var textModifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp)
if (selected) {
textModifier =
Modifier.border(BorderStroke(2.dp, Color.White), RoundedCornerShape(16.dp))
Modifier
.border(BorderStroke(2.dp, Color.White), RoundedCornerShape(16.dp))
.then(textModifier)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
Expand Down Expand Up @@ -96,11 +97,13 @@ private fun ExploreItem(
data = item.imageUrl,
fadeIn = true,
contentScale = ContentScale.Crop,
contentDescription = null,
loading = {
Box(Modifier.fillMaxSize()) {
Image(
modifier = Modifier.preferredSize(36.dp).align(Alignment.Center),
imageVector = vectorResource(id = R.drawable.ic_crane_logo)
imageVector = vectorResource(id = R.drawable.ic_crane_logo),
contentDescription = null
)
}
}
Expand Down
Loading

0 comments on commit 46a9ebf

Please sign in to comment.