private void loadChallenges() {

    mProgressBar.setVisibility(View.VISIBLE);
    mNoItem.setVisibility(View.GONE);
    mList.setVisibility(View.GONE);

    ParseQuery<ParseObject> query = ParseQuery.getQuery(Constants.Parse.Challenge.CHALLENGE);
    query.include(Constants.Parse.Challenge.CHALLENGE_TO);
    query.include(Constants.Parse.Challenge.CHALLENGE_FROM);
    query.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {
              mChallengesWhereImInvolved = null;
              mChallengesWhereImInvolved = new ArrayList<ParseObject>();
              mDidISendTheChallenge = null;
              mDidISendTheChallenge = new ArrayList<Boolean>();
              for (ParseObject parseObject : objects) {

                List<String> challengeToFriends =
                    (List<String>)
                        parseObject
                            .getParseObject(Constants.Parse.Challenge.CHALLENGE_TO)
                            .get(Constants.Parse.Team.JOINED_FRIENDS);

                List<String> challengeFromFriends =
                    (List<String>)
                        parseObject
                            .getParseObject(Constants.Parse.Challenge.CHALLENGE_FROM)
                            .get(Constants.Parse.Team.JOINED_FRIENDS);

                if (challengeFromFriends.contains(ParseUser.getCurrentUser().getEmail())) {
                  mChallengesWhereImInvolved.add(parseObject);
                  mDidISendTheChallenge.add(true);
                } else if (challengeToFriends.contains(ParseUser.getCurrentUser().getEmail())) {
                  mChallengesWhereImInvolved.add(parseObject);
                  mDidISendTheChallenge.add(false);
                }
                receivedChallenges();
              }
            } else {
              mNoItem.setVisibility(View.VISIBLE);
              mNoItem.setText(
                  "It looks like some error occurred :( Try restarting the application");
              mList.setVisibility(View.GONE);
              mProgressBar.setVisibility(View.GONE);
            }
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_trainer_details);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getWindow().setNavigationBarColor(getResources().getColor(R.color.navigationBarColor));
    }

    setupToolbar();

    // Get the trainer object from parse and setup the view
    trainerId = getIntent().getStringExtra("trainerId");
    ParseQuery<Trainer> query = ParseQuery.getQuery("Trainer");
    query.whereEqualTo("objectId", trainerId);
    query.include("favorited_by");
    query.findInBackground(
        new FindCallback<Trainer>() {
          @Override
          public void done(List<Trainer> list, com.parse.ParseException e) {
            Log.d("DEBUG", ((Trainer) list.get(0)).getName());
            m_trainer = list.get(0);

            // Get the gym where the trainer goes to workout
            getTrainerGym();
          }
        });
  }
 public static void findUsersWithRecognition(
     Recognition recognition, final FindCallback<UserRecognition> callback) {
   ParseQuery<UserRecognition> userRecognitionQuery = ParseQuery.getQuery(UserRecognition.class);
   userRecognitionQuery.include("achievedBy");
   userRecognitionQuery.whereEqualTo("recognition", recognition);
   userRecognitionQuery.addDescendingOrder("dateAchieved");
   userRecognitionQuery.findInBackground(
       new FindCallback<UserRecognition>() {
         @Override
         public void done(List<UserRecognition> objects, ParseException e) {
           callback.done(objects, null);
         }
       });
 }
 // Reviews are in a separate table so it needs to be fetched separately
 private void getReviewsAndSetupViews(String trainerId) {
   ParseQuery<Review> query = ParseQuery.getQuery("Review");
   query.whereEqualTo("reviewee", m_trainer);
   query.include("reviewer");
   query.include("reviewee");
   query.findInBackground(
       new FindCallback<Review>() {
         @Override
         public void done(List<Review> reviews, com.parse.ParseException e) {
           TrainerDetailsActivity.this.reviews = new ArrayList<Review>(reviews);
           setupTrainerView();
         }
       });
 }
  private void getTrainerGym() {
    ParseQuery<Gym> query = ParseQuery.getQuery("Gym");
    query.whereEqualTo("trainers", m_trainer);
    query.include("address");
    query.findInBackground(
        new FindCallback<Gym>() {
          public void done(List<Gym> gyms, com.parse.ParseException e) {
            // Associate the gym with the trainer
            m_trainer.setGym(gyms.get(0));

            // Get all the reviews for the trainer
            getReviewsAndSetupViews(m_trainer.getObjectId());
          }
        });
  }
  private void getBookingList() {
    ParseUser currentUser = ParseUser.getCurrentUser();

    ParseQuery<ParseObject> userbookingQuery = ParseQuery.getQuery("UserBooking");
    userbookingQuery.whereEqualTo("User", currentUser);
    userbookingQuery.include("BookedHotel");
    userbookingQuery.orderByDescending("ReservationTime");
    userbookingQuery.findInBackground(
        new FindCallback<ParseObject>() {
          @Override
          public void done(List<ParseObject> bookings, ParseException e) {
            for (int i = 0; i < bookings.size(); ++i) {
              userboookingAdapter.add(bookings.get(i));
            }
          }
        });
  }
 public static void findLatestUserRecognitionInBackground(
     ParseUser user, final GetCallback<UserRecognition> callback) {
   ParseQuery<UserRecognition> userRecognitionQuery = ParseQuery.getQuery(UserRecognition.class);
   userRecognitionQuery.include("achievedBy");
   userRecognitionQuery.whereEqualTo("achievedBy", user);
   userRecognitionQuery.addDescendingOrder("dateAchieved");
   userRecognitionQuery.getFirstInBackground(
       new GetCallback<UserRecognition>() {
         @Override
         public void done(UserRecognition userRecognition, ParseException e) {
           if (e == null) {
             callback.done(userRecognition, null);
           } else {
             callback.done(null, e);
           }
         }
       });
 }
 public void getAllMessages() {
   Log.d("demo", "called get all messages");
   ParseQuery<ParseObject> query = ParseQuery.getQuery("Message");
   query.include("createdBy");
   query.findInBackground(
       new FindCallback<ParseObject>() {
         @Override
         public void done(List<ParseObject> objects, ParseException e) {
           Log.d("demo", "query find in background done " + objects);
           for (ParseObject message : objects) {
             Log.d("demo", "objects retrieved " + message.get("content").toString());
           }
           messages = objects;
           MessageAdapter adapter =
               new MessageAdapter(MessagesActivity.this, R.layout.message_layout, objects);
           listView.setAdapter(adapter);
           adapter.setNotifyOnChange(true);
         }
       });
 }
Beispiel #9
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;
            }
          });
    }
  private void loadData() {

    Log.d(TAG, "friends load Data" + isLoadData);

    if (!isLoadData) {

      // Build query
      ParseQuery<ParseObject> qUser = ParseQuery.getQuery("User_friends");
      qUser.whereEqualTo("user_id", parseUser);

      ParseQuery<ParseObject> qFriend = ParseQuery.getQuery("User_friends");
      qFriend.whereEqualTo("friend_id", parseUser);

      ArrayList<ParseQuery<ParseObject>> queries = new ArrayList<ParseQuery<ParseObject>>();
      queries.add(qUser);
      queries.add(qFriend);

      ParseQuery<ParseObject> mainQuery = ParseQuery.or(queries);
      mainQuery.include("user_id");
      mainQuery.include("friend_id");

      mainQuery.findInBackground(
          new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> list, ParseException e) {

              // clean array
              UserFriendsIdList.clear();
              MyInviteIdList.clear();
              UserInvitesIdList.clear();
              UserInvitesList.clear();

              if (e == null) {

                int i = 0;
                while (list.size() > i) {
                  ParseObject obj = list.get(i);

                  String id_User;
                  ParseUser userFriend;

                  Log.d(TAG, "id = " + obj.getObjectId());

                  if (obj.getParseUser("user_id").equals(parseUser)) {
                    Log.d(TAG, "userFriend = " + obj.getParseUser("friend_id").getUsername());
                    id_User = obj.getParseUser("friend_id").getObjectId();
                    userFriend = obj.getParseUser("friend_id");
                  } else {
                    Log.d(TAG, "userFriend = " + obj.getParseUser("user_id").getUsername());
                    id_User = obj.getParseUser("user_id").getObjectId();
                    userFriend = obj.getParseUser("user_id");
                  }

                  if (obj.getBoolean("accept")) {
                    Log.d(TAG, "accept ");
                    UserFriendsIdList.add(id_User);
                    UserFriendsList.add(new Friend(userFriend));
                  } else {
                    if (obj.getParseUser("user_id").equals(parseUser)) {
                      Log.d(TAG, "to my invites");
                      MyInviteIdList.add(id_User);
                    } else {
                      Log.d(TAG, "to userinvites");
                      UserInvitesIdList.add(id_User);
                      UserInvitesList.add(new Friend(userFriend));
                    }
                  }

                  i++;
                }
              } else {
                Log.d(TAG, "Open alert 1");
                openAlertError();
              }
              isLoadData = true;
            }
          });
    }
  }