Esempio n. 1
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   switch (requestCode) {
     case MainActivity.REQUEST_NEW_ITEM:
       if (resultCode == Activity.RESULT_OK) {
         Utility.addToFavorites(
             getActivity(), (Item) data.getParcelableExtra(ItemChooserActivity.EXTRA_ITEM));
         mPresenter.loadFavorites();
       }
   }
   super.onActivityResult(requestCode, resultCode, data);
 }
Esempio n. 2
0
  @Override
  public void onMoreClicked(View view, final Item item) {
    PopupMenu menu = new PopupMenu(getActivity(), view);
    menu.getMenuInflater().inflate(R.menu.popup_item, menu.getMenu());
    menu.getMenu().findItem(R.id.favorite).setTitle("Remove from favorites");
    menu.getMenu()
        .findItem(R.id.calculator)
        .setEnabled(!Utility.isInCalculator(getActivity(), item));
    menu.setOnMenuItemClickListener(
        new PopupMenu.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
              case R.id.history:
                Intent i = new Intent(getActivity(), PriceHistoryActivity.class);
                i.putExtra(PriceHistoryActivity.EXTRA_ITEM, item);
                startActivity(i);
                break;
              case R.id.favorite:
                Utility.removeFromFavorites(getActivity(), item);
                mAdapter.removeItem(item);
                break;
              case R.id.calculator:
                Utility.addToCalculator(getActivity(), item);
                menuItem.setEnabled(false);
                break;
              case R.id.backpack_tf:
                CustomTabActivityHelper.openCustomTab(
                    getActivity(),
                    new CustomTabsIntent.Builder().build(),
                    Uri.parse(item.getBackpackTfUrl()),
                    new WebViewFallback());
                break;
              case R.id.wiki:
                CustomTabActivityHelper.openCustomTab(
                    getActivity(),
                    new CustomTabsIntent.Builder().build(),
                    Uri.parse(item.getTf2WikiUrl()),
                    new WebViewFallback());
                break;
            }
            return true;
          }
        });

    menu.show();
  }