Android Open Source - BBC-News-Reader R S S Manager






From Project

Back to project page BBC-News-Reader.

License

The source code is released under:

Copyright (c) 2011, 2012, Digital Lizard (Oscar Key, Thomas Boby) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the...

If you think the Android project BBC-News-Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * BBC News Reader/*from   w w  w  .  ja v a 2s .c  om*/
 * Released under the BSD License. See README or LICENSE.
 * Copyright (c) 2011, Digital Lizard (Oscar Key, Thomas Boby)
 * All rights reserved.
 ******************************************************************************/
package com.digitallizard.bbcnewsreader;

import java.util.ArrayList;
import java.util.List;

import org.mcsoxford.rss.RSSException;
import org.mcsoxford.rss.RSSFault;
import org.mcsoxford.rss.RSSFeed;
import org.mcsoxford.rss.RSSItem;
import org.mcsoxford.rss.RSSReader;

public class RSSManager implements Runnable {
  /* constants */
  
  /* variables */
  ResourceInterface resourceInterface;
  Thread thread;
  String[] names;
  String[] urls;
  ArrayList<RSSFeed> feeds;
  RSSReader reader;
  boolean isLoading;
  volatile boolean noError;
  
  synchronized void setIsLoading(boolean keepLoading) {
    this.isLoading = keepLoading;
  }
  
  synchronized boolean isLoading() {
    return isLoading;
  }
  
  public RSSManager(ResourceInterface service) {
    this.resourceInterface = service;
  }
  
  public void load(String[] names, String[] urls) {
    // check we are not already loading
    if (!isLoading()) {
      this.names = names; // store the names
      this.urls = urls; // store the URLS
      feeds = new ArrayList<RSSFeed>();
      thread = new Thread(this);
      setIsLoading(true);
      noError = true;
      thread.start();
    }
  }
  
  public void stopLoading() {
    noError = false;
    setIsLoading(false);
  }
  
  public void run() {
    // create a reader
    reader = new RSSReader();
    // load in the feeds
    for (int i = 0; i < urls.length; i++) {
      // check we haven't been cancelled
      if (isLoading()) {
        RSSFeed feed;
        try {
          feed = reader.load(urls[i]);
          feeds.add(feed);
          List<RSSItem> items = feed.getItems();
          // loop through the items and send them to the parent service
          resourceInterface.categoryRssLoaded(items.toArray(new RSSItem[items.size()]), names[i]);
        } catch (RSSException e) {
          // FIXME not a good way to handle these errors, will be fixed by new RSSManager
          // report the error to the resource service
          resourceInterface.reportError(ReaderActivity.ERROR_TYPE_GENERAL, "The rss feed could not be read.", e.toString());
          // give up loading
          stopLoading();
        } catch (RSSFault e) {
          // FIXME not a good way to handle these errors, will be fixed by new RSSManager
          // report the error to the resource service
          resourceInterface.reportError(ReaderActivity.ERROR_TYPE_INTERNET,
              "The rss feed could not be read. Check your internet connection.", e.toString());
          // give up loading
          stopLoading();
        }
      }
    }
    // report that the load is complete
    resourceInterface.rssLoadComplete(noError);
    setIsLoading(false); // we are not longer loading
  }
}




Java Source Code List

com.digitallizard.bbcnewsreader.ArticleActivity.java
com.digitallizard.bbcnewsreader.CategoryActivity.java
com.digitallizard.bbcnewsreader.CategoryChooserActivity.java
com.digitallizard.bbcnewsreader.CategoryChooserAdapter.java
com.digitallizard.bbcnewsreader.CategoryPagerAdapter.java
com.digitallizard.bbcnewsreader.Eula.java
com.digitallizard.bbcnewsreader.ItemAdapter.java
com.digitallizard.bbcnewsreader.ItemLayout.java
com.digitallizard.bbcnewsreader.Item.java
com.digitallizard.bbcnewsreader.RSSManager.java
com.digitallizard.bbcnewsreader.ReaderActivity.java
com.digitallizard.bbcnewsreader.ResourceInterface.java
com.digitallizard.bbcnewsreader.ResourceService.java
com.digitallizard.bbcnewsreader.ServiceManager.java
com.digitallizard.bbcnewsreader.SettingsActivity.java
com.digitallizard.bbcnewsreader.data.DatabaseHandler.java
com.digitallizard.bbcnewsreader.data.DatabaseHelper.java
com.digitallizard.bbcnewsreader.data.DatabaseProvider.java
com.digitallizard.bbcnewsreader.data.ItemClearer.java
com.digitallizard.bbcnewsreader.data.WrapBackwards.java
com.digitallizard.bbcnewsreader.fragments.ArticleFragment.java
com.digitallizard.bbcnewsreader.fragments.CategoryChooserFragment.java
com.digitallizard.bbcnewsreader.fragments.CategoryFragment.java
com.digitallizard.bbcnewsreader.fragments.FrontpageFragment.java
com.digitallizard.bbcnewsreader.resource.web.HtmlParser.java
com.digitallizard.bbcnewsreader.resource.web.ImageDownloader.java
com.digitallizard.bbcnewsreader.resource.web.QueueItem.java
com.digitallizard.bbcnewsreader.resource.web.WebManager.java
com.digitallizard.bbcnewsreader.widget.ReaderWidget.java
com.digitallizard.bbcnewsreader.widget.WidgetConfigActivity.java
com.hlidskialf.android.preference.SeekBarPreference.java