private void uploadShirt() { final ParseObject newShirt = new ParseObject("Shirt"); User currentUser = UserDataSource.getCurrentUser(); final String username = (currentUser != null) ? currentUser.getFirstName() : "Jane"; final String userID = (currentUser != null) ? currentUser.getId() : "Doe"; final ParseFile imgFile = new ParseFile("shirtImage.jpeg", imageBytes); imgFile.saveInBackground( new SaveCallback() { @Override public void done(ParseException e) { newShirt.put("image", imgFile); newShirt.put("user", username); newShirt.put("userID", userID); newShirt.put("tag", shirtTag.getText().toString()); newShirt.put("description", shirtDesc.getText().toString()); newShirt.put("size", shirtSize.getSelectedItem().toString()); newShirt.saveInBackground(); ArrayList<Shirt> oldShirts = UserDataSource.getCurrentUserShirts(); Shirt shirt = new Shirt(); shirt.description = shirtDesc.getText().toString(); shirt.size = shirtSize.getSelectedItem().toString(); shirt.url = new Uri.Builder().path(imgFile.getUrl()).build(); oldShirts.add(shirt); UserDataSource.setCurrentUserShirts(oldShirts); ((SellingFragment) parentFragment).notifyDataChanged(); dismiss(); } }); }
@Override public void onUsersFetched(List<User> users) { final List<Shirt> otherUsersShirts = new ArrayList<>(); final ArrayList<Shirt> currentUserShirts = new ArrayList<>(); final User currentUser = UserDataSource.getCurrentUser(); ParseQuery<ParseObject> query = new ParseQuery<>("Shirt"); query.findInBackground( new FindCallback<ParseObject>() { public void done(List<ParseObject> markers, ParseException e) { if (e == null) { for (ParseObject po : markers) { User shirtOwner = new User(); shirtOwner.setFirstName(po.getString("user")); shirtOwner.setId(po.getString("userID")); ParseFile postImage = po.getParseFile("image"); Shirt shirt = new Shirt(); shirt.id = po.getObjectId(); shirt.user = shirtOwner; shirt.description = po.getString("description"); shirt.size = po.getString("size"); shirt.tag = po.getString("tag"); shirt.url = Uri.parse(postImage.getUrl()); if (shirt.user.getId().equals(currentUser.getId())) { currentUserShirts.add(shirt); } // else { // TODO ADD THIS BACK IN -- FOR DEBUGGING ADD ALL SHIRTS TO QUEUE otherUsersShirts.add(shirt); // } } mCardAdapter.addCards(otherUsersShirts); mCardAdapter.notifyDataSetChanged(); UserDataSource.setCurrentUserShirts(currentUserShirts); } else { Log.e(TAG, "Error in fetching users."); } } }); }
public UserManagement() { setWidth100(); setHeight100(); setLayoutMargin(20); UserDataSource userDS = UserDataSource.getInstance(); searchForm = new SearchForm(userDS); // final ComboBoxItem searchConditions = searchForm.getSearchConditionField(); setupContextMenu(); userList = new ItemListGrid(userDS); userList.addRecordClickHandler( new RecordClickHandler() { public void onRecordClick(RecordClickEvent event) { userDetailTabPane.updateDetails(); } }); userList.addCellSavedHandler( new CellSavedHandler() { public void onCellSaved(CellSavedEvent event) { userDetailTabPane.updateDetails(); } }); userList.addCellContextClickHandler( new CellContextClickHandler() { public void onCellContextClick(CellContextClickEvent event) { userListMenu.showContextMenu(); event.cancel(); } }); SectionStack sessionLayout = new SectionStack(); sessionLayout.setVisibilityMode(VisibilityMode.MULTIPLE); sessionLayout.setAnimateSections(true); searchForm.setHeight(60); searchForm.addFindListener( new com.smartgwt.client.widgets.form.fields.events.ClickHandler() { public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) { findUsers(); } }); SectionStackSection findSection = new SectionStackSection("Find Users"); findSection.setItems(searchForm); findSection.setExpanded(true); SectionStackSection usersSection = new SectionStackSection("User List"); usersSection.setItems(userList); usersSection.setExpanded(true); userDetailTabPane = new UserDetailTabPane(userDS, userList); SectionStackSection userDetailsSection = new SectionStackSection("User Details"); userDetailsSection.setItems(userDetailTabPane); userDetailsSection.setExpanded(true); sessionLayout.setSections(findSection, usersSection, userDetailsSection); addMember(sessionLayout); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_main, container, false); UserDataSource.getUnseenUsers(this); final SwipeFlingAdapterView flingContainer = (SwipeFlingAdapterView) v.findViewById(R.id.swipe_view); List<Shirt> shirts = new ArrayList<>(); mCardAdapter = new CardAdapter(getActivity(), shirts); flingContainer.setAdapter(mCardAdapter); flingContainer.setFlingListener( new SwipeFlingAdapterView.onFlingListener() { @Override public void removeFirstObjectInAdapter() { // This is the simplest way to delete an object from the adapter mCardAdapter.removeFrontItem(); } @Override public void onLeftCardExit(Object o) { // Do something on the left; you still have access to the original object flingContainer.requestLayout(); // ActionDataSource.saveUserLiked(user.getId()); } @Override public void onRightCardExit(Object o) { flingContainer.requestLayout(); // ActionDataSource.saveUserSkipped(user.getId()); if (o instanceof Shirt) { final User currentUser = UserDataSource.getCurrentUser(); final Shirt likedShirt = (Shirt) o; currentUser.addLikedShirt(likedShirt.id); // check for match // if other user has liked one of my shirts then match List<String> otherUserLikedShirts = likedShirt.user.getLikedShirts(); List<String> myShirts = currentUser.getShirts(); for (String shirtID : myShirts) { final String shirtIDCopy = shirtID; if (otherUserLikedShirts.contains(shirtID)) { // there's a match bitches!!! // get Shirt URL from parse ParseQuery<ParseObject> query = ParseQuery.getQuery("Shirt"); query.getInBackground( shirtID, new GetCallback<ParseObject>() { public void done(ParseObject object, ParseException e) { if (e == null) { ParseFile postImage = object.getParseFile("image"); final ParseObject yourMatch = new ParseObject("Match"); yourMatch.put("yourShirtID", shirtIDCopy); yourMatch.put("yourShirtURL", Uri.parse(postImage.getUrl())); yourMatch.put("theirShirtID", likedShirt.id); yourMatch.put("theirShirtURL", likedShirt.url); yourMatch.put("otherUserID", likedShirt.user.getId()); yourMatch.saveInBackground( new SaveCallback() { @Override public void done(ParseException parseException) { currentUser.addMatch(yourMatch.getObjectId()); } }); final ParseObject theirMatch = new ParseObject("Match"); theirMatch.put("yourShirtID", likedShirt.id); theirMatch.put("yourShirtURL", likedShirt.url); theirMatch.put("theirShirtID", shirtIDCopy); theirMatch.put("theirShirtURL", Uri.parse(postImage.getUrl())); theirMatch.put("otherUserID", currentUser.getId()); theirMatch.saveInBackground( new SaveCallback() { @Override public void done(ParseException parseException) { likedShirt.user.addMatch(theirMatch.getObjectId()); } }); } else { // something went wrong } } }); } } } else { // Something went wrong... } } @Override public void onAdapterAboutToEmpty(int i) { // TODO: Don't fetch all at once; use this } @Override public void onScroll(float scrollProgressPercent) {} }); ImageButton yesButton = (ImageButton) v.findViewById(R.id.yes_button); yesButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { flingContainer.getTopCardListener().selectRight(); } }); ImageButton noButton = (ImageButton) v.findViewById(R.id.no_button); noButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { flingContainer.getTopCardListener().selectLeft(); } }); return v; }