Ejemplo n.º 1
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    if (searchMode == Var.SEARCH_YOUTUBE) {
      searchChannel = youtubeChannelSearch.get(position - 1);
      Log.d(TAG, searchChannel.toString());

      addThumbnail(searchChannel.getThumbnail());
      if (Var.isEmpty(userName_edt.getText().toString()))
        userName_edt.setText(searchChannel.getName());
      name_tv.setText(searchChannel.getName());
      imageLoader.DisplayImage(searchChannel.getThumbnail(), thumbnail_iv);

      toggleSearch(Var.SEARCH_YT_CHANNEL);
      searchChannel();
    }

    if (searchMode == Var.SEARCH_TWITTER) {
      editUser.getMediaFeed().add(twitterFeedSearch.get(position - 1));
      addThumbnail(twitterFeedSearch.get(position - 1).getThumbnail());

      if (Var.isEmpty(userName_edt.getText().toString()))
        userName_edt.setText(twitterFeedSearch.get(position - 1).getDisplayName());

      toggleSearch(Var.SEARCH_NONE);
    }
  }
Ejemplo n.º 2
0
    @Override
    protected void onPostExecute(String result) {

      if (isCancelled()) return;
      else {
        if (isNew) {
          youtubeChannelSearch.clear();
          searchAdapter.notifyDataSetChanged();
        }
        try {
          JSONObject res = new JSONObject(response);

          if (Var.isJsonString(res, "nextPageToken")) pageToken = res.getString("nextPageToken");

          if (Var.isJsonArray(res, "items")) {
            JSONArray items = res.getJSONArray("items");
            for (int i = 0; i < items.length(); i++) {
              JSONObject item = items.getJSONObject(i);

              YoutubeChannel channel = new YoutubeChannel();
              if (Var.isJsonObject(item, "id")) { // Channel Id
                JSONObject id = item.getJSONObject(("id"));
                if (Var.isJsonString(id, "channelId")) {
                  channel.setFeedId(id.getString("channelId"));
                }
              }

              if (Var.isJsonObject(item, "snippet")) { // Channel Name
                JSONObject snippet = item.getJSONObject("snippet");
                if (Var.isJsonString(snippet, "title")) {
                  channel.setName(snippet.getString("title"));
                }

                if (Var.isJsonObject(snippet, "thumbnails")) { // Channel Thumbnail
                  JSONObject thumbnails = snippet.getJSONObject("thumbnails");
                  if (Var.isJsonObject(thumbnails, "default")) {
                    JSONObject def = thumbnails.getJSONObject("default");
                    if (Var.isJsonString(def, "url")) {
                      channel.setThumbnail(def.getString("url"));
                    }
                  }
                }

                youtubeChannelSearch.add(channel);
              }
            }
            searchAdapter.notifyDataSetChanged();
            if (youtubeChannelSearch.size() >= maxResults)
              searchBusy = false; // Keep busy if nothing is returned
          }

        } catch (Throwable t) {
          t.printStackTrace();
        }
      }
    }
Ejemplo n.º 3
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      ViewHolder holder;

      if (convertView == null) {
        convertView =
            inflater.inflate(
                (getItemViewType(position) == 0
                    ? R.layout.item_youtube_search
                    : R.layout.item_twitter_search),
                parent,
                false);
        holder = new ViewHolder();
        holder.image_iv = (ImageView) convertView.findViewById(R.id.thumbnail_iv);
        holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
        holder.screenName_tv = (TextView) convertView.findViewById(R.id.screen_name_tv);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }

      if (searchMode == Var.SEARCH_YOUTUBE) {
        YoutubeChannel feed = (YoutubeChannel) getItem(position);
        holder.image_iv.setImageResource(R.drawable.ic_youtube_icon);
        if (feed.getThumbnail() != null)
          imageLoader.DisplayImage(feed.getThumbnail(), holder.image_iv);

        holder.name_tv.setText(feed.getName());
      }

      if (searchMode == Var.SEARCH_TWITTER) {
        TwitterFeed feed = (TwitterFeed) getItem(position);
        holder.image_iv.setImageResource(R.drawable.ic_twitter_icon);
        if (feed.getThumbnail() != null)
          imageLoader.DisplayImage(feed.getThumbnail(), holder.image_iv);

        holder.name_tv.setText(feed.getDisplayName());
        holder.screenName_tv.setText(feed.getName());
      }

      if (searchMode == Var.SEARCH_YT_CHANNEL) {
        YoutubeFeed feed = (YoutubeFeed) getItem(position);
        holder.image_iv.setImageResource(R.drawable.ic_youtube_icon);
        if (feed.getThumbnail() != null)
          imageLoader.DisplayImage(feed.getThumbnail(), holder.image_iv);

        holder.name_tv.setText(feed.getName());
      }

      return convertView;
    }
Ejemplo n.º 4
0
  @Override
  public void onClick(View v) {
    Log.d(TAG, "onclick " + (v == action_fab) + ", " + searchMode);
    if (v == search_fab) {
      if (searchMode == Var.SEARCH_NONE) toggleSearch(Var.SEARCH_OPTIONS);
      else if (searchMode == Var.SEARCH_OPTIONS) toggleSearch(Var.SEARCH_NONE);
    }

    if (v == action_fab) {
      if (searchMode == Var.SEARCH_YT_CHANNEL) {
        SparseBooleanArray checked = search_lv.getCheckedItemPositions();
        for (int i = 0; i < checked.size(); i++) {
          if (checked.valueAt(i) == true) {
            YoutubeFeed youtubeFeed = (YoutubeFeed) search_lv.getItemAtPosition(checked.keyAt(i));
            youtubeFeed.setChannelHandle(searchChannel.getFeedId());
            editUser.getMediaFeed().add(youtubeFeed);
          }
        }

        feedAdapter.notifyDataSetChanged();
        clearSearchOptions();

        toggleSearch(Var.SEARCH_NONE);
      } else if (searchMode == Var.SEARCH_NONE) {

        editUser.setName(userName_edt.getText().toString().trim());
        editUser.setNotification(notification_sw.isChecked());
        editUser.setThumbnail((String) userPicture_sp.getSelectedItem());

        UserORM.saveUser(this, editUser);

        finish();
      }
    }
    if (v == youtube_ll) toggleSearch(Var.SEARCH_YOUTUBE);
    if (v == twitter_ll) toggleSearch(Var.SEARCH_TWITTER);
    if (v == search_v) toggleSearch(Var.SEARCH_NONE);
    if (v == searchTwitterLogin_tv) {
      twitter.resetAccessToken();
      if (!twitter.hasAccessToken()) twitter.authorize();
      // Hide the signin
      searchTwitter_v.setVisibility(View.GONE);
      searchDiv_v.setVisibility(View.GONE);
    }
    if (v == clearSearch_iv) search_edt.getText().clear();
  }