コード例 #1
0
ファイル: AddActivity.java プロジェクト: Ertyguy/ContTent
  @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);
    }
  }
コード例 #2
0
ファイル: AddActivity.java プロジェクト: Ertyguy/ContTent
  private void addThumbnail(String thumbnail) {
    if (!Var.isEmpty(thumbnail)) {
      userPictureThumbnails.add(thumbnail);

      if (Var.isEmpty(editUser.getThumbnail())) {
        editUser.setThumbnail(userPictureThumbnails.get(0));
        userPicture_sp.setSelection(0);
      }

      iconAdapter.notifyDataSetChanged();
    }
  }
コード例 #3
0
ファイル: AddActivity.java プロジェクト: Ertyguy/ContTent
    @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();
        }
      }
    }
コード例 #4
0
ファイル: AddActivity.java プロジェクト: Ertyguy/ContTent
    @Override
    protected Integer doInBackground(Void... params) {
      searchBusy = true;
      try {
        if (!twitter.hasAccessToken()) {
          String tweeterURL = "https://api.twitter.com/1.1/users/lookup.json?screen_name=" + search;
          HttpGet httpget = new HttpGet(tweeterURL);
          httpget.setHeader("Authorization", "Bearer " + twitter.getBearerToken());
          httpget.setHeader("Content-type", "application/json");

          jsonTokenStream = Var.HTTPGet(httpget);
        } else {
          users = twitter.twitter.searchUsers(search, twitterPage++);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      return 1;
    }
コード例 #5
0
ファイル: AddActivity.java プロジェクト: Ertyguy/ContTent
    @Override
    protected String doInBackground(String... search) {
      searchBusy = true;
      try {

        // TODO check the internet connection here

        String url =
            "https://www.googleapis.com/youtube/v3/search?part=snippet&q="
                + URLEncoder.encode(search[0], "UTF-8")
                + "&maxResults="
                + maxResults
                + "&type=channel&fields=items(id%2Csnippet)%2CnextPageToken&key="
                + Var.DEVELOPER_KEY;
        if (pageToken != null && !pageToken.isEmpty()) url += "&pageToken=" + pageToken;
        else isNew = true;

        response = Var.HTTPGet(url);

      } catch (Throwable t) {
        t.printStackTrace();
      }
      return null;
    }
コード例 #6
0
ファイル: AddActivity.java プロジェクト: Ertyguy/ContTent
    @Override
    protected String doInBackground(Void... params) {
      searchBusy = true;
      try {

        searchChannel.getYoutubeFeeds().clear();

        // TODO check the internet connection here
        String channelUrl =
            "https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id="
                + searchChannel.getFeedId()
                + "&fields=items%2FcontentDetails&key="
                + Var.DEVELOPER_KEY;
        String playlists = "";
        String channel = Var.HTTPGet(channelUrl);

        JSONObject res = new JSONObject(channel);
        if (Var.isJsonArray(res, "items")) {
          JSONArray items = res.getJSONArray("items");
          if (items.length() > 0) {
            JSONObject item = items.getJSONObject(0);
            if (Var.isJsonObject(item, "contentDetails")) {
              JSONObject contentDetails = item.getJSONObject(("contentDetails"));
              if (Var.isJsonObject(contentDetails, "relatedPlaylists")) { // Channel Name
                JSONObject relatedPlaylists = contentDetails.getJSONObject("relatedPlaylists");
                if (Var.isJsonString(relatedPlaylists, "uploads"))
                  playlists +=
                      (Var.isEmpty(playlists) ? "" : ",") + relatedPlaylists.getString("uploads");
                if (Var.isJsonString(relatedPlaylists, "likes"))
                  playlists +=
                      (Var.isEmpty(playlists) ? "" : ",") + relatedPlaylists.getString("likes");
                if (Var.isJsonString(relatedPlaylists, "favorites"))
                  playlists +=
                      (Var.isEmpty(playlists) ? "" : ",") + relatedPlaylists.getString("favorites");
              }
            }
          }
        }

        String playlistUrl =
            "https://www.googleapis.com/youtube/v3/playlists?part=snippet&id="
                + URLEncoder.encode(playlists, "UTF-8")
                + "&fields=items(id%2Csnippet)&key="
                + Var.DEVELOPER_KEY;
        String playlist = Var.HTTPGet(playlistUrl);

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

            if (Var.isJsonString(item, "id")) { // Feed Id
              YoutubeFeed feed = new YoutubeFeed(item.getString("id"));
              feed.setType(Var.TYPE_YOUTUBE_PLAYLIST);
              feed.setChannelHandle(searchChannel.getFeedId());

              if (Var.isJsonObject(item, "snippet")) { // Feed Name
                JSONObject snippet = item.getJSONObject("snippet");
                if (Var.isJsonString(snippet, "title")) {
                  if (snippet.getString("title").startsWith("Upload")) feed.setName("Uploads");
                  else feed.setName(snippet.getString("title"));
                }

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

              searchChannel.getYoutubeFeeds().add(feed);

              Log.d(TAG, "youtube feed added " + feed.getName());
            }
          }

          YoutubeFeed activityFeed = new YoutubeFeed();
          activityFeed.setChannelHandle(searchChannel.getFeedId());
          searchChannel.getYoutubeFeeds().add(activityFeed); // Activity
        }

      } catch (Throwable t) {
        t.printStackTrace();
      }
      return null;
    }
コード例 #7
0
ファイル: AddActivity.java プロジェクト: Ertyguy/ContTent
    protected void onPostExecute(Integer result) {
      if (isCancelled()) return;
      else {

        if (users == null || twitterPage == 1) {
          twitterFeedSearch.clear();
        }

        try {

          if (users != null) {
            for (twitter4j.User u : users) {
              TwitterFeed feed = new TwitterFeed(String.valueOf(u.getId()));
              feed.setDisplayName(u.getName());
              feed.setChannelHandle("@" + u.getScreenName());
              feed.setThumbnail(u.getProfileImageURL());

              twitterFeedSearch.add(feed);
            }

            searchBusy = false;
          } else if (jsonTokenStream != null) {

            //  Log error and clear the adapter
            Object json = new JSONTokener(jsonTokenStream).nextValue();
            if (json instanceof JSONObject) {
              if (Var.isJsonArray(((JSONObject) json), "errors")) {
                JSONArray errors = ((JSONObject) json).getJSONArray("errors");
                if (errors.length() > 0) {
                  Log.d(TAG, jsonTokenStream);

                  if (Var.isJsonString(errors.getJSONObject(0), "message")) {
                    String message = errors.getJSONObject(0).getString("message");
                    int code = errors.getJSONObject(0).getInt("code");

                    searchMessage_tv.setVisibility(View.VISIBLE);
                    if (code == 88) searchMessage_tv.setText(R.string.rate_limit_error);
                    if (code == 34) searchMessage_tv.setText(R.string.page_does_not_exist_error);
                    else searchMessage_tv.setText(message);
                  }
                }
              }
            } else if (json instanceof JSONArray) {

              if (!twitter.hasAccessToken()) {

                JSONArray results = new JSONArray(jsonTokenStream);
                for (int i = 0; i < results.length(); i++) {
                  JSONObject item = results.getJSONObject(i);

                  if (Var.isJsonString(item, "id")) {

                    TwitterFeed feed = new TwitterFeed(item.getString("id"));
                    if (Var.isJsonString(item, "name")) feed.setDisplayName(item.getString("name"));
                    if (Var.isJsonString(item, "screen_name"))
                      feed.setChannelHandle("@" + item.getString("screen_name"));
                    if (Var.isJsonString(item, "profile_image_url"))
                      feed.setThumbnail(
                          item.getString("profile_image_url").replace("_normal", "_bigger"));

                    twitterFeedSearch.add(feed);
                  }
                }
              }
            }
          }
          searchAdapter.notifyDataSetChanged();
        } catch (Exception e) {
          Log.e("Tweet", "Error retrieving JSON stream" + e.getMessage());
          e.printStackTrace();
        }
      }
    }