/** * Gets User associated to system config. Loads any data associated to user. * * @param savedInstanceState */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivity = getActivity(); positionMap = new HashMap<>(); filters = new ArrayList<>(); setHasOptionsMenu(true); if (getArguments() != null) { // String username = getArguments().getString(ARG_PARAM1); user = Parcels.unwrap(getArguments().getParcelable(ARG_PARAM1)); if (PrimaryUser.getInstance().equals(user)) { user = PrimaryUser.getInstance(); } else { // user = new User(user.getUsername(), // getActivity().getApplicationContext()); try { user = PrimaryUser.getInstance().getFriends().getFriend(user.getUsername()); } catch (IOException e) { e.printStackTrace(); } catch (ServiceNotAvailableException e) { throw new RuntimeException("OFFLINE CANT DO THIS I GUESS"); } } } else { user = PrimaryUser.getInstance(); } AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void[] params) { try { // user = PrimaryUser.getInstance(); model = user.getInventory(); if (!PrimaryUser.getInstance().equals(user)) { filters.add(new PrivateFilterCriteria()); // no refresh here } controller = new UserInventoryController(getContext(), model); } catch (IOException e) { e.printStackTrace(); } catch (ServiceNotAvailableException e) { throw new RuntimeException("App is offline.", e); } return null; } @Override protected void onPostExecute(Void o) { fragmentSetup(getView()); setupFab(getView()); } }; task.execute(); }
/** * Starts activity in which an Item Can be inspected * * @param item */ public void inspectItem(Item item) { Intent intent = null; if (PrimaryUser.getInstance().equals(user)) { intent = new Intent(getContext(), EditItemView.class); intent.putExtra("user", user.getUsername()); intent.putExtra("ITEM_UUID", item.getUuid().toString()); } else { intent = new Intent(getContext(), InspectItemView.class); // intent.putExtra("user", Parcels.wrap(user)); // intent.putExtra("inventory/inspect/item", Parcels.wrap(item)); // new and improved way intent.putExtra("user", user.getUsername()); intent.putExtra("ITEM_UUID", item.getUuid().toString()); } startActivity(intent); }