Exemplo n.º 1
0
 public static <T extends ParseObject> List<T> findAllParseObjects(ParseQuery<T> query)
     throws ParseException {
   List<T> result = new ArrayList<T>();
   query.setLimit(DEFAULT_PARSE_QUERY_LIMIT);
   List<T> chunk = null;
   do {
     chunk = query.find();
     result.addAll(chunk);
     query.setSkip(query.getSkip() + query.getLimit());
   } while (chunk.size() == query.getLimit());
   return result;
 }
Exemplo n.º 2
0
    public void runLoadDropItemsFromParse() {

      if (pageNumber != 0) {
        int pageMultiplier = pageNumber - 1;
        skipNumber = pageMultiplier * queryLimit;
        // Otherwise, clear the list, because this is a default(refresh) query
      } else {
        if (mDropListFromParse != null) {
          mDropListFromParse.clear();
        }
      }

      ParseUser user = ParseUser.getCurrentUser();

      ParseRelation relation = user.getRelation("todoDrops");

      ParseQuery query = relation.getQuery();

      query.setLimit(queryLimit);
      query.setSkip(skipNumber);
      query.include("authorPointer");
      query.orderByDescending("createdAt");
      query.findInBackground(
          new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> list, ParseException e) {

              if (e != null) {
                Log.i("KEVIN", "error error");

              } else {

                for (int i = 0; i < list.size(); i++) {

                  // Collects Drop Objects
                  //                        dropObjectsList.add(list.get(i));

                  final DropItem dropItem = new DropItem();

                  // Drop Author Data//////////////////////////////////////////////////////////
                  ParseObject authorData = (ParseObject) list.get(i).get("authorPointer");

                  ParseFile parseProfilePicture = (ParseFile) authorData.get("parseProfilePicture");
                  if (parseProfilePicture != null) {
                    parseProfilePicture.getDataInBackground(
                        new GetDataCallback() {
                          @Override
                          public void done(byte[] data, ParseException e) {
                            if (e == null) {
                              Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                              Bitmap resized = Bitmap.createScaledBitmap(bmp, 100, 100, true);
                              dropItem.setParseProfilePicture(resized);
                              if (pageNumber != 0) {
                                mDropAdapter.notifyDataSetChanged();
                              } else {

                                if (mDropListFromParse != null) {
                                  updateRecyclerView(mDropListFromParse);
                                }
                              }
                            }
                          }
                        });
                  }

                  // dropItemAll.setAuthorName(authorName);
                  dropItem.setAuthorName((String) authorData.get("displayName"));
                  // Author id
                  dropItem.setAuthorId(authorData.getObjectId());
                  // Author Rank
                  dropItem.setAuthorRank(authorData.getString("userRank"));
                  // Author Riple Count
                  dropItem.setAuthorRipleCount(String.valueOf(authorData.getInt("userRipleCount")));
                  // Author Info
                  dropItem.setAuthorInfo(authorData.getString("userInfo"));

                  // Drop Data////////////////////////////////////////////////////////////////
                  // DropObjectId
                  dropItem.setObjectId(list.get(i).getObjectId());
                  // Drop description
                  dropItem.setDescription(list.get(i).getString("description"));

                  // Get created at from parse and convert it to friendly String
                  Format formatter = new SimpleDateFormat("MMM dd, yyyy @ h a");
                  String dateAfter = formatter.format(list.get(i).getCreatedAt());
                  dropItem.setCreatedAt(dateAfter);

                  // Riple Count
                  int ripleCount = (list.get(i).getInt("ripleCount"));
                  if (ripleCount == 1) {
                    dropItem.setRipleCount(
                        String.valueOf(list.get(i).getInt("ripleCount") + " Riple"));
                  } else {
                    dropItem.setRipleCount(
                        String.valueOf(list.get(i).getInt("ripleCount") + " Riples"));
                  }

                  // Comment Count
                  int commentCount = (list.get(i).getInt("commentCount"));
                  if (commentCount == 1) {
                    dropItem.setCommentCount(
                        String.valueOf(list.get(i).getInt("commentCount") + " Comment"));
                  } else {
                    dropItem.setCommentCount(
                        String.valueOf(list.get(i).getInt("commentCount") + " Comments"));
                  }

                  mDropListFromParse.add(dropItem);
                }
              }

              Log.d(TAG, "DropList = " + mDropListFromParse.size());
              dropTabInteractionList = mDropListFromParse;
            }
          });
    }