From f73c4020055f5eaab121ca1959c2cd8dda54ccf0 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 9 Jul 2012 13:51:08 +0200 Subject: Added menu item to update a single feed --- .../podfetcher/activity/FeedItemlistActivity.java | 3 +++ src/de/podfetcher/feed/FeedManager.java | 8 +++++-- src/de/podfetcher/fragment/ItemlistFragment.java | 27 ++++++++++++++++++++-- src/de/podfetcher/storage/DownloadRequester.java | 12 ++++++++++ src/de/podfetcher/util/FeedMenuHandler.java | 19 ++++++++++++++- 5 files changed, 64 insertions(+), 5 deletions(-) (limited to 'src/de') diff --git a/src/de/podfetcher/activity/FeedItemlistActivity.java b/src/de/podfetcher/activity/FeedItemlistActivity.java index 4e3aeabd3..e4642eb46 100644 --- a/src/de/podfetcher/activity/FeedItemlistActivity.java +++ b/src/de/podfetcher/activity/FeedItemlistActivity.java @@ -12,6 +12,7 @@ import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.Window; import de.podfetcher.R; import de.podfetcher.asynctask.FeedRemover; @@ -34,6 +35,8 @@ public class FeedItemlistActivity extends SherlockFragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.feeditemlist_activity); diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java index c564f0070..86cb6e806 100644 --- a/src/de/podfetcher/feed/FeedManager.java +++ b/src/de/podfetcher/feed/FeedManager.java @@ -172,10 +172,14 @@ public class FeedManager { public void refreshAllFeeds(Context context) { Log.d(TAG, "Refreshing all feeds."); for (Feed feed : feeds) { - requester.downloadFeed(context, new Feed(feed.getDownload_url(), - new Date())); + refreshFeed(context, feed); } } + + public void refreshFeed(Context context, Feed feed) { + requester.downloadFeed(context, new Feed(feed.getDownload_url(), + new Date())); + } public long addDownloadStatus(Context context, DownloadStatus status) { PodDBAdapter adapter = new PodDBAdapter(context); diff --git a/src/de/podfetcher/fragment/ItemlistFragment.java b/src/de/podfetcher/fragment/ItemlistFragment.java index 438f0873d..a4870c3dd 100644 --- a/src/de/podfetcher/fragment/ItemlistFragment.java +++ b/src/de/podfetcher/fragment/ItemlistFragment.java @@ -21,6 +21,7 @@ import com.actionbarsherlock.view.MenuItem; import de.podfetcher.R; import de.podfetcher.activity.ItemviewActivity; import de.podfetcher.adapter.FeedItemlistAdapter; +import de.podfetcher.feed.Feed; import de.podfetcher.feed.FeedItem; import de.podfetcher.feed.FeedManager; import de.podfetcher.service.DownloadService; @@ -31,7 +32,7 @@ import de.podfetcher.util.FeedItemMenuHandler; public class ItemlistFragment extends SherlockListFragment implements ActionMode.Callback { - private static final String TAG = "FeedItemlistFragment"; + private static final String TAG = "ItemlistFragment"; public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem"; public static final String ARGUMENT_FEED_ID = "argument.de.podfetcher.feed_id"; protected FeedItemlistAdapter fila; @@ -40,6 +41,11 @@ public class ItemlistFragment extends SherlockListFragment implements /** The feed which the activity displays */ protected ArrayList items; + /** + * This is only not null if the fragment displays the items of a specific + * feed + */ + protected Feed feed; protected FeedItem selectedItem; protected ActionMode mActionMode; @@ -80,7 +86,8 @@ public class ItemlistFragment extends SherlockListFragment implements super.onCreate(savedInstanceState); if (items == null) { long feedId = getArguments().getLong(ARGUMENT_FEED_ID); - items = FeedManager.getInstance().getFeed(feedId).getItems(); + feed = FeedManager.getInstance().getFeed(feedId); + items = feed.getItems(); } fila = new FeedItemlistAdapter(getActivity(), 0, items, onButActionClicked, showFeedtitle); @@ -100,6 +107,7 @@ public class ItemlistFragment extends SherlockListFragment implements public void onResume() { super.onResume(); fila.notifyDataSetChanged(); + updateProgressBarVisibility(); IntentFilter filter = new IntentFilter(); filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED); filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED); @@ -123,9 +131,24 @@ public class ItemlistFragment extends SherlockListFragment implements public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received contentUpdate Intent."); fila.notifyDataSetChanged(); + updateProgressBarVisibility(); } }; + private void updateProgressBarVisibility() { + if (feed != null) { + if (DownloadService.isRunning + && DownloadRequester.getInstance().isDownloadingFile(feed)) { + getSherlockActivity() + .setSupportProgressBarIndeterminateVisibility(true); + } else { + getSherlockActivity() + .setSupportProgressBarIndeterminateVisibility(false); + } + getSherlockActivity().invalidateOptionsMenu(); + } + } + private final OnClickListener onButActionClicked = new OnClickListener() { @Override public void onClick(View v) { diff --git a/src/de/podfetcher/storage/DownloadRequester.java b/src/de/podfetcher/storage/DownloadRequester.java index f859fd409..06e125df8 100644 --- a/src/de/podfetcher/storage/DownloadRequester.java +++ b/src/de/podfetcher/storage/DownloadRequester.java @@ -11,6 +11,7 @@ import de.podfetcher.R; import android.util.Log; import android.database.Cursor; +import android.annotation.SuppressLint; import android.app.DownloadManager; import android.content.Context; import android.net.Uri; @@ -54,6 +55,7 @@ public class DownloadRequester { return downloader; } + @SuppressLint("NewApi") private long download(Context context, FeedFile item, File dest) { if (dest.exists()) { Log.d(TAG, "File already exists. Deleting !"); @@ -157,6 +159,16 @@ public class DownloadRequester { } return false; } + + /** Checks if feedfile is in the downloads list */ + public boolean isDownloadingFile(FeedFile item) { + for (FeedFile f : downloads) { + if (f.getDownload_url().equals(item.getDownload_url())) { + return true; + } + } + return false; + } /** Remove an object from the downloads-list of the requester. */ public void removeDownload(FeedFile f) { diff --git a/src/de/podfetcher/util/FeedMenuHandler.java b/src/de/podfetcher/util/FeedMenuHandler.java index dcf6f3f32..10fdcb2ab 100644 --- a/src/de/podfetcher/util/FeedMenuHandler.java +++ b/src/de/podfetcher/util/FeedMenuHandler.java @@ -3,6 +3,7 @@ package de.podfetcher.util; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.util.Log; import com.actionbarsherlock.view.ActionMode; import com.actionbarsherlock.view.Menu; @@ -14,9 +15,12 @@ import de.podfetcher.activity.FeedInfoActivity; import de.podfetcher.feed.Feed; import de.podfetcher.feed.FeedItem; import de.podfetcher.feed.FeedManager; +import de.podfetcher.service.DownloadService; +import de.podfetcher.storage.DownloadRequester; /** Handles interactions with the FeedItemMenu. */ public class FeedMenuHandler { + private static final String TAG = "FeedMenuHandler"; public static boolean onCreateOptionsMenu(MenuInflater inflater, Menu menu) { inflater.inflate(R.menu.feedlist, menu); @@ -24,9 +28,18 @@ public class FeedMenuHandler { } public static boolean onPrepareOptionsMenu(Menu menu, Feed selectedFeed) { + Log.d(TAG, "Preparing options menu"); if (selectedFeed.getPaymentLink() != null) { menu.findItem(R.id.support_item).setVisible(true); } + MenuItem refresh = menu.findItem(R.id.refresh_item); + if (DownloadService.isRunning + && DownloadRequester.getInstance().isDownloadingFile( + selectedFeed)) { + refresh.setVisible(false); + } else { + refresh.setVisible(true); + } return true; } @@ -37,9 +50,13 @@ public class FeedMenuHandler { switch (item.getItemId()) { case R.id.show_info_item: Intent startIntent = new Intent(context, FeedInfoActivity.class); - startIntent.putExtra(FeedInfoActivity.EXTRA_FEED_ID, selectedFeed.getId()); + startIntent.putExtra(FeedInfoActivity.EXTRA_FEED_ID, + selectedFeed.getId()); context.startActivity(startIntent); break; + case R.id.refresh_item: + manager.refreshFeed(context, selectedFeed); + break; case R.id.mark_all_read_item: manager.markFeedRead(context, selectedFeed); break; -- cgit v1.2.3