// Uploads data to parse server as student object private void addToParse() { ParseObject studentObj = new ParseObject("Student"); studentObj.put("name", name); studentObj.put("facebookID", facebookID); studentObj.addAll("courses", classes); studentObj.addAll("friendsList", friendsList); try { studentObj.save(); } catch (ParseException a) { a.printStackTrace(); } }
protected ParseObject createRoute() { // create a new parse object called route // (we can create a whole new class of parse objects in the back end by simply using a new name) ParseObject route = new ParseObject(ParseConstants.CLASS_ROUTES); // add the LatLng points from the plotted map to the ParseObject route route.addAll( ParseConstants.KEY_LATLNGPOINTS, (convertLatLngToParseGeoPointArray(markerPoints))); // now that we have an object, we can start adding data, using the key-value pairs... // first, get a String representation of the ID route.put(ParseConstants.KEY_SENDER_IDS, ParseUser.getCurrentUser().getObjectId()); // put the senders name route.put(ParseConstants.KEY_SENDER_NAME, ParseUser.getCurrentUser().getUsername()); // put the recipient ID's // get the selected friends from the list through the helper method getRecipientIds() route.put(ParseConstants.KEY_RECIPIENT_IDS, getRecipientIds()); // return a successful route return route; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } if (id == R.id.post) { Bundle bundle = getIntent().getExtras(); String postContent = (String) bundle.get("post"); String postType = (String) bundle.get("postType"); String panelContent = (String) bundle.get("panelContent"); String panelHeadline = (String) bundle.get("headline"); String title = (String) bundle.get("title"); Intent postIntent = new Intent(PostDiscSettingsActivity.this, DiscoverUserPostsActivity.class); ArrayList<String> bidOptionList = (ArrayList<String>) bundle.getStringArrayList("bidOptionList"); ParseUser currentUser = ParseUser.getCurrentUser(); String currentUsername = currentUser.getUsername(); ParseObject allPosts = new ParseObject("DiscoverUserPosts"); allPosts.put("category", postCategory); allPosts.put("Username", currentUsername); switch (postType) { case "thought": ParseObject thoughtPost = new ParseObject("Thought_Post"); thoughtPost.put("ThoughtPost", postContent); thoughtPost.put("Username", currentUsername); allPosts.put("content", postContent); allPosts.put("headline", panelContent); allPosts.put("featured", false); allPosts.put("type", postType); // allPosts.put("postColor", "#EC7568"); allPosts.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Toast.makeText(PostDiscSettingsActivity.this, "success", Toast.LENGTH_LONG) .show(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(PostDiscSettingsActivity.this); dialog.setTitle("Sorry"); dialog.setMessage(e.getMessage()); dialog.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); } } }); thoughtPost.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Toast.makeText(PostDiscSettingsActivity.this, "success", Toast.LENGTH_LONG) .show(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(PostDiscSettingsActivity.this); dialog.setTitle("Sorry"); dialog.setMessage(e.getMessage()); dialog.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); } } }); break; case "prediction": ParseObject predictionPost = new ParseObject("DiscoverUserPosts"); predictionPost.put("PredictionPost", postContent); predictionPost.put("Username", currentUsername); allPosts.put("content", postContent); allPosts.put("featured", false); allPosts.put("headline", panelContent); allPosts.put("type", postType); // allPosts.put("postColor", "#55D98D"); allPosts.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Toast.makeText(PostDiscSettingsActivity.this, "success", Toast.LENGTH_LONG) .show(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(PostDiscSettingsActivity.this); dialog.setTitle("Sorry"); dialog.setMessage(e.getMessage()); dialog.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); } } }); predictionPost.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Toast.makeText(PostDiscSettingsActivity.this, "success", Toast.LENGTH_LONG) .show(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(PostDiscSettingsActivity.this); dialog.setTitle("Sorry"); dialog.setMessage(e.getMessage()); dialog.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); } } }); break; case "question": ParseObject questionPost = new ParseObject("DiscoverUserPosts"); questionPost.put("QuestionPost", postContent); questionPost.put("Username", currentUsername); allPosts.put("content", postContent); allPosts.put("featured", false); allPosts.put("type", postType); allPosts.put("headline", panelContent); allPosts.addAll("bidOptionList", Arrays.asList(bidOptionList)); // allPosts.put("postColor", "#60AEE3"); allPosts.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Toast.makeText(PostDiscSettingsActivity.this, "success", Toast.LENGTH_LONG) .show(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(PostDiscSettingsActivity.this); dialog.setTitle("Sorry"); dialog.setMessage(e.getMessage()); dialog.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); } } }); questionPost.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Toast.makeText(PostDiscSettingsActivity.this, "success", Toast.LENGTH_LONG) .show(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(PostDiscSettingsActivity.this); dialog.setTitle("Sorry"); dialog.setMessage(e.getMessage()); dialog.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); } } }); break; default: break; } postIntent.putExtra("title", title); postIntent.putExtra("headline", panelHeadline); postIntent.putExtra("content", panelContent); postIntent.putExtra("postCategory", postCategory); startActivity(postIntent); } return super.onOptionsItemSelected(item); }