Added refreshing functionality and Log messages

This commit is contained in:
Daniel Oeh 2012-04-12 22:37:38 +02:00
parent 58e229b7f9
commit eb24d41e1d
3 changed files with 16 additions and 1 deletions

View File

@ -48,6 +48,9 @@ public class FeedlistActivity extends SherlockListActivity {
case R.id.add_feed:
startActivity(new Intent(this, AddFeedActivity.class));
return true;
case R.id.all_feed_refresh:
manager.refreshAllFeeds(this);
return true;
default:
return super.onOptionsItemSelected(item);
}

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import de.podfetcher.storage.*;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
/**
@ -21,12 +22,13 @@ public class FeedManager {
private ArrayList<Feed> feeds;
private ArrayList<FeedCategory> categories;
private DownloadRequester requester;
private FeedManager() {
feeds = new ArrayList<Feed>();
categories = new ArrayList<FeedCategory>();
requester = DownloadRequester.getInstance();
}
@ -37,6 +39,13 @@ public class FeedManager {
return singleton;
}
public void refreshAllFeeds(Context context) {
Log.d(TAG, "Refreshing all feeds.");
for(Feed feed : feeds) {
requester.downloadFeed(context, feed);
}
}
private void addNewFeed(Context context, Feed feed) {
feeds.add(feed);
feed.setId(setFeed(context, feed));
@ -68,9 +77,11 @@ public class FeedManager {
// Look up feed in the feedslist
Feed savedFeed = searchFeedByLink(newFeed.getLink());
if(savedFeed == null) {
Log.d(TAG, "Found no existing Feed with title " + newFeed.getTitle() + ". Adding as new one.");
// Add a new Feed
addNewFeed(context, newFeed);
}else {
Log.d(TAG, "Feed with title " + newFeed.getTitle() + " already exists. Syncing new with existing one.");
// Look for new or updated Items
for(FeedItem item : newFeed.getItems()) {
FeedItem oldItem = searchFeedItemByLink(savedFeed, item.getLink());

View File

@ -51,6 +51,7 @@ public class DownloadRequester {
}
private void download(Context context, ArrayList<FeedFile> type, FeedFile item, File dest, boolean visibleInUI) {
Log.d(TAG, "Requesting download of url "+ item.getDownload_url());
type.add(item);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(item.getDownload_url()));
//request.allowScanningByMediaScanner();