本文整理汇总了Java中com.google.firebase.firestore.FirebaseFirestoreException类的典型用法代码示例。如果您正苦于以下问题:Java FirebaseFirestoreException类的具体用法?Java FirebaseFirestoreException怎么用?Java FirebaseFirestoreException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FirebaseFirestoreException类属于com.google.firebase.firestore包,在下文中一共展示了FirebaseFirestoreException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
}
示例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();
}
}));
}
示例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]
}
示例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]
}
示例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]
}
示例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]
}
示例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]
}
示例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]
}
示例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();
}
示例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();
}
示例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;
}
}
}
示例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)));
}
示例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)));
}
示例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);
}
示例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();
}