@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);
  }
Esempio n. 2
0
 public static <Item> List<Item> toList(
     Iterable<DataSnapshot> dataSnapshots, Class<Item> classFile) {
   List<Item> list = new ArrayList<>();
   for (DataSnapshot dataSnapshot : dataSnapshots) {
     list.add(dataSnapshot.getValue(classFile));
   }
   return list;
 }
  @NonNull
  private Comment[] parseCommentsFromCallbackData() {
    DataSnapshot commentCallbackData = dataFromCallbackAtomicRef.get();

    Comment[] comments = new Comment[(int) commentCallbackData.getChildrenCount()];

    Iterator<DataSnapshot> userDataIterator = commentCallbackData.getChildren().iterator();

    for (int i = comments.length - 1; userDataIterator.hasNext(); i--) {
      comments[i] = userDataIterator.next().getValue(Comment.class);
    }
    return comments;
  }
Esempio n. 4
0
 @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 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 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);
 }
Esempio n. 7
0
 @Override
 public void onDataChange(DataSnapshot dataSnapshot) {
   UserData u = dataSnapshot.getValue(UserData.class);
   if (mCurrentUser == null) {
     mCurrentUser = new UserWrapper(mUid, u);
   } else {
     mCurrentUser.setId(mUid);
     mCurrentUser.setData(u);
   }
   checkResult(true, mResultListener);
 }
Esempio n. 8
0
 @Override
 public void onDataChange(DataSnapshot dataSnapshot) {
   if (dataSnapshot.getValue() != null) {
     try {
       HashMap<String, Map<String, String>> map = dataSnapshot.getValue(HashMap.class);
       mFriends = new FriendWrapper[map.size()];
       int i = 0;
       for (Map.Entry<String, Map<String, String>> entry : map.entrySet()) {
         FriendWrapper friendWrapper = new FriendWrapper();
         friendWrapper.setId(entry.getKey());
         friendWrapper.setData(
             JsonUtil.getObjectMapper().convertValue(entry.getValue(), FriendData.class));
         mFriends[i] = friendWrapper;
         i++;
       }
       checkResult(true, mResultListener);
     } catch (Exception e) {
       checkResult(false, mResultListener);
     }
   } else {
     checkResult(true, mResultListener);
   }
 }
  @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);
  }
 /** 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();
   }
 }