diff --git a/app/build.gradle b/app/build.gradle index 66742fdc0..93dcc5d0c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,7 +55,7 @@ dependencies { kapt "com.github.bumptech.glide:compiler:$rootProject.glideVersion" implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion" implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion" - implementation "androidx.core:core-ktx:$rootProject.ktxVersion" + implementation "androidx.core:core-ktx:${ktxVersion}" implementation "androidx.fragment:fragment-ktx:$rootProject.fragmentVersion" implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycleVersion" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.lifecycleVersion" @@ -69,7 +69,6 @@ dependencies { implementation "androidx.work:work-runtime-ktx:$rootProject.workVersion" implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion" implementation "com.google.android.material:material:$rootProject.materialVersion" - implementation "com.google.code.gson:gson:$rootProject.gsonVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutinesVersion" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutinesVersion" @@ -84,4 +83,6 @@ dependencies { androidTestImplementation "androidx.work:work-testing:$rootProject.workVersion" androidTestImplementation "com.google.truth:truth:$rootProject.truthVersion" testImplementation "junit:junit:$rootProject.junitVersion" -} + androidTestImplementation project(path: ':androidtest-library') + implementation "com.google.code.gson:gson:${gsonVersion}" +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/google/samples/apps/sunflower/Model.kt b/app/src/androidTest/java/com/google/samples/apps/sunflower/Model.kt new file mode 100644 index 000000000..36012e3cc --- /dev/null +++ b/app/src/androidTest/java/com/google/samples/apps/sunflower/Model.kt @@ -0,0 +1,97 @@ +/* + * Copyright 2020 Google LLC + * + * 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 com.google.samples.apps.sunflower + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.PerformException +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers.* +import org.hamcrest.Matchers.allOf + +class GardenList { + companion object { + private val instance = GardenList() + fun get() = instance + } + + fun openDescription(name: String): PlantDescription { + onView(withText(name)).perform(click()) + return PlantDescription.from(this) + } + + fun longTest(v: Long): GardenList = this + + fun openPlantList(useAddButton: Boolean): GardenList { + val matcher = if (useAddButton) { + withId(R.id.add_plant) + } else { + withContentDescription("Plant list") + } + + onView(matcher).perform(click()) + return this + } + + fun expectPlantList(): PlantList { + return PlantList.get() + } +} + +class PlantList { + companion object { + private val instance = PlantList() + fun get() = instance + } + + fun openDescription(name: String): PlantDescription { + onView(withText(name)).perform(click()) + return PlantDescription.from(this) + } + + fun openGardenList(): PlantList { + onView(withContentDescription("My garden")).perform(click()) + return this + } + + fun expectGardenList(): GardenList { + return GardenList.get() + } +} + +class PlantDescription(private val parent: T) { + companion object { + fun from(parent: T) = PlantDescription(parent) + } + + fun add(): PlantDescription { + onView(withId(R.id.fab)) + .withFailureHandler { error, _ -> + if (error !is PerformException) { + throw error + } + + error.printStackTrace() + } + .perform(click()) + return this + } + + fun backToList(): T { + onView(allOf(withParent(withId(R.id.toolbar)), withParentIndex(0))).perform(click()) + return parent + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/google/samples/apps/sunflower/Robo.kt b/app/src/androidTest/java/com/google/samples/apps/sunflower/Robo.kt new file mode 100644 index 000000000..d745ad879 --- /dev/null +++ b/app/src/androidTest/java/com/google/samples/apps/sunflower/Robo.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2020 Google LLC + * + * 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 com.google.samples.apps.sunflower + +import androidx.test.rule.ActivityTestRule +import com.moquality.android.RoboConfig +import com.moquality.android.RoboState +import com.moquality.android.RoboTest +import com.moquality.android.printStackTrace +import org.junit.Rule +import org.junit.Test +import java.lang.reflect.Method + +class Robo { + @get:Rule + val activityRule = ActivityTestRule(GardenActivity::class.java) + + @Test + fun model() { + GardenList.get() + .openPlantList(false) + .expectPlantList() + .openDescription("Avocado") + .add() + .backToList() + .openGardenList() + .expectGardenList() + } + + @Test + fun robo() { + val state = RoboTest(Config).run(GardenList.get()) + state.printStackTrace() + } +} + +object Config : RoboConfig { + override fun generateArguments(state: List, method: Method) = when (method.name) { + "openDescription" -> listOf(arrayOf("Avocado", "Tomato", "Apple").random()) + else -> super.generateArguments(state, method) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/sunflower/GardenFragment.kt b/app/src/main/java/com/google/samples/apps/sunflower/GardenFragment.kt index 0aa9fc286..789120e8a 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/GardenFragment.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/GardenFragment.kt @@ -67,4 +67,4 @@ class GardenFragment : Fragment() { requireActivity().findViewById(R.id.view_pager).currentItem = PLANT_LIST_PAGE_INDEX } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/sunflower/PlantDetailFragment.kt b/app/src/main/java/com/google/samples/apps/sunflower/PlantDetailFragment.kt index 59479a32e..b30d124d0 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/PlantDetailFragment.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/PlantDetailFragment.kt @@ -122,11 +122,13 @@ class PlantDetailFragment : Fragment() { getString(R.string.share_text_plant, plant.name) } } - val shareIntent = ShareCompat.IntentBuilder.from(activity) - .setText(shareText) - .setType("text/plain") - .createChooserIntent() - .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_MULTIPLE_TASK) + val shareIntent = activity?.let { + ShareCompat.IntentBuilder.from(it) + .setText(shareText) + .setType("text/plain") + .createChooserIntent() + .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_MULTIPLE_TASK) + } startActivity(shareIntent) } diff --git a/app/src/main/java/com/google/samples/apps/sunflower/data/AppDatabase.kt b/app/src/main/java/com/google/samples/apps/sunflower/data/AppDatabase.kt index 04201aaad..43af8aff2 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/data/AppDatabase.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/data/AppDatabase.kt @@ -61,4 +61,4 @@ abstract class AppDatabase : RoomDatabase() { .build() } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/google/samples/apps/sunflower/views/MaskedCardView.kt b/app/src/main/java/com/google/samples/apps/sunflower/views/MaskedCardView.kt index 7e4c0a392..1d0849801 100644 --- a/app/src/main/java/com/google/samples/apps/sunflower/views/MaskedCardView.kt +++ b/app/src/main/java/com/google/samples/apps/sunflower/views/MaskedCardView.kt @@ -39,12 +39,12 @@ class MaskedCardView @JvmOverloads constructor( @SuppressLint("RestrictedApi") private val pathProvider = ShapeAppearancePathProvider() private val path: Path = Path() - private val shapeAppearance: ShapeAppearanceModel = ShapeAppearanceModel( - context, - attrs, - defStyle, - R.style.Widget_MaterialComponents_CardView - ) + private val shapeAppearance: ShapeAppearanceModel = ShapeAppearanceModel() + //context, + //attrs, + //defStyle, + //R.style.Widget_MaterialComponents_CardView + private val rectF = RectF(0f, 0f, 0f, 0f) override fun onDraw(canvas: Canvas) { diff --git a/app/src/main/res/layout/fragment_plant_list.xml b/app/src/main/res/layout/fragment_plant_list.xml index 1f75cd6d8..a59d615c7 100644 --- a/app/src/main/res/layout/fragment_plant_list.xml +++ b/app/src/main/res/layout/fragment_plant_list.xml @@ -37,4 +37,4 @@ tools:listitem="@layout/list_item_plant"/> - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index a72943af6..6459664ba 100644 --- a/build.gradle +++ b/build.gradle @@ -24,29 +24,29 @@ buildscript { // App dependencies appCompatVersion = '1.1.0' - constraintLayoutVersion = '2.0.0-beta3' - coreTestingVersion = '2.0.0' - coroutinesVersion = "1.3.0-M2" - espressoVersion = '3.1.1' - fragmentVersion = '1.1.0-alpha09' - glideVersion = '4.10.0' - gradleVersion = '3.5.1' - gsonVersion = '2.8.2' - junitVersion = '4.12' - kotlinVersion = '1.3.41' + constraintLayoutVersion = '2.0.0-beta4' + coreTestingVersion = '2.1.0' + coroutinesVersion = '1.3.3' + espressoVersion = '3.2.0' + fragmentVersion = '1.2.2' + glideVersion = '4.11.0' + gradleVersion = '3.6.0' + gsonVersion = '2.8.6' + junitVersion = '4.13' + kotlinVersion = '1.3.61' ktlintVersion = '0.33.0' - ktxVersion = '1.0.2' - lifecycleVersion = '2.2.0-alpha01' - materialVersion = '1.1.0-alpha09' - navigationVersion = '2.0.0' - recyclerViewVersion = '1.1.0-alpha05' - roomVersion = '2.1.0' + lifecycleVersion = '2.2.0' + materialVersion = '1.2.0-alpha05' + navigationVersion = '2.2.1' + recyclerViewVersion = '1.2.0-alpha01' + roomVersion = '2.2.4' runnerVersion = '1.0.1' - truthVersion = '0.42' - testExtJunit = '1.1.0' + truthVersion = '1.0.1' + testExtJunit = '1.1.1' uiAutomatorVersion = '2.2.0' viewPagerVersion = '1.0.0' - workVersion = '2.1.0' + workVersion = '2.3.2' + ktxVersion = '1.2.0' } repositories { @@ -55,7 +55,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:$gradleVersion" + classpath "com.android.tools.build:gradle:${gradleVersion}" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion" } @@ -77,4 +77,4 @@ spotless { target "**/*.kt" ktlint(ktlintVersion).userData(['max_line_length' : '100']) } -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c8e98a255..fd80b5f1e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,4 +32,4 @@ org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true +# org.gradle.parallel=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 234a2fd29..4a21261c1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,21 +1,6 @@ -# -# Copyright 2018 Google LLC -# -# 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. -# -#Thu Aug 22 10:20:57 PDT 2019 +#Mon Feb 24 17:14:55 EST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/settings.gradle b/settings.gradle index 1ebe8029a..d5d261f14 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,4 +14,5 @@ * limitations under the License. */ -include ':app' +include ':app', ':androidtest-library' +project(':androidtest-library').projectDir = new File('../android-library/androidtest-library') \ No newline at end of file