Skip to content

Commit 020d6f4

Browse files
authored
Restructure docs for KTX (#314)
1 parent ca101e1 commit 020d6f4

File tree

4 files changed

+158
-6
lines changed

4 files changed

+158
-6
lines changed

.opensource/project.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
"platforms": [
55
"Android"
66
],
7-
"content": "README.md",
8-
"pages": [
9-
"firebase-common/README.md",
10-
"firebase-firestore/README.md",
11-
"protolite-well-known-types/README.md"
12-
],
7+
"content": "docs/README.md",
8+
"pages": {
9+
"README.md": "Development Guide",
10+
"docs/ktx/common.md": "Common KTX",
11+
"docs/ktx/firestore.md": "Firestore KTX"
12+
},
1313
"related": [
1414
"firebase/quickstart-android"
15+
],
16+
"tabs": [
17+
{
18+
"title": "Main Reference",
19+
"href": "https://firebase.google.com/docs/reference/android/"
20+
},
21+
{
22+
"title": "KTX Reference",
23+
"href": "https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/"
24+
}
1525
]
1626
}

docs/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Firebase Android SDK
2+
3+
The Firebase SDK for Android is the official way to add Firebase to your
4+
Android app. To get started, visit the [setup instructions][android-setup].
5+
6+
## Open Source
7+
8+
This repository includes the following Firebase SDKs for Android:
9+
10+
* `firebase-common`
11+
* `firebase-database`
12+
* `firebase-firestore`
13+
* `firebase-functions`
14+
* `firebase-inappmessaging-display`
15+
* `firebase-storage`
16+
17+
For more information on building the SDKs from source or contributing,
18+
visit the [main README][main-readme].
19+
20+
## Kotlin Extensions
21+
22+
The following Firebase SDKs for Android have Kotlin extension libraries
23+
that allow you to write more idiomatic Kotlin code when using Firebase
24+
in your app:
25+
26+
* [`firebase-common`](./ktx/common.md)
27+
* [`firebase-firestore`](./ktx/firestore.md)
28+
29+
[android-setup]: https://firebase.google.com/docs/android/setup
30+
[main-readme]: https://github.com/firebase/firebase-android-sdk/blob/master/README.md

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 Extensions, 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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Firestore Kotlin Extensions
2+
3+
## Getting Started
4+
5+
To use the Cloud Firestore Android SDK with Kotlin Extensions, 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-firestore library
11+
implementation 'com.google.firebase:firebase-firestore-ktx:$VERSION'
12+
```
13+
14+
## Features
15+
16+
### Get an instance of FirebaseFirestore
17+
18+
**Kotlin**
19+
```kotlin
20+
val firestore = FirebaseFirestore.getInstance()
21+
val anotherFirestore = FirebaseFirestore.getInstance(FirebaseApp.getInstance("myApp"))
22+
```
23+
24+
**Kotlin + KTX**
25+
```kotlin
26+
val firestore = Firebase.firestore
27+
val anotherFirestore = Firebase.firestore(Firebase.app("myApp"))
28+
```
29+
30+
### Convert a DocumentSnapshot field to a POJO
31+
32+
**Kotlin**
33+
```kotlin
34+
val snapshot: DocumentSnapshot = ...
35+
val myObject = snapshot.get("fieldPath", MyClass::class.java)
36+
```
37+
38+
**Kotlin + KTX**
39+
```kotlin
40+
val snapshot: DocumentSnapshot = ...
41+
val myObject = snapshot.get<MyClass>("fieldPath")
42+
```
43+
44+
### Convert a DocumentSnapshot to a POJO
45+
46+
**Kotlin**
47+
```kotlin
48+
val snapshot: DocumentSnapshot = ...
49+
val myObject = snapshot.toObject(MyClass::class.java)
50+
```
51+
52+
**Kotlin + KTX**
53+
```kotlin
54+
val snapshot: DocumentSnapshot = ...
55+
val myObject = snapshot.toObject<MyClass>()
56+
```
57+
58+
### Convert a QuerySnapshot to a list of POJOs
59+
60+
**Kotlin**
61+
```kotlin
62+
val snapshot: QuerySnapshot = ...
63+
val objectList = snapshot.toObjects(MyClass::class.java)
64+
```
65+
66+
**Kotlin + KTX**
67+
```kotlin
68+
val snapshot: QuerySnapshot = ...
69+
val objectList = snapshot.toObjects<MyClass>()
70+
```

0 commit comments

Comments
 (0)