@Override
        public void onClick(DialogInterface dialog, int which) {
          switch (which) {
            case 0: // make user into a moderator
              ParseRelation moderators =
                  TheGroupUtil.getCurrentGroup().getRelation(TheGroupUtil.GROUP_MODERATORS);
              if (!isMod(TheGroupUtil.getAUser())) {
                moderators.add(TheGroupUtil.getAUser());
              }
              TheGroupUtil.getCurrentGroup().saveInBackground();

              break;
            case 1: // remove user
              ParseRelation members =
                  TheGroupUtil.getCurrentGroup().getRelation(TheGroupUtil.GROUP_MEMBERS);
              members.remove(TheGroupUtil.getAUser());
              TheGroupUtil.getCurrentGroup().saveInBackground();

              // check this, it will throw an error b/c user is not authenticated.
              /*ParseRelation relation = TheGroupUtil.getAUser().getRelation(TheGroupUtil.MEMBERSHIP);
              relation.remove(TheGroupUtil.getCurrentGroup());
              TheGroupUtil.getAUser().saveInBackground();
              */

              Intent intent = new Intent(SelectUserActivity.this, ViewBlogActivity.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
              startActivity(intent);

              break;
          }
        }
  @Override
  protected void onListItemClick(ListView l, View v, final int position, long id) {
    super.onListItemClick(l, v, position, id);

    if (getListView().isItemChecked(position)) {
      // add friend
      mFriendsRelation.add(mUsers.get(position));

    } else {
      // remove friend
      mFriendsRelation.remove(mUsers.get(position));
    }

    mCurrentUser.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            if (e != null) {
              // failed

              Log.e(TAG, e.getMessage());
            }
          }
        });
  }
Exemple #3
0
  public static void addCommunityToUser(final ParseObject community) {
    ParseUser user = ParseUser.getCurrentUser();
    ParseRelation<ParseObject> relation = user.getRelation(Common.OBJECT_USER_COMMUNITY_RELATION);
    relation.add(community);
    user.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            getUserCommunity(ParseUser.getCurrentUser());
          }
        });

    ParseRelation<ParseObject> communityUsers =
        community.getRelation(Common.OBJECT_COMMUNITY_USERS);
    communityUsers.add(user);
    community.saveInBackground();

    String channel = "community_" + community.getObjectId();
    ParsePush.subscribeInBackground(channel);
  }
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
   super.onListItemClick(l, v, position, id);
   if (getListView().isItemChecked(position)) {
     // add friend
     mFriendRelation.add(mUsers.get(position));
   } else {
     // remove friends
     mFriendRelation.remove(mUsers.get((position)));
   }
   mCurrentUser.saveInBackground(
       new SaveCallback() {
         @Override
         public void done(ParseException e) {
           if (e != null) {
             // there is an error
             Toast.makeText(EditFriendsActivity.this, android.R.string.no, Toast.LENGTH_SHORT)
                 .show();
           }
         }
       });
 }
  public static void addDiaryEntries(
      final Calendar cal,
      final ParseUser user,
      final List<DiaryEntry> entries,
      final String userMeal) {

    ParseRelation<ParseObject> pastRecipesRelation = user.getRelation("pastRecipes");
    List<DiaryEntry> diaryEntriesList = new ArrayList<>();
    for (DiaryEntry entry : entries) {
      // Add to user's past recipes
      pastRecipesRelation.add(entry.getRecipe());

      final DiaryEntry diaryEntry = new DiaryEntry();
      diaryEntry.setDate(cal.getTime());
      diaryEntry.setUser(user);
      diaryEntry.setRecipe(entry.getRecipe());
      diaryEntry.setServingsMultiplier(entry.getServingsMultiplier());
      diaryEntry.saveInBackground();
      diaryEntriesList.add(diaryEntry);
    }
    user.saveInBackground();
    addUserMeal(cal, user, diaryEntriesList, userMeal);
  }
  public static void addDiaryEntry(
      final Calendar cal,
      final ParseUser user,
      final Recipe recipe,
      float servings,
      final String userMeal) {

    // Add recipe to users past recipes
    ParseRelation<ParseObject> relation = user.getRelation("pastRecipes");
    relation.add(recipe);
    user.saveInBackground();

    // Create new diary entry and save to parse
    final DiaryEntry diaryEntry = new DiaryEntry();
    diaryEntry.setDate(cal.getTime());
    diaryEntry.setUser(user);
    diaryEntry.setRecipe(recipe);
    diaryEntry.setServingsMultiplier(servings);
    diaryEntry.saveInBackground();

    List<DiaryEntry> entries = new ArrayList<>();
    entries.add(diaryEntry);
    addUserMeal(cal, user, entries, userMeal);
  }