@Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.getValue() != null) { UserWrapper userWrapper = new UserWrapper(); userWrapper.setId(dataSnapshot.getKey()); userWrapper.setData(dataSnapshot.getValue(UserData.class)); mValueListener.onFinish(); mValueListener.onSuccess(new UserWrapper[] {userWrapper}); } else { Log.i(TAG, "user not found " + dataSnapshot.getKey()); onCancelled(new FirebaseError(96, "user not found : " + dataSnapshot.getKey())); } }
@Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { String modelName = dataSnapshot.getKey(); T oldModel = keys.get(modelName); T newModel = dataSnapshot.getValue(itemClass); setKey(modelName, newModel); int index = list.indexOf(oldModel); list.remove(index); if (s == null) { list.add(0, newModel); } else { T previousModel = keys.get(s); int previousIndex = list.indexOf(previousModel); int nextIndex = previousIndex + 1; if (nextIndex == list.size()) { list.add(newModel); } else { list.add(nextIndex, newModel); } } sortList(); adapter.animateTo(list); onChildAfter(dataSnapshot, State.MOVED); }
/** This will be called when the points data in Firebase is updated */ public void onChildChanged(DataSnapshot arg0, String arg1) { if (arg0.getKey().equals("claimed")) { this.bounty.claimed = arg0.getValue().toString(); } else if (arg0.getKey().equals("description")) { this.bounty.description = arg0.getValue().toString(); } else if (arg0.getKey().equals("due_date")) { this.bounty.dueDate = new DueDate(arg0.getValue().toString()); } else if (arg0.getKey().equals("hour_limit")) { this.bounty.hourLimit = this.bounty.convertLimitFromFirebaseForm(arg0.getValue()); } else if (arg0.getKey().equals("line_limit")) { this.bounty.lineLimit = this.bounty.convertLimitFromFirebaseForm(arg0.getValue()); } else if (arg0.getKey().equals("name")) { this.bounty.name = arg0.getValue().toString(); } else if (arg0.getKey().equals("points")) { this.bounty.points = (int) arg0.getValue(int.class); // because we have now found the points, we can allow the task to change the points, // because now we won't wipe them out by setting to zero this.bounty.canChangePoints = true; if (this.bounty.isCompletion()) { this.bounty.parentTask.setPoints(this.bounty.points); } } if (this.bounty.listViewCallback != null) { this.bounty.listViewCallback.onChange(); } }
@Override public void onChildRemoved(DataSnapshot dataSnapshot) { String modelName = dataSnapshot.getKey(); T oldModel = keys.get(modelName); list.remove(oldModel); keys.remove(modelName); sortList(); adapter.animateTo(list); onChildAfter(dataSnapshot, State.REMOVED); }
@Override public void onChildChanged(DataSnapshot dataSnapshot, String s) { String modelName = dataSnapshot.getKey(); T oldModel = keys.get(modelName); T newModel = dataSnapshot.getValue(itemClass); setKey(modelName, newModel); int index = list.indexOf(oldModel); list.set(index, newModel); keys.put(modelName, newModel); sortList(); adapter.animateTo(list); onChildAfter(dataSnapshot, State.CHANGED); }
@Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { T model = dataSnapshot.getValue(itemClass); String modelName = dataSnapshot.getKey(); keys.put(modelName, model); setKey(modelName, model); if (s == null) { list.add(0, model); } else { T previousModel = keys.get(s); int previousIndex = list.indexOf(previousModel); int nextIndex = previousIndex + 1; if (nextIndex == list.size()) { list.add(model); } else { list.add(nextIndex, model); } } sortList(); adapter.animateTo(list); onChildAfter(dataSnapshot, State.ADDED); }