Skip to content

Commit 14db8be

Browse files
committed
Update docs, add kotlin
1 parent ae71df9 commit 14db8be

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

.opensource/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"content": "docs/README.md",
88
"pages": {
99
"README.md": "Development Guide",
10+
"docs/ktx/common.md": "Common KTX",
1011
"docs/ktx/firestore.md": "Firestore KTX"
1112
},
1213
"related": [

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The following Firebase SDKs for Android have Kotlin extension libraries
2424
that allow you to write more idiomatic Kotlin code when using Firebase
2525
in your app:
2626

27+
* [`firebase-common`](./ktx/common.md)
2728
* [`firebase-firestore`](./ktx/firestore.md)
2829

2930
[android-setup]: https://firebase.google.com/docs/android/setup

docs/ktx/common.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Firebase Common Kotlin Extensions
2+
3+
## Getting Started
4+
5+
To use the Firebase Common Android SDK with Kotlin Extenstions, add the following
6+
to your app's `build.gradle` file:
7+
8+
```groovy
9+
// See maven.google.com for the latest versions
10+
// This library transitively includes the firebase-common library
11+
implementation 'com.google.firebase:firebase-common-ktx:$VERSION'
12+
```
13+
14+
## Features
15+
16+
### Get the default FirebaseApp and FirebaseOptions
17+
18+
**Kotlin**
19+
```kotlin
20+
val defaultApp = FirebaseApp.getInstance()
21+
val defaultOptions = defaultApp.options
22+
```
23+
24+
**Kotlin + KTX**
25+
```kotlin
26+
val defaultApp = Firebase.app
27+
val defaultOptions = Firebase.options
28+
```
29+
30+
### Initialize a FirebaseApp
31+
32+
**Kotlin**
33+
```kotlin
34+
val options = FirebaseApp.getInstance().options
35+
val anotherApp = FirebaseApp.initializeApp(context, options, "myApp")
36+
```
37+
38+
**Kotlin + KTX**
39+
```kotlin
40+
var anotherApp = Firebase.initialize(context, Firebase.options, "myApp")
41+
```
42+

docs/ktx/firestore.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,39 @@ To use the Cloud Firestore Android SDK with Kotlin Extenstions, add the followin
66
to your app's `build.gradle` file:
77

88
```groovy
9-
// This library transitively includes the Firestore Android SDK
10-
implementation 'com.google.firebase:firebase-firestore-ktx:18.1.0
9+
// See maven.google.com for the latest versions
10+
// This library transitively includes the firebase-firestore library
11+
implementation 'com.google.firebase:firebase-firestore-ktx:$VERSION'
1112
```
1213

1314
## Features
1415

15-
### Convert a DocumentSnapshot field to a POJO
16+
### Get an instance of FirebaseFirestore
1617

1718
**Kotlin**
1819
```kotlin
19-
val snapshot: DocumentSnapshot = ...
20-
val myObject = snapshot.get("fieldPath", MyClass::class.java)
20+
val firestore = FirebaseFirestore.getInstance()
21+
val anotherFirestore = FirebaseFirestore.getInstance(FirebaseApp.getInstance("myApp"))
2122
```
2223

2324
**Kotlin + KTX**
2425
```kotlin
25-
val snapshot: DocumentSnapshot = ...
26-
val myObject = snapshot.get<MyClass>("fieldPath")
26+
val firestore = Firebase.firestore
27+
val anotherFirestore = Firebase.firestore(Firebase.app("myApp"))
2728
```
2829

29-
### Get an instance of FirebaseFirestore
30+
### Convert a DocumentSnapshot field to a POJO
3031

3132
**Kotlin**
3233
```kotlin
33-
val firestore = FirebaseFirestore.getInstance()
34+
val snapshot: DocumentSnapshot = ...
35+
val myObject = snapshot.get("fieldPath", MyClass::class.java)
3436
```
3537

3638
**Kotlin + KTX**
3739
```kotlin
38-
val firestore = Firebase.firestore
40+
val snapshot: DocumentSnapshot = ...
41+
val myObject = snapshot.get<MyClass>("fieldPath")
3942
```
4043

4144
### Convert a DocumentSnapshot to a POJO

0 commit comments

Comments
 (0)