├── 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 | 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 | 19 | 20 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /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 | 20 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /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 |