Пример #1
0
  /**
   * This method defines a feed URL and then calles our SAX Handler to read the article list from
   * the stream
   *
   * @return List<JSONObject> - suitable for the List View activity
   */
  public static List<JSONObject> getLatestRssFeed(CommonStringsHelper res) {
    String feed = res.getString(R.string.rss_url);

    RSSHandler rh = new RSSHandler();
    List<Article> articles = rh.getLatestArticles(feed);

    if (articles == null || articles.size() <= 0) {
      Article article = new Article();

      article.setArticleId(-9999);
      article.setTitle(res.getString(R.string.rss_unavailable_title));
      article.setDescription(res.getString(R.string.rss_unavailable_description));
      article.setPubDate(res.getString(R.string.rss_unavailable_date));
      article.setUrl(null);

      articles.add(article);
    } else {
      Article article = new Article();

      article.setArticleId(-9999);
      article.setTitle(res.getString(R.string.author_title));
      article.setDescription(res.getString(R.string.author_description));
      article.setPubDate(res.getString(R.string.author_date));

      try {
        article.setUrl(new URL(res.getString(R.string.author_url)));
      } catch (MalformedURLException e) {
        // Oops... fallback to default.
        article.setUrl(null);
      }

      articles.add(article);
    }

    Log.e("RSS ERROR", "Number of articles " + articles.size());
    return fillData(articles);
  }