├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_plus.png
│ │ │ │ └── ic_navigation_drawer_header_logo.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_plus.png
│ │ │ │ └── ic_navigation_drawer_header_logo.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_plus.png
│ │ │ │ └── ic_navigation_drawer_header_logo.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_plus.png
│ │ │ │ └── ic_navigation_drawer_header_logo.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── layout
│ │ │ │ ├── activity_plant_detail.xml
│ │ │ │ ├── fragment_plant_list.xml
│ │ │ │ ├── fragment_garden.xml
│ │ │ │ ├── nav_header.xml
│ │ │ │ ├── list_item_plant.xml
│ │ │ │ ├── list_item_garden_planting.xml
│ │ │ │ ├── activity_garden.xml
│ │ │ │ └── fragment_plant_detail.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ ├── menu_navigation.xml
│ │ │ │ └── menu_plant_list.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_filter_list_24dp.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ └── navigation
│ │ │ │ └── nav_garden.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── google
│ │ │ │ └── samples
│ │ │ │ └── apps
│ │ │ │ └── sunflower
│ │ │ │ ├── utilities
│ │ │ │ ├── Constants.kt
│ │ │ │ ├── AppExecutors.kt
│ │ │ │ ├── GrowZoneUtil.kt
│ │ │ │ └── InjectorUtils.kt
│ │ │ │ ├── data
│ │ │ │ ├── Converters.kt
│ │ │ │ ├── PlantAndGardenPlantings.kt
│ │ │ │ ├── PlantRepository.kt
│ │ │ │ ├── PlantDao.kt
│ │ │ │ ├── Plant.kt
│ │ │ │ ├── GardenPlantingDao.kt
│ │ │ │ ├── GardenPlantingRepository.kt
│ │ │ │ ├── GardenPlanting.kt
│ │ │ │ └── AppDatabase.kt
│ │ │ │ ├── viewmodels
│ │ │ │ ├── GardenPlantingListViewModel.kt
│ │ │ │ ├── PlantListViewModelFactory.kt
│ │ │ │ ├── GardenPlantingListViewModelFactory.kt
│ │ │ │ ├── PlantDetailViewModelFactory.kt
│ │ │ │ ├── PlantListViewModel.kt
│ │ │ │ └── PlantDetailViewModel.kt
│ │ │ │ ├── PlantDetailActivity.kt
│ │ │ │ ├── workers
│ │ │ │ └── SeedDatabaseWorker.kt
│ │ │ │ ├── adapters
│ │ │ │ ├── PlantDetailBindingAdapter.kt
│ │ │ │ ├── PlantAdapter.kt
│ │ │ │ └── GardenPlantingAdapter.kt
│ │ │ │ ├── GardenFragment.kt
│ │ │ │ ├── PlantListFragment.kt
│ │ │ │ ├── GardenActivity.kt
│ │ │ │ └── PlantDetailFragment.kt
│ │ ├── AndroidManifest.xml
│ │ └── assets
│ │ │ └── plants.json
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── google
│ │ │ └── samples
│ │ │ └── apps
│ │ │ └── sunflower
│ │ │ ├── data
│ │ │ ├── PlantAndGardenPlantingTest.kt
│ │ │ ├── ConvertersTest.kt
│ │ │ ├── GardenPlantingTest.kt
│ │ │ └── PlantTest.kt
│ │ │ └── utilities
│ │ │ └── GrowZoneUtilTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── google
│ │ └── samples
│ │ └── apps
│ │ └── sunflower
│ │ ├── utilities
│ │ ├── LiveDataTestUtil.kt
│ │ └── TestUtils.kt
│ │ ├── viewmodels
│ │ └── PlantDetailViewModelTest.kt
│ │ ├── PlantDetailActivityTest.kt
│ │ ├── data
│ │ ├── PlantDaoTest.kt
│ │ └── GardenPlantingDaoTest.kt
│ │ └── GardenActivityTest.kt
├── proguard-rules.pro
└── build.gradle
├── screenshots
├── jetpack_donut.png
├── phone_my_garden.png
├── phone_plant_detail.png
└── phone_plant_list.png
├── .idea
└── copyright
│ ├── profiles_settings.xml
│ └── google.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── CONTRIBUTING.md
├── .google
└── packaging.yaml
├── gradle.properties
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/screenshots/jetpack_donut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/screenshots/jetpack_donut.png
--------------------------------------------------------------------------------
/screenshots/phone_my_garden.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/screenshots/phone_my_garden.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/screenshots/phone_plant_detail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/screenshots/phone_plant_detail.png
--------------------------------------------------------------------------------
/screenshots/phone_plant_list.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/screenshots/phone_plant_list.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-hdpi/ic_plus.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-mdpi/ic_plus.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-xhdpi/ic_plus.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-xxhdpi/ic_plus.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea/*
5 | !.idea/copyright
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_navigation_drawer_header_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-hdpi/ic_navigation_drawer_header_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_navigation_drawer_header_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-mdpi/ic_navigation_drawer_header_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_navigation_drawer_header_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-xhdpi/ic_navigation_drawer_header_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_navigation_drawer_header_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Phonbopit/android-sunflower/master/app/src/main/res/drawable-xxhdpi/ic_navigation_drawer_header_logo.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 | include ':app'
18 |
--------------------------------------------------------------------------------
/.idea/copyright/google.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_plant_detail.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2018 Google LLC
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 | #Mon Sep 11 11:17:48 PDT 2017
18 | distributionBase=GRADLE_USER_HOME
19 | distributionPath=wrapper/dists
20 | zipStoreBase=GRADLE_USER_HOME
21 | zipStorePath=wrapper/dists
22 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/utilities/Constants.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.utilities
18 |
19 | /**
20 | * Constants used throughout the app.
21 | */
22 | const val DATABASE_NAME = "sunflower-db"
23 | const val PLANT_DATA_FILENAME = "plants.json"
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #3F51B5
20 | #303F9F
21 | #FF4081
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/google/home/tiem/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/utilities/AppExecutors.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.utilities
18 |
19 | import java.util.concurrent.Executors
20 |
21 | private val IO_EXECUTOR = Executors.newSingleThreadExecutor()
22 |
23 | /**
24 | * Utility method to run blocks on a dedicated background thread, used for io/database work.
25 | */
26 | fun runOnIoThread(f : () -> Unit) {
27 | IO_EXECUTOR.execute(f)
28 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_plant_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_filter_list_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
26 |
--------------------------------------------------------------------------------
/app/src/test/java/com/google/samples/apps/sunflower/data/PlantAndGardenPlantingTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import org.junit.Assert.assertNull
20 | import org.junit.Assert.assertTrue
21 | import org.junit.Test
22 |
23 | class PlantAndGardenPlantingTest {
24 |
25 | @Test fun test_default_values() {
26 | val p = PlantAndGardenPlantings()
27 | assertNull(p.plant)
28 | assertTrue(p.gardenPlantings.isEmpty())
29 | }
30 | }
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution,
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
29 |
--------------------------------------------------------------------------------
/.google/packaging.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # GOOGLE SAMPLE PACKAGING DATA
16 | #
17 | # This file is used by Google as part of our samples packaging process.
18 | # End users may safely ignore this file. It has no relevance to other systems.
19 | ---
20 | status: DRAFT
21 | technologies: [Android]
22 | categories: [Getting Started]
23 | languages: [Java, Kotlin]
24 | solutions: [Mobile]
25 |
26 | github: googlesamples/android-sunflower
27 |
28 | level: INTERMEDIATE
29 |
30 | icon: screenshots/icon.png
31 |
32 | apiRefs:
33 | - android:com.android.ui.ActionBar
34 |
35 | license: apache2
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/Converters.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.persistence.room.TypeConverter
20 | import java.util.Calendar
21 |
22 | /**
23 | * Type converters to allow Room to reference complex data types.
24 | */
25 | class Converters {
26 | @TypeConverter fun calendarToDatestamp(calendar: Calendar): Long = calendar.timeInMillis
27 |
28 | @TypeConverter fun datestampToCalendar(value: Long): Calendar =
29 | Calendar.getInstance().apply { timeInMillis = value }
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/GardenPlantingListViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.viewmodels
18 |
19 | import android.arch.lifecycle.ViewModel
20 | import com.google.samples.apps.sunflower.data.GardenPlantingRepository
21 |
22 | class GardenPlantingListViewModel internal constructor(
23 | private val gardenPlantingRepository: GardenPlantingRepository
24 | ) : ViewModel() {
25 |
26 | fun getGardenPlantings() = gardenPlantingRepository.getGardenPlantings()
27 |
28 | fun getPlantAndGardenPlantings() = gardenPlantingRepository.getPlantAndGardenPlantings()
29 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 16dp
20 | 200dp
21 | 200dp
22 |
23 | 16dp
24 | 8dp
25 |
26 | 100dp
27 |
28 | 192dp
29 | 16dp
30 | 100dp
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/PlantAndGardenPlantings.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.persistence.room.Embedded
20 | import android.arch.persistence.room.Relation
21 |
22 | /**
23 | * This class captures the relationship between a [Plant] and a user's [GardenPlanting], which is
24 | * used by Room to fetch the related entities.
25 | */
26 | class PlantAndGardenPlantings {
27 |
28 | @Embedded
29 | var plant: Plant? = null
30 |
31 | @Relation(parentColumn = "id", entityColumn = "plant_id")
32 | var gardenPlantings: List = arrayListOf()
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantListViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.viewmodels
18 |
19 | import android.arch.lifecycle.ViewModel
20 | import android.arch.lifecycle.ViewModelProvider
21 |
22 | import com.google.samples.apps.sunflower.data.PlantRepository
23 |
24 | /**
25 | * Factory for creating a [PlantListViewModel] with a constructor that takes a [PlantRepository].
26 | */
27 | class PlantListViewModelFactory(
28 | private val repository: PlantRepository
29 | ) : ViewModelProvider.NewInstanceFactory() {
30 |
31 | @Suppress("UNCHECKED_CAST")
32 | override fun create(modelClass: Class) = PlantListViewModel(repository) as T
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_garden.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
22 |
23 |
27 |
31 |
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2018 Google LLC
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 | # Project-wide Gradle settings.
18 |
19 | # IDE (e.g. Android Studio) users:
20 | # Gradle settings configured through the IDE *will override*
21 | # any settings specified in this file.
22 |
23 | # For more details on how to configure your build environment visit
24 | # http://www.gradle.org/docs/current/userguide/build_environment.html
25 |
26 | # Specifies the JVM arguments used for the daemon process.
27 | # The setting is particularly useful for tweaking memory settings.
28 | org.gradle.jvmargs=-Xmx1536m
29 |
30 | # When configured, Gradle will run in incubating parallel mode.
31 | # This option should only be used with decoupled projects. More details, visit
32 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
33 | # org.gradle.parallel=true
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/GardenPlantingListViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.viewmodels
18 |
19 | import android.arch.lifecycle.ViewModel
20 | import android.arch.lifecycle.ViewModelProvider
21 | import com.google.samples.apps.sunflower.data.GardenPlantingRepository
22 |
23 | /**
24 | * Factory for creating a [GardenPlantingListViewModel] with a constructor that takes a
25 | * [GardenPlantingRepository].
26 | */
27 | class GardenPlantingListViewModelFactory(
28 | private val repository: GardenPlantingRepository
29 | ) : ViewModelProvider.NewInstanceFactory() {
30 |
31 | @Suppress("UNCHECKED_CAST")
32 | override fun create(modelClass: Class): T {
33 | return GardenPlantingListViewModel(repository) as T
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/test/java/com/google/samples/apps/sunflower/data/ConvertersTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import org.junit.Assert.assertEquals
20 | import org.junit.Test
21 | import java.util.Calendar
22 | import java.util.Calendar.DAY_OF_MONTH
23 | import java.util.Calendar.MONTH
24 | import java.util.Calendar.SEPTEMBER
25 | import java.util.Calendar.YEAR
26 |
27 | class ConvertersTest {
28 |
29 | private val cal = Calendar.getInstance().apply {
30 | set(YEAR, 1998)
31 | set(MONTH, SEPTEMBER)
32 | set(DAY_OF_MONTH, 4)
33 | }
34 |
35 | @Test fun calendarToDatestamp() {
36 | assertEquals(cal.timeInMillis, Converters().calendarToDatestamp(cal))
37 | }
38 |
39 | @Test fun datestampToCalendar() {
40 | assertEquals(Converters().datestampToCalendar(cal.timeInMillis), cal)
41 | }
42 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/google/samples/apps/sunflower/utilities/GrowZoneUtilTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.utilities
18 |
19 | import org.junit.Assert.assertEquals
20 | import org.junit.Test
21 |
22 | class GrowZoneUtilTest {
23 |
24 | @Test fun getZoneForLatitude() {
25 | assertEquals(13, getZoneForLatitude(0.0))
26 | assertEquals(13, getZoneForLatitude(7.0))
27 | assertEquals(12, getZoneForLatitude(7.1))
28 | assertEquals(1, getZoneForLatitude(84.1))
29 | assertEquals(1, getZoneForLatitude(90.0))
30 | }
31 |
32 | @Test fun getZoneForLatitude_negativeLatitudes() {
33 | assertEquals(13, getZoneForLatitude(-7.0))
34 | assertEquals(12, getZoneForLatitude(-7.1))
35 | assertEquals(1, getZoneForLatitude(-84.1))
36 | assertEquals(1, getZoneForLatitude(-90.0))
37 | }
38 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_plant_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/PlantRepository.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | /**
20 | * Repository module for handling data operations.
21 | */
22 | class PlantRepository private constructor(private val plantDao: PlantDao) {
23 |
24 | fun getPlants() = plantDao.getPlants()
25 |
26 | fun getPlant(plantId: String) = plantDao.getPlant(plantId)
27 |
28 | fun getPlantsWithGrowZoneNumber(growZoneNumber: Int) =
29 | plantDao.getPlantsWithGrowZoneNumber(growZoneNumber)
30 |
31 | companion object {
32 |
33 | // For Singleton instantiation
34 | @Volatile private var instance: PlantRepository? = null
35 |
36 | fun getInstance(plantDao: PlantDao) =
37 | instance ?: synchronized(this) {
38 | instance ?: PlantRepository(plantDao).also { instance = it }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/PlantDao.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.lifecycle.LiveData
20 | import android.arch.persistence.room.Dao
21 | import android.arch.persistence.room.Insert
22 | import android.arch.persistence.room.OnConflictStrategy
23 | import android.arch.persistence.room.Query
24 |
25 | /**
26 | * The Data Access Object for the Plant class.
27 | */
28 | @Dao
29 | interface PlantDao {
30 | @Query("SELECT * FROM plants ORDER BY name")
31 | fun getPlants(): LiveData>
32 |
33 | @Query("SELECT * FROM plants WHERE growZoneNumber = :growZoneNumber ORDER BY name")
34 | fun getPlantsWithGrowZoneNumber(growZoneNumber: Int): LiveData>
35 |
36 | @Query("SELECT * FROM plants WHERE id = :plantId")
37 | fun getPlant(plantId: String): LiveData
38 |
39 | @Insert(onConflict = OnConflictStrategy.REPLACE)
40 | fun insertAll(plants: List)
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/google/samples/apps/sunflower/utilities/LiveDataTestUtil.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.utilities
18 |
19 | import android.arch.lifecycle.LiveData
20 | import java.util.concurrent.CountDownLatch
21 | import java.util.concurrent.TimeUnit
22 |
23 | /**
24 | * Helper method for testing LiveData objects, from
25 | * https://github.com/googlesamples/android-architecture-components.
26 | *
27 | * Get the value from a LiveData object. We're waiting for LiveData to emit, for 2 seconds.
28 | * Once we got a notification via onChanged, we stop observing.
29 | */
30 | @Throws(InterruptedException::class)
31 | fun getValue(liveData: LiveData): T {
32 | val data = arrayOfNulls(1)
33 | val latch = CountDownLatch(1)
34 | liveData.observeForever { o ->
35 | data[0] = o
36 | latch.countDown()
37 | }
38 | latch.await(2, TimeUnit.SECONDS)
39 |
40 | @Suppress("UNCHECKED_CAST")
41 | return data[0] as T
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_garden.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
22 |
23 |
30 |
31 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.viewmodels
18 |
19 | import android.arch.lifecycle.ViewModel
20 | import android.arch.lifecycle.ViewModelProvider
21 |
22 | import com.google.samples.apps.sunflower.data.GardenPlantingRepository
23 | import com.google.samples.apps.sunflower.data.Plant
24 | import com.google.samples.apps.sunflower.data.PlantRepository
25 |
26 | /**
27 | * Factory for creating a [PlantDetailViewModel] with a constructor that takes a [PlantRepository]
28 | * and an ID for the current [Plant].
29 | */
30 | class PlantDetailViewModelFactory(
31 | private val plantRepository: PlantRepository,
32 | private val gardenPlantingRepository: GardenPlantingRepository,
33 | private val plantId: String
34 | ) : ViewModelProvider.NewInstanceFactory() {
35 |
36 | @Suppress("UNCHECKED_CAST")
37 | override fun create(modelClass: Class): T {
38 | return PlantDetailViewModel(plantRepository, gardenPlantingRepository, plantId) as T
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/Plant.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.persistence.room.ColumnInfo
20 | import android.arch.persistence.room.Entity
21 | import android.arch.persistence.room.PrimaryKey
22 | import java.util.Calendar
23 | import java.util.Calendar.DAY_OF_YEAR
24 |
25 | @Entity(tableName = "plants")
26 | data class Plant(
27 | @PrimaryKey @ColumnInfo(name = "id") val plantId: String,
28 | val name: String,
29 | val description: String,
30 | val growZoneNumber: Int,
31 | val wateringInterval: Int = 7, // how often the plant should be watered, in days
32 | val imageUrl: String = ""
33 | ) {
34 |
35 | /**
36 | * Determines if the plant should be watered. Returns true if today's date > date of last
37 | * watering + watering Interval; false otherwise.
38 | */
39 | fun shouldBeWatered(lastWateringDate: Calendar) =
40 | Calendar.getInstance() > lastWateringDate.apply { add(DAY_OF_YEAR, wateringInterval) }
41 |
42 | override fun toString() = name
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/test/java/com/google/samples/apps/sunflower/data/GardenPlantingTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import org.hamcrest.CoreMatchers.equalTo
20 | import org.junit.Assert.assertThat
21 | import org.junit.Test
22 | import java.util.Calendar
23 | import java.util.Calendar.DAY_OF_MONTH
24 | import java.util.Calendar.MONTH
25 | import java.util.Calendar.YEAR
26 |
27 | class GardenPlantingTest {
28 |
29 | @Test fun testDefaultValues() {
30 | val gardenPlanting = GardenPlanting("1", "1")
31 | val cal = Calendar.getInstance()
32 | assertYMD(cal, gardenPlanting.plantDate)
33 | assertYMD(cal, gardenPlanting.lastWateringDate)
34 | }
35 |
36 | // Only Year/Month/Day precision is needed for comparing GardenPlanting Calendar entries
37 | private fun assertYMD(expectedCal: Calendar, actualCal: Calendar) {
38 | assertThat(actualCal.get(YEAR), equalTo(expectedCal.get(YEAR)))
39 | assertThat(actualCal.get(MONTH), equalTo(expectedCal.get(MONTH)))
40 | assertThat(actualCal.get(DAY_OF_MONTH), equalTo(expectedCal.get(DAY_OF_MONTH)))
41 | }
42 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/utilities/GrowZoneUtil.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.utilities
18 |
19 | /**
20 | * A helper function to determine a Plant's growing zone for a given latitude.
21 | *
22 | * The numbers listed here are roughly based on the United States Department of Agriculture's
23 | * Plant Hardiness Zone Map (http://planthardiness.ars.usda.gov/), which helps determine which
24 | * plants are most likely to thrive at a location.
25 | *
26 | * If a given latitude falls on the border between two zone ranges, the larger zone range is chosen
27 | * (e.g. latitude 14.0 => zone 12).
28 | *
29 | * Negative latitude values are converted to positive with [Math.abs].
30 | *
31 | * For latitude values greater than max (90.0), zone 1 is returned.
32 | */
33 | fun getZoneForLatitude(latitude: Double) = when (Math.abs(latitude)) {
34 | in 0.0..7.0 -> 13
35 | in 7.0..14.0 -> 12
36 | in 14.0..21.0 -> 11
37 | in 21.0..28.0 -> 10
38 | in 28.0..21.0 -> 9
39 | in 35.0..21.0 -> 8
40 | in 42.0..21.0 -> 7
41 | in 49.0..21.0 -> 6
42 | in 56.0..21.0 -> 5
43 | in 63.0..21.0 -> 4
44 | in 70.0..77.0 -> 3
45 | in 77.0..84.0 -> 2
46 | else -> 1 // Remaining latitudes are assigned to zone 1.
47 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
27 |
28 |
29 |
35 |
36 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/PlantDetailActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower
18 |
19 | import android.content.Intent
20 | import android.os.Bundle
21 | import android.support.v7.app.AppCompatActivity
22 | import android.view.MenuItem
23 |
24 | /**
25 | * An activity representing a single Plant detail screen.
26 | */
27 | class PlantDetailActivity : AppCompatActivity() {
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | setContentView(R.layout.activity_plant_detail)
32 |
33 | if (savedInstanceState == null) {
34 | val plantId = intent.getStringExtra(PlantDetailFragment.ARG_ITEM_ID)
35 | val fragment = PlantDetailFragment.newInstance(plantId)
36 | supportFragmentManager.beginTransaction()
37 | .add(R.id.plant_detail_container, fragment)
38 | .commit()
39 | }
40 | }
41 |
42 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
43 | val id = item.itemId
44 | if (id == android.R.id.home) {
45 | navigateUpTo(Intent(this, GardenActivity::class.java))
46 | return true
47 | }
48 | return super.onOptionsItemSelected(item)
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/GardenPlantingDao.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.lifecycle.LiveData
20 | import android.arch.persistence.room.Dao
21 | import android.arch.persistence.room.Insert
22 | import android.arch.persistence.room.Query
23 | import android.arch.persistence.room.Transaction
24 |
25 | /**
26 | * The Data Access Object for the [GardenPlanting] class.
27 | */
28 | @Dao
29 | interface GardenPlantingDao {
30 | @Query("SELECT * FROM garden_plantings")
31 | fun getGardenPlantings(): LiveData>
32 |
33 | @Query("SELECT * FROM garden_plantings WHERE id = :gardenPlantingId")
34 | fun getGardenPlanting(gardenPlantingId: String): LiveData
35 |
36 | @Query("SELECT * FROM garden_plantings WHERE plant_id = :plantId")
37 | fun getGardenPlantingForPlant(plantId: String): LiveData
38 |
39 | /**
40 | * This query will tell Room to query both the [Plant] and [GardenPlanting] tables and handle
41 | * the object mapping.
42 | */
43 | @Transaction
44 | @Query("SELECT * FROM plants")
45 | fun getPlantAndGardenPlantings(): LiveData>
46 |
47 | @Insert
48 | fun insertGardenPlanting(gardenPlanting: GardenPlanting)
49 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/google/samples/apps/sunflower/data/PlantTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import org.junit.Assert.assertEquals
20 | import org.junit.Assert.assertFalse
21 | import org.junit.Assert.assertTrue
22 | import org.junit.Before
23 | import org.junit.Test
24 | import java.util.Calendar
25 | import java.util.Calendar.DAY_OF_YEAR
26 |
27 | class PlantTest {
28 |
29 | private lateinit var plant: Plant
30 |
31 | @Before fun setUp() {
32 | plant = Plant("1", "Tomato", "A red vegetable", 1, 2, "")
33 | }
34 |
35 | @Test fun test_default_values() {
36 | val defaultPlant = Plant("2", "Apple", "Description", 1)
37 | assertEquals(7, defaultPlant.wateringInterval)
38 | assertEquals("", defaultPlant.imageUrl)
39 | }
40 |
41 | @Test fun test_shouldBeWatered() {
42 | assertFalse(plant.shouldBeWatered(Calendar.getInstance()))
43 | assertFalse(plant.shouldBeWatered(Calendar.getInstance().apply { add(DAY_OF_YEAR, -1) }))
44 | assertFalse(plant.shouldBeWatered(Calendar.getInstance().apply { add(DAY_OF_YEAR, -2) }))
45 | assertTrue(plant.shouldBeWatered(Calendar.getInstance().apply { add(DAY_OF_YEAR, -3) }))
46 | }
47 |
48 | @Test fun test_toString() {
49 | assertEquals("Tomato", plant.toString())
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/GardenPlantingRepository.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import com.google.samples.apps.sunflower.utilities.runOnIoThread
20 |
21 | class GardenPlantingRepository private constructor(
22 | private val gardenPlantingDao: GardenPlantingDao
23 | ) {
24 |
25 | fun createGardenPlanting(plantId: String) {
26 | runOnIoThread {
27 | // TODO remove gardenPlantingId from constructor once ID is auto-generated
28 | val gardenPlanting = GardenPlanting("gp$plantId", plantId)
29 | gardenPlantingDao.insertGardenPlanting(gardenPlanting)
30 | }
31 | }
32 |
33 | fun getGardenPlantingForPlant(plantId: String) =
34 | gardenPlantingDao.getGardenPlantingForPlant(plantId)
35 |
36 | fun getGardenPlantings() = gardenPlantingDao.getGardenPlantings()
37 |
38 | fun getPlantAndGardenPlantings() = gardenPlantingDao.getPlantAndGardenPlantings()
39 |
40 | companion object {
41 |
42 | // For Singleton instantiation
43 | @Volatile private var instance: GardenPlantingRepository? = null
44 |
45 | fun getInstance(gardenPlantingDao: GardenPlantingDao) =
46 | instance ?: synchronized(this) {
47 | instance ?: GardenPlantingRepository(gardenPlantingDao).also { instance = it }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantListViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.viewmodels
18 |
19 | import android.arch.lifecycle.LiveData
20 | import android.arch.lifecycle.MutableLiveData
21 | import android.arch.lifecycle.Transformations
22 | import android.arch.lifecycle.ViewModel
23 | import com.google.samples.apps.sunflower.PlantListFragment
24 | import com.google.samples.apps.sunflower.data.Plant
25 | import com.google.samples.apps.sunflower.data.PlantRepository
26 |
27 | /**
28 | * The ViewModel for [PlantListFragment].
29 | */
30 | class PlantListViewModel internal constructor(
31 | private val plantRepository: PlantRepository
32 | ) : ViewModel() {
33 |
34 | private val NO_GROW_ZONE = -1
35 | private val growZoneNumber: MutableLiveData = MutableLiveData()
36 |
37 | init {
38 | growZoneNumber.value = NO_GROW_ZONE
39 | }
40 |
41 | fun getPlants(): LiveData> = Transformations.switchMap(growZoneNumber) {
42 | if (it == NO_GROW_ZONE) {
43 | plantRepository.getPlants()
44 | } else {
45 | plantRepository.getPlantsWithGrowZoneNumber(it)
46 | }
47 | }
48 |
49 | fun setGrowZoneNumber(num: Int) {
50 | growZoneNumber.value = num
51 | }
52 |
53 | fun clearGrowZoneNumber() {
54 | growZoneNumber.value = NO_GROW_ZONE
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/workers/SeedDatabaseWorker.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.workers
18 |
19 | import android.util.Log
20 | import androidx.work.Worker
21 | import com.google.gson.Gson
22 | import com.google.gson.reflect.TypeToken
23 | import com.google.gson.stream.JsonReader
24 | import com.google.samples.apps.sunflower.data.AppDatabase
25 | import com.google.samples.apps.sunflower.data.Plant
26 | import com.google.samples.apps.sunflower.utilities.PLANT_DATA_FILENAME
27 |
28 | class SeedDatabaseWorker : Worker() {
29 | private val TAG = SeedDatabaseWorker::class.java.simpleName
30 |
31 | override fun doWork(): WorkerResult {
32 | val plantType = object : TypeToken>() {}.type
33 | var jsonReader: JsonReader? = null
34 |
35 | return try {
36 | val inputStream = applicationContext.assets.open(PLANT_DATA_FILENAME)
37 | jsonReader = JsonReader(inputStream.reader())
38 | val plantList: List = Gson().fromJson(jsonReader, plantType)
39 | val database = AppDatabase.getInstance(applicationContext)
40 | database.plantDao().insertAll(plantList)
41 | WorkerResult.SUCCESS
42 | } catch (ex: Exception) {
43 | Log.e(TAG, "Error seeding database", ex)
44 | WorkerResult.FAILURE
45 | } finally {
46 | jsonReader?.close()
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
31 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
45 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/adapters/PlantDetailBindingAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.adapters
18 |
19 | import android.databinding.BindingAdapter
20 | import android.text.SpannableStringBuilder
21 | import android.view.View
22 | import android.widget.ImageView
23 | import android.widget.TextView
24 | import androidx.core.text.bold
25 | import androidx.core.text.italic
26 | import com.bumptech.glide.Glide
27 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
28 | import com.google.samples.apps.sunflower.R
29 |
30 | @BindingAdapter("imageFromUrl")
31 | fun imageFromUrl(view: ImageView, imageUrl: String?) {
32 | if (!imageUrl.isNullOrEmpty()) {
33 | Glide.with(view.context)
34 | .load(imageUrl)
35 | .transition(DrawableTransitionOptions.withCrossFade())
36 | .into(view)
37 | }
38 | }
39 |
40 | @BindingAdapter("goneIf")
41 | fun goneIf(view: View, isGone: Boolean) {
42 | view.visibility = if (isGone) View.GONE else View.VISIBLE
43 | }
44 |
45 | @BindingAdapter("wateringText")
46 | fun wateringText(textView: TextView, wateringInterval: Int) {
47 | val resources = textView.context.resources
48 | val quantityString = resources.getQuantityString(R.plurals.watering_needs_suffix,
49 | wateringInterval, wateringInterval)
50 |
51 | textView.text = SpannableStringBuilder()
52 | .bold { append(resources.getString(R.string.watering_needs_prefix)) }
53 | .append(" ")
54 | .italic { append(quantityString) }
55 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModelTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.viewmodels
18 |
19 | import android.arch.persistence.room.Room
20 | import android.support.test.InstrumentationRegistry
21 | import com.google.samples.apps.sunflower.data.AppDatabase
22 | import com.google.samples.apps.sunflower.data.GardenPlantingRepository
23 | import com.google.samples.apps.sunflower.data.PlantRepository
24 | import com.google.samples.apps.sunflower.utilities.getValue
25 | import com.google.samples.apps.sunflower.utilities.testPlant
26 | import org.junit.After
27 | import org.junit.Assert.assertFalse
28 | import org.junit.Before
29 | import org.junit.Test
30 |
31 | class PlantDetailViewModelTest {
32 |
33 | private lateinit var appDatabase: AppDatabase
34 | private lateinit var viewModel: PlantDetailViewModel
35 |
36 | @Before
37 | fun setUp() {
38 | val context = InstrumentationRegistry.getTargetContext()
39 | appDatabase = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
40 |
41 | val plantRepo = PlantRepository.getInstance(appDatabase.plantDao())
42 | val gardenPlantingRepo = GardenPlantingRepository.getInstance(
43 | appDatabase.gardenPlantingDao())
44 | viewModel = PlantDetailViewModel(plantRepo, gardenPlantingRepo, testPlant.plantId)
45 | }
46 |
47 | @After
48 | fun tearDown() {
49 | appDatabase.close()
50 | }
51 |
52 | @Test
53 | @Throws(InterruptedException::class)
54 | fun testDefaultValues() {
55 | assertFalse(getValue(viewModel.isPlanted))
56 | }
57 |
58 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Sunflower
19 | Filter by grow zone
20 | Image of plant
21 | Plants
22 | My Garden
23 | Open navigation drawer
24 | Close navigation drawer
25 | My Garden
26 | Plant list
27 | Sunflower
28 |
29 | Navigation drawer header logo
30 |
31 | Added plant to garden
32 | Your garden is empty
33 | %s planted on %s
34 |
35 | Watering needs:
36 |
37 | every day
38 | every %d days
39 |
40 |
41 | Last watered on %s
42 |
43 | water tomorrow.
44 | water in %d days.
45 |
46 |
47 |
48 | Picture of plant
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/GardenPlanting.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.persistence.room.ColumnInfo
20 | import android.arch.persistence.room.Entity
21 | import android.arch.persistence.room.ForeignKey
22 | import android.arch.persistence.room.PrimaryKey
23 | import java.util.Calendar
24 |
25 | /**
26 | * [GardenPlanting] represents when a user adds a [Plant] to their garden, with useful metadata.
27 | * Properties such as [lastWateringDate] are used for notifications (such as when to water the
28 | * plant).
29 | *
30 | * Declaring the column info allows for the renaming of variables without implementing a
31 | * database migration, as the column name would not change.
32 | */
33 | @Entity(tableName = "garden_plantings", foreignKeys = [ForeignKey(entity = Plant::class,
34 | parentColumns = ["id"], childColumns = ["plant_id"])])
35 | data class GardenPlanting(
36 | @PrimaryKey @ColumnInfo(name = "id") val gardenPlantingId: String, // TODO auto-generate ID.
37 | @ColumnInfo(name = "plant_id") val plantId: String,
38 |
39 | /**
40 | * Indicates when the [Plant] was planted. Used for showing notification when it's time
41 | * to harvest the plant.
42 | */
43 | @ColumnInfo(name = "plant_date") val plantDate: Calendar = Calendar.getInstance(),
44 |
45 | /**
46 | * Indicates when the [Plant] was last watered. Used for showing notification when it's
47 | * time to water the plant.
48 | */
49 | @ColumnInfo(name = "last_watering_date")
50 | val lastWateringDate: Calendar = Calendar.getInstance()
51 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantDetailViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.viewmodels
18 |
19 | import android.arch.lifecycle.LiveData
20 | import android.arch.lifecycle.Transformations
21 | import android.arch.lifecycle.ViewModel
22 | import com.google.samples.apps.sunflower.PlantDetailActivity
23 | import com.google.samples.apps.sunflower.PlantDetailFragment
24 | import com.google.samples.apps.sunflower.data.GardenPlantingRepository
25 | import com.google.samples.apps.sunflower.data.Plant
26 | import com.google.samples.apps.sunflower.data.PlantRepository
27 |
28 | /**
29 | * The ViewModel used in [PlantDetailActivity] and [PlantDetailFragment].
30 | */
31 | class PlantDetailViewModel(
32 | plantRepository: PlantRepository,
33 | private val gardenPlantingRepository: GardenPlantingRepository,
34 | private val plantId: String
35 | ) : ViewModel() {
36 |
37 | val isPlanted: LiveData
38 | val plant: LiveData
39 |
40 | init {
41 |
42 | /* The getGardenPlantingForPlant method returns a LiveData from querying the database. The
43 | * method can return null in two cases: when the database query is running and if no records
44 | * are found. In these cases isPlanted is false. If a record is found then isPlanted is
45 | * true. */
46 | val gardenPlantingForPlant = gardenPlantingRepository.getGardenPlantingForPlant(plantId)
47 | isPlanted = Transformations.map(gardenPlantingForPlant) { it != null }
48 |
49 | plant = plantRepository.getPlant(plantId)
50 | }
51 |
52 | fun addPlantToGarden() {
53 | gardenPlantingRepository.createGardenPlanting(plantId)
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_plant.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
38 |
39 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/google/samples/apps/sunflower/PlantDetailActivityTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower
18 |
19 | import android.content.Intent
20 | import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
21 | import android.support.test.InstrumentationRegistry
22 | import android.support.test.espresso.Espresso.onView
23 | import android.support.test.espresso.assertion.ViewAssertions.matches
24 | import android.support.test.espresso.matcher.ViewMatchers.withId
25 | import android.support.test.filters.LargeTest
26 | import android.support.test.rule.ActivityTestRule
27 | import android.support.test.runner.AndroidJUnit4
28 | import com.google.samples.apps.sunflower.utilities.testPlant
29 | import com.google.samples.apps.sunflower.utilities.withCollapsingToolbarTitle
30 | import org.junit.Rule
31 | import org.junit.Test
32 | import org.junit.runner.RunWith
33 |
34 | @RunWith(AndroidJUnit4::class)
35 | @LargeTest
36 | class PlantDetailActivityTest {
37 |
38 | @Rule @JvmField
39 | val activityTestRule: ActivityTestRule =
40 | object : ActivityTestRule(PlantDetailActivity::class.java) {
41 | override fun getActivityIntent() : Intent {
42 | val targetContext = InstrumentationRegistry.getInstrumentation().targetContext
43 | val result = Intent(targetContext, PlantDetailActivity::class.java)
44 | result.putExtra(PlantDetailFragment.ARG_ITEM_ID, testPlant.plantId)
45 | return result
46 | }
47 | }
48 |
49 | @Test
50 | fun viewTextPersistAfterOrientationChange() {
51 | onView(withId(R.id.toolbar_layout))
52 | .check(matches(withCollapsingToolbarTitle(testPlant.name)))
53 |
54 | activityTestRule.activity.requestedOrientation = SCREEN_ORIENTATION_LANDSCAPE
55 | onView(withId(R.id.toolbar_layout))
56 | .check(matches(withCollapsingToolbarTitle(testPlant.name)))
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/utilities/InjectorUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.utilities
18 |
19 | import android.content.Context
20 | import com.google.samples.apps.sunflower.data.AppDatabase
21 | import com.google.samples.apps.sunflower.data.GardenPlantingRepository
22 | import com.google.samples.apps.sunflower.data.PlantRepository
23 | import com.google.samples.apps.sunflower.viewmodels.GardenPlantingListViewModelFactory
24 | import com.google.samples.apps.sunflower.viewmodels.PlantDetailViewModelFactory
25 | import com.google.samples.apps.sunflower.viewmodels.PlantListViewModelFactory
26 |
27 | /**
28 | * Static methods used to inject classes needed for various Activities and Fragments.
29 | */
30 | object InjectorUtils {
31 |
32 | private fun getPlantRepository(context: Context): PlantRepository {
33 | return PlantRepository.getInstance(AppDatabase.getInstance(context).plantDao())
34 | }
35 |
36 | private fun getGardenPlantingRepository(context: Context): GardenPlantingRepository {
37 | return GardenPlantingRepository.getInstance(
38 | AppDatabase.getInstance(context).gardenPlantingDao())
39 | }
40 |
41 | fun provideGardenPlantingListViewModelFactory(
42 | context: Context
43 | ): GardenPlantingListViewModelFactory {
44 | val repository = getGardenPlantingRepository(context)
45 | return GardenPlantingListViewModelFactory(repository)
46 | }
47 |
48 | fun providePlantListViewModelFactory(context: Context): PlantListViewModelFactory {
49 | val repository = getPlantRepository(context)
50 | return PlantListViewModelFactory(repository)
51 | }
52 |
53 | fun providePlantDetailViewModelFactory(
54 | context: Context,
55 | plantId: String
56 | ): PlantDetailViewModelFactory {
57 | return PlantDetailViewModelFactory(getPlantRepository(context),
58 | getGardenPlantingRepository(context), plantId)
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/google/samples/apps/sunflower/utilities/TestUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.utilities
18 |
19 | import android.app.Activity
20 | import android.support.design.widget.CollapsingToolbarLayout
21 | import android.support.test.espresso.matcher.BoundedMatcher
22 | import android.support.v7.widget.Toolbar
23 | import android.view.View
24 | import com.google.samples.apps.sunflower.data.GardenPlanting
25 | import com.google.samples.apps.sunflower.data.Plant
26 | import org.hamcrest.Description
27 | import org.hamcrest.Matcher
28 | import java.util.Calendar
29 |
30 | /**
31 | * [Plant] objects used for tests.
32 | */
33 | val testPlants = arrayListOf(
34 | Plant("1", "Apple", "A red fruit", 1),
35 | Plant("2", "B", "Description B", 1),
36 | Plant("3", "C", "Description C", 2)
37 | )
38 | val testPlant = testPlants[0]
39 |
40 | /**
41 | * [Calendar] object used for tests.
42 | */
43 | val testCalendar: Calendar = Calendar.getInstance().apply {
44 | set(Calendar.YEAR, 1998)
45 | set(Calendar.MONTH, Calendar.SEPTEMBER)
46 | set(Calendar.DAY_OF_MONTH, 4)
47 | }
48 |
49 | /**
50 | * [GardenPlanting] object used for tests.
51 | */
52 | val testGardenPlanting = GardenPlanting("1", testPlant.plantId, testCalendar, testCalendar)
53 |
54 | /**
55 | * Matches the toolbar title with a specific string.
56 | *
57 | * @param string the string to match
58 | */
59 | fun withCollapsingToolbarTitle(string: String): Matcher {
60 | return object : BoundedMatcher(
61 | CollapsingToolbarLayout::class.java) {
62 |
63 | override fun describeTo(description: Description) {
64 | description.appendText("with toolbar title: $string")
65 | }
66 |
67 | override fun matchesSafely(toolbar: CollapsingToolbarLayout) = (string == toolbar.title)
68 | }
69 | }
70 |
71 | /**
72 | * Returns the content description for the navigation button view in the toolbar.
73 | */
74 | fun getToolbarNavigationContentDescription(activity: Activity, toolbarId: Int) =
75 | activity.findViewById(toolbarId).navigationContentDescription as String
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_garden_planting.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
22 |
23 |
37 |
38 |
48 |
49 |
60 |
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_garden.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
29 |
30 |
33 |
34 |
39 |
40 |
45 |
46 |
47 |
48 |
49 |
50 |
57 |
58 |
59 |
60 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/data/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.persistence.db.SupportSQLiteDatabase
20 | import android.arch.persistence.room.Database
21 | import android.arch.persistence.room.Room
22 | import android.arch.persistence.room.RoomDatabase
23 | import android.arch.persistence.room.TypeConverters
24 | import android.content.Context
25 | import androidx.work.OneTimeWorkRequest
26 | import androidx.work.WorkManager
27 | import com.google.samples.apps.sunflower.utilities.DATABASE_NAME
28 | import com.google.samples.apps.sunflower.workers.SeedDatabaseWorker
29 |
30 | /**
31 | * The Room database for this app
32 | */
33 | @Database(entities = [GardenPlanting::class, Plant::class], version = 1, exportSchema = false)
34 | @TypeConverters(Converters::class)
35 | abstract class AppDatabase : RoomDatabase() {
36 | abstract fun gardenPlantingDao(): GardenPlantingDao
37 | abstract fun plantDao(): PlantDao
38 |
39 | companion object {
40 |
41 | // For Singleton instantiation
42 | @Volatile private var instance: AppDatabase? = null
43 |
44 | fun getInstance(context: Context): AppDatabase {
45 | return instance ?: synchronized(this) {
46 | instance ?: buildDatabase(context).also { instance = it }
47 | }
48 | }
49 |
50 | // Create and pre-populate the database. See this article for more details:
51 | // https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1#4785
52 | private fun buildDatabase(context: Context): AppDatabase {
53 | return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
54 | .addCallback(object : RoomDatabase.Callback() {
55 | override fun onCreate(db: SupportSQLiteDatabase) {
56 | super.onCreate(db)
57 | val seedRequest = OneTimeWorkRequest.Builder(
58 | SeedDatabaseWorker::class.java).build()
59 | WorkManager.getInstance().enqueue(seedRequest)
60 | }
61 | })
62 | .build()
63 | }
64 |
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/google/samples/apps/sunflower/data/PlantDaoTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.persistence.room.Room
20 | import android.support.test.InstrumentationRegistry
21 | import android.support.test.runner.AndroidJUnit4
22 | import com.google.samples.apps.sunflower.utilities.getValue
23 | import org.hamcrest.Matchers.equalTo
24 | import org.junit.After
25 | import org.junit.Assert.assertThat
26 | import org.junit.Before
27 | import org.junit.Test
28 | import org.junit.runner.RunWith
29 |
30 | @RunWith(AndroidJUnit4::class)
31 | class PlantDaoTest {
32 | private lateinit var database: AppDatabase
33 | private lateinit var plantDao: PlantDao
34 | private val plantA = Plant("1", "A", "", 1, 1, "")
35 | private val plantB = Plant("2", "B", "", 1, 1, "")
36 | private val plantC = Plant("3", "C", "", 2, 2, "")
37 |
38 | @Before fun createDb() {
39 | val context = InstrumentationRegistry.getTargetContext()
40 | database = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
41 | plantDao = database.plantDao()
42 |
43 | // Insert plants in non-alphabetical order to test that results are sorted by name
44 | plantDao.insertAll(listOf(plantB, plantC, plantA))
45 | }
46 |
47 | @After fun closeDb() {
48 | database.close()
49 | }
50 |
51 | @Test fun testGetPlants() {
52 | val plantList = getValue(plantDao.getPlants())
53 | assertThat(plantList.size, equalTo(3))
54 |
55 | // Ensure plant list is sorted by name
56 | assertThat(plantList[0], equalTo(plantA))
57 | assertThat(plantList[1], equalTo(plantB))
58 | assertThat(plantList[2], equalTo(plantC))
59 | }
60 |
61 | @Test fun testGetPlantsWithGrowZoneNumber() {
62 | val plantList = getValue(plantDao.getPlantsWithGrowZoneNumber(1))
63 | assertThat(plantList.size, equalTo(2))
64 | assertThat(getValue(plantDao.getPlantsWithGrowZoneNumber(2)).size, equalTo(1))
65 | assertThat(getValue(plantDao.getPlantsWithGrowZoneNumber(3)).size, equalTo(0))
66 |
67 | // Ensure plant list is sorted by name
68 | assertThat(plantList[0], equalTo(plantA))
69 | assertThat(plantList[1], equalTo(plantB))
70 | }
71 |
72 | @Test fun testGetPlant() {
73 | assertThat(getValue(plantDao.getPlant(plantA.plantId)), equalTo(plantA))
74 | }
75 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/GardenFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower
18 |
19 | import android.arch.lifecycle.Observer
20 | import android.arch.lifecycle.ViewModelProviders
21 | import android.os.Bundle
22 | import android.support.v4.app.Fragment
23 | import android.support.v7.widget.RecyclerView
24 | import android.view.LayoutInflater
25 | import android.view.View
26 | import android.view.ViewGroup
27 | import android.widget.TextView
28 | import com.google.samples.apps.sunflower.adapters.GardenPlantingAdapter
29 | import com.google.samples.apps.sunflower.utilities.InjectorUtils
30 | import com.google.samples.apps.sunflower.viewmodels.GardenPlantingListViewModel
31 |
32 | class GardenFragment : Fragment() {
33 |
34 | override fun onCreateView(
35 | inflater: LayoutInflater,
36 | container: ViewGroup?,
37 | savedInstanceState: Bundle?
38 | ): View? {
39 | val view = inflater.inflate(R.layout.fragment_garden, container, false)
40 | val adapter = GardenPlantingAdapter(view.context)
41 | view.findViewById(R.id.garden_list).adapter = adapter
42 | subscribeUi(adapter)
43 | return view
44 | }
45 |
46 | private fun subscribeUi(adapter: GardenPlantingAdapter) {
47 | val factory = InjectorUtils.provideGardenPlantingListViewModelFactory(requireContext())
48 | val viewModel = ViewModelProviders.of(this, factory)
49 | .get(GardenPlantingListViewModel::class.java)
50 |
51 | viewModel.getGardenPlantings().observe(this, Observer { plantings ->
52 | if (plantings != null && plantings.isNotEmpty()) {
53 | activity?.run {
54 | findViewById(R.id.garden_list).run { visibility = View.VISIBLE }
55 | findViewById(R.id.empty_garden).run { visibility = View.GONE }
56 | }
57 | } else {
58 | activity?.run {
59 | findViewById(R.id.garden_list).run { visibility = View.GONE }
60 | findViewById(R.id.empty_garden).run { visibility = View.VISIBLE }
61 | }
62 | }
63 | })
64 |
65 | // TODO handle this better - shouldn't need to filter
66 | viewModel.getPlantAndGardenPlantings().observe(this, Observer { result ->
67 | if (result != null && result.isNotEmpty())
68 | adapter.values = result.filter { it.gardenPlantings.isNotEmpty() }
69 | })
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/PlantListFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower
18 |
19 | import android.arch.lifecycle.Observer
20 | import android.arch.lifecycle.ViewModelProviders
21 | import android.os.Bundle
22 | import android.support.v4.app.Fragment
23 | import android.support.v7.widget.RecyclerView
24 | import android.view.LayoutInflater
25 | import android.view.Menu
26 | import android.view.MenuInflater
27 | import android.view.MenuItem
28 | import android.view.View
29 | import android.view.ViewGroup
30 | import com.google.samples.apps.sunflower.adapters.PlantAdapter
31 | import com.google.samples.apps.sunflower.utilities.InjectorUtils
32 | import com.google.samples.apps.sunflower.viewmodels.PlantListViewModel
33 |
34 | class PlantListFragment : Fragment() {
35 |
36 | private lateinit var viewModel: PlantListViewModel
37 | private var arePlantsFiltered = false // TODO remove this, used for development
38 |
39 | override fun onCreateView(
40 | inflater: LayoutInflater,
41 | container: ViewGroup?,
42 | savedInstanceState: Bundle?
43 | ): View? {
44 | val view = inflater.inflate(R.layout.fragment_plant_list, container, false)
45 | val context = context ?: return view
46 |
47 | val factory = InjectorUtils.providePlantListViewModelFactory(context)
48 | viewModel = ViewModelProviders.of(this, factory).get(PlantListViewModel::class.java)
49 |
50 | val adapter = PlantAdapter()
51 | view.findViewById(R.id.plant_list).adapter = adapter
52 | subscribeUi(adapter)
53 |
54 | setHasOptionsMenu(true)
55 | return view
56 | }
57 |
58 | override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
59 | inflater?.inflate(R.menu.menu_plant_list, menu)
60 | }
61 |
62 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
63 | return when (item.itemId) {
64 | R.id.filter_zone -> {
65 | updateData()
66 | true
67 | }
68 | else -> super.onOptionsItemSelected(item)
69 | }
70 | }
71 |
72 | private fun subscribeUi(adapter: PlantAdapter) {
73 | viewModel.getPlants().observe(this, Observer { plants ->
74 | if (plants != null) adapter.values = plants
75 | })
76 | }
77 |
78 | private fun updateData() {
79 | arePlantsFiltered = if (arePlantsFiltered) {
80 | viewModel.clearGrowZoneNumber()
81 | false
82 | } else {
83 | viewModel.setGrowZoneNumber(9)
84 | true
85 | }
86 | }
87 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 | apply plugin: 'com.android.application'
18 | apply plugin: 'kotlin-android'
19 | apply plugin: 'kotlin-android-extensions'
20 | apply plugin: 'kotlin-kapt'
21 |
22 | android {
23 | compileSdkVersion rootProject.compileSdkVersion
24 | dataBinding {
25 | enabled = true
26 | }
27 | defaultConfig {
28 | applicationId "com.google.samples.apps.sunflower"
29 | minSdkVersion rootProject.minSdkVersion
30 | targetSdkVersion rootProject.targetSdkVersion
31 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
32 | versionCode 1
33 | versionName "0.1.0"
34 | }
35 | buildTypes {
36 | release {
37 | minifyEnabled false
38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39 | }
40 | }
41 | compileOptions {
42 | targetCompatibility 1.8
43 | sourceCompatibility 1.8
44 | }
45 | }
46 |
47 | dependencies {
48 | kapt "android.arch.persistence.room:compiler:$rootProject.roomVersion"
49 | kapt "com.github.bumptech.glide:compiler:$rootProject.glideVersion"
50 | implementation "android.arch.lifecycle:extensions:$rootProject.lifecycleVersion"
51 | implementation "android.arch.navigation:navigation-fragment-ktx:$rootProject.navigationVersion"
52 | implementation "android.arch.navigation:navigation-ui-ktx:$rootProject.navigationVersion"
53 | implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
54 | implementation "android.arch.work:work-runtime-ktx:$rootProject.workVersion"
55 | implementation "androidx.core:core-ktx:$rootProject.ktxVersion"
56 | implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
57 | implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
58 | implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
59 | implementation "com.android.support.constraint:constraint-layout:$rootProject.constraintLayoutVersion"
60 | implementation "com.android.support:design:$rootProject.supportLibraryVersion"
61 | implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
62 | implementation "com.google.code.gson:gson:$rootProject.gsonVersion"
63 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion"
64 |
65 | // Testing dependencies
66 | androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$rootProject.espressoVersion"
67 | androidTestImplementation "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion"
68 | testImplementation "junit:junit:$rootProject.junitVersion"
69 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/GardenActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower
18 |
19 | import android.content.res.Configuration
20 | import android.os.Bundle
21 | import android.support.design.widget.NavigationView
22 | import android.support.v4.widget.DrawerLayout
23 | import android.support.v7.app.ActionBarDrawerToggle
24 | import android.support.v7.app.AppCompatActivity
25 | import android.view.MenuItem
26 | import androidx.navigation.Navigation
27 | import androidx.navigation.ui.setupWithNavController
28 |
29 | class GardenActivity : AppCompatActivity() {
30 |
31 | private lateinit var drawerLayout: DrawerLayout
32 | private lateinit var drawerToggle: ActionBarDrawerToggle
33 |
34 | override fun onCreate(savedInstanceState: Bundle?) {
35 | super.onCreate(savedInstanceState)
36 | setContentView(R.layout.activity_garden)
37 | setupToolbar()
38 | setupNavigationDrawer()
39 | }
40 |
41 | private fun setupToolbar() {
42 | setSupportActionBar(findViewById(R.id.toolbar))
43 | supportActionBar?.run {
44 | setDisplayHomeAsUpEnabled(true)
45 | setHomeButtonEnabled(true)
46 | }
47 | }
48 |
49 | private fun setupNavigationDrawer() {
50 | drawerLayout = findViewById(R.id.drawer_layout)
51 | drawerToggle = ActionBarDrawerToggle(
52 | this, drawerLayout, R.string.drawer_open, R.string.drawer_close)
53 | drawerLayout.addDrawerListener(drawerToggle)
54 | val navController = Navigation.findNavController(this, R.id.garden_nav_fragment)
55 | findViewById(R.id.navigation_view).setupWithNavController(navController)
56 | }
57 |
58 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
59 | // The action bar home/up action should open or close the drawer.
60 | // [ActionBarDrawerToggle] will take care of this.
61 | if (drawerToggle.onOptionsItemSelected(item)) {
62 | return true
63 | }
64 | return super.onOptionsItemSelected(item)
65 | }
66 |
67 | /**
68 | * If [ActionBarDrawerToggle] is used, it must be called in [onPostCreate] and
69 | * [onConfigurationChanged].
70 | */
71 | override fun onPostCreate(savedInstanceState: Bundle?) {
72 | super.onPostCreate(savedInstanceState)
73 | // Sync the toggle state after has occurred.
74 | drawerToggle.syncState()
75 | }
76 |
77 | override fun onConfigurationChanged(newConfig: Configuration?) {
78 | super.onConfigurationChanged(newConfig)
79 | // Pass any configuration change to the drawer toggle.
80 | drawerToggle.onConfigurationChanged(newConfig)
81 | }
82 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/adapters/PlantAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.adapters
18 |
19 | import android.content.Intent
20 | import android.support.v7.widget.RecyclerView
21 | import android.view.LayoutInflater
22 | import android.view.View
23 | import android.view.ViewGroup
24 | import android.widget.ImageView
25 | import android.widget.TextView
26 | import com.bumptech.glide.Glide
27 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
28 | import com.google.samples.apps.sunflower.PlantDetailActivity
29 | import com.google.samples.apps.sunflower.PlantDetailFragment
30 | import com.google.samples.apps.sunflower.PlantListFragment
31 | import com.google.samples.apps.sunflower.R
32 | import com.google.samples.apps.sunflower.data.Plant
33 |
34 | /**
35 | * Adapter for the [RecyclerView] in [PlantListFragment].
36 | */
37 | class PlantAdapter : RecyclerView.Adapter() {
38 |
39 | var values: List = ArrayList(0)
40 | set(items) {
41 | field = items
42 | notifyDataSetChanged()
43 | }
44 |
45 | private val onClickListener = View.OnClickListener { view ->
46 | val item = view.tag as Plant
47 | val intent = Intent(view.context, PlantDetailActivity::class.java).apply {
48 | putExtra(PlantDetailFragment.ARG_ITEM_ID, item.plantId)
49 | }
50 | view.context.startActivity(intent)
51 | }
52 |
53 | override fun getItemCount() = values.size
54 |
55 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
56 | holder.apply {
57 | Glide.with(imageView.context)
58 | .load(values[position].imageUrl)
59 | .transition(DrawableTransitionOptions.withCrossFade())
60 | .into(imageView)
61 | contentView.text = values[position].name
62 | with(itemView) {
63 | tag = values[position]
64 | setOnClickListener(onClickListener)
65 | }
66 | }
67 | }
68 |
69 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
70 | return ViewHolder(LayoutInflater.from(parent.context).inflate(
71 | R.layout.list_item_plant, parent, false))
72 | }
73 |
74 | /**
75 | * Use this constructor to create a new ViewHolder.
76 | *
77 | * @param itemView - view to store in the ViewHolder
78 | */
79 | class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
80 | val imageView: ImageView = itemView.findViewById(R.id.plant_item_image)
81 | val contentView: TextView = itemView.findViewById(R.id.plant_item_title)
82 | }
83 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/PlantDetailFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower
18 |
19 | import android.arch.lifecycle.ViewModelProviders
20 | import android.databinding.DataBindingUtil
21 | import android.os.Bundle
22 | import android.support.design.widget.Snackbar
23 | import android.support.v4.app.Fragment
24 | import android.support.v7.app.AppCompatActivity
25 | import android.view.LayoutInflater
26 | import android.view.View
27 | import android.view.ViewGroup
28 |
29 | import com.google.samples.apps.sunflower.databinding.FragmentPlantDetailBinding
30 | import com.google.samples.apps.sunflower.utilities.InjectorUtils
31 | import com.google.samples.apps.sunflower.viewmodels.PlantDetailViewModel
32 |
33 | /**
34 | * A fragment representing a single Plant detail screen.
35 | */
36 | class PlantDetailFragment : Fragment() {
37 |
38 | override fun onCreateView(
39 | inflater: LayoutInflater,
40 | container: ViewGroup?,
41 | savedInstanceState: Bundle?
42 | ): View? {
43 | val plantId = requireNotNull(arguments).getString(ARG_ITEM_ID)
44 |
45 | val factory = InjectorUtils.providePlantDetailViewModelFactory(requireActivity(), plantId)
46 | val plantDetailViewModel = ViewModelProviders.of(this, factory)
47 | .get(PlantDetailViewModel::class.java)
48 |
49 | val binding = DataBindingUtil.inflate(
50 | inflater, R.layout.fragment_plant_detail, container, false).apply {
51 | viewModel = plantDetailViewModel
52 | setLifecycleOwner(this@PlantDetailFragment)
53 | fab.setOnClickListener { view ->
54 | plantDetailViewModel.addPlantToGarden()
55 | Snackbar.make(view, R.string.added_plant_to_garden, Snackbar.LENGTH_LONG).show()
56 | }
57 | }
58 |
59 | val appCompatActivity = requireActivity() as AppCompatActivity
60 | appCompatActivity.setSupportActionBar(binding.detailToolbar)
61 |
62 | // Show the Up button in the action bar.
63 | appCompatActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
64 |
65 | return binding.root
66 | }
67 |
68 | companion object {
69 |
70 | /**
71 | * The fragment argument representing the item ID that this fragment
72 | * represents.
73 | */
74 | const val ARG_ITEM_ID = "item_id"
75 |
76 | /**
77 | * Create a new instance of PlantDetailFragment, initialized with a plant ID.
78 | */
79 | fun newInstance(plantId: String): PlantDetailFragment {
80 |
81 | // Supply plant ID as an argument.
82 | val bundle = Bundle().apply { putString(ARG_ITEM_ID, plantId) }
83 | return PlantDetailFragment().apply { arguments = bundle }
84 | }
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/google/samples/apps/sunflower/GardenActivityTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower
18 |
19 | import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
20 | import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
21 | import android.support.test.espresso.Espresso.onView
22 | import android.support.test.espresso.action.ViewActions.click
23 | import android.support.test.espresso.assertion.ViewAssertions.matches
24 | import android.support.test.espresso.contrib.DrawerMatchers.isClosed
25 | import android.support.test.espresso.contrib.DrawerMatchers.isOpen
26 | import android.support.test.espresso.contrib.NavigationViewActions.navigateTo
27 | import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
28 | import android.support.test.espresso.matcher.ViewMatchers.withContentDescription
29 | import android.support.test.espresso.matcher.ViewMatchers.withId
30 | import android.support.test.rule.ActivityTestRule
31 | import android.view.Gravity
32 | import com.google.samples.apps.sunflower.utilities.getToolbarNavigationContentDescription
33 | import org.junit.Rule
34 | import org.junit.Test
35 |
36 | class GardenActivityTest {
37 |
38 | @Rule @JvmField
39 | var activityTestRule = ActivityTestRule(GardenActivity::class.java)
40 |
41 | @Test fun clickOnAndroidHomeIcon_OpensAndClosesNavigation() {
42 | // Check that drawer is closed at startup
43 | onView(withId(R.id.drawer_layout)).check(matches(isClosed(Gravity.START)))
44 |
45 | clickOnHomeIconToOpenNavigationDrawer()
46 | checkDrawerIsOpen()
47 | }
48 |
49 | @Test fun onRotate_NavigationStaysOpen() {
50 | clickOnHomeIconToOpenNavigationDrawer()
51 |
52 | // Rotate device to landscape
53 | activityTestRule.activity.requestedOrientation = SCREEN_ORIENTATION_LANDSCAPE
54 | checkDrawerIsOpen()
55 |
56 | // Rotate device back to portrait
57 | activityTestRule.activity.requestedOrientation = SCREEN_ORIENTATION_PORTRAIT
58 | checkDrawerIsOpen()
59 | }
60 |
61 | @Test fun clickOnPlantListDrawerMenuItem_StartsPlantListActivity() {
62 | clickOnHomeIconToOpenNavigationDrawer()
63 |
64 | // Press on Plant List navigation item
65 | onView(withId(R.id.navigation_view))
66 | .perform(navigateTo(R.id.plant_list_fragment))
67 |
68 | // Check that the PlantListFragment is visible
69 | onView(withId(R.id.plant_list)).check(matches(isDisplayed()))
70 | }
71 |
72 | private fun clickOnHomeIconToOpenNavigationDrawer() {
73 | onView(withContentDescription(getToolbarNavigationContentDescription(
74 | activityTestRule.activity, R.id.toolbar))).perform(click())
75 | }
76 |
77 | private fun checkDrawerIsOpen() {
78 | onView(withId(R.id.drawer_layout)).check(matches(isOpen(Gravity.START)))
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/apps/sunflower/adapters/GardenPlantingAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.adapters
18 |
19 | import android.annotation.SuppressLint
20 | import android.content.Context
21 | import android.support.v7.widget.RecyclerView
22 | import android.view.LayoutInflater
23 | import android.view.View
24 | import android.view.ViewGroup
25 | import android.widget.ImageView
26 | import android.widget.TextView
27 | import com.bumptech.glide.Glide
28 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
29 | import com.google.samples.apps.sunflower.R
30 | import com.google.samples.apps.sunflower.data.PlantAndGardenPlantings
31 | import java.text.SimpleDateFormat
32 | import java.util.Locale
33 |
34 | class GardenPlantingAdapter(
35 | val context: Context
36 | ) : RecyclerView.Adapter() {
37 |
38 | var values: List = ArrayList(0)
39 | set(items) {
40 | field = items
41 | notifyDataSetChanged()
42 | }
43 |
44 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
45 | return ViewHolder(LayoutInflater.from(parent.context).inflate(
46 | R.layout.list_item_garden_planting, parent, false))
47 | }
48 |
49 | override fun getItemCount() = values.size
50 |
51 | @SuppressLint("SetTextI18n")
52 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
53 | val dateFormat = SimpleDateFormat("MMM d, yyyy", Locale.US)
54 |
55 | val plant = checkNotNull(values[position].plant)
56 | val gardenPlanting = values[position].gardenPlantings[0]
57 | val plantDateString = dateFormat.format(gardenPlanting.plantDate.time)
58 | val waterDateString = dateFormat.format(gardenPlanting.lastWateringDate.time)
59 | val wateringPrefix = context.getString(R.string.watering_next_prefix, waterDateString)
60 | val wateringSuffix = context.resources.getQuantityString(R.plurals.watering_next_suffix,
61 | plant.wateringInterval, plant.wateringInterval)
62 |
63 | holder.apply {
64 | Glide.with(context)
65 | .load(plant.imageUrl)
66 | .transition(DrawableTransitionOptions.withCrossFade())
67 | .into(plantImageView)
68 | plantDateView.text = context.getString(R.string.planted_date, plant.name,
69 | plantDateString)
70 | waterDateView.text = "$wateringPrefix - $wateringSuffix"
71 | itemView.tag = values[position]
72 | }
73 | }
74 |
75 | class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
76 | val plantImageView: ImageView = itemView.findViewById(R.id.imageView)
77 | val plantDateView: TextView = itemView.findViewById(R.id.plant_date)
78 | val waterDateView: TextView = itemView.findViewById(R.id.water_date)
79 | }
80 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/google/samples/apps/sunflower/data/GardenPlantingDaoTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google LLC
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 com.google.samples.apps.sunflower.data
18 |
19 | import android.arch.persistence.room.Room
20 | import android.support.test.InstrumentationRegistry
21 | import android.support.test.espresso.matcher.ViewMatchers.assertThat
22 | import com.google.samples.apps.sunflower.utilities.getValue
23 | import com.google.samples.apps.sunflower.utilities.testCalendar
24 | import com.google.samples.apps.sunflower.utilities.testGardenPlanting
25 | import com.google.samples.apps.sunflower.utilities.testPlant
26 | import com.google.samples.apps.sunflower.utilities.testPlants
27 | import org.hamcrest.CoreMatchers.equalTo
28 | import org.junit.After
29 | import org.junit.Assert.assertNull
30 | import org.junit.Before
31 | import org.junit.Test
32 |
33 | class GardenPlantingDaoTest {
34 | private lateinit var database: AppDatabase
35 | private lateinit var gardenPlantingDao: GardenPlantingDao
36 |
37 | @Before fun createDb() {
38 | val context = InstrumentationRegistry.getTargetContext()
39 | database = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
40 | gardenPlantingDao = database.gardenPlantingDao()
41 |
42 | database.plantDao().insertAll(testPlants)
43 | gardenPlantingDao.insertGardenPlanting(testGardenPlanting)
44 | }
45 |
46 | @After fun closeDb() {
47 | database.close()
48 | }
49 |
50 | @Test fun testGetGardenPlantings() {
51 | val gardenPlanting2 = GardenPlanting("2", testPlants[1].plantId, testCalendar, testCalendar)
52 | gardenPlantingDao.insertGardenPlanting(gardenPlanting2)
53 | assertThat(getValue(gardenPlantingDao.getGardenPlantings()).size, equalTo(2))
54 | }
55 |
56 | @Test fun testGetGardenPlanting() {
57 | assertThat(getValue(gardenPlantingDao.getGardenPlanting(
58 | testGardenPlanting.gardenPlantingId)), equalTo(testGardenPlanting))
59 | }
60 |
61 | @Test fun testGetGardenPlantingForPlant() {
62 | assertThat(getValue(gardenPlantingDao.getGardenPlantingForPlant(testPlant.plantId)),
63 | equalTo(testGardenPlanting))
64 | }
65 |
66 | @Test fun testGetGardenPlantingForPlant_notFound() {
67 | assertNull(getValue(gardenPlantingDao.getGardenPlantingForPlant(testPlants[2].plantId)))
68 | }
69 |
70 | @Test fun testGetPlantAndGardenPlantings() {
71 | val plantAndGardenPlantings = getValue(gardenPlantingDao.getPlantAndGardenPlantings())
72 | assertThat(plantAndGardenPlantings.size, equalTo(3))
73 |
74 | /**
75 | * Only the [testPlant] has been planted, and thus has an associated [GardenPlanting]
76 | */
77 | assertThat(plantAndGardenPlantings[0].plant, equalTo(testPlant))
78 | assertThat(plantAndGardenPlantings[0].gardenPlantings.size, equalTo(1))
79 | assertThat(plantAndGardenPlantings[0].gardenPlantings[0], equalTo(testGardenPlanting))
80 |
81 | // The other plants in the database have not been planted and thus have no GardenPlantings
82 | assertThat(plantAndGardenPlantings[1].gardenPlantings.size, equalTo(0))
83 | assertThat(plantAndGardenPlantings[2].gardenPlantings.size, equalTo(0))
84 | }
85 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
28 |
33 |
38 |
43 |
48 |
53 |
58 |
63 |
68 |
73 |
78 |
83 |
88 |
93 |
98 |
103 |
108 |
113 |
118 |
123 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android Sunflower (alpha)
2 | =========================
3 |
4 | A gardening app illustrating Android development best practices with Android Jetpack.
5 |
6 | Android Sunflower is currently released as an alpha and is under heavy development.
7 |
8 | Introduction
9 | ------------
10 |
11 | Android Jetpack is a set of components, tools and guidance to make great Android apps. They bring
12 | together the existing Support Library and Architecture Components and arranges them into four
13 | categories:
14 |
15 | 
16 |
17 | Android Sunflower demonstrates utilizing these components to create a simple gardening app.
18 |
19 | Getting Started
20 | ---------------
21 | This project uses the Gradle build system. To build this project, use the
22 | `gradlew build` command or use "Import Project" in Android Studio.
23 |
24 | There are two Gradle tasks for testing the project:
25 | * `connectedAndroidTest` - for running Espresso on a connected device
26 | * `test` - for running unit tests
27 |
28 | Screenshots
29 | -----------
30 |
31 | 
32 | 
33 | 
34 |
35 | Libraries Used
36 | --------------
37 | * [Foundation][0] - Components for core system capabilities, Kotlin extensions and support for
38 | multidex and automated testing.
39 | * [AppCompat][1] - Degrade gracefully on older versions of Android.
40 | * [Android KTX][2] - Write more concise, idiomatic Kotlin code.
41 | * [Test][4] - An Android testing framework for unit and runtime UI tests.
42 | * [Architecture][10] - A collection of libraries that help you design robust, testable, and
43 | maintainable apps. Start with classes for managing your UI component lifecycle and handling data
44 | persistence.
45 | * [Data Binding][11] - Declaratively bind observable data to UI elements.
46 | * [Lifecycles][12] - Create a UI that automatically responds to lifecycle events.
47 | * [LiveData][13] - Build data objects that notify views when the underlying database changes.
48 | * [Navigation][14] - Handle everything needed for in-app navigation.
49 | * [Room][16] - Access your app's SQLite database with in-app objects and compile-time checks.
50 | * [ViewModel][17] - Store UI-related data that isn't destroyed on app rotations.Easily schedule
51 | asynchronous tasks for optimal execution.
52 | * [WorkManager][18] - Manage your Android background jobs.
53 | * [UI][30] - Details on why and how to use UI Components in your apps - together or separate
54 | * [Fragment][34] - A basic unit of composable UI.
55 | * [Layout][35] - Lay out widgets using different algorithms.
56 | * Third party
57 | * [Glide][90] for image loading
58 |
59 | [0]: https://developer.android.com/jetpack/foundation/
60 | [1]: https://developer.android.com/topic/libraries/support-library/packages#v7-appcompat
61 | [2]: https://developer.android.com/kotlin/ktx
62 | [4]: https://developer.android.com/training/testing/
63 | [10]: https://developer.android.com/jetpack/arch/
64 | [11]: https://developer.android.com/topic/libraries/data-binding/
65 | [12]: https://developer.android.com/topic/libraries/architecture/lifecycle
66 | [13]: https://developer.android.com/topic/libraries/architecture/livedata
67 | [14]: https://developer.android.com/topic/libraries/architecture/navigation/
68 | [16]: https://developer.android.com/topic/libraries/architecture/room
69 | [17]: https://developer.android.com/topic/libraries/architecture/viewmodel
70 | [18]: https://developer.android.com/topic/libraries/architecture/workmanager
71 | [30]: https://developer.android.com/jetpack/ui/
72 | [34]: https://developer.android.com/guide/components/fragments
73 | [35]: https://developer.android.com/guide/topics/ui/declaring-layout
74 | [90]: https://bumptech.github.io/glide/
75 |
76 | Upcoming features
77 | -----------------
78 | Updates will include incorporating additional Jetpack components and updating existing components
79 | as the component libraries evolve.
80 |
81 | Interested in seeing a particular feature of the Android Framework or Jetpack implemented in this
82 | app? Please open a new [issue](https://github.com/googlesamples/android-sunflower/issues).
83 |
84 | Support
85 | -------
86 |
87 | - Google+ Community: https://plus.google.com/communities/105153134372062985968
88 | - Stack Overflow:
89 | - http://stackoverflow.com/questions/tagged/android
90 | - http://stackoverflow.com/questions/tagged/android-jetpack
91 |
92 | If you've found an error in this sample, please file an issue:
93 | https://github.com/googlesamples/android-sunflower/issues
94 |
95 | Patches are encouraged, and may be submitted by forking this project and submitting a pull request
96 | through GitHub.
97 |
98 | License
99 | -------
100 |
101 | Copyright 2018 Google, Inc.
102 |
103 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
104 | license agreements. See the NOTICE file distributed with this work for
105 | additional information regarding copyright ownership. The ASF licenses this
106 | file to you under the Apache License, Version 2.0 (the "License"); you may not
107 | use this file except in compliance with the License. You may obtain a copy of
108 | the License at
109 |
110 | http://www.apache.org/licenses/LICENSE-2.0
111 |
112 | Unless required by applicable law or agreed to in writing, software
113 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
114 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
115 | License for the specific language governing permissions and limitations under
116 | the License.
117 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_plant_detail.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 |
21 |
22 |
25 |
26 |
27 |
33 |
34 |
40 |
41 |
50 |
51 |
60 |
61 |
67 |
68 |
69 |
70 |
71 |
72 |
77 |
78 |
81 |
82 |
94 |
95 |
109 |
110 |
111 |
112 |
113 |
114 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/app/src/main/assets/plants.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "plantId": "1",
4 | "name": "Apple",
5 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
6 | "growZoneNumber": 3,
7 | "wateringInterval": 30,
8 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/5/55/Apple_orchard_in_Tasmania.jpg"
9 | },
10 | {
11 | "plantId": "2",
12 | "name": "Beet",
13 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
14 | "growZoneNumber": 2,
15 | "wateringInterval": 7,
16 | "imageUrl": "https://static.pexels.com/photos/264101/pexels-photo-264101.jpeg"
17 | },
18 | {
19 | "plantId": "3",
20 | "name": "Celery",
21 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
22 | "growZoneNumber": 2,
23 | "wateringInterval": 2,
24 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/5/51/A_scene_of_Coriander_leaves.JPG"
25 | },
26 | {
27 | "plantId": "4",
28 | "name": "Tomato",
29 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
30 | "growZoneNumber": 9,
31 | "wateringInterval": 4,
32 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/1/17/Cherry_tomatoes_red_and_green_2009_16x9.jpg"
33 | },
34 | {
35 | "plantId": "5",
36 | "name": "Avocado",
37 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
38 | "growZoneNumber": 9,
39 | "wateringInterval": 3,
40 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/e/e4/Branch_and_fruit_of_the_Maluma_avocado_cultivar.jpg"
41 | },
42 | {
43 | "plantId": "6",
44 | "name": "Pear",
45 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
46 | "growZoneNumber": 3,
47 | "wateringInterval": 30,
48 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/1/13/More_pears.jpg"
49 | },
50 | {
51 | "plantId": "7",
52 | "name": "Eggplant",
53 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
54 | "growZoneNumber": 4,
55 | "wateringInterval": 3,
56 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/e/e5/Eggplant_display.JPG"
57 | },
58 | {
59 | "plantId": "8",
60 | "name": "Grape",
61 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
62 | "growZoneNumber": 9,
63 | "wateringInterval": 9,
64 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/0/03/Grape_Plant_and_grapes9.jpg"
65 | },
66 | {
67 | "plantId": "9",
68 | "name": "Mango",
69 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
70 | "growZoneNumber": 11,
71 | "wateringInterval": 7,
72 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/6/67/Mangos_criollos_y_pera.JPG"
73 | },
74 | {
75 | "plantId": "10",
76 | "name": "Orange",
77 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
78 | "growZoneNumber": 9,
79 | "wateringInterval": 30,
80 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/2/22/Apfelsinenbaum--Orange_tree.jpg"
81 | },
82 | {
83 | "plantId": "11",
84 | "name": "Sunflower",
85 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
86 | "growZoneNumber": 8,
87 | "wateringInterval": 3,
88 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/a/aa/Sunflowers_in_field_flower.jpg"
89 | },
90 | {
91 | "plantId": "12",
92 | "name": "Watermelon",
93 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
94 | "growZoneNumber": 7,
95 | "wateringInterval": 3,
96 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/f/fc/01266jfWatermelons_Philippines_textures_Apolonio_Samson_Market_Quezon_Cityfvf_02.jpg"
97 | },
98 | {
99 | "plantId": "13",
100 | "name": "Hibiscus",
101 | "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
102 | "growZoneNumber": 10,
103 | "wateringInterval": 1,
104 | "imageUrl": "https://upload.wikimedia.org/wikipedia/commons/8/82/Hibiscus_rosa-sinensis_flower_2.JPG"
105 | }
106 | ]
107 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2014 The Android Open Source Project
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------