-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Add Firebase Data Connect quickstart #1671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
2648e40
Initial commit for dataconnect sample app
thatfiredev 2e242ff
chore: add Firebase dependencies
thatfiredev bc89f0b
add first schema
thatfiredev 441033f
update with new schema
thatfiredev 3c99916
add kotlin serialization and androidx.lifecycle
thatfiredev 44a274d
firebase init
thatfiredev 08a034c
setup bottom navigation
thatfiredev 1273149
feat: create movies screen
thatfiredev 30d6298
add firebase data connect logo
thatfiredev 6bb2988
add top 10 movies and latest to the MoviesScreen
thatfiredev 84bf1b0
create GenresScreen
thatfiredev 0b156e2
create GenreDetailScreen
thatfiredev d288623
create MovieDetailScreen
thatfiredev 7d7170e
Merge branch 'master' of github.com:firebase/quickstart-android into …
thatfiredev bdcd7e8
chore: bump gradle plugins
thatfiredev 27aa537
test: delete test modules
thatfiredev 24ca051
chore: add compose compiler
thatfiredev ab176f6
chore: move location from firebase.json to dataconnect.yaml
thatfiredev de4b232
feat: create an auth screen
thatfiredev d6de3cc
create user profile favorites list and sign out button
thatfiredev acc78fc
ellipsize text in Movie Tile
thatfiredev f37f21e
refactor: reuse MovieTile UI component
thatfiredev afe7d69
delete UserRepository
thatfiredev e3dd016
refactor: delete MovieRepository
thatfiredev eb76c92
refactor: delete the data package
thatfiredev 6a29c55
feat: list actors in the movie details screen
thatfiredev 0b9ef77
refactor: movie review list to bottom of profile screen
thatfiredev 1af90a7
feat: add reviews to movie detail screen
thatfiredev d9293ae
refactor: dateformat for reviews
thatfiredev a309c17
feat: mark movies as watched and/or favorite
thatfiredev 7fa7803
refactor: move AuthScreen into its own file
thatfiredev 609e504
docs: add a README file
thatfiredev 30a904b
feat: support reviewing movies :)
thatfiredev 14034c6
feat: create actor details screen
thatfiredev dff9533
refactor: make actor list reusable
thatfiredev 155d7a5
refactor: make movies list reusable
thatfiredev b15d0ab
refactor: make error and loading reusable components
thatfiredev 49a20a1
refactor: make toggle button reusable
thatfiredev 8546e34
refactor: make actor details screen stateless
thatfiredev a45c5d4
refactor: move UserReviews into its own dedicated file
thatfiredev f0f5ce4
refactor: turn actor tile into a card
thatfiredev bca483a
docs: update the getting started
thatfiredev a24417e
docs: update README.md
thatfiredev a8b2bf5
docs: update README.md
thatfiredev c06b22c
add data_seed.gql and useEmulator()
thatfiredev 2912f29
Update README.md
thatfiredev 142dcb9
refactor: use Navigation type safety
thatfiredev 3e0b914
refactor: delete extra uiState
thatfiredev 496af82
refactor favoriteActor for readability
thatfiredev 287adb1
refactor: make error messages nullable and add default error message
thatfiredev 01e072a
refactor: ensure a user is logged in before marking as favorite
thatfiredev 6077294
update GenreDetailScreen
thatfiredev 4a4401b
chore: use v1beta
thatfiredev 172e457
ci: remove Data Connect from build
thatfiredev 68b2595
chore: upgrade to 16.0.0-beta01
thatfiredev 8dc1a40
ci: remove -i parameter
thatfiredev 782010b
ci: output file
thatfiredev f76a395
Merge branch 'master' of github.com:firebase/quickstart-android into …
thatfiredev 851252f
ci: overwrite instead of append
thatfiredev 922c940
chore: agp 8.7.0
thatfiredev 85f1fb9
testing
thatfiredev a2e39b7
revert ci changes
thatfiredev d7fcb93
ci: add python script to remove fdc
thatfiredev d4249df
docs: update README.md
thatfiredev 83c7a3d
docs: remove deploy step
thatfiredev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,17 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
.dataconnect/ | ||
.firebaserc |
This file contains hidden or 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,73 @@ | ||
# Firebase Data Connect Quickstart | ||
|
||
## Introduction | ||
|
||
This quickstart is a movie review app to demonstrate the use of Firebase Data Connect | ||
with a Cloud SQL database. | ||
For more information about Firebase Data Connect visit [the docs](https://firebase.google.com/docs/data-connect/). | ||
|
||
## Getting Started | ||
|
||
Follow these steps to get up and running with Firebase Data Connect. For more detailed instructions, | ||
check out the [official documentation](https://firebase.google.com/docs/data-connect/quickstart). | ||
|
||
### 0. Prerequisites | ||
- Latest version of [Android Studio](https://developer.android.com/studio) | ||
- Latest version of [Visual Studio Code](https://code.visualstudio.com/) | ||
- The [Firebase Data Connect VS Code Extension](https://marketplace.visualstudio.com/items?itemName=GoogleCloudTools.firebase-dataconnect-vscode) | ||
|
||
### 1. Connect to your Firebase project | ||
|
||
1. If you haven't already, create a Firebase project. | ||
1. In the [Firebase console](https://console.firebase.google.com), click | ||
**Add project**, then follow the on-screen instructions. | ||
|
||
2. Upgrade your project to the Blaze plan. This lets you create a Cloud SQL | ||
for PostgreSQL instance. | ||
|
||
> Note: Though you set up billing in your Blaze upgrade, you won't be | ||
charged for usage of Firebase Data Connect or the | ||
[default Cloud SQL for PostgreSQL configuration](https://firebase.google.com/docs/data-connect/#pricing) | ||
during the preview. | ||
|
||
3. Navigate to the [Data Connect section](https://console.firebase.google.com/u/0/project/_/dataconnect) | ||
of the Firebase console, click on the "Get Started" button and follow the setup workflow: | ||
- Select a location for your Cloud SQL for PostgreSQL database (this sample uses `us-central1`). If you choose a different location, you'll also need to change the `quickstart-android/dataconnect/dataconnect/dataconnect.yaml` file. | ||
- Select the option to create a new Cloud SQL instance and fill in the following fields: | ||
- Service ID: `dataconnect` | ||
- Cloud SQL Instance ID: `fdc-sql` | ||
- Database name: `fdcdb` | ||
4. Allow some time for the Cloud SQL instance to be provisioned. After it's provisioned, the instance | ||
can be managed in the [Cloud Console](https://console.cloud.google.com/sql). | ||
|
||
5. If you haven’t already, add an Android app to your Firebase project, with the android package name `com.google.firebase.example.dataconnect`. | ||
Click **Download google-services.json** to obtain your Firebase Android config file. | ||
|
||
### 2. Cloning the repository | ||
|
||
1. Clone this repository to your local machine: | ||
```sh | ||
git clone https://github.com/firebase/quickstart-android.git | ||
``` | ||
|
||
2. Move the `google-services.json` config file (downloaded in the previous step) into the | ||
`quickstart-android/dataconnect/app/` directory. | ||
|
||
### 3. Open in Visual Studio Code (VS Code) | ||
|
||
1. Open the `quickstart-android/dataconnect` directory in VS Code. | ||
2. Click on the Firebase Data Connect icon on the VS Code sidebar to load the Extension. | ||
a. Sign in with your Google Account if you haven't already. | ||
3. Click on "Connect a Firebase project" and choose the project where you have set up Data Connect. | ||
4. Click on "Start Emulators" - this should generate the Kotlin SDK for you and start the emulators. | ||
|
||
### 4. Populate the database | ||
In VS Code, open the `quickstart-android/dataconnect/dataconnect/data_seed.gql` file and click the | ||
`Run (local)` button at the top of the file. | ||
|
||
If you’d like to confirm that the data was correctly inserted, | ||
open `quickstart-android/dataconnect/connectors/queries.gql` and run the `ListMovies` query. | ||
|
||
### 5. Running the app | ||
|
||
Press the Run button in Android Studio to run the sample app on your device. |
This file contains hidden or 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 hidden or 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,85 @@ | ||
plugins { | ||
alias(libs.plugins.android.application) | ||
alias(libs.plugins.jetbrains.kotlin.android) | ||
alias(libs.plugins.kotlin.serialization) | ||
alias(libs.plugins.google.services) | ||
alias(libs.plugins.compose.compiler) | ||
} | ||
|
||
android { | ||
namespace = "com.google.firebase.example.dataconnect" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "com.google.firebase.example.dataconnect" | ||
minSdk = 23 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary = true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
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 | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = "1.5.13" | ||
} | ||
packaging { | ||
resources { | ||
excludes += "/META-INF/{AL2.0,LGPL2.1}" | ||
} | ||
} | ||
sourceSets.getByName("main") { | ||
java.srcDirs("build/generated/sources") | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.androidx.core.ktx) | ||
implementation(libs.androidx.lifecycle.runtime.ktx) | ||
implementation(libs.androidx.lifecycle.viewmodel.compose) | ||
implementation(libs.androidx.activity.compose) | ||
implementation(platform(libs.androidx.compose.bom)) | ||
implementation(libs.androidx.ui) | ||
implementation(libs.androidx.ui.graphics) | ||
implementation(libs.androidx.ui.tooling.preview) | ||
implementation(libs.androidx.material3) | ||
implementation(libs.compose.navigation) | ||
implementation(libs.androidx.lifecycle.runtime.compose.android) | ||
implementation(libs.coil.compose) | ||
|
||
// Firebase dependencies | ||
implementation(libs.firebase.auth) | ||
implementation(libs.firebase.dataconnect) | ||
implementation(libs.kotlinx.serialization.core) | ||
|
||
testImplementation(libs.junit) | ||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
androidTestImplementation(platform(libs.androidx.compose.bom)) | ||
androidTestImplementation(libs.androidx.ui.test.junit4) | ||
debugImplementation(libs.androidx.ui.tooling) | ||
debugImplementation(libs.androidx.ui.test.manifest) | ||
} |
This file contains hidden or 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,21 @@ | ||
# 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 |
This file contains hidden or 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,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.FirebaseDataConnect" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.FirebaseDataConnect"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
135 changes: 135 additions & 0 deletions
135
dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/MainActivity.kt
This file contains hidden or 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,135 @@ | ||
package com.google.firebase.example.dataconnect | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.compose.foundation.layout.consumeWindowInsets | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Home | ||
import androidx.compose.material.icons.filled.Menu | ||
import androidx.compose.material.icons.filled.Person | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.NavigationBar | ||
import androidx.compose.material3.NavigationBarItem | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.navigation.NavDestination.Companion.hasRoute | ||
import androidx.navigation.NavDestination.Companion.hierarchy | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.currentBackStackEntryAsState | ||
import androidx.navigation.compose.rememberNavController | ||
import com.google.firebase.dataconnect.movies.MoviesConnector | ||
import com.google.firebase.dataconnect.movies.instance | ||
import com.google.firebase.example.dataconnect.feature.actordetail.ActorDetailRoute | ||
import com.google.firebase.example.dataconnect.feature.actordetail.ActorDetailScreen | ||
import com.google.firebase.example.dataconnect.feature.genredetail.GenreDetailRoute | ||
import com.google.firebase.example.dataconnect.feature.genredetail.GenreDetailScreen | ||
import com.google.firebase.example.dataconnect.feature.genres.GenresRoute | ||
import com.google.firebase.example.dataconnect.feature.genres.GenresScreen | ||
import com.google.firebase.example.dataconnect.feature.moviedetail.MovieDetailRoute | ||
import com.google.firebase.example.dataconnect.feature.moviedetail.MovieDetailScreen | ||
import com.google.firebase.example.dataconnect.feature.movies.MoviesRoute | ||
import com.google.firebase.example.dataconnect.feature.movies.MoviesScreen | ||
import com.google.firebase.example.dataconnect.feature.profile.ProfileRoute | ||
import com.google.firebase.example.dataconnect.feature.profile.ProfileScreen | ||
import com.google.firebase.example.dataconnect.feature.search.searchScreen | ||
import com.google.firebase.example.dataconnect.ui.theme.FirebaseDataConnectTheme | ||
|
||
data class TopLevelRoute<T : Any>(val labelResId: Int, val route: T, val icon: ImageVector) | ||
|
||
val TOP_LEVEL_ROUTES = listOf( | ||
TopLevelRoute(R.string.label_movies, MoviesRoute, Icons.Filled.Home), | ||
TopLevelRoute(R.string.label_genres, GenresRoute, Icons.Filled.Menu), | ||
TopLevelRoute(R.string.label_profile, ProfileRoute, Icons.Filled.Person) | ||
) | ||
|
||
class MainActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enableEdgeToEdge() | ||
// Comment the line below to use a production environment instead | ||
MoviesConnector.instance.dataConnect.useEmulator("10.0.2.2", 9399) | ||
setContent { | ||
FirebaseDataConnectTheme { | ||
val navController = rememberNavController() | ||
Scaffold( | ||
modifier = Modifier.fillMaxSize(), | ||
bottomBar = { | ||
NavigationBar { | ||
val navBackStackEntry by navController.currentBackStackEntryAsState() | ||
val currentDestination = navBackStackEntry?.destination | ||
|
||
TOP_LEVEL_ROUTES.forEach { topLevelRoute -> | ||
val label = stringResource(topLevelRoute.labelResId) | ||
NavigationBarItem( | ||
icon = { Icon(topLevelRoute.icon, contentDescription = label) }, | ||
label = { Text(label) }, | ||
selected = currentDestination?.hierarchy?.any { | ||
it.hasRoute(topLevelRoute.route::class) | ||
} == true, | ||
onClick = { | ||
navController.navigate( | ||
topLevelRoute.route, | ||
{ launchSingleTop = true } | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
) { innerPadding -> | ||
NavHost( | ||
navController, | ||
startDestination = MoviesRoute, | ||
Modifier | ||
.padding(innerPadding) | ||
.consumeWindowInsets(innerPadding), | ||
) { | ||
composable<MoviesRoute>() { | ||
MoviesScreen( | ||
onMovieClicked = { movieId -> | ||
navController.navigate( | ||
route = MovieDetailRoute(movieId), | ||
builder = { | ||
launchSingleTop = true | ||
} | ||
) | ||
} | ||
) | ||
} | ||
composable<MovieDetailRoute> { | ||
MovieDetailScreen( | ||
onActorClicked = { actorId -> | ||
navController.navigate( | ||
ActorDetailRoute(actorId), | ||
{ launchSingleTop = true } | ||
) | ||
} | ||
) | ||
} | ||
composable<ActorDetailRoute>() { ActorDetailScreen() } | ||
composable<GenresRoute> { | ||
GenresScreen(onGenreClicked = { genre -> | ||
navController.navigate( | ||
GenreDetailRoute(genre), | ||
{ launchSingleTop = true } | ||
) | ||
}) | ||
} | ||
composable<GenreDetailRoute> { GenreDetailScreen() } | ||
searchScreen() | ||
composable<ProfileRoute> { ProfileScreen() } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.