parse-community / Parse-SDK-Android

The Android SDK for Parse Platform
https://parseplatform.org/
Other
1.89k stars 735 forks source link

whereNotContainedIn is not working properly. #730

Open mginz83 opened 7 years ago

mginz83 commented 7 years ago

This would also be my code, but have a look at this.


ParseQuery<ParseObject> queryLeagues2 = ParseQuery.getQuery("Leagues");
queryLeagues2.fromLocalDatastore();
queryLeagues2.findInBackground(new FindCallback<ParseObject>() {
    @Override
    public void done(List<ParseObject> objects, ParseException e) {
        for (int i = 0; i < objects.size(); i++){
            queryLeaguesObjectsList.add(objects.get(i).getString("leagueID"));
        }
        LinkedHashSet<String> lhs = new LinkedHashSet<String>();
        lhs.addAll(queryLeaguesObjectsList);
        // Removing ArrayList elements
        queryLeaguesObjectsList.clear();
        // Adding LinkedHashSet elements to the ArrayList
        queryLeaguesObjectsList.addAll(lhs);
    }
});

For this query, I am going through the Leagues table and pulled out the League ID, throwing it through a hashes to remove a dup. The queryLeaguesObjectsList is a List

After that, I run this query.

ParseQuery<ParseObject> queryLeagues = ParseQuery.getQuery("Leagues");
        //queryLeagues.fromLocalDatastore();
        queryLeagues.whereNotContainedIn("leagueID", Arrays.asList(queryLeaguesObjectsList));
        queryLeagues.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(final List<ParseObject> queryLeaguesObjects, ParseException e) {
                if (e == null) {

                    if (queryLeaguesObjects.size() == 0) {
                        MethodContants.showLog(TAG, "No leagues to join", true);
                        progressBarContainer.setVisibility(View.GONE);
                        noLeaguesToJoin.setVisibility(View.VISIBLE);
                    } else {
                        ListViewAdapterLeagues adapter = new ListViewAdapterLeagues(listView.getContext(), queryLeaguesObjects);
                        listView.setAdapter(adapter);
                    }

                    if (!ListViewAdapterLeagues.getLoading()) {
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable(){
                            @Override
                            public void run(){
                                progressBarContainer.setVisibility(View.GONE);
                                viewContainer.setVisibility(View.VISIBLE);
                            }
                        }, 750);
                    }

                } else {
                    Toast.makeText(getContext(), "Error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
                    MethodContants.showLog(TAG, "Error with league in browse. " + e.getMessage(), true);
                }
            }
        });

All of the items are in my list view still. Even the duplicates of leagueID

mginz83 commented 7 years ago

Ill include some screen shots. The first one is my Leagues table. As you can see, there are four in there, and four are still in my list. I only want the leagues that I DO NOT belong to in the list and to remove the duplicate.

Leagues Table

screen shot 2017-09-01 at 11 19 17 am

Created Leagues Table

screen shot 2017-09-01 at 11 19 32 am