-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
3,708 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/* | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
/buildSrc/.gradle/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Advanced State in Jetpack Compose Codelab | ||
|
||
This folder contains the source code for the | ||
[Advanced State in Jetpack Compose Codelab](https://developer.android.com/codelabs/jetpack-compose-advanced-state-side-effects) | ||
codelab. | ||
|
||
The project is built in multiple git branches: | ||
* `main` – the starter code for this project, you will make changes to this to complete the codelab | ||
* `end` – contains the solution to this codelab | ||
|
||
## [Optional] Google Maps SDK setup | ||
|
||
Seeing the city on the MapView is not necessary to complete the codelab. However, if you want | ||
to get the MapView to render on the screen, you need to get an API key as | ||
the [documentation says](https://developers.google.com/maps/documentation/android-sdk/get-api-key), | ||
and include it in the `local.properties` file as follows: | ||
|
||
``` | ||
google.maps.key={insert_your_api_key_here} | ||
``` | ||
|
||
When restricting the Key to Android apps, use `androidx.compose.samples.crane` as package name, and | ||
`A0:BD:B3:B6:F0:C4:BE:90:C6:9D:5F:4C:1D:F0:90:80:7F:D7:FE:1F` as SHA-1 certificate fingerprint. | ||
|
||
## License | ||
``` | ||
Copyright 2021 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright 2021 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
id 'kotlin-kapt' | ||
id 'dagger.hilt.android.plugin' | ||
} | ||
|
||
// Reads the Google maps key that is used in the AndroidManifest | ||
Properties properties = new Properties() | ||
if (rootProject.file("local.properties").exists()) { | ||
properties.load(rootProject.file("local.properties").newDataInputStream()) | ||
} | ||
|
||
android { | ||
compileSdkVersion 33 | ||
defaultConfig { | ||
applicationId "androidx.compose.samples.crane" | ||
minSdkVersion 21 | ||
targetSdkVersion 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
vectorDrawables.useSupportLibrary = true | ||
testInstrumentationRunner "androidx.compose.samples.crane.CustomTestRunner" | ||
|
||
manifestPlaceholders = [googleMapsKey: properties.getProperty("google.maps.key", "")] | ||
} | ||
|
||
signingConfigs { | ||
// We use a bundled debug keystore, to allow debug builds from CI to be upgradable | ||
debug { | ||
storeFile rootProject.file('debug.keystore') | ||
storePassword 'android' | ||
keyAlias 'androiddebugkey' | ||
keyPassword 'android' | ||
} | ||
} | ||
|
||
buildTypes { | ||
debug { | ||
signingConfig signingConfigs.debug | ||
} | ||
|
||
release { | ||
minifyEnabled true | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
buildFeatures { | ||
compose true | ||
|
||
// Disable unused AGP features | ||
buildConfig false | ||
aidl false | ||
renderScript false | ||
resValues false | ||
shaders false | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion "1.3.2" | ||
} | ||
|
||
packagingOptions { | ||
// Multiple dependency bring these files in. Exclude them to enable | ||
// our test APK to build (has no effect on our AARs) | ||
excludes += "/META-INF/AL2.0" | ||
excludes += "/META-INF/LGPL2.1" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4" | ||
implementation "com.google.android.libraries.maps:maps:3.1.0-beta" | ||
implementation "com.google.maps.android:maps-v3-ktx:3.4.0" | ||
constraints { | ||
// Volley is a transitive dependency of maps | ||
implementation("com.android.volley:volley:1.2.1") { | ||
because("Only volley 1.2.0 or newer are available on maven.google.com") | ||
} | ||
} | ||
|
||
implementation "com.google.accompanist:accompanist-insets:0.28.0" | ||
implementation "androidx.activity:activity-compose:1.6.1" | ||
implementation "androidx.appcompat:appcompat:1.6.0" | ||
|
||
def composeBom = platform('androidx.compose:compose-bom:2023.01.00') | ||
implementation(composeBom) | ||
androidTestImplementation(composeBom) | ||
implementation "androidx.compose.runtime:runtime" | ||
implementation "androidx.compose.material:material" | ||
implementation "androidx.compose.foundation:foundation" | ||
implementation "androidx.compose.foundation:foundation-layout" | ||
implementation "androidx.compose.animation:animation" | ||
implementation "androidx.compose.ui:ui-tooling-preview" | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4" | ||
debugImplementation "androidx.compose.ui:ui-tooling" | ||
debugImplementation "androidx.compose.ui:ui-test-manifest" | ||
|
||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1" | ||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1" | ||
implementation "com.google.dagger:hilt-android:2.44.2" | ||
kapt "com.google.dagger:hilt-compiler:2.44.2" | ||
|
||
implementation "io.coil-kt:coil-compose:2.2.2" | ||
|
||
androidTestImplementation "junit:junit:4.13.2" | ||
androidTestImplementation "androidx.test:core:1.5.0" | ||
androidTestImplementation "androidx.test:runner:1.5.2" | ||
androidTestImplementation "androidx.test:rules:1.5.0" | ||
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1" | ||
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5" | ||
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4" | ||
androidTestImplementation "com.google.dagger:hilt-android:2.44.2" | ||
androidTestImplementation "com.google.dagger:hilt-android-testing:2.44.2" | ||
kaptAndroidTest "com.google.dagger:hilt-compiler:2.44.2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
-renamesourcefileattribute SourceFile | ||
|
||
# Repackage classes into the top-level. | ||
-repackageclasses |
42 changes: 42 additions & 0 deletions
42
...ectsCodelab/app/src/androidTest/java/androidx/compose/samples/crane/CoroutinesTestRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2021 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.samples.crane | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.TestCoroutineDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class CoroutinesTestRule constructor( | ||
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher() | ||
) : TestWatcher() { | ||
|
||
override fun starting(description: Description?) { | ||
super.starting(description) | ||
Dispatchers.setMain(testDispatcher) | ||
} | ||
|
||
override fun finished(description: Description?) { | ||
super.finished(description) | ||
Dispatchers.resetMain() | ||
testDispatcher.cleanupTestCoroutines() | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ffectsCodelab/app/src/androidTest/java/androidx/compose/samples/crane/CustomTestRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2020 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.samples.crane | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
import dagger.hilt.android.testing.HiltTestApplication | ||
|
||
class CustomTestRunner : AndroidJUnitRunner() { | ||
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { | ||
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | ||
} | ||
} |
Oops, something went wrong.