Skip to content

Restructure docs for KTX #314

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 4 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .opensource/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@
"platforms": [
"Android"
],
"content": "README.md",
"pages": [
"firebase-common/README.md",
"firebase-firestore/README.md",
"protolite-well-known-types/README.md"
],
"content": "docs/README.md",
"pages": {
"README.md": "Development Guide",
"docs/ktx/common.md": "Common KTX",
"docs/ktx/firestore.md": "Firestore KTX"
},
"related": [
"firebase/quickstart-android"
],
"tabs": [
{
"title": "Main Reference",
"href": "https://firebase.google.com/docs/reference/android/"
},
{
"title": "KTX Reference",
"href": "https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/"
}
]
}
30 changes: 30 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Firebase Android SDK

The Firebase SDK for Android is the official way to add Firebase to your
Android app. To get started, visit the [setup instructions][android-setup].

## Open Source

This repository includes the following Firebase SDKs for Android:

* `firebase-common`
* `firebase-database`
* `firebase-firestore`
* `firebase-functions`
* `firebase-inappmessaging-display`
* `firebase-storage`

For more information on building the SDKs from source or contributing,
visit the [main README][main-readme].

## Kotlin Extensions

The following Firebase SDKs for Android have Kotlin extension libraries
that allow you to write more idiomatic Kotlin code when using Firebase
in your app:

* [`firebase-common`](./ktx/common.md)
* [`firebase-firestore`](./ktx/firestore.md)

[android-setup]: https://firebase.google.com/docs/android/setup
[main-readme]: https://github.com/firebase/firebase-android-sdk/blob/master/README.md
42 changes: 42 additions & 0 deletions docs/ktx/common.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Firebase Common Kotlin Extensions

## Getting Started

To use the Firebase Common Android SDK with Kotlin Extensions, add the following
to your app's `build.gradle` file:

```groovy
// See maven.google.com for the latest versions
// This library transitively includes the firebase-common library
implementation 'com.google.firebase:firebase-common-ktx:$VERSION'
```

## Features

### Get the default FirebaseApp and FirebaseOptions

**Kotlin**
```kotlin
val defaultApp = FirebaseApp.getInstance()
val defaultOptions = defaultApp.options
```

**Kotlin + KTX**
```kotlin
val defaultApp = Firebase.app
val defaultOptions = Firebase.options
```

### Initialize a FirebaseApp

**Kotlin**
```kotlin
val options = FirebaseApp.getInstance().options
val anotherApp = FirebaseApp.initializeApp(context, options, "myApp")
```

**Kotlin + KTX**
```kotlin
var anotherApp = Firebase.initialize(context, Firebase.options, "myApp")
```

70 changes: 70 additions & 0 deletions docs/ktx/firestore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Firestore Kotlin Extensions

## Getting Started

To use the Cloud Firestore Android SDK with Kotlin Extensions, add the following
to your app's `build.gradle` file:

```groovy
// See maven.google.com for the latest versions
// This library transitively includes the firebase-firestore library
implementation 'com.google.firebase:firebase-firestore-ktx:$VERSION'
```

## Features

### Get an instance of FirebaseFirestore

**Kotlin**
```kotlin
val firestore = FirebaseFirestore.getInstance()
val anotherFirestore = FirebaseFirestore.getInstance(FirebaseApp.getInstance("myApp"))
```

**Kotlin + KTX**
```kotlin
val firestore = Firebase.firestore
val anotherFirestore = Firebase.firestore(Firebase.app("myApp"))
```

### Convert a DocumentSnapshot field to a POJO

**Kotlin**
```kotlin
val snapshot: DocumentSnapshot = ...
val myObject = snapshot.get("fieldPath", MyClass::class.java)
```

**Kotlin + KTX**
```kotlin
val snapshot: DocumentSnapshot = ...
val myObject = snapshot.get<MyClass>("fieldPath")
```

### Convert a DocumentSnapshot to a POJO

**Kotlin**
```kotlin
val snapshot: DocumentSnapshot = ...
val myObject = snapshot.toObject(MyClass::class.java)
```

**Kotlin + KTX**
```kotlin
val snapshot: DocumentSnapshot = ...
val myObject = snapshot.toObject<MyClass>()
```

### Convert a QuerySnapshot to a list of POJOs

**Kotlin**
```kotlin
val snapshot: QuerySnapshot = ...
val objectList = snapshot.toObjects(MyClass::class.java)
```

**Kotlin + KTX**
```kotlin
val snapshot: QuerySnapshot = ...
val objectList = snapshot.toObjects<MyClass>()
```