Skip to content
This repository was archived by the owner on Aug 2, 2024. It is now read-only.

Commit bc49636

Browse files
committed
Merge main into compose.
1 parent 395d403 commit bc49636

File tree

81 files changed

+11134
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+11134
-362
lines changed

.github/workflows/copy-branch.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Duplicates default main branch to the old master branch
2+
3+
name: Duplicates main to old master branch
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the main branch
7+
on:
8+
push:
9+
branches: [ main ]
10+
11+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
12+
jobs:
13+
# This workflow contains a single job called "copy-branch"
14+
copy-branch:
15+
# The type of runner that the job will run on
16+
runs-on: ubuntu-latest
17+
18+
# Steps represent a sequence of tasks that will be executed as part of the job
19+
steps:
20+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it,
21+
# but specifies master branch (old default).
22+
- uses: actions/checkout@v2
23+
with:
24+
fetch-depth: 0
25+
ref: master
26+
27+
- run: |
28+
git config user.name github-actions
29+
git config user.email [email protected]
30+
git merge origin/main
31+
git push

README.md

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Android Sunflower with Compose
22

3-
For more information about Sunflower, check out the `main` branch
4-
[README file](https://github.com/android/sunflower/blob/main/README.md).
5-
This branch has Sunflower partially built with
6-
[Jetpack Compose](https://developer.android.com/jetpack/compose).
3+
A gardening app illustrating Android development best practices with migrating
4+
a View-based app to Jetpack Compose.
75

86
This sample showcases:
97
* Compose working in an existing app: including integration with strings, resources, and themes and styles.
108
* Integration with an existing architecture based on Jetpack libraries.
119
* `CollapsingToolbarLayout` behavior implemented manually with Compose.
1210
* Showing [Snackbars](https://material.io/components/snackbars) with Compose.
13-
* Using Compose within a `RecyclerView` ([PR #763](https://github.com/android/sunflower/pull/763))
11+
* Using Compose within a `RecyclerView`
1412

1513
## Screenshots
1614

@@ -32,22 +30,88 @@ All Compose code can be found in the `compose`
3230

3331
## Requirements
3432

35-
[Android Studio Chipmunk 2021.2.1](https://developer.android.com/studio) or newer.
33+
### Unsplash API key
3634

37-
## License
35+
Sunflower uses the [Unsplash API](https://unsplash.com/developers) to load pictures on the gallery
36+
screen. To use the API, you will need to obtain a free developer API key. See the
37+
[Unsplash API Documentation](https://unsplash.com/documentation) for instructions.
3838

39+
Once you have the key, add this line to the `gradle.properties` file, either in your user home
40+
directory (usually `~/.gradle/gradle.properties` on Linux and Mac) or in the project's root folder:
41+
42+
```
43+
unsplash_access_key=<your Unsplash access key>
3944
```
40-
Copyright 2020 The Android Open Source Project
4145

42-
Licensed under the Apache License, Version 2.0 (the "License");
43-
you may not use this file except in compliance with the License.
44-
You may obtain a copy of the License at
46+
The app is still usable without an API key, though you won't be able to navigate to the gallery screen.
47+
48+
Android Studio IDE setup
49+
------------------------
50+
For development, the latest version of Android Studio is required. The latest version can be
51+
downloaded from [here](https://developer.android.com/studio/).
52+
53+
Sunflower uses [ktlint](https://ktlint.github.io/) to enforce Kotlin coding styles.
54+
Here's how to configure it for use with Android Studio (instructions adapted
55+
from the ktlint [README](https://github.com/shyiko/ktlint/blob/master/README.md)):
56+
57+
- Close Android Studio if it's open
58+
59+
- Download ktlint using these [installation instructions](https://github.com/pinterest/ktlint/blob/master/README.md#installation)
60+
61+
- Apply ktlint settings to Android Studio using these [instructions](https://github.com/pinterest/ktlint/blob/master/README.md#-with-intellij-idea)
62+
63+
- Start Android Studio
64+
65+
Additional resources
66+
--------------------
67+
Check out these Wiki pages to learn more about Android Sunflower:
68+
69+
- [Notable Community Contributions](https://github.com/android/sunflower/wiki/Notable-Community-Contributions)
70+
71+
- [Publications](https://github.com/android/sunflower/wiki/Sunflower-Publications)
4572

46-
https://www.apache.org/licenses/LICENSE-2.0
73+
Non-Goals
74+
---------
75+
Previously, this sample app was focused on demonstrating best practices for
76+
multiple Jetpack libraries. However, this is no longer the case and development
77+
will instead be focused on how to adopt Compose in an existing View-based app.
78+
So, there are no plans to implement features outside of this scope. Keep this
79+
in mind when making contributions to this library.
80+
81+
Support
82+
-------
83+
84+
- Stack Overflow:
85+
- https://stackoverflow.com/questions/tagged/android-jetpack-compose
86+
87+
If you've found an error in this sample, please file an issue:
88+
https://github.com/android/sunflower/issues
89+
90+
Patches are encouraged, and may be submitted by forking this project and submitting a pull request
91+
through GitHub.
92+
93+
Third Party Content
94+
-------------------
95+
Select text used for describing the plants (in `plants.json`) are used from Wikipedia via CC BY-SA 3.0 US (license in `ASSETS_LICENSE`).
96+
97+
"[seed](https://thenounproject.com/search/?q=seed&i=1585971)" by [Aisyah](https://thenounproject.com/aisyahalmasyira/) is licensed under [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/us/legalcode)
98+
99+
License
100+
-------
101+
102+
Copyright 2018 Google, Inc.
103+
104+
Licensed to the Apache Software Foundation (ASF) under one or more contributor
105+
license agreements. See the NOTICE file distributed with this work for
106+
additional information regarding copyright ownership. The ASF licenses this
107+
file to you under the Apache License, Version 2.0 (the "License"); you may not
108+
use this file except in compliance with the License. You may obtain a copy of
109+
the License at
110+
111+
https://www.apache.org/licenses/LICENSE-2.0
47112

48113
Unless required by applicable law or agreed to in writing, software
49114
distributed under the License is distributed on an "AS IS" BASIS,
50115
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51116
See the License for the specific language governing permissions and
52117
limitations under the License.
53-
```

app/build.gradle

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,56 @@ apply plugin: 'com.android.application'
1818
apply plugin: 'kotlin-android'
1919
apply plugin: 'kotlin-parcelize'
2020
apply plugin: 'kotlin-kapt'
21+
apply plugin: 'dagger.hilt.android.plugin'
2122
apply plugin: 'androidx.navigation.safeargs.kotlin'
2223

2324
android {
2425
compileSdkVersion rootProject.compileSdkVersion
26+
buildFeatures {
27+
dataBinding true
28+
}
2529
defaultConfig {
2630
applicationId "com.google.samples.apps.sunflower"
2731
minSdkVersion rootProject.minSdkVersion
2832
targetSdkVersion rootProject.targetSdkVersion
29-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
33+
testInstrumentationRunner "com.google.samples.apps.sunflower.utilities.MainTestRunner"
3034
versionCode 1
3135
versionName "0.1.6"
3236
vectorDrawables.useSupportLibrary true
37+
38+
// Consult the README on instructions for setting up Unsplash API key
39+
buildConfigField("String", "UNSPLASH_ACCESS_KEY", "\"" + getUnsplashAccess() + "\"")
40+
javaCompileOptions {
41+
annotationProcessorOptions {
42+
arguments["dagger.hilt.disableModulesHaveInstallInCheck"] = "true"
43+
}
44+
}
3345
}
3446
buildTypes {
3547
release {
36-
minifyEnabled false
48+
minifyEnabled true
3749
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3850
}
51+
benchmark {
52+
initWith buildTypes.release
53+
signingConfig signingConfigs.debug
54+
debuggable false
55+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-rules-benchmark.pro'
56+
}
3957
}
4058
compileOptions {
4159
sourceCompatibility JavaVersion.VERSION_1_8
4260
targetCompatibility JavaVersion.VERSION_1_8
4361
}
62+
4463
kotlinOptions {
64+
// work-runtime-ktx 2.1.0 and above now requires Java 8
4565
jvmTarget = "1.8"
4666
useIR = true
67+
68+
// Enable Coroutines and Flow APIs
69+
freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
70+
freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.FlowPreview"
4771
}
4872
buildFeatures {
4973
compose true
@@ -62,6 +86,7 @@ android {
6286

6387
dependencies {
6488
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
89+
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"
6590
implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
6691
implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
6792
implementation "androidx.core:core-ktx:$rootProject.ktxVersion"
@@ -70,16 +95,21 @@ dependencies {
7095
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion"
7196
implementation "androidx.navigation:navigation-fragment-ktx:$rootProject.navigationVersion"
7297
implementation "androidx.navigation:navigation-ui-ktx:$rootProject.navigationVersion"
73-
implementation "androidx.recyclerview:recyclerview:$rootProject.recyclerViewVersion"
98+
implementation "androidx.paging:paging-runtime-ktx:$rootProject.pagingVersion"
7499
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
75100
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
76101
implementation "androidx.viewpager2:viewpager2:$rootProject.viewPagerVersion"
77102
implementation "androidx.work:work-runtime-ktx:$rootProject.workVersion"
78103
implementation "com.google.android.material:material:$rootProject.materialVersion"
79104
implementation "com.google.code.gson:gson:$rootProject.gsonVersion"
80-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion"
105+
implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttpLoggingVersion"
106+
implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
107+
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
81108
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutinesVersion"
82109
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutinesVersion"
110+
implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
111+
implementation "androidx.profileinstaller:profileinstaller:$rootProject.profileInstallerVersion"
112+
implementation "androidx.tracing:tracing-ktx:$rootProject.tracingVersion"
83113

84114
// Compose
85115
implementation "androidx.activity:activity-compose:$rootProject.activityComposeVersion"
@@ -98,6 +128,7 @@ dependencies {
98128
debugImplementation "androidx.compose.ui:ui-tooling:$rootProject.composeVersion"
99129

100130
// Testing dependencies
131+
kaptAndroidTest "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"
101132
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
102133
androidTestImplementation "androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion"
103134
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion"
@@ -107,5 +138,11 @@ dependencies {
107138
androidTestImplementation "androidx.work:work-testing:$rootProject.workVersion"
108139
androidTestImplementation "com.google.truth:truth:$rootProject.truthVersion"
109140
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$rootProject.composeVersion"
141+
androidTestImplementation "com.google.dagger:hilt-android-testing:$rootProject.hiltVersion"
142+
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$rootProject.coroutinesVersion"
110143
testImplementation "junit:junit:$rootProject.junitVersion"
111144
}
145+
146+
def getUnsplashAccess() {
147+
return project.findProperty("unsplash_access_key")
148+
}

app/proguard-rules-benchmark.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Not obfuscating benchmark builds to be readable with profilers and compatible with baseline profiles
2+
-dontobfuscate

0 commit comments

Comments
 (0)