Exemplo n.º 1
0
 /**
  * Launches corresponding activity that was selected from the menu options.
  *
  * @param item menu item that was clicked
  * @return true if menu action was successful, false otherwise
  */
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case 0: // Remove show
       if (FavoriteShows.instance().deleteShow(s.getShowid()))
         Toast.makeText(getApplicationContext(), "Show removed!", Toast.LENGTH_SHORT).show();
       else
         Toast.makeText(
                 getApplicationContext(),
                 "Unable to remove show. Try again :(",
                 Toast.LENGTH_SHORT)
             .show();
       isTracked = false;
       return true;
     case 1: // Add show
       if (FavoriteShows.instance().addShow(s))
         Toast.makeText(getApplicationContext(), "Show added!", Toast.LENGTH_SHORT).show();
       else
         Toast.makeText(
                 getApplicationContext(), "Unable to add show. Try again :(", Toast.LENGTH_SHORT)
             .show();
       isTracked = true;
       return true;
     case 2: // Launch TVRage
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(s.getShowlink())));
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
Exemplo n.º 2
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    List<Show> favShows = FavoriteShows.instance().getAll();

    if (!favShows.isEmpty()) {
      for (Show sho : favShows) {
        if (sho.getShowid().equals(this.s.getShowid())) {
          isTracked = true;
        }
      }
    }

    menu.add(0, 0, 0, "Remove show").setIcon(R.drawable.ic_menu_delete).setVisible(isTracked);
    menu.add(0, 1, 0, "Add show").setIcon(R.drawable.ic_menu_add).setVisible(!isTracked);
    menu.add(0, 2, 1, "View on TVRage").setIcon(R.drawable.ic_menu_browse);

    return true;
  }