示例#1
0
  // @Override
  public Query<T> newOrQuery(Query<T>... queries) {
    // new ParseQuery(RegionUser.class.getSimpleName())
    // .whereEqualTo("name", name)
    // .whereEqualTo("user", ParseUser.getCurrentUser())
    // .

    ArrayList<ParseQuery> list = new ArrayList<ParseQuery>();
    for (Query<T> q : queries) {
      list.add(q.pq);
    }

    Query<T> query = wrap(ParseQuery.or((List) list));
    return query;
  }
示例#2
0
 private void getAllAlbums() {
   ParseQuery<Album> queryAuthor = ParseQuery.getQuery("Album");
   queryAuthor.whereEqualTo("author", ParseUser.getCurrentUser());
   ParseQuery<Album> queryCollaborator = ParseQuery.getQuery("Album");
   queryCollaborator.whereEqualTo("collaborators", ParseUser.getCurrentUser());
   List<ParseQuery<Album>> queries = new ArrayList<>();
   queries.add(queryAuthor);
   queries.add(queryCollaborator);
   ParseQuery<Album> mainQuery = ParseQuery.or(queries);
   mainQuery.orderByDescending("createdAt");
   mainQuery.findInBackground(
       new FindCallback<Album>() {
         public void done(List<Album> results, ParseException e) {
           if (e == null) {
             mAllAlbums = results;
             mAdapter.setAlbums(mAllAlbums);
             mResultsView.scrollToPosition(0);
           }
         }
       });
 }
示例#3
0
  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;
            }
          });
    }
  }