Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1669b01

Browse files
authored
Update for M24 (firebase#20)
2 parents 931f5f8 + da67fe1 commit 1669b01

File tree

9 files changed

+82
-89
lines changed

9 files changed

+82
-89
lines changed

auth/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ android {
2222
dependencies {
2323
implementation "com.android.support:support-v4:27.1.1"
2424
implementation "com.android.support:appcompat-v7:27.1.1"
25-
implementation "com.google.firebase:firebase-auth:15.0.0"
25+
implementation "com.google.firebase:firebase-auth:15.1.0"
2626
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2727
}
2828
repositories {

build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
ext.kotlin_version = '1.2.30'
4-
ext.kotlin_version = '1.2.21'
54
repositories {
65
jcenter()
76
mavenCentral()
87
google()
98
}
109
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.1.0'
12-
classpath 'com.google.gms:google-services:3.2.1'
13-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10+
classpath 'com.android.tools.build:gradle:3.1.2'
11+
classpath 'com.google.gms:google-services:3.3.0'
1412
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1513
}
1614
}

firestore/app/build.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ android {
1010
targetSdkVersion 27
1111
versionCode 1
1212
versionName "1.0"
13+
multiDexEnabled true
1314
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1415
}
16+
17+
lintOptions {
18+
warning 'InvalidPackage'
19+
}
20+
1521
buildTypes {
1622
release {
1723
minifyEnabled false
@@ -30,13 +36,14 @@ dependencies {
3036
implementation "com.android.support:support-v4:27.1.1"
3137
implementation "com.android.support:appcompat-v7:27.1.1"
3238
implementation "com.android.support.constraint:constraint-layout:1.1.0"
39+
implementation "com.android.support:multidex:1.0.3"
3340

3441
// Firestore
35-
implementation "com.google.firebase:firebase-firestore:15.0.0"
42+
implementation "com.google.firebase:firebase-firestore:16.0.0"
3643

3744
// Firebase / Play Services
38-
implementation "com.google.firebase:firebase-auth:15.0.0"
39-
implementation "com.google.android.gms:play-services-auth:15.0.0"
45+
implementation "com.google.firebase:firebase-auth:15.1.0"
46+
implementation "com.google.android.gms:play-services-auth:15.0.1"
4047
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.31"
4148
}
4249

firestore/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
android:label="@string/app_name"
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
11+
android:theme="@style/AppTheme"
12+
android:name="android.support.multidex.MultiDexApplication">
1213
<activity android:name=".MainActivity">
1314
<intent-filter>
1415
<action android:name="android.intent.action.MAIN" />

firestore/app/src/main/java/com/google/example/firestore/DocSnippets.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.google.firebase.firestore.CollectionReference;
1414
import com.google.firebase.firestore.DocumentChange;
1515
import com.google.firebase.firestore.DocumentChange.Type;
16-
import com.google.firebase.firestore.DocumentListenOptions;
1716
import com.google.firebase.firestore.DocumentReference;
1817
import com.google.firebase.firestore.DocumentSnapshot;
1918
import com.google.firebase.firestore.EventListener;
@@ -23,6 +22,7 @@
2322
import com.google.firebase.firestore.FirebaseFirestoreException;
2423
import com.google.firebase.firestore.FirebaseFirestoreSettings;
2524
import com.google.firebase.firestore.ListenerRegistration;
25+
import com.google.firebase.firestore.MetadataChanges;
2626
import com.google.firebase.firestore.Query;
2727
import com.google.firebase.firestore.Query.Direction;
2828
import com.google.firebase.firestore.QueryDocumentSnapshot;
@@ -677,11 +677,8 @@ public void onEvent(@Nullable DocumentSnapshot snapshot,
677677
public void listenWithMetadata() {
678678
// [START listen_with_metadata]
679679
// Listen for metadata changes to the document.
680-
DocumentListenOptions options = new DocumentListenOptions()
681-
.includeMetadataChanges();
682-
683680
DocumentReference docRef = db.collection("cities").document("SF");
684-
docRef.addSnapshotListener(options, new EventListener<DocumentSnapshot>() {
681+
docRef.addSnapshotListener(MetadataChanges.INCLUDE, new EventListener<DocumentSnapshot>() {
685682
@Override
686683
public void onEvent(@Nullable DocumentSnapshot snapshot,
687684
@Nullable FirebaseFirestoreException e) {

firestore/app/src/main/java/com/google/example/firestore/SolutionRateLimiting.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import android.support.annotation.Nullable;
55
import android.util.Log;
66

7-
import com.google.firebase.firestore.DocumentListenOptions;
87
import com.google.firebase.firestore.DocumentReference;
98
import com.google.firebase.firestore.DocumentSnapshot;
109
import com.google.firebase.firestore.EventListener;
1110
import com.google.firebase.firestore.FieldValue;
1211
import com.google.firebase.firestore.FirebaseFirestore;
1312
import com.google.firebase.firestore.FirebaseFirestoreException;
1413
import com.google.firebase.firestore.ListenerRegistration;
14+
import com.google.firebase.firestore.MetadataChanges;
1515
import com.google.firebase.firestore.SetOptions;
1616

1717
import java.util.HashMap;
@@ -44,8 +44,7 @@ public void startUpdates() {
4444

4545
// Listen to the document, including metadata changes so we get notified
4646
// when writes have propagated to the server.
47-
DocumentListenOptions options = new DocumentListenOptions().includeMetadataChanges();
48-
mRegistration = reference.addSnapshotListener(options, new EventListener<DocumentSnapshot>() {
47+
mRegistration = reference.addSnapshotListener(MetadataChanges.INCLUDE, new EventListener<DocumentSnapshot>() {
4948
@Override
5049
public void onEvent(@Nullable DocumentSnapshot documentSnapshot,
5150
@Nullable FirebaseFirestoreException e) {

firestore/app/src/main/java/com/google/example/firestore/kotlin/DocSnippets.kt

Lines changed: 60 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("UNUSED_VARIABLE", "UNUSED_ANONYMOUS_PARAMETER")
2+
13
package com.google.example.firestore.kotlin
24

35
import android.support.annotation.WorkerThread
@@ -80,16 +82,6 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
8082

8183
}
8284

83-
84-
internal fun deleteAll() {
85-
deleteCollection("cities")
86-
deleteCollection("users")
87-
}
88-
89-
private fun deleteCollection(path: String) {
90-
deleteCollection(db.collection(path), 50, EXECUTOR)
91-
}
92-
9385
override fun setup() {
9486
// [START get_firestore_instance]
9587
val db = FirebaseFirestore.getInstance()
@@ -107,9 +99,9 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
10799
// [START add_ada_lovelace]
108100
// Create a new user with a first and last name
109101
val user = HashMap<String, Any>()
110-
user.put("first", "Ada")
111-
user.put("last", "Lovelace")
112-
user.put("born", 1815)
102+
user["first"] = "Ada"
103+
user["last"] = "Lovelace"
104+
user["born"] = 1815
113105

114106
// Add a new document with a generated ID
115107
db.collection("users")
@@ -124,10 +116,10 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
124116
// [START add_alan_turing]
125117
// Create a new user with a first, middle, and last name
126118
val user = HashMap<String, Any>()
127-
user.put("first", "Alan")
128-
user.put("middle", "Mathison")
129-
user.put("last", "Turring")
130-
user.put("born", 1912)
119+
user["first"] = "Alan"
120+
user["middle"] = "Mathison"
121+
user["last"] = "Turring"
122+
user["born"] = 1912
131123

132124
// Add a new document with a generated ID
133125
db.collection("users")
@@ -214,9 +206,9 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
214206
override fun setDocument() {
215207
// [START set_document]
216208
val city = HashMap<String, Any>()
217-
city.put("name", "Los Angeles")
218-
city.put("state", "CA")
219-
city.put("country", "USA")
209+
city["name"] = "Los Angeles"
210+
city["state"] = "CA"
211+
city["country"] = "USA"
220212

221213
db.collection("cities").document("LA")
222214
.set(city)
@@ -234,18 +226,18 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
234226
override fun dataTypes() {
235227
// [START data_types]
236228
val docData = HashMap<String, Any?>()
237-
docData.put("stringExample", "Hello world!")
238-
docData.put("booleanExample", true)
239-
docData.put("numberExample", 3.14159265)
240-
docData.put("dateExample", Date())
241-
docData.put("listExample", Arrays.asList(1, 2, 3))
242-
docData.put("nullExample", null)
229+
docData["stringExample"] = "Hello world!"
230+
docData["booleanExample"] = true
231+
docData["numberExample"] = 3.14159265
232+
docData["dateExample"] = Date()
233+
docData["listExample"] = Arrays.asList(1, 2, 3)
234+
docData["nullExample"] = null
243235

244236
val nestedData = HashMap<String, Any>()
245-
nestedData.put("a", 5)
246-
nestedData.put("b", true)
237+
nestedData["a"] = 5
238+
nestedData["b"] = true
247239

248-
docData.put("objectExample", nestedData)
240+
docData["objectExample"] = nestedData
249241

250242
db.collection("data").document("one")
251243
.set(docData)
@@ -265,8 +257,8 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
265257
// [START add_document]
266258
// Add a new document with a generated id.
267259
val data = HashMap<String, Any>()
268-
data.put("name", "Tokyo")
269-
data.put("country", "Japan")
260+
data["name"] = "Tokyo"
261+
data["country"] = "Japan"
270262

271263
db.collection("cities")
272264
.add(data)
@@ -320,7 +312,7 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
320312
// [START set_field_with_merge]
321313
// Update one field, creating the document if it does not already exist.
322314
val data = HashMap<String, Any>()
323-
data.put("capital", true)
315+
data["capital"] = true
324316

325317
db.collection("cities").document("BJ")
326318
.set(data, SetOptions.merge())
@@ -433,8 +425,8 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
433425
return@EventListener
434426
}
435427

436-
if (snapshot != null && snapshot!!.exists()) {
437-
Log.d(TAG, "Current data: " + snapshot!!.data)
428+
if (snapshot != null && snapshot.exists()) {
429+
Log.d(TAG, "Current data: " + snapshot.data)
438430
} else {
439431
Log.d(TAG, "Current data: null")
440432
}
@@ -452,13 +444,13 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
452444
return@EventListener
453445
}
454446

455-
val source = if (snapshot != null && snapshot!!.metadata.hasPendingWrites())
447+
val source = if (snapshot != null && snapshot.metadata.hasPendingWrites())
456448
"Local"
457449
else
458450
"Server"
459451

460-
if (snapshot != null && snapshot!!.exists()) {
461-
Log.d(TAG, source + " data: " + snapshot!!.data)
452+
if (snapshot != null && snapshot.exists()) {
453+
Log.d(TAG, source + " data: " + snapshot.data)
462454
} else {
463455
Log.d(TAG, source + " data: null")
464456
}
@@ -470,10 +462,8 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
470462
override fun listenWithMetadata() {
471463
// [START listen_with_metadata]
472464
// Listen for metadata changes to the document.
473-
val options = DocumentListenOptions().includeMetadataChanges()
474-
475465
val docRef = db.collection("cities").document("SF")
476-
docRef.addSnapshotListener(options) { snapshot, e ->
466+
docRef.addSnapshotListener(MetadataChanges.INCLUDE) { snapshot, e ->
477467
// ...
478468
}
479469
// [END listen_with_metadata]
@@ -572,7 +562,7 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
572562
}
573563
}
574564

575-
if (!snapshots!!.metadata.isFromCache) {
565+
if (!snapshots.metadata.isFromCache) {
576566
Log.d(TAG, "Got initial state.")
577567
}
578568
}
@@ -623,43 +613,43 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
623613
val cities = db.collection("cities")
624614

625615
val data1 = HashMap<String, Any>()
626-
data1.put("name", "San Francisco")
627-
data1.put("state", "CA")
628-
data1.put("country", "USA")
629-
data1.put("capital", false)
630-
data1.put("population", 860000)
616+
data1["name"] = "San Francisco"
617+
data1["state"] = "CA"
618+
data1["country"] = "USA"
619+
data1["capital"] = false
620+
data1["population"] = 860000
631621
cities.document("SF").set(data1)
632622

633623
val data2 = HashMap<String, Any>()
634-
data2.put("name", "Los Angeles")
635-
data2.put("state", "CA")
636-
data2.put("country", "USA")
637-
data2.put("capital", false)
638-
data2.put("population", 3900000)
624+
data2["name"] = "Los Angeles"
625+
data2["state"] = "CA"
626+
data2["country"] = "USA"
627+
data2["capital"] = false
628+
data2["population"] = 3900000
639629
cities.document("LA").set(data2)
640630

641631
val data3 = HashMap<String, Any?>()
642-
data3.put("name", "Washington D.C.")
643-
data3.put("state", null)
644-
data3.put("country", "USA")
645-
data3.put("capital", true)
646-
data3.put("population", 680000)
632+
data3["name"] = "Washington D.C."
633+
data3["state"] = null
634+
data3["country"] = "USA"
635+
data3["capital"] = true
636+
data3["population"] = 680000
647637
cities.document("DC").set(data3)
648638

649639
val data4 = HashMap<String, Any?>()
650-
data4.put("name", "Tokyo")
651-
data4.put("state", null)
652-
data4.put("country", "Japan")
653-
data4.put("capital", true)
654-
data4.put("population", 9000000)
640+
data4["name"] = "Tokyo"
641+
data4["state"] = null
642+
data4["country"] = "Japan"
643+
data4["capital"] = true
644+
data4["population"] = 9000000
655645
cities.document("TOK").set(data4)
656646

657647
val data5 = HashMap<String, Any?>()
658-
data5.put("name", "Beijing")
659-
data5.put("state", null)
660-
data5.put("country", "China")
661-
data5.put("capital", true)
662-
data5.put("population", 21500000)
648+
data5["name"] = "Beijing"
649+
data5["state"] = null
650+
data5["country"] = "China"
651+
data5["capital"] = true
652+
data5["population"] = 21500000
663653
cities.document("BJ").set(data5)
664654
// [END example_data]
665655
}
@@ -906,7 +896,7 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
906896
Log.d(TAG, "New city:" + change.document.data)
907897
}
908898

909-
val source = if (querySnapshot!!.metadata.isFromCache)
899+
val source = if (querySnapshot.metadata.isFromCache)
910900
"local cache"
911901
else
912902
"server"
@@ -926,6 +916,7 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
926916
var name: String? = null
927917
@ServerTimestamp
928918
var timestamp: Date? = null
919+
929920
}
930921
// [END server_timestamp_annotation]
931922

@@ -935,7 +926,7 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
935926

936927
// Update the timestamp field with the value from the server
937928
val updates = HashMap<String, Any>()
938-
updates.put("timestamp", FieldValue.serverTimestamp())
929+
updates["timestamp"] = FieldValue.serverTimestamp()
939930

940931
docRef.update(updates).addOnCompleteListener(object : OnCompleteListener<Void> {
941932
// [START_EXCLUDE]
@@ -952,7 +943,7 @@ class DocSnippets(val db: FirebaseFirestore) : DocSnippetsInterface {
952943

953944
// Remove the 'capital' field from the document
954945
val updates = HashMap<String, Any>()
955-
updates.put("capital", FieldValue.delete())
946+
updates["capital"] = FieldValue.delete()
956947

957948
docRef.update(updates).addOnCompleteListener(object : OnCompleteListener<Void> {
958949
// [START_EXCLUDE]

storage/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ android {
2121
dependencies {
2222
implementation "com.android.support:support-v4:27.1.1"
2323
implementation "com.android.support:appcompat-v7:27.1.1"
24-
implementation "com.google.firebase:firebase-storage:15.0.0"
24+
implementation "com.google.firebase:firebase-storage:15.0.2"
2525
}
2626

2727
apply plugin: 'com.google.gms.google-services'

0 commit comments

Comments
 (0)