Skip to content

Commit 067d83a

Browse files
authored
refactor(analytics, firestore, mlkit): fix deprecation warnings (#424)
* refactor(analytics): replace deprecated getDisplayName() with getLabel() * refactor(firestore): remove unused delete_collection snippet * chore: remove mlkit module from the build * refactor(firestore): remove deleteAll() from MainActivity.java
1 parent fcf89d4 commit 067d83a

File tree

6 files changed

+5
-144
lines changed

6 files changed

+5
-144
lines changed

analytics/app/src/main/java/com/google/firebase/example/analytics/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public void onAdRevenuePaid(MaxAd impressionData) {
260260
Bundle params = new Bundle();
261261
params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin");
262262
params.putString(FirebaseAnalytics.Param.AD_SOURCE, impressionData.getNetworkName());
263-
params.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getFormat().getDisplayName());
263+
params.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.getFormat().getLabel());
264264
params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.getAdUnitId());
265265
params.putDouble(FirebaseAnalytics.Param.VALUE, revenue);
266266
params.putString(FirebaseAnalytics.Param.CURRENCY, "USD"); // All Applovin revenue is sent in USD

analytics/app/src/main/java/com/google/firebase/example/analytics/kotlin/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class MainActivity :
272272
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION) {
273273
param(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin")
274274
param(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.adUnitId)
275-
param(FirebaseAnalytics.Param.AD_FORMAT, impressionData.format.displayName)
275+
param(FirebaseAnalytics.Param.AD_FORMAT, impressionData.format.label)
276276
param(FirebaseAnalytics.Param.AD_SOURCE, impressionData.networkName)
277277
param(FirebaseAnalytics.Param.VALUE, impressionData.revenue)
278278
param(FirebaseAnalytics.Param.CURRENCY, "USD") // All Applovin revenue is sent in USD

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

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ void runAll() {
122122
}
123123
}
124124

125-
126-
void deleteAll() {
127-
deleteCollection("cities");
128-
deleteCollection("users");
129-
}
130-
131-
private void deleteCollection(final String path) {
132-
deleteCollection(db.collection(path), 50, EXECUTOR);
133-
}
134-
135125
public void setup() {
136126
// [START get_firestore_instance]
137127
FirebaseFirestore db = FirebaseFirestore.getInstance();
@@ -1212,63 +1202,6 @@ public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
12121202
// [END fs_collection_group_query]
12131203
}
12141204

1215-
// [START delete_collection]
1216-
/**
1217-
* Delete all documents in a collection. Uses an Executor to perform work on a background
1218-
* thread. This does *not* automatically discover and delete subcollections.
1219-
*/
1220-
private Task<Void> deleteCollection(final CollectionReference collection,
1221-
final int batchSize,
1222-
Executor executor) {
1223-
1224-
// Perform the delete operation on the provided Executor, which allows us to use
1225-
// simpler synchronous logic without blocking the main thread.
1226-
return Tasks.call(executor, new Callable<Void>() {
1227-
@Override
1228-
public Void call() throws Exception {
1229-
// Get the first batch of documents in the collection
1230-
Query query = collection.orderBy(FieldPath.documentId()).limit(batchSize);
1231-
1232-
// Get a list of deleted documents
1233-
List<DocumentSnapshot> deleted = deleteQueryBatch(query);
1234-
1235-
// While the deleted documents in the last batch indicate that there
1236-
// may still be more documents in the collection, page down to the
1237-
// next batch and delete again
1238-
while (deleted.size() >= batchSize) {
1239-
// Move the query cursor to start after the last doc in the batch
1240-
DocumentSnapshot last = deleted.get(deleted.size() - 1);
1241-
query = collection.orderBy(FieldPath.documentId())
1242-
.startAfter(last.getId())
1243-
.limit(batchSize);
1244-
1245-
deleted = deleteQueryBatch(query);
1246-
}
1247-
1248-
return null;
1249-
}
1250-
});
1251-
1252-
}
1253-
1254-
/**
1255-
* Delete all results from a query in a single WriteBatch. Must be run on a worker thread
1256-
* to avoid blocking/crashing the main thread.
1257-
*/
1258-
@WorkerThread
1259-
private List<DocumentSnapshot> deleteQueryBatch(final Query query) throws Exception {
1260-
QuerySnapshot querySnapshot = Tasks.await(query.get());
1261-
1262-
WriteBatch batch = query.getFirestore().batch();
1263-
for (QueryDocumentSnapshot snapshot : querySnapshot) {
1264-
batch.delete(snapshot.getReference());
1265-
}
1266-
Tasks.await(batch.commit());
1267-
1268-
return querySnapshot.getDocuments();
1269-
}
1270-
// [END delete_collection]
1271-
12721205
public void toggleOffline() {
12731206
// [START disable_network]
12741207
db.disableNetwork()

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.util.Log;
88
import android.view.View;
99
import android.view.View.OnClickListener;
10+
import android.widget.Toast;
1011

1112
import com.google.android.gms.tasks.OnCompleteListener;
1213
import com.google.android.gms.tasks.OnFailureListener;
@@ -85,24 +86,8 @@ public void onFailure(@NonNull Exception e) {
8586
}
8687

8788
private void onDeleteAllClicked() {
88-
FirebaseAuth.getInstance()
89-
.signInAnonymously()
90-
.addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
91-
@Override
92-
public void onSuccess(AuthResult authResult) {
93-
Log.d(TAG, "auth:onSuccess");
94-
95-
// Delete
96-
DocSnippets docSnippets = new DocSnippets(mFirestore);
97-
docSnippets.deleteAll();
98-
}
99-
})
100-
.addOnFailureListener(this, new OnFailureListener() {
101-
@Override
102-
public void onFailure(@NonNull Exception e) {
103-
Log.d(TAG, "auth:onFailure", e);
104-
}
105-
});
89+
// See: https://firebase.google.com/docs/firestore/manage-data/delete-data#collections
90+
Toast.makeText(this, "Deleting all is no longer supported", Toast.LENGTH_LONG).show();
10691
}
10792

10893
@Override

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,62 +1001,6 @@ abstract class DocSnippets(val db: FirebaseFirestore) {
10011001
// [END fs_collection_group_query]
10021002
}
10031003

1004-
// [START delete_collection]
1005-
/**
1006-
* Delete all documents in a collection. Uses an Executor to perform work on a background
1007-
* thread. This does *not* automatically discover and delete subcollections.
1008-
*/
1009-
private fun deleteCollection(
1010-
collection: CollectionReference,
1011-
batchSize: Int,
1012-
executor: Executor
1013-
): Task<Void> {
1014-
1015-
// Perform the delete operation on the provided Executor, which allows us to use
1016-
// simpler synchronous logic without blocking the main thread.
1017-
return Tasks.call(executor, Callable<Void> {
1018-
// Get the first batch of documents in the collection
1019-
var query = collection.orderBy(FieldPath.documentId()).limit(batchSize.toLong())
1020-
1021-
// Get a list of deleted documents
1022-
var deleted = deleteQueryBatch(query)
1023-
1024-
// While the deleted documents in the last batch indicate that there
1025-
// may still be more documents in the collection, page down to the
1026-
// next batch and delete again
1027-
while (deleted.size >= batchSize) {
1028-
// Move the query cursor to start after the last doc in the batch
1029-
val last = deleted[deleted.size - 1]
1030-
query = collection.orderBy(FieldPath.documentId())
1031-
.startAfter(last.id)
1032-
.limit(batchSize.toLong())
1033-
1034-
deleted = deleteQueryBatch(query)
1035-
}
1036-
1037-
null
1038-
})
1039-
}
1040-
1041-
/**
1042-
* Delete all results from a query in a single WriteBatch. Must be run on a worker thread
1043-
* to avoid blocking/crashing the main thread.
1044-
*/
1045-
@WorkerThread
1046-
@Throws(Exception::class)
1047-
private fun deleteQueryBatch(query: Query): List<DocumentSnapshot> {
1048-
val querySnapshot = Tasks.await(query.get())
1049-
1050-
val batch = query.firestore.batch()
1051-
for (snapshot in querySnapshot) {
1052-
batch.delete(snapshot.reference)
1053-
}
1054-
Tasks.await(batch.commit())
1055-
1056-
return querySnapshot.documents
1057-
}
1058-
// [END delete_collection]
1059-
10601004
fun toggleOffline() {
10611005
// [START disable_network]
10621006
db.disableNetwork().addOnCompleteListener {

settings.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ include ':auth:app',
1313
':admob:app',
1414
':messaging:app',
1515
':crashlytics:app',
16-
':mlkit:app',
1716
':perf:app',
1817
':test-lab:app',
1918
':analytics:app',

0 commit comments

Comments
 (0)