@Override public void onDataChange(DataSnapshot dataSnapshot) { Map<String, Object> td = (HashMap<String, Object>) dataSnapshot.getValue(); if (td==null)return; double lat = Double.parseDouble(td.get("lat").toString()); double lag = Double.parseDouble(td.get("lag").toString()); /** Make sure that the map has been initialised **/ sydney = new LatLng(lat, lag); LastDateOnline= td.get("LastOnlineDate").toString(); LoadMap(); }
@Override public void onDataChange(DataSnapshot dataSnapshot) { Map<String, Object> td = (HashMap<String, Object>) dataSnapshot.getValue();
private boolean hasValue (DataSnapshot s) { return s != null && s.getValue() != null; }
@Override public void onDataChange(DataSnapshot dataSnapshot) { RGBColor color = dataSnapshot.getValue(RGBColor.class); Log.d(TAG, "Red ["+color.getRed()+"]"); Log.d(TAG, "Green ["+color.getGreen()+"]"); Log.d(TAG, "Blue ["+color.getBlue()+"]"); // update pins updatePin(redPin, color.getRed()); updatePin(greenPin, color.getGreen()); updatePin(bluePin, color.getBlue()); }
public Observable<Thread> metaOn () { return Observable.create((ObservableOnSubscribe<Thread>) e -> { DatabaseReference ref = FirebasePaths.threadMetaRef(model.getEntityID()); FirebaseReferenceManager.shared().addRef(ref, ref.addValueEventListener(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if(hasValue && snapshot.getValue() instanceof Map) { Map<String, Object> value = (Map<String, Object>) snapshot.getValue(); for (String key : value.keySet()) { if (value.get(key) instanceof String) { model.setMetaValue(key, (String) value.get(key)); } } } e.onNext(model); }))); }).subscribeOn(Schedulers.single()); }
public UserWrapper(DataSnapshot snapshot){ model = StorageManager.shared().fetchOrCreateEntityWithEntityID(User.class, snapshot.getKey()); deserialize((Map<String, Object>) snapshot.getValue()); }
public Completable once () { return Completable.create(e -> { DatabaseReference detailsRef = FirebasePaths.threadDetailsRef(model.getEntityID()); detailsRef.addValueEventListener(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if(hasValue && snapshot.getValue() instanceof Map) { deserialize((Map<String, Object>) snapshot.getValue()); } e.onComplete(); })); }).subscribeOn(Schedulers.single()); }
public Observable<User> metaOn() { return Observable.create((ObservableOnSubscribe<User>) e -> { metaOff(); final DatabaseReference userMetaRef = FirebasePaths.userMetaRef(model.getEntityID()); if(FirebaseReferenceManager.shared().isOn(userMetaRef)) { e.onNext(model); } ValueEventListener listener = userMetaRef.addValueEventListener(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if (hasValue && snapshot.getValue() instanceof Map) { deserializeMeta((Map<String, Object>) snapshot.getValue()); e.onNext(model); } })); FirebaseReferenceManager.shared().addRef(userMetaRef, listener); }).subscribeOn(Schedulers.single()); }
Object valueObject = snapshot.getValue(); if (valueObject instanceof HashMap) { for (Object key : ((HashMap) valueObject).keySet()) { DataSnapshot meta = userSnapshot.child(Keys.Meta); if (meta.hasChild(index)) { String childValue = (String) meta.child(index).getValue(); String name = (String) meta.child(Keys.Name).getValue(); if (childValue.toLowerCase().indexOf(finalValue.toLowerCase()) == 0 && name != null && !name.isEmpty()) { final UserWrapper wrapper = new UserWrapper(userSnapshot);
for (String key : ((Map<String, Object>) snapshot.getValue()).keySet())
public Completable once(){ return Completable.create(e -> { final DatabaseReference ref = ref(); ref.addListenerForSingleValueEvent(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if(hasValue) { deserialize((Map<String, Object>) snapshot.getValue()); } e.onComplete(); })); }).subscribeOn(Schedulers.single()); }
public Observable<Boolean> onlineOn () { onlineOff(); return Observable.create((ObservableOnSubscribe<Boolean>) e -> { DatabaseReference ref = FirebasePaths.userOnlineRef(model.getEntityID()); ValueEventListener listener = ref.addValueEventListener(new FirebaseEventListener().onValue((snapshot, hasValue) -> { Boolean available = false; if(hasValue) { available = (boolean) snapshot.getValue(); } model.setIsOnline(available); e.onNext(available); })); FirebaseReferenceManager.shared().addRef(ref, listener); }).subscribeOn(Schedulers.single()); }
/** * Start listening to thread details changes. **/ public Observable<Thread> on() { return Observable.create((ObservableOnSubscribe<Thread>) e -> { DatabaseReference detailsRef = FirebasePaths.threadDetailsRef(model.getEntityID()); if (FirebaseReferenceManager.shared().isOn(detailsRef)) { e.onComplete(); return; } ValueEventListener listener = detailsRef.addValueEventListener(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if (hasValue && snapshot.getValue() instanceof Map) { deserialize((Map<String, Object>)snapshot.getValue()); } updateReadReceipts(); e.onNext(model); })); FirebaseReferenceManager.shared().addRef(detailsRef, listener); if(ChatSDK.typingIndicator() != null) { ChatSDK.typingIndicator().typingOn(model); } }).subscribeOn(Schedulers.single()); }
/** * Get the date when the thread was deleted * @return Single On success return the date or -1 if the thread hasn't been deleted **/ private Single<Long> threadDeletedDate() { return Single.create((SingleOnSubscribe<Long>) e -> { User user = ChatSDK.currentUser(); DatabaseReference currentThreadUser = FirebasePaths.threadRef(model.getEntityID()) .child(FirebasePaths.UsersPath) .child(user.getEntityID()) .child(Keys.Deleted); currentThreadUser.addListenerForSingleValueEvent(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if(hasValue) { e.onSuccess((Long) snapshot.getValue()); } else { e.onSuccess(Long.valueOf(-1)); } })); }).subscribeOn(Schedulers.single()); }
@Override public TestData call(DataSnapshot dataSnapshot) { return dataSnapshot.getValue(TestData.class); } }, new Func0<Map<String, TestData>>() {
@Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.getValue() != null) { HashMap mapStatus = (HashMap) dataSnapshot.getValue(); if ((boolean) mapStatus.get("isOnline") && (System.currentTimeMillis() - (long) mapStatus.get("timestamp")) > StaticConfig.TIME_TO_OFFLINE) { FirebaseDatabase.getInstance().getReference().child("user/" + fid + "/status/isOnline").setValue(false); } } }
@Override public U apply(DataSnapshot dataSnapshot) { U value = dataSnapshot.getValue(genericTypeIndicator); if (value == null) { throw Exceptions.propagate(new RxFirebaseDataCastException( "unable to cast firebase data response to generic type")); } return value; } }
if (hasValue) { User contact = StorageManager.shared().fetchOrCreateEntityWithEntityID(User.class, snapshot.getKey()); Object value = snapshot.getValue(); if (value instanceof HashMap) { Object type = ((HashMap) value).get(Keys.Type); if (hasValue) { User contact = StorageManager.shared().fetchOrCreateEntityWithEntityID(User.class, snapshot.getKey()); Object value = snapshot.getValue(); if (value instanceof HashMap) { Object type = ((HashMap) value).get(Keys.Type);