コード例 #1
0
ファイル: RibbitUser.java プロジェクト: felixsu/ribbit-app
 @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()));
   }
 }
コード例 #2
0
 /** Fills in the new point's properties. */
 public void onChildAdded(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")) {
     if (arg0.getValue(String.class).equals(Bounty.completionName)) {
       this.bounty.parentTask.setCompletionBounty(this.bounty);
       this.bounty.isCompletion = true;
       this.bounty.parentTask.setPoints(this.bounty.points);
     }
     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;
     this.bounty.parentTask.setPoints(this.bounty.points);
   }
   if (this.bounty.listViewCallback != null) {
     this.bounty.listViewCallback.onChange();
   }
 }
コード例 #3
0
  @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);
  }
コード例 #4
0
ファイル: IteratorUtils.java プロジェクト: zetbaitsu/Sigap
 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;
 }
コード例 #5
0
ファイル: RibbitUser.java プロジェクト: felixsu/ribbit-app
 @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);
 }
コード例 #6
0
ファイル: RibbitUser.java プロジェクト: felixsu/ribbit-app
 @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);
   }
 }
コード例 #7
0
  @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);
  }
コード例 #8
0
  @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);
  }