@Override public void onResume() { super.onResume(); mCurrentUser = ParseUser.getCurrentUser(); mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); mProgressBar.setVisibility(View.VISIBLE); ParseQuery<ParseUser> query = mFriendsRelation.getQuery(); query.addAscendingOrder(ParseConstants.KEY_USERNAME); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> friends, ParseException e) { mProgressBar.setVisibility(View.INVISIBLE); if (e == null) { mFriends = friends; String[] usernames = new String[mFriends.size()]; // For loop to iterate through the list of users int i = 0; for (ParseUser user : mFriends) { usernames[i] = user.getUsername(); i++; } ArrayAdapter<String> adapter = new ArrayAdapter<String>( mListView.getContext(), android.R.layout.simple_list_item_checked, usernames); mListView.setAdapter(adapter); mListView.setEmptyView(mTextView); // Set the EmptyTextView } else { Log.e(TAG, e.getMessage()); AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this); builder .setMessage(e.getMessage()) .setTitle(R.string.error_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }
public static void getUserCommunity(ParseUser user) { ParseRelation<ParseObject> relation = user.getRelation(Common.OBJECT_USER_COMMUNITY_RELATION); relation .getQuery() .findInBackground( new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> list, ParseException e) { if (e == null) { EventBus.getDefault().post(new UserCommunityEvent(list)); } } }); }
public static void removeCommunityFromCurrentUser(final ParseObject community) { ParseUser user = ParseUser.getCurrentUser(); ParseRelation<ParseObject> relation = user.getRelation(Common.OBJECT_USER_COMMUNITY_RELATION); relation.remove(community); user.saveInBackground(); ParseRelation<ParseObject> communityUsers = community.getRelation(Common.OBJECT_COMMUNITY_USERS); communityUsers.remove(user); community.saveInBackground(); String channel = "community_" + community.getObjectId(); ParsePush.unsubscribeInBackground(channel); }
@Override protected void onResume() { super.onResume(); mCurrentUser = ParseUser.getCurrentUser(); mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); ParseQuery<ParseUser> query = mFriendsRelation.getQuery(); query.orderByAscending(ParseConstants.KEY_USERNAME); setProgressBarIndeterminateVisibility(true); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> friends, ParseException e) { setProgressBarIndeterminateVisibility(false); if (e == null) { mFriends = friends; String[] usernames = new String[mFriends.size()]; int i = 0; for (ParseUser user : mFriends) { usernames[i] = user.getUsername(); i++; } ArrayAdapter<String> adapter = new ArrayAdapter<String>( getListView().getContext(), android.R.layout.simple_list_item_checked, usernames); setListAdapter(adapter); } else { Log.e(TAG, e.getMessage()); AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this); builder .setMessage(e.getMessage()) .setTitle(R.string.error_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }
@Override protected void onResume() { super.onResume(); mCurrentUser = ParseUser.getCurrentUser(); mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); setProgressBarIndeterminateVisibility(true); ParseQuery<ParseUser> query = ParseUser.getQuery(); query.orderByAscending(ParseConstants.KEY_USERNAME); query.setLimit(1000); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> users, ParseException e) { setProgressBarIndeterminateVisibility(false); if (e == null && users != null) { // Success mUsers = users; String[] userNames = new String[mUsers.size()]; int i = 0; for (ParseUser user : mUsers) { userNames[i] = user.getUsername(); i++; } ArrayAdapter<String> adapter = new ArrayAdapter<String>( EditFriendsActivity.this, android.R.layout.simple_list_item_checked, userNames); setListAdapter(adapter); addFriendCheckMarks(); } else { Tools.displayErrorDialog( e.getMessage(), getString(R.string.ERROR_TITLE), EditFriendsActivity.this); Log.e(TAG, e.getMessage()); } } }); }
@Override public void onResume() { super.onResume(); mCurrentUser = ParseUser.getCurrentUser(); mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); getActivity().setProgressBarIndeterminateVisibility(true); ParseQuery<ParseUser> query = mFriendsRelation.getQuery(); query.addAscendingOrder(ParseConstants.KEY_USERNAME); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> friends, ParseException e) { getActivity().setProgressBarIndeterminateVisibility(false); if (e == null) { mFriends = friends; String[] usernames = new String[mFriends.size()]; int i = 0; for (ParseUser user : mFriends) { usernames[i] = user.getUsername(); i++; } if (mGridView.getAdapter() == null) { UserAdapter adapter = new UserAdapter(getActivity(), mFriends); mGridView.setAdapter(adapter); } else { ((UserAdapter) mGridView.getAdapter()).refill(mFriends); } } else { Log.e(TAG, e.getMessage()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder .setMessage(e.getMessage()) .setTitle(R.string.error_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }
public static void getMyQuestions(ParseUser user) { ParseQuery<ParseObject> query = user.getRelation(Common.OBJECT_USER_MY_QUESTIONS).getQuery(); // ParseQuery<ParseObject> query = ParseQuery.getQuery("Colleciton"); query.orderByDescending("updatedAt"); // query.whereEqualTo("uid",uid); query.findInBackground( new FindCallback<ParseObject>() { public void done(List<ParseObject> myQuestionsList, ParseException e) { if (e == null) { Log.d("myQuesions", "Retrieved " + myQuestionsList.size() + " collections"); EventBus.getDefault().post(new MyQuestionsEvent(myQuestionsList)); } else { Log.d("myQuesions", "Error: " + e.getMessage()); } } }); }
@Override protected void onResume() { super.onResume(); // getting the current user mCurrentUser = ParseUser.getCurrentUser(); // now the relation mFriendRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); ParseQuery<ParseUser> query = ParseUser.getQuery(); query.orderByAscending(ParseConstants.KEY_USERNAME); query.setLimit(1000); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> users, ParseException e) { if (e == null) { // it worked. create list and adapter mUsers = users; String[] usernames = new String[mUsers.size()]; int i = 0; for (ParseUser user : mUsers) { usernames[i] = user.getUsername(); i++; } ArrayAdapter<String> adapter = new ArrayAdapter<String>( EditFriendsActivity.this, android.R.layout.simple_list_item_checked, usernames); setListAdapter(adapter); // method to add checkmarks next friends addFriendCheckmarks(); } else { // something didnt work well. show alert message. AlertDialog.Builder builder = new AlertDialog.Builder(EditFriendsActivity.this); builder.setTitle(R.string.title_error); builder.setMessage(e.getMessage()); builder.setPositiveButton(android.R.string.ok, null); AlertDialog alertDialog = builder.create(); alertDialog.show(); } } }); }
@Override public void onResume() { super.onResume(); mCurrentUser = ParseUser.getCurrentUser(); mFriendRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIEND_RELATION); getActivity().setProgressBarIndeterminateVisibility(true); ParseQuery<ParseUser> query = mFriendRelation.getQuery(); query.addAscendingOrder(ParseConstants.KEY_USERNAME); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> friends, ParseException e) { getActivity().setProgressBarIndeterminateVisibility(false); if (e == null) { mFriends = friends; String[] usernames = new String[mFriends.size()]; int i = 0; for (ParseUser friend : mFriends) { usernames[i] = friend.getUsername(); i++; } // setting the adapter ArrayAdapter<String> adapter = new ArrayAdapter<String>( getListView().getContext(), android.R.layout.simple_list_item_1, usernames); setListAdapter(adapter); } else { Log.i(TAG, e.getMessage()); // Building an alert dialog AlertDialog.Builder UserBuilder = new AlertDialog.Builder(getListView().getContext()); UserBuilder.setTitle(e.getMessage()); UserBuilder.setMessage(R.string.error_title); UserBuilder.setPositiveButton(android.R.string.ok, null); UserBuilder.create(); UserBuilder.show(); } } }); }
@Override public void onResume() { super.onResume(); mCurrentUser = ParseUser.getCurrentUser(); mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_RELATION); mFriendsRelation .getQuery() .findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> friends, ParseException e) { mFriends = friends; if (e == null) { String[] usernames = new String[mFriends.size()]; int i = 0; for (ParseUser user : mFriends) { usernames[i] = user.getUsername(); i++; } ArrayAdapter<String> adapter = new ArrayAdapter<String>( getListView().getContext(), android.R.layout.simple_list_item_1, usernames); setListAdapter(adapter); } else { Log.e(TAG, e.getMessage()); AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext()); builder .setTitle(getString(R.string.Error_Title)) .setMessage(e.getMessage()) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }
@Override public void onResume() { super.onResume(); mCurrentUser = ParseUser.getCurrentUser(); // get relations for the current user if the column exists it is returned else it is created. mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); // we are querying into parse relational object. // get the list of parse user objects which are in relation with the current parse user. mProgressBar.setVisibility(View.VISIBLE); ParseQuery<ParseUser> query = mFriendsRelation.getQuery(); query.addAscendingOrder(ParseConstants.KEY_USERNAME); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> friends, ParseException e) { mProgressBar.setVisibility(View.INVISIBLE); mFriends = friends; if (e == null) { if (mGridView.getAdapter() == null) { UserAdapter adapter = new UserAdapter(getActivity(), mFriends); mGridView.setAdapter(adapter); } else { ((UserAdapter) mGridView.getAdapter()).refill(mFriends); } } else if (e.getMessage() .equals( "java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject")) { // Do nothing since friends are not yet added. // ignore } else { // Log.e(TAG, e.getMessage()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.error_title); builder.setMessage(e.getMessage()); builder.setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }
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); }
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); }
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; } }); }
// get a list of all your friends - this code is copied from the onResume() method in the // FriendsFragment with some additions @Override public void onResume() { super.onResume(); // get the current user using the getCurrentUser() method mCurrentUser = ParseUser.getCurrentUser(); // for the relation, from this user we want to call a method called getRelation() mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION); // start the progress indicator before we run our query // use the getActivity() to get a reference to the activity in which the fragment is running (as // setProgressBarIndeterminateVisibility() is an Activity method) // note: Window provided Progress Bars are now deprecated with Toolbar. // see: // http://stackoverflow.com/questions/27788195/setprogressbarindeterminatevisibilitytrue-not-working // getActivity().setProgressBarIndeterminateVisibility(true); // the first thing we need is a list of the users friends... // we have the friend relation, but this doesn't give us a list of users to work with // the list itself is still on the back end, we need to use the ParseRelation to retrieve it // use the build in query to retrieve it - this gets us the query associated with this // ParseRelation ParseQuery<ParseUser> query = mFriendsRelation.getQuery(); // sort the list by username before calling it query.addAscendingOrder(ParseConstants.KEY_USERNAME); query.findInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> friends, ParseException e) { // getActivity().setProgressBarIndeterminateVisibility(false); // include an if statement to check the exception if (e == null) { // set the mFriends variable based on the list of friends that is returned mFriends = friends; // now we need to use mFriends as the data source for the list view in our fragments // we need to create an adapter and set it as the list adapter, just like we do for // lost activities // this is very similar to what we are ding for all users in the EditFriends activity, // so copy and paste that code // create an array of strings to store the usernames and set the size equal to that of // the list returned String[] usernames = new String[mFriends.size()]; // enhanced for loop to go through the list of parse users and create an array of // usernames int i = 0; for (ParseUser user : mFriends) { usernames[i] = user.getUsername(); i++; } // create an array adapter and set it as the adapter for this activity ArrayAdapter<String> adapter = new ArrayAdapter<String>( // for the first parameter here, need to get the context of a fragment through // the list view itself // the list view knows which context it is in because of its layout in the // fragment and in the activity that contains the fragment, so use... getListView().getContext(), android.R.layout.simple_list_item_checked, usernames); // need to call setListAdapter for this activity. This method is specifically from // the ListActivity class setListAdapter(adapter); } else { // display a message to the user (copied from EditFriendsActivity) // there was an error - log the message Log.e(TAG, e.getMessage()); // display an alert to the user // if there is a parse exception then... AlertDialog.Builder builder = new AlertDialog.Builder(RouteRecipientsActivity.this); // set the message from the exception builder .setMessage(e.getMessage()) .setTitle(R.string.error_title) .setPositiveButton(android.R.string.ok, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); }