diff --git a/lint.xml b/lint.xml new file mode 100644 index 000000000..ee0eead5b --- /dev/null +++ b/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 000000000..f2fe1559a --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/project.properties b/project.properties index 7d7aaf426..a84a31943 100644 --- a/project.properties +++ b/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-10 -android.library.reference.1=libs/GreenDroid/GreenDroid +target=android-14 +android.library.reference.1=/home/daniel/src/android/actionbarsherlock/library/ diff --git a/src/de/podfetcher/activity/AddFeedActivity.java b/src/de/podfetcher/activity/AddFeedActivity.java index e5d9c64a8..14cd30e54 100644 --- a/src/de/podfetcher/activity/AddFeedActivity.java +++ b/src/de/podfetcher/activity/AddFeedActivity.java @@ -6,22 +6,20 @@ import android.widget.Button; import android.widget.EditText; import android.view.View; import de.podfetcher.R; -import de.podfetcher.feed.FeedManager; +import de.podfetcher.feed.Feed; +import de.podfetcher.storage.DownloadRequester; /** Activity for adding/editing a Feed */ public class AddFeedActivity extends Activity { private EditText etxtFeedurl; private Button butConfirm; - private FeedManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.addfeed); - manager = FeedManager.getInstance(); - etxtFeedurl = (EditText) findViewById(R.id.etxtFeedurl); butConfirm = (Button) findViewById(R.id.butConfirm); @@ -38,7 +36,9 @@ public class AddFeedActivity extends Activity { private void addNewFeed() { String url = etxtFeedurl.getText().toString(); - manager.addFeed(this, url); + Feed feed = new Feed(url); + DownloadRequester req = DownloadRequester.getInstance(); + req.downloadFeed(this, feed); } diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java index a3f3a12db..44794c2c5 100644 --- a/src/de/podfetcher/feed/FeedManager.java +++ b/src/de/podfetcher/feed/FeedManager.java @@ -37,24 +37,14 @@ public class FeedManager { return singleton; } - /** Add and Download a new Feed */ - public void addFeed(Context context, String url) { - // TODO Check if URL is correct - PodDBAdapter adapter = new PodDBAdapter(context); - Feed feed = new Feed(url); - feed.download_url = url; - feed.id = adapter.setFeed(feed); - // Add Feed to Feedlist if not available - Feed foundFeed = getFeed(feed.id); - if(foundFeed == null) { - feeds.add(feed); - }else { - feed = foundFeed; + private void addNewFeed(Context context, Feed feed) { + feeds.add(feed); + feed.setId(setFeed(context, feed)); + for(FeedItem item : feed.getItems()) { + setFeedItem(context, item); } - DownloadRequester req = DownloadRequester.getInstance(); - req.downloadFeed(context, feed); - - } + } + /** Adds a new Feeditem if its not in the list */ public void addFeedItem(Context context, FeedItem item) { @@ -74,6 +64,30 @@ public class FeedManager { } } + public void updateFeed(Context context, Feed newFeed) { + // Look up feed in the feedslist + Feed savedFeed = searchFeedByLink(newFeed.getLink()); + if(savedFeed == null) { + // Add a new Feed + addNewFeed(context, newFeed); + }else { + // Look for new or updated Items + for(FeedItem item : newFeed.getItems()) { + FeedItem oldItem = searchFeedItemByLink(savedFeed, item.getLink()); + if(oldItem != null) { + FeedItem newItem = searchFeedItemByLink(newFeed, item.getLink()); + if(newItem != null) { + newItem.setRead(oldItem.isRead()); + } + } + } + newFeed.setId(savedFeed.getId()); + savedFeed = newFeed; + setFeed(context, newFeed); + } + + } + /** Get a Feed by its link */ private Feed searchFeedByLink(String link) { for(Feed feed : feeds) { @@ -95,9 +109,14 @@ public class FeedManager { } /** Updates Information of an existing Feed */ - public void setFeed(Context context, Feed feed) { + public long setFeed(Context context, Feed feed) { PodDBAdapter adapter = new PodDBAdapter(context); - adapter.setFeed(feed); + return adapter.setFeed(feed); + } + + public long setFeedItem(Context context, FeedItem item) { + PodDBAdapter adapter = new PodDBAdapter(context); + return adapter.setFeedItem(item); } /** Get a Feed by its id */ diff --git a/src/de/podfetcher/service/DownloadService.java b/src/de/podfetcher/service/DownloadService.java index 2fc11ca0e..26e62069f 100644 --- a/src/de/podfetcher/service/DownloadService.java +++ b/src/de/podfetcher/service/DownloadService.java @@ -106,8 +106,6 @@ public class DownloadService extends Service { requester.removeFeed(feed); // Get Feed Information feed.setFile_url((new File(requester.getFeedfilePath(context), requester.getFeedfileName(feed.getId()))).toString()); - // Update Information in Database - manager.setFeed(context, feed); // Download Feed Image if provided if(feed.getImage() != null) { Log.d(this.toString(), "Feed has image; Downloading...."); @@ -142,13 +140,8 @@ public class DownloadService extends Service { feed = handler.parseFeed(feed); Log.d(this.toString(), feed.getTitle() + " parsed"); // Save information of feed in DB - Log.d(this.toString(), "Passing new Feed to DB"); - manager.setFeed(service, feed); - // Add Feeditems to the database + manager.updateFeed(service, feed); Log.d(this.toString(), "Walking through " + feed.getItems().size() + " feeditems"); - for(FeedItem item : feed.getItems()) { - manager.addFeedItem(service, item); - } Log.d(this.toString(), "Done."); }