Added menu item to update a single feed

This commit is contained in:
daniel oeh 2012-07-09 13:51:08 +02:00
parent d4188088ce
commit f73c402005
8 changed files with 68 additions and 7 deletions

View File

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/mark_all_read_item" android:title="@string/mark_all_read_label" android:showAsAction="ifRoom|withText"></item><item android:id="@+id/show_info_item" android:icon="@drawable/action_about" android:title="@string/show_info_label" android:showAsAction="always"></item><item android:id="@+id/remove_item" android:title="@string/remove_feed_label" android:icon="@drawable/content_discard" android:visible="true" android:showAsAction="collapseActionView"></item>
<item android:id="@+id/refresh_item" android:title="@string/refresh_label" android:showAsAction="collapseActionView"></item><item android:id="@+id/mark_all_read_item" android:title="@string/mark_all_read_label" android:showAsAction="ifRoom|withText"></item><item android:id="@+id/show_info_item" android:icon="@drawable/action_about" android:title="@string/show_info_label" android:showAsAction="always"></item><item android:id="@+id/remove_item" android:title="@string/remove_feed_label" android:icon="@drawable/content_discard" android:visible="true" android:showAsAction="collapseActionView"></item>
<item android:id="@+id/visit_website_item" android:showAsAction="ifRoom|collapseActionView" android:icon="@drawable/location_web_site" android:title="@string/visit_website_label" android:visible="true"></item>
<item android:id="@+id/support_item" android:title="@string/support_label" android:showAsAction="collapseActionView" android:visible="false"></item>
</menu>

View File

@ -8,7 +8,7 @@
</item>
<item
android:id="@+id/all_feed_refresh"
android:title="Refresh"
android:title="@string/refresh_label"
android:icon="@drawable/navigation_refresh"
android:showAsAction="ifRoom|collapseActionView">
</item>

View File

@ -92,5 +92,6 @@
<string name="pref_mobileUpdate_title">Mobile Updates</string>
<string name="pref_mobileUpdate_sum">Allow updates over the mobile data connection</string>
<string name="download_report_title">All downloads completed</string>
<string name="refresh_label">Refresh</string>
</resources>

View File

@ -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);

View File

@ -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);

View File

@ -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<FeedItem> 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) {

View File

@ -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) {

View File

@ -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;