Exemplo n.º 1
0
  private void showFavouritesDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle(R.string.favorites);

    List<CharSequence> items = new ArrayList<CharSequence>();
    final List<Favourite> activeFavourites = new ArrayList<Favourite>(mService.getFavourites());

    for (Favourite favourite : mService.getFavourites()) {
      int channelId = favourite.getChannelId();
      Channel channel = mService.getChannel(channelId);

      if (channel != null) {
        items.add(channel.name);
      } else {
        // TODO remove the favourite from DB here if channel is not found.
        activeFavourites.remove(favourite);
      }
    }

    if (items.size() > 0) {
      builder.setItems(
          items.toArray(new CharSequence[items.size()]),
          new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              Favourite favourite = activeFavourites.get(which);
              final Channel channel = mService.getChannel(favourite.getChannelId());

              new AsyncTask<Channel, Void, Void>() {

                @Override
                protected Void doInBackground(Channel... params) {
                  mService.joinChannel(params[0].id);
                  return null;
                }
              }.execute(channel);
            }
          });
    } else {
      builder.setMessage(R.string.noFavorites);
    }

    builder.setNegativeButton(android.R.string.cancel, null);

    builder.show();
  }
Exemplo n.º 2
0
 public Favourite getFavouriteForChannel(Channel channel) {
   for (Favourite favourite : favourites) {
     if (favourite.getChannelId() == channel.id) return favourite;
   }
   return null;
 }