Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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}"
}
Original file line number Diff line number Diff line change
@@ -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<GardenList> {
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<PlantList> {
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<T>(private val parent: T) {
companion object {
fun <T> from(parent: T) = PlantDescription(parent)
}

fun add(): PlantDescription<T> {
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
}
}
56 changes: 56 additions & 0 deletions app/src/androidTest/java/com/google/samples/apps/sunflower/Robo.kt
Original file line number Diff line number Diff line change
@@ -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<RoboState>, method: Method) = when (method.name) {
"openDescription" -> listOf(arrayOf("Avocado", "Tomato", "Apple").random())
else -> super.generateArguments(state, method)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ class GardenFragment : Fragment() {
requireActivity().findViewById<ViewPager2>(R.id.view_pager).currentItem =
PLANT_LIST_PAGE_INDEX
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ abstract class AppDatabase : RoomDatabase() {
.build()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_plant_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
tools:listitem="@layout/list_item_plant"/>

</FrameLayout>
</layout>
</layout>
42 changes: 21 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
}
Expand All @@ -77,4 +77,4 @@ spotless {
target "**/*.kt"
ktlint(ktlintVersion).userData(['max_line_length' : '100'])
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 2 additions & 17 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
* limitations under the License.
*/

include ':app'
include ':app', ':androidtest-library'
project(':androidtest-library').projectDir = new File('../android-library/androidtest-library')