Skip to content

Commit 3394dfe

Browse files
authored
Update docs, update dependency versions (firebase#1635)
1 parent e5a6286 commit 3394dfe

File tree

6 files changed

+205
-47
lines changed

6 files changed

+205
-47
lines changed

README.md

+3-35
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ A compatible FirebaseUI client is also available for [iOS](https://github.com/fi
1616
1. [Installation](#installation)
1717
1. [Upgrading](#upgrading)
1818
1. [Dependencies](#dependencies)
19-
1. [Compatability](#compatibility-with-firebase--google-play-services-libraries)
19+
1. [Compatibility](#compatibility-with-firebase--google-play-services-libraries)
2020
1. [Upgrading dependencies](#upgrading-dependencies)
2121
1. [Sample App](#sample-app)
2222
1. [Snapshot Builds](#snapshot-builds)
2323
1. [Contributing](#contributing)
2424
1. [Installing](#installing-locally)
25-
1. [Deploying](#deployment)
26-
1. [Tagging](#tag-a-release-on-github)
2725
1. [License agreements](#contributor-license-agreements)
2826
1. [Process](#contribution-process)
2927

@@ -76,6 +74,7 @@ After the project is synchronized, we're ready to start using Firebase functiona
7674
If you are using an old version of FirebaseUI and upgrading, please see the appropriate
7775
migration guide:
7876

77+
* [Upgrade from 4.3.2 to 5.x.x](./docs/upgrade-to-5.0.md)
7978
* [Upgrade from 3.3.1 to 4.x.x](./docs/upgrade-to-4.0.md)
8079
* [Upgrade from 2.3.0 to 3.x.x](./docs/upgrade-to-3.0.md)
8180
* [Upgrade from 1.2.0 to 2.x.x](./docs/upgrade-to-2.0.md)
@@ -149,22 +148,6 @@ implementation "com.android.support:appcompat-v7:$BAR"
149148
implementation "com.android.support:palette-v7:$BAR"
150149
```
151150

152-
#### Note
153-
154-
Starting version 25.4.0, support libraries are now available through
155-
[Google's Maven repository](https://developer.android.com/studio/build/dependencies.html#google-maven),
156-
so ensure that you have that added to your project's repositories.
157-
158-
Open the `build.gradle` file for your project and modify it as following,
159-
160-
```
161-
allprojects {
162-
repositories {
163-
google()
164-
jcenter()
165-
}
166-
}
167-
```
168151

169152
## Sample app
170153

@@ -194,7 +177,7 @@ from external model`.
194177

195178
## Snapshot builds
196179

197-
Like to live on the cutting edge? Want to try the next release of FirebaseUI before anyone else? As of version `3.2.2`
180+
Like to live on the cutting edge? Want to try the next release of FirebaseUI before anyone else?
198181
FirebaseUI hosts "snapshot" builds on oss.jfrog.org.
199182

200183
Just add the following to your `build.gradle`:
@@ -229,21 +212,6 @@ repository and running:
229212
./gradlew :library:prepareArtifacts :library:publishAllToMavenLocal
230213
```
231214

232-
### Deployment
233-
234-
To deploy FirebaseUI to Bintray
235-
236-
1. Set `BINTRAY_USER` and `BINTRAY_KEY` in your environment. You must
237-
be a member of the firebaseui Bintray organization.
238-
1. Run `./gradlew clean :library:prepareArtifacts :library:bintrayUploadAll`
239-
1. Go to the Bintray dashboard and click 'Publish'.
240-
1. In Bintray click the 'Maven Central' tab and publish the release.
241-
242-
### Tag a release on GitHub
243-
244-
* Ensure that all your changes are on master and that your local build is on master
245-
* Ensure that the correct version number is in `common/constants.gradle`
246-
247215
### Contributor License Agreements
248216

249217
We'd love to accept your sample apps and patches! Before we can take them, we

auth/src/test/java/com/firebase/ui/auth/testhelpers/FakeAuthResult.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.os.Parcel;
1818

1919
import com.google.firebase.auth.AdditionalUserInfo;
20+
import com.google.firebase.auth.AuthCredential;
2021
import com.google.firebase.auth.AuthResult;
2122
import com.google.firebase.auth.FirebaseUser;
2223

@@ -45,6 +46,11 @@ public AdditionalUserInfo getAdditionalUserInfo() {
4546
return FakeAdditionalUserInfo.INSTANCE;
4647
}
4748

49+
@Override
50+
public AuthCredential getCredential() {
51+
throw new IllegalStateException("FakeAuthResult has no Credential!");
52+
}
53+
4854
@Override
4955
public int describeContents() {
5056
return 0;

buildSrc/src/main/kotlin/Config.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ object Config {
5252
}
5353

5454
object Firebase {
55-
const val core = "com.google.firebase:firebase-core:16.0.6"
56-
const val auth = "com.google.firebase:firebase-auth:16.1.0"
57-
const val firestore = "com.google.firebase:firebase-firestore:17.1.4"
58-
const val database = "com.google.firebase:firebase-database:16.0.5"
59-
const val storage = "com.google.firebase:firebase-storage:16.0.5"
55+
const val core = "com.google.firebase:firebase-core:16.0.9"
56+
const val auth = "com.google.firebase:firebase-auth:17.0.0"
57+
const val firestore = "com.google.firebase:firebase-firestore:19.0.0"
58+
const val database = "com.google.firebase:firebase-database:17.0.0"
59+
const val storage = "com.google.firebase:firebase-storage:17.0.0"
6060
}
6161

6262
object PlayServices {

database/README.md

+167-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ Before using this library, you should be familiar with the following topics:
1212
1. [Data model](#data-model)
1313
1. [Querying](#querying)
1414
1. [Populating a RecyclerView](#using-firebaseui-to-populate-a-recyclerview)
15-
1. [Using the adapter](#using-the-firebaserecycleradapter)
16-
1. [Adapter lifecyle](#firebaserecycleradapter-lifecycle)
17-
1. [Events](#data-and-error-events)
15+
1. [Using the FirebaseRecyclerAdapter](#using-the-firebaserecycleradapter)
16+
1. [Using the FirebaseRecyclerPagingAdapter](#using-the-firebaserecyclerpagingadapter)
1817
1. [Populating a ListView](#using-firebaseui-to-populate-a-listview)
1918
1. [Handling indexed data](#using-firebaseui-with-indexed-data)
2019
1. [Warnings](#a-note-on-ordering)
@@ -115,6 +114,17 @@ This means implementing a custom `RecyclerView.Adapter` and coordinating updates
115114

116115
Fear not, FirebaseUI does all of this for you automatically!
117116

117+
### Choosing an adapter
118+
119+
FirebaseUI offers two types of RecyclerView adapters for the Realtime Database:
120+
121+
* `FirebaseRecyclerAdapter` — binds a `Query` to a `RecyclerView` and responds to all real-time
122+
events included items being added, removed, moved, or changed. Best used with small result sets
123+
since all results are loaded at once.
124+
* `FirebasePagingRecyclerAdapter` — binds a `Query` to a `RecyclerView` by loading data in pages. Best
125+
used with large, static data sets. Real-time events are not respected by this adapter, so it
126+
will not detect new/removed items or changes to items already loaded.
127+
118128
### Using the FirebaseRecyclerAdapter
119129

120130
The `FirebaseRecyclerAdapter` binds a `Query` to a `RecyclerView`. When data is added, removed,
@@ -169,9 +179,9 @@ Finally attach the adapter to your `RecyclerView` with the `RecyclerView#setAdap
169179
Don't forget to also set a `LayoutManager`!
170180

171181

172-
### FirebaseRecyclerAdapter lifecycle
182+
#### FirebaseRecyclerAdapter lifecycle
173183

174-
#### Start/stop listening
184+
##### Start/stop listening
175185

176186
The `FirebaseRecyclerAdapter` uses an event listener to monitor changes to the Firebase query.
177187
To begin listening for data, call the `startListening()` method. You may want to call this in your
@@ -197,15 +207,15 @@ protected void onStop() {
197207
}
198208
```
199209

200-
#### Automatic listening
210+
##### Automatic listening
201211

202212
If you don't want to manually start/stop listening you can use
203213
[Android Architecture Components][arch-components] to automatically manage the lifecycle of the
204214
`FirebaseRecyclerAdapter`. Pass a `LifecycleOwner` to
205215
`FirebaseRecyclerOptions.Builder#setLifecycleOwner(...)` and FirebaseUI will automatically
206216
start and stop listening in `onStart()` and `onStop()`.
207217

208-
### Data and error events
218+
#### Data and error events
209219

210220
When using the `FirebaseRecyclerAdapter` you may want to perform some action every time data
211221
changes or when there is an error. To do this, override the `onDataChanged()` and `onError()`
@@ -231,6 +241,156 @@ FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(
231241
};
232242
```
233243

244+
### Using the `FirebaseRecyclerPagingAdapter`
245+
246+
The `FirebaseRecyclerPagingAdapter` binds a `Query` to a `RecyclerView` by loading documents in pages.
247+
This results in a time and memory efficient binding, however it gives up the real-time events
248+
afforted by the `FirestoreRecyclerAdapter`.
249+
250+
The `FirebaseRecyclerPagingAdapter` is built on top of the [Android Paging Support Library][paging-support].
251+
Before using the adapter in your application, you must add a dependency on the support library:
252+
253+
```groovy
254+
implementation 'android.arch.paging:runtime:1.x.x'
255+
```
256+
257+
First, configure the adapter by building `DatabasePagingOptions`. Since the paging adapter
258+
is not appropriate for a chat application (it would not detect new messages), we will consider
259+
an adapter that loads a generic `Item`:
260+
261+
```java
262+
// The "base query" is a query with no startAt/endAt/limit clauses that the adapter can use
263+
// to form smaller queries for each page.
264+
Query baseQuery = mDatabase.getReference().child("items");
265+
266+
// This configuration comes from the Paging Support Library
267+
// https://developer.android.com/reference/android/arch/paging/PagedList.Config.html
268+
PagedList.Config config = new PagedList.Config.Builder()
269+
.setEnablePlaceholders(false)
270+
.setPrefetchDistance(10)
271+
.setPageSize(20)
272+
.build();
273+
274+
// The options for the adapter combine the paging configuration with query information
275+
// and application-specific options for lifecycle, etc.
276+
DatabasePagingOptions<Item> options = new DatabasePagingOptions.Builder<Item>()
277+
.setLifecycleOwner(this)
278+
.setQuery(baseQuery, config, Item.class)
279+
.build();
280+
```
281+
282+
If you need to customize how your model class is parsed, you can use a custom `SnapshotParser`:
283+
284+
```java
285+
...setQuery(..., new SnapshotParser<Item>() {
286+
@NonNull
287+
@Override
288+
public Item parseSnapshot(@NonNull DocumentSnapshot snapshot) {
289+
return ...;
290+
}
291+
});
292+
```
293+
294+
Next, create the `FirebaseRecyclerPagingAdapter` object. You should already have a `ViewHolder` subclass
295+
for displaying each item. In this case we will use a custom `ItemViewHolder` class:
296+
297+
```java
298+
FirebaseRecyclerPagingAdapter<Item, ItemViewHolder> adapter =
299+
new FirebaseRecyclerPagingAdapter<Item, ItemViewHolder>(options) {
300+
@NonNull
301+
@Override
302+
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
303+
// Create the ItemViewHolder
304+
// ...
305+
}
306+
307+
@Override
308+
protected void onBindViewHolder(@NonNull ItemViewHolder holder,
309+
int position,
310+
@NonNull Item model) {
311+
// Bind the item to the view holder
312+
// ...
313+
}
314+
};
315+
```
316+
317+
Finally attach the adapter to your `RecyclerView` with the `RecyclerView#setAdapter()` method.
318+
Don't forget to also set a `LayoutManager`!
319+
320+
#### `FirebaseRecyclerPagingAdapter` lifecycle
321+
322+
##### Start/stop listening
323+
324+
The `FirebaseRecyclerPagingAdapter` listens for scrolling events and loads additional pages from the
325+
database only when needed.
326+
327+
To begin populating data, call the `startListening()` method. You may want to call this
328+
in your `onStart()` method. Make sure you have finished any authentication necessary to read the
329+
data before calling `startListening()` or your query will fail.
330+
331+
```java
332+
@Override
333+
protected void onStart() {
334+
super.onStart();
335+
adapter.startListening();
336+
}
337+
```
338+
339+
Similarly, the `stopListening()` call freezes the data in the `RecyclerView` and prevents any future
340+
loading of data pages.
341+
342+
Call this method when the containing Activity or Fragment stops:
343+
344+
```java
345+
@Override
346+
protected void onStop() {
347+
super.onStop();
348+
adapter.stopListening();
349+
}
350+
```
351+
352+
##### Automatic listening
353+
354+
If you don't want to manually start/stop listening you can use
355+
[Android Architecture Components][arch-components] to automatically manage the lifecycle of the
356+
`FirebaseRecyclerPagingAdapter`. Pass a `LifecycleOwner` to
357+
`DatabasePagingOptions.Builder#setLifecycleOwner(...)` and FirebaseUI will automatically
358+
start and stop listening in `onStart()` and `onStop()`.
359+
360+
#### Paging events
361+
362+
When using the `FirebaseRecyclerPagingAdapter`, you may want to perform some action every time data
363+
changes or when there is an error. To do this, override the `onLoadingStateChanged()`
364+
method of the adapter:
365+
366+
```java
367+
FirebaseRecyclerPagingAdapter<Item, ItemViewHolder> adapter =
368+
new FirebaseRecyclerPagingAdapter<Item, ItemViewHolder>(options) {
369+
370+
// ...
371+
372+
@Override
373+
protected void onLoadingStateChanged(@NonNull LoadingState state) {
374+
switch (state) {
375+
case LOADING_INITIAL:
376+
// The initial load has begun
377+
// ...
378+
case LOADING_MORE:
379+
// The adapter has started to load an additional page
380+
// ...
381+
case LOADED:
382+
// The previous load (either initial or additional) completed
383+
// ...
384+
case ERROR:
385+
// The previous load (either initial or additional) failed. Call
386+
// the retry() method in order to retry the load operation.
387+
// ...
388+
}
389+
}
390+
};
391+
```
392+
393+
234394
## Using FirebaseUI to populate a `ListView`
235395

236396
ListView is the older, yet simpler way to handle lists of items. Using it is analogous to

database/src/main/java/com/firebase/ui/database/paging/FirebaseDataSource.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.firebase.ui.database.paging;
22

3+
import android.annotation.SuppressLint;
34
import android.arch.lifecycle.LiveData;
45
import android.arch.lifecycle.MutableLiveData;
56
import android.arch.paging.DataSource;
@@ -213,6 +214,10 @@ private String getLastPageKey(@NonNull List<DataSnapshot> data) {
213214
}
214215
}
215216

217+
/**
218+
* DatabaseError.fromStatus() is not meant to be public.
219+
*/
220+
@SuppressLint("RestrictedApi")
216221
private void setDatabaseNotFoundError(){
217222
String details = DETAILS_DATABASE_NOT_FOUND + mQuery.toString();
218223
mError.postValue(DatabaseError.fromStatus(

docs/upgrade-to-5.0.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Upgrading to FirebaseUI 5.0
2+
3+
FirebaseUI version `5.0.0` has no breaking API changes from version `4.3.2` but updates some
4+
critical dependencies to new major versions.
5+
6+
In order to use FirebaseUI, make sure your application does not declare any of the following
7+
dependencies at a lower version:
8+
9+
```
10+
com.google.firebase:firebase-core:16.0.9
11+
com.google.firebase:firebase-auth:17.0.0
12+
com.google.firebase:firebase-firestore:19.0.0
13+
com.google.firebase:firebase-database:17.0.0
14+
com.google.firebase:firebase-storage:17.0.0
15+
```
16+
17+
All of the underlying breaking changes were part of the May 7th Firebase SDK release. You can read
18+
more about this release here:
19+
https://firebase.google.com/support/release-notes/android#update_-_may_07_2019

0 commit comments

Comments
 (0)