Skip to content

Commit 44dccbf

Browse files
authored
refactor(dataconnect): update schema to match quickstart-js (#1678)
* refactor: use the latest schema from quickstart-js * refactor: connectors -> movie-connector * docs: update README.md * refactor: rating is an Int after all :) * add empty lines at the end of the files
1 parent 68d41be commit 44dccbf

28 files changed

+1212
-1661
lines changed

dataconnect/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ check out the [official documentation](https://firebase.google.com/docs/data-con
6262
4. Click on "Start Emulators" - this should generate the Kotlin SDK for you and start the emulators.
6363

6464
### 4. Populate the database
65-
In VS Code, open the `quickstart-android/dataconnect/dataconnect/data_seed.gql` file and click the
65+
In VS Code, open the `quickstart-android/dataconnect/dataconnect/moviedata_insert.gql` file and click the
6666
`Run (local)` button at the top of the file.
6767

6868
If you’d like to confirm that the data was correctly inserted,
69-
open `quickstart-android/dataconnect/connectors/queries.gql` and run the `ListMovies` query.
69+
open `quickstart-android/dataconnect/movie-connector/queries.gql` and run the `ListMovies` query.
7070

7171
### 5. Running the app
7272

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/MainActivity.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.fillMaxSize
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.material.icons.Icons
1111
import androidx.compose.material.icons.filled.Home
12-
import androidx.compose.material.icons.filled.Menu
1312
import androidx.compose.material.icons.filled.Person
1413
import androidx.compose.material3.Icon
1514
import androidx.compose.material3.NavigationBar
@@ -30,10 +29,6 @@ import com.google.firebase.dataconnect.movies.MoviesConnector
3029
import com.google.firebase.dataconnect.movies.instance
3130
import com.google.firebase.example.dataconnect.feature.actordetail.ActorDetailRoute
3231
import com.google.firebase.example.dataconnect.feature.actordetail.ActorDetailScreen
33-
import com.google.firebase.example.dataconnect.feature.genredetail.GenreDetailRoute
34-
import com.google.firebase.example.dataconnect.feature.genredetail.GenreDetailScreen
35-
import com.google.firebase.example.dataconnect.feature.genres.GenresRoute
36-
import com.google.firebase.example.dataconnect.feature.genres.GenresScreen
3732
import com.google.firebase.example.dataconnect.feature.moviedetail.MovieDetailRoute
3833
import com.google.firebase.example.dataconnect.feature.moviedetail.MovieDetailScreen
3934
import com.google.firebase.example.dataconnect.feature.movies.MoviesRoute
@@ -47,7 +42,6 @@ data class TopLevelRoute<T : Any>(val labelResId: Int, val route: T, val icon: I
4742

4843
val TOP_LEVEL_ROUTES = listOf(
4944
TopLevelRoute(R.string.label_movies, MoviesRoute, Icons.Filled.Home),
50-
TopLevelRoute(R.string.label_genres, GenresRoute, Icons.Filled.Menu),
5145
TopLevelRoute(R.string.label_profile, ProfileRoute, Icons.Filled.Person)
5246
)
5347

@@ -116,15 +110,6 @@ class MainActivity : ComponentActivity() {
116110
)
117111
}
118112
composable<ActorDetailRoute>() { ActorDetailScreen() }
119-
composable<GenresRoute> {
120-
GenresScreen(onGenreClicked = { genre ->
121-
navController.navigate(
122-
GenreDetailRoute(genre),
123-
{ launchSingleTop = true }
124-
)
125-
})
126-
}
127-
composable<GenreDetailRoute> { GenreDetailScreen() }
128113
searchScreen()
129114
composable<ProfileRoute> { ProfileScreen() }
130115
}

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/feature/actordetail/ActorDetailScreen.kt

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.layout.width
1111
import androidx.compose.foundation.rememberScrollState
1212
import androidx.compose.foundation.verticalScroll
13-
import androidx.compose.material.icons.Icons
14-
import androidx.compose.material.icons.filled.Favorite
15-
import androidx.compose.material.icons.outlined.FavoriteBorder
1613
import androidx.compose.material3.MaterialTheme
1714
import androidx.compose.material3.Scaffold
1815
import androidx.compose.material3.Text
@@ -31,7 +28,6 @@ import com.google.firebase.example.dataconnect.ui.components.ErrorCard
3128
import com.google.firebase.example.dataconnect.ui.components.LoadingScreen
3229
import com.google.firebase.example.dataconnect.ui.components.Movie
3330
import com.google.firebase.example.dataconnect.ui.components.MoviesList
34-
import com.google.firebase.example.dataconnect.ui.components.ToggleButton
3531
import kotlinx.serialization.Serializable
3632

3733

@@ -47,18 +43,14 @@ fun ActorDetailScreen(
4743
uiState = uiState,
4844
onMovieClicked = {
4945
// TODO
50-
},
51-
onFavoriteToggled = {
52-
actorDetailViewModel.toggleFavorite(it)
5346
}
5447
)
5548
}
5649

5750
@Composable
5851
fun ActorDetailScreen(
5952
uiState: ActorDetailUIState,
60-
onMovieClicked: (actorId: String) -> Unit,
61-
onFavoriteToggled: (newValue: Boolean) -> Unit
53+
onMovieClicked: (actorId: String) -> Unit
6254
) {
6355
when (uiState) {
6456
is ActorDetailUIState.Error -> ErrorCard(uiState.errorMessage)
@@ -75,8 +67,6 @@ fun ActorDetailScreen(
7567
) {
7668
ActorInformation(
7769
actor = uiState.actor,
78-
isActorFavorite = uiState.isFavorite,
79-
onFavoriteToggled = onFavoriteToggled
8070
)
8171
MoviesList(
8272
listTitle = stringResource(R.string.title_main_roles),
@@ -103,9 +93,7 @@ fun ActorDetailScreen(
10393
@Composable
10494
fun ActorInformation(
10595
modifier: Modifier = Modifier,
106-
actor: GetActorByIdQuery.Data.Actor?,
107-
isActorFavorite: Boolean,
108-
onFavoriteToggled: (newValue: Boolean) -> Unit
96+
actor: GetActorByIdQuery.Data.Actor?
10997
) {
11098
if (actor == null) {
11199
ErrorCard(stringResource(R.string.error_actor_not_found))
@@ -128,22 +116,14 @@ fun ActorInformation(
128116
.aspectRatio(9f / 16f)
129117
.padding(vertical = 8.dp)
130118
)
119+
// TODO(thatfiredev): Remove biography
131120
Text(
132-
text = actor.biography ?: stringResource(R.string.biography_not_available),
121+
text = stringResource(R.string.biography_not_available),
133122
modifier = Modifier
134123
.padding(horizontal = 16.dp)
135124
.fillMaxWidth()
136125
)
137126
}
138-
Spacer(modifier = Modifier.height(8.dp))
139-
ToggleButton(
140-
iconEnabled = Icons.Filled.Favorite,
141-
iconDisabled = Icons.Outlined.FavoriteBorder,
142-
textEnabled = stringResource(R.string.button_remove_favorite),
143-
textDisabled = stringResource(R.string.button_favorite),
144-
isEnabled = isActorFavorite,
145-
onToggle = onFavoriteToggled
146-
)
147127
}
148128
}
149129
}

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/feature/actordetail/ActorDetailUIState.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ sealed class ActorDetailUIState {
1313
// Actor is null if it can't be found on the DB
1414
val actor: GetActorByIdQuery.Data.Actor?,
1515
val isUserSignedIn: Boolean = false,
16-
var isFavorite: Boolean = false
1716
) : ActorDetailUIState()
1817
}

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/feature/actordetail/ActorDetailViewModel.kt

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,10 @@ class ActorDetailViewModel(
4040
id = UUID.fromString(actorId)
4141
).data.actor
4242

43-
_uiState.value = if (user == null) {
44-
ActorDetailUIState.Success(actor, isUserSignedIn = false)
45-
} else {
46-
val favoriteActor = moviesConnector.getIfFavoritedActor.execute(
47-
id = user.uid,
48-
actorId = UUID.fromString(actorId)
49-
).data.favoriteActor
50-
51-
val isFavorite = favoriteActor != null
52-
53-
ActorDetailUIState.Success(
54-
actor,
55-
isUserSignedIn = true,
56-
isFavorite = isFavorite
57-
)
58-
}
59-
} catch (e: Exception) {
60-
_uiState.value = ActorDetailUIState.Error(e.message)
61-
}
62-
}
63-
}
64-
65-
fun toggleFavorite(newValue: Boolean) {
66-
// TODO(thatfiredev): hide the button if there's no user logged in
67-
val uid = firebaseAuth.currentUser?.uid ?: return
68-
viewModelScope.launch {
69-
try {
70-
if (newValue) {
71-
moviesConnector.addFavoritedActor.execute(UUID.fromString(actorId))
72-
} else {
73-
moviesConnector.deleteFavoriteActor.execute(
74-
userId = uid,
75-
actorId = UUID.fromString(actorId)
76-
)
77-
}
78-
// Re-run the query to fetch the actor details
79-
fetchActor()
43+
_uiState.value = ActorDetailUIState.Success(
44+
actor = actor,
45+
isUserSignedIn = user != null
46+
)
8047
} catch (e: Exception) {
8148
_uiState.value = ActorDetailUIState.Error(e.message)
8249
}

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/feature/genredetail/GenreDetailScreen.kt

Lines changed: 0 additions & 76 deletions
This file was deleted.

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/feature/genredetail/GenreDetailUIState.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/feature/genredetail/GenreDetailViewModel.kt

Lines changed: 0 additions & 44 deletions
This file was deleted.

dataconnect/app/src/main/java/com/google/firebase/example/dataconnect/feature/genres/GenresScreen.kt

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)