Пример #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();
  }
Пример #2
0
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Join channel selected in search suggestions if present
    if (intent != null
        && intent.getAction() != null
        && intent.getAction().equals(Intent.ACTION_SEARCH)) {
      String resultType = (String) intent.getSerializableExtra(SearchManager.EXTRA_DATA_KEY);
      Uri data = intent.getData();

      if (resultType.equals(ChannelSearchProvider.INTENT_DATA_CHANNEL)) {
        int channelId = Integer.parseInt(data.getLastPathSegment());
        Channel channel = mService.getChannel(channelId);
        listFragment.scrollToChannel(channel);
      } else if (resultType.equals(ChannelSearchProvider.INTENT_DATA_USER)) {
        int session = Integer.parseInt(data.getLastPathSegment());
        User user = mService.getUser(session);
        listFragment.scrollToUser(user);
      }

      if (searchItem != null) searchItem.collapseActionView();
    }
  }