@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_all_friends_inventories);

    this.controller = new AllFriendsInventoriesController(this);
    this.inventory = new Inventory();
    this.completeInventory = new Inventory();
    this.inventoryItemsListView = (ListView) findViewById(R.id.friendsDisplayedTrinkets);
    this.searchBox = (EditText) findViewById(R.id.search_box_all_friends);

    FriendsList friends = LoggedInUser.getInstance().getFriendsList();
    final HashMap<Trinket, Friend> trinketToUserMap = new HashMap<>();
    for (Friend f : friends) {
      for (Trinket t : f.getActualFriend().getInventory()) {
        this.inventory.add(t);
        this.completeInventory.add(t);
        trinketToUserMap.put(t, f);
      }
    }
    this.inventoryItemsListView = (ListView) findViewById(R.id.allFriendsDisplayedTrinkets);

    trinketArrayAdapter = new ArrayAdapter<>(this, R.layout.activity_inventory_trinket, inventory);
    inventoryItemsListView.setAdapter(trinketArrayAdapter);

    final AllFriendsInventoriesActivity activity = this;
    // When a trinket in the ListView is clicked, user is directed to its TrinketDetailsActivity
    inventoryItemsListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> v, View view, int position, long id) {
            Trinket selectedTrinket = inventory.get(position);
            Friend owner = trinketToUserMap.get(selectedTrinket);

            ApplicationState.getInstance().setClickedTrinket(selectedTrinket);
            ApplicationState.getInstance().setClickedFriend(owner);

            Intent intent =
                new Intent(AllFriendsInventoriesActivity.this, FriendsTrinketDetailsActivity.class);
            activity.startActivity(intent);
          }
        });
    // Dhawal Sodha Parmar;
    // http://stackoverflow.com/questions/15804805/android-action-bar-searchview-as-autocomplete;
    // 2015-29-11
    autocompleteAdapter =
        new ArrayAdapter<Trinket>(
            this, android.R.layout.simple_dropdown_item_1line, completeInventory);

    filterButton = (Button) findViewById(R.id.allFriendsFilterButtton);
    filterButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            controller.friendsFilterButtonOnClick();
          }
        });
    categorySpinner = (Spinner) findViewById(R.id.allFriendsCategorySpinner);
    locationSpinner = (Spinner) findViewById(R.id.allFriendsLocationSpinner);
  }
예제 #2
0
  /**
   * This method override is responsible for determining how trades will be shown to the user when
   * they view their Current Trades list and Past Trades list.
   *
   * <p>For each trade in the list, it's number, the other person involved in the trade (not
   * LoggedInUser) and it's status will be displayed. The number for a trade is it's index + 1 in
   * the list it belongs to in the TradeArchiver (currentTrades or pastTrades).
   *
   * <p>If a trade has not yet been clicked (viewed) by a user, <b>NEW!</b> will also be displayed.
   *
   * <p>
   *
   * @return String Text displayed for each trade in current trades list of ActiveTradesActivity and
   *     in past trades list of PastTradesActivity
   */
  @Override
  public String toString() {
    String otherUser;
    String status = this.getStatus();
    int tNo;

    // determine name of other user involved in trade
    if (LoggedInUser.getInstance().getProfile().getEmail().equals(receiver.getUsername())) {
      otherUser = sender.getUsername();
    } else {
      otherUser = receiver.getUsername();
    }

    // use status to determine which list the trade is in (past trades or current trades)
    // to determine it's number in the list
    if (status.equals("pending")) {
      tNo =
          LoggedInUser.getInstance()
                  .getTradeManager()
                  .getTradeArchiver()
                  .getCurrentTrades()
                  .indexOf(this)
              + 1;
    } else {
      tNo =
          LoggedInUser.getInstance()
                  .getTradeManager()
                  .getTradeArchiver()
                  .getPastTrades()
                  .indexOf(this)
              + 1;
    }

    // if trade hasn't been clicked (viewed) by user, display NEW! beside it
    if (isNewOfferedTrade) {
      return "NEW! Trade No. " + tNo + " with " + otherUser + "\nStatus: " + status;
    } else {
      return "Trade No. " + tNo + " with " + otherUser + "\nStatus: " + status;
    }
  }
예제 #3
0
  /**
   * Searches for ElasticStorable objects on the network matching the attribute and attribute value
   * pairs. Calls onSearchResult with the results when the search completes.
   *
   * <p>
   *
   * @param postParameters pairs of attributes to use when searching
   * @param type
   * @throws IOException
   */
  @Override
  public <T extends ElasticStorable> void searchOnNetwork(
      ArrayList<NameValuePair> postParameters, Class<T> type) throws IOException {
    // Alexis C.;
    // http://stackoverflow.com/questions/27253555/com-google-gson-internal-linkedtreemap-cannot-be-cast-to-my-class; 2015-11-28
    // Android-Droid;
    // http://stackoverflow.com/questions/8120220/how-to-use-parameters-with-httppost; 2015-11-18
    String username = LoggedInUser.getInstance().getProfile().getEmail();
    final HttpGet searchRequest =
        new HttpGet(
            this.getSearchUrl()
                + "?q=\"recieverUsername:"******" OR senderUsername:"******"\"");
    searchRequest.setHeader("Accept", "application/json");

    final HttpClient httpClient = new DefaultHttpClient();
    Thread thread =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  ArrayList<Trade> result = new ArrayList<>();
                  HttpResponse response = httpClient.execute(searchRequest);
                  Log.i("HttpResponse", response.getStatusLine().toString());
                  Log.i("HttpResponse Body", EntityUtils.toString(response.getEntity(), "UTF-8"));

                  Type searchResponseType = new TypeToken<SearchHit<Trade>>() {}.getType();
                  InputStreamReader streamReader =
                      new InputStreamReader(response.getEntity().getContent());
                  SearchResponse<Trade> esResponse =
                      new Gson().fromJson(streamReader, searchResponseType);

                  for (SearchHit<Trade> hit : esResponse.getHits().getHits()) {
                    result.add(hit.getSource());
                  }

                  onSearchResult(result);
                } catch (IOException e) {
                  e.printStackTrace();
                }
              }
            });
    thread.start();
  }