本文整理汇总了Java中com.google.firebase.firestore.FirebaseFirestoreException类的典型用法代码示例。如果您正苦于以下问题:Java FirebaseFirestoreException类的具体用法?Java FirebaseFirestoreException怎么用?Java FirebaseFirestoreException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FirebaseFirestoreException类属于com.google.firebase.firestore包,在下文中一共展示了FirebaseFirestoreException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentChange change : documentSnapshots.getDocumentChanges()) {
switch (change.getType()) {
case ADDED: {
String groupId = change.getDocument().getId();
FirebaseFirestore.getInstance()
.collection("groups")
.document(groupId)
.collection("items")
.addSnapshotListener(new GroupItemsChangeListener(groupId));
}
break;
}
}
}
开发者ID:whirlwind-studios,项目名称:School1-Android,代码行数:17,代码来源:DashboardAdapter.java
示例2: subscribe
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void subscribe(final ObservableEmitter<DocumentSnapshot> emitter) throws Exception {
final EventListener<DocumentSnapshot> listener = new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(DocumentSnapshot documentSnapshot, FirebaseFirestoreException e) {
if (!emitter.isDisposed()) {
if (e == null) {
emitter.onNext(documentSnapshot);
} else {
emitter.onError(e);
}
}
}
};
registration = documentReference.addSnapshotListener(listener);
emitter.setDisposable(Disposables.fromAction(new Action() {
@Override
public void run() throws Exception {
registration.remove();
}
}));
}
开发者ID:btrautmann,项目名称:RxFirestore,代码行数:26,代码来源:DocumentSnapshotsOnSubscribe.java
示例3: listenForUsers
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private void listenForUsers() {
// [START listen_for_users]
// Listen for users born before 1900.
//
// You will get a first snapshot with the initial results and a new
// snapshot each time there is a change in the results.
db.collection("users")
.whereLessThan("born", 1900)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot snapshots,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
return;
}
Log.d(TAG, "Current users born before 1900: " + snapshots);
}
});
// [END listen_for_users]
}
开发者ID:firebase,项目名称:snippets-android,代码行数:24,代码来源:DocSnippets.java
示例4: listenToDocument
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private void listenToDocument() {
// [START listen_document]
final DocumentReference docRef = db.collection("cities").document("SF");
docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
return;
}
if (snapshot != null && snapshot.exists()) {
Log.d(TAG, "Current data: " + snapshot.getData());
} else {
Log.d(TAG, "Current data: null");
}
}
});
// [END listen_document]
}
开发者ID:firebase,项目名称:snippets-android,代码行数:22,代码来源:DocSnippets.java
示例5: listenToDocumentLocal
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private void listenToDocumentLocal() {
// [START listen_document_local]
final DocumentReference docRef = db.collection("cities").document("SF");
docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
return;
}
String source = snapshot != null && snapshot.getMetadata().hasPendingWrites()
? "Local" : "Server";
if (snapshot != null && snapshot.exists()) {
Log.d(TAG, source + " data: " + snapshot.getData());
} else {
Log.d(TAG, source + " data: null");
}
}
});
// [END listen_document_local]
}
开发者ID:firebase,项目名称:snippets-android,代码行数:25,代码来源:DocSnippets.java
示例6: detachListener
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private void detachListener() {
// [START detach_listener]
Query query = db.collection("cities");
ListenerRegistration registration = query.addSnapshotListener(
new EventListener<QuerySnapshot>() {
// [START_EXCLUDE]
@Override
public void onEvent(@Nullable QuerySnapshot snapshots,
@Nullable FirebaseFirestoreException e) {
// ...
}
// [END_EXCLUDE]
});
// ...
// Stop listening to changes
registration.remove();
// [END detach_listener]
}
开发者ID:firebase,项目名称:snippets-android,代码行数:21,代码来源:DocSnippets.java
示例7: handleListenErrors
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private void handleListenErrors() {
// [START handle_listen_errors]
db.collection("cities")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot snapshots,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "listen:error", e);
return;
}
for (DocumentChange dc : snapshots.getDocumentChanges()) {
if (dc.getType() == Type.ADDED) {
Log.d(TAG, "New city: " + dc.getDocument().getData());
}
}
}
});
// [END handle_listen_errors]
}
开发者ID:firebase,项目名称:snippets-android,代码行数:23,代码来源:DocSnippets.java
示例8: offlineListen
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private void offlineListen(FirebaseFirestore db) {
// [START offline_listen]
db.collection("cities").whereEqualTo("state", "CA")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot querySnapshot,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen error", e);
return;
}
for (DocumentChange change : querySnapshot.getDocumentChanges()) {
if (change.getType() == Type.ADDED) {
Log.d(TAG, "New city:" + change.getDocument().getData());
}
String source = querySnapshot.getMetadata().isFromCache() ?
"local cache" : "server";
Log.d(TAG, "Data fetched from " + source);
}
}
});
// [END offline_listen]
}
开发者ID:firebase,项目名称:snippets-android,代码行数:27,代码来源:DocSnippets.java
示例9: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "onEvent:error", e);
onError(e);
return;
}
// Dispatch the event
Log.d(TAG, "onEvent:numChanges:" + documentSnapshots.getDocumentChanges().size());
for (DocumentChange change : documentSnapshots.getDocumentChanges()) {
switch (change.getType()) {
case ADDED:
onDocumentAdded(change);
break;
case MODIFIED:
onDocumentModified(change);
break;
case REMOVED:
onDocumentRemoved(change);
break;
}
}
onDataChanged();
}
开发者ID:firebase,项目名称:quickstart-android,代码行数:27,代码来源:FirestoreAdapter.java
示例10: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void onEvent(QuerySnapshot snapshots, FirebaseFirestoreException e) {
if (e != null) {
notifyOnError(e);
return;
}
// Break down each document event
List<DocumentChange> changes = snapshots.getDocumentChanges();
for (DocumentChange change : changes) {
switch (change.getType()) {
case ADDED:
onDocumentAdded(change);
break;
case REMOVED:
onDocumentRemoved(change);
break;
case MODIFIED:
onDocumentModified(change);
break;
}
}
notifyOnDataChanged();
}
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:26,代码来源:FirestoreArray.java
示例11: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentChange change : documentSnapshots.getDocumentChanges()) {
switch (change.getType()) {
case ADDED: {
Group group = new Group();
group.setId(change.getDocument().getId());
userGroups.add(group);
adapter.setUserGroups(userGroups);
FirebaseFirestore.getInstance()
.collection("groups")
.whereEqualTo("parentGroup", change.getDocument().getId())
.addSnapshotListener(CoursesFragment.this);
}
break;
case REMOVED: {
for (int i = 0; i < userGroups.size(); i++)
if (userGroups.get(i).getId().equals(change.getDocument().getId())) {
userGroups.remove(i);
adapter.notifyDataSetChanged();
return;
}
}
break;
}
}
}
开发者ID:whirlwind-studios,项目名称:School1-Android,代码行数:29,代码来源:CoursesFragment.java
示例12: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void onEvent(DocumentSnapshot snapshot, FirebaseFirestoreException e) {
if (e != null) {
setValue(new Resource<>(e));
return;
}
setValue(new Resource<>(snapshot.toObject(type)));
}
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:9,代码来源:DocumentLiveData.java
示例13: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void onEvent(QuerySnapshot snapshots, FirebaseFirestoreException e) {
if (e != null) {
setValue(new Resource<>(e));
return;
}
setValue(new Resource<>(documentToList(snapshots)));
}
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:9,代码来源:QueryLiveData.java
示例14: initRecyclerView
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private void initRecyclerView() {
if (mQuery == null) {
Log.w(TAG, "No query, not initializing RecyclerView");
}
mAdapter = new RestaurantAdapter(mQuery, this) {
@Override
protected void onDataChanged() {
// Show/hide content if the query returns empty.
if (getItemCount() == 0) {
mRestaurantsRecycler.setVisibility(View.GONE);
mEmptyView.setVisibility(View.VISIBLE);
} else {
mRestaurantsRecycler.setVisibility(View.VISIBLE);
mEmptyView.setVisibility(View.GONE);
}
}
@Override
protected void onError(FirebaseFirestoreException e) {
// Show a snackbar on errors
Snackbar.make(findViewById(android.R.id.content),
"Error: check logs for info.", Snackbar.LENGTH_LONG).show();
}
};
mRestaurantsRecycler.setLayoutManager(new LinearLayoutManager(this));
mRestaurantsRecycler.setAdapter(mAdapter);
}
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:31,代码来源:MainActivity.java
示例15: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void onEvent(QuerySnapshot documentSnapshots,
FirebaseFirestoreException e) {
// Handle errors
if (e != null) {
Log.w(TAG, "onEvent:error", e);
return;
}
// Dispatch the event
for (DocumentChange change : documentSnapshots.getDocumentChanges()) {
// Snapshot of the changed document
DocumentSnapshot snapshot = change.getDocument();
switch (change.getType()) {
case ADDED:
onDocumentAdded(change);
break;
case MODIFIED:
onDocumentModified(change);
break;
case REMOVED:
onDocumentRemoved(change);
break;
}
}
onDataChanged();
}
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:31,代码来源:FirestoreAdapter.java
示例16: addRating
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
private Task<Void> addRating(final DocumentReference restaurantRef,
final Rating rating) {
// Create reference for new rating, for use inside the transaction
final DocumentReference ratingRef = restaurantRef.collection("ratings")
.document();
// In a transaction, add the new rating and update the aggregate totals
return mFirestore.runTransaction(new Transaction.Function<Void>() {
@Override
public Void apply(Transaction transaction)
throws FirebaseFirestoreException {
Restaurant restaurant = transaction.get(restaurantRef)
.toObject(Restaurant.class);
// Compute new number of ratings
int newNumRatings = restaurant.getNumRatings() + 1;
// Compute new average rating
double oldRatingTotal = restaurant.getAvgRating() *
restaurant.getNumRatings();
double newAvgRating = (oldRatingTotal + rating.getRating()) /
newNumRatings;
// Set new restaurant info
restaurant.setNumRatings(newNumRatings);
restaurant.setAvgRating(newAvgRating);
// Commit to Firestore
transaction.set(restaurantRef, restaurant);
transaction.set(ratingRef, rating);
return null;
}
});
}
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:37,代码来源:RestaurantDetailActivity.java
示例17: onEvent
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
/**
* Listener for the Restaurant document ({@link #mRestaurantRef}).
*/
@Override
public void onEvent(DocumentSnapshot snapshot, FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "restaurant:onEvent", e);
return;
}
onRestaurantLoaded(snapshot.toObject(Restaurant.class));
}
开发者ID:chauhan-abhi,项目名称:CloudFirestore,代码行数:13,代码来源:RestaurantDetailActivity.java
示例18: subscribe
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void subscribe(final ObservableEmitter<QuerySnapshot> emitter) throws Exception {
final EventListener<QuerySnapshot> listener = new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot querySnapshot, FirebaseFirestoreException e) {
if (!emitter.isDisposed()) {
if (e == null) {
emitter.onNext(querySnapshot);
} else {
emitter.onError(e);
}
}
}
};
registration = query.addSnapshotListener(listener);
emitter.setDisposable(Disposables.fromAction(new Action() {
@Override
public void run() throws Exception {
registration.remove();
}
}));
}
开发者ID:btrautmann,项目名称:RxFirestore,代码行数:28,代码来源:QuerySnapshotsOnSubscribe.java
示例19: subscribe
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
@Override
public void subscribe(final ObservableEmitter<DocumentChange> emitter) throws Exception {
final EventListener<QuerySnapshot> listener = new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot querySnapshot, FirebaseFirestoreException e) {
if (!emitter.isDisposed()) {
if (e == null) {
for (DocumentChange change : querySnapshot.getDocumentChanges()) {
emitter.onNext(change);
}
} else {
emitter.onError(e);
}
}
}
};
registration = query.addSnapshotListener(listener);
emitter.setDisposable(Disposables.fromAction(new Action() {
@Override
public void run() throws Exception {
registration.remove();
}
}));
}
开发者ID:btrautmann,项目名称:RxFirestore,代码行数:30,代码来源:DocumentChangesOnSubscribe.java
示例20: incrementCounter
import com.google.firebase.firestore.FirebaseFirestoreException; //导入依赖的package包/类
public Task<Void> incrementCounter(final DocumentReference ref, final int numShards) {
int shardId = (int) Math.floor(Math.random() * numShards);
final DocumentReference shardRef = ref.collection("shards").document(String.valueOf(shardId));
return db.runTransaction(new Transaction.Function<Void>() {
@Override
public Void apply(Transaction transaction) throws FirebaseFirestoreException {
Shard shard = transaction.get(shardRef).toObject(Shard.class);
shard.count += 1;
transaction.set(shardRef, shard);
return null;
}
});
}
开发者ID:firebase,项目名称:snippets-android,代码行数:16,代码来源:SolutionCounters.java
注:本文中的com.google.firebase.firestore.FirebaseFirestoreException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论