diff --git a/res/layout/feedlist_item.xml b/res/layout/feedlist_item.xml index 12d1afb80..4f90d3d74 100644 --- a/res/layout/feedlist_item.xml +++ b/res/layout/feedlist_item.xml @@ -55,14 +55,5 @@ android:textSize="20dp" android:textStyle="bold" android:visibility="gone" /> - - \ No newline at end of file diff --git a/src/de/podfetcher/activity/PodfetcherActivity.java b/src/de/podfetcher/activity/PodfetcherActivity.java index 338965e23..24264c64b 100644 --- a/src/de/podfetcher/activity/PodfetcherActivity.java +++ b/src/de/podfetcher/activity/PodfetcherActivity.java @@ -1,13 +1,18 @@ package de.podfetcher.activity; import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.actionbarsherlock.view.Window; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.Tab; @@ -22,6 +27,8 @@ import de.podfetcher.fragment.ItemlistFragment; import de.podfetcher.fragment.FeedlistFragment; import de.podfetcher.fragment.QueueFragment; import de.podfetcher.fragment.UnreadItemlistFragment; +import de.podfetcher.service.DownloadService; +import de.podfetcher.storage.DownloadRequester; public class PodfetcherActivity extends SherlockFragmentActivity { private static final String TAG = "PodfetcherActivity"; @@ -36,6 +43,7 @@ public class PodfetcherActivity extends SherlockFragmentActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); manager = FeedManager.getInstance(); + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.main); // Set up tabs ActionBar actionBar = getSupportActionBar(); @@ -71,6 +79,38 @@ public class PodfetcherActivity extends SherlockFragmentActivity { actionBar.addTab(tab); } + @Override + protected void onPause() { + super.onPause(); + unregisterReceiver(contentUpdate); + } + + @Override + protected void onResume() { + super.onResume(); + updateProgressBarVisibility(); + IntentFilter filter = new IntentFilter(); + filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED); + filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED); + registerReceiver(contentUpdate, filter); + } + + private BroadcastReceiver contentUpdate = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + Log.d(TAG, "Received contentUpdate Intent."); + updateProgressBarVisibility(); + } + }; + + private void updateProgressBarVisibility() { + if (DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFeeds()) { + setSupportProgressBarIndeterminateVisibility(true); + } else { + setSupportProgressBarIndeterminateVisibility(false); + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { diff --git a/src/de/podfetcher/adapter/FeedlistAdapter.java b/src/de/podfetcher/adapter/FeedlistAdapter.java index e229a55f3..99676e866 100644 --- a/src/de/podfetcher/adapter/FeedlistAdapter.java +++ b/src/de/podfetcher/adapter/FeedlistAdapter.java @@ -23,7 +23,7 @@ import android.graphics.Color; public class FeedlistAdapter extends ArrayAdapter { private static final String TAG = "FeedlistAdapter"; - + public FeedlistAdapter(Context context, int textViewResourceId, List objects) { super(context, textViewResourceId, objects); @@ -43,39 +43,34 @@ public class FeedlistAdapter extends ArrayAdapter { convertView = inflater.inflate(R.layout.feedlist_item, null); holder.title = (TextView) convertView .findViewById(R.id.txtvFeedname); - - holder.newEpisodes = (TextView) convertView.findViewById(R.id.txtvNewEps); + + holder.newEpisodes = (TextView) convertView + .findViewById(R.id.txtvNewEps); holder.image = (ImageView) convertView .findViewById(R.id.imgvFeedimage); holder.lastUpdate = (TextView) convertView .findViewById(R.id.txtvLastUpdate); - holder.numberOfEpisodes = (TextView) convertView.findViewById(R.id.txtvNumEpisodes); + holder.numberOfEpisodes = (TextView) convertView + .findViewById(R.id.txtvNumEpisodes); convertView.setTag(holder); - holder.refreshing = (ImageView) convertView.findViewById(R.id.imgvRefreshing); } else { holder = (Holder) convertView.getTag(); } holder.title.setText(feed.getTitle()); - holder.lastUpdate.setText("Last Update: " + DateUtils.formatSameDayTime(feed - .getLastUpdate().getTime(), System.currentTimeMillis(), - DateFormat.SHORT, DateFormat.SHORT)); + holder.lastUpdate.setText("Last Update: " + + DateUtils.formatSameDayTime(feed.getLastUpdate().getTime(), + System.currentTimeMillis(), DateFormat.SHORT, + DateFormat.SHORT)); holder.numberOfEpisodes.setText(feed.getItems().size() + " Episodes"); - - if (DownloadRequester.getInstance().downloads.contains(feed)) { - Log.d(TAG, "Feed is downloading"); - holder.newEpisodes.setVisibility(View.GONE); - holder.refreshing.setVisibility(View.VISIBLE); + int newItems = feed.getNumOfNewItems(); + if (newItems > 0) { + holder.newEpisodes.setText(Integer.toString(newItems)); + holder.newEpisodes.setVisibility(View.VISIBLE); } else { - int newItems = feed.getNumOfNewItems(); - if (newItems > 0) { - holder.newEpisodes.setText(Integer.toString(newItems)); - holder.newEpisodes.setVisibility(View.VISIBLE); - } else { - holder.newEpisodes.setVisibility(View.INVISIBLE); - } + holder.newEpisodes.setVisibility(View.INVISIBLE); } - + if (feed.getImage() != null) { holder.image.setImageBitmap(feed.getImage().getImageBitmap()); // TODO // select @@ -96,7 +91,6 @@ public class FeedlistAdapter extends ArrayAdapter { TextView numberOfEpisodes; TextView newEpisodes; ImageView image; - ImageView refreshing; } } diff --git a/src/de/podfetcher/service/DownloadService.java b/src/de/podfetcher/service/DownloadService.java index 9f78bd1f5..c453c03d3 100644 --- a/src/de/podfetcher/service/DownloadService.java +++ b/src/de/podfetcher/service/DownloadService.java @@ -64,6 +64,8 @@ public class DownloadService extends Service { private DownloadManager downloadManager; private volatile boolean shutdownInitiated = false; + /** True if service is running. */ + public static boolean isRunning = false; private final IBinder mBinder = new LocalBinder(); @@ -82,6 +84,7 @@ public class DownloadService extends Service { @Override public void onCreate() { Log.d(TAG, "Service started"); + isRunning = true; registerReceiver(downloadReceiver, createIntentFilter()); syncExecutor = Executors.newSingleThreadExecutor(); manager = FeedManager.getInstance(); @@ -99,6 +102,7 @@ public class DownloadService extends Service { @Override public void onDestroy() { Log.d(TAG, "Service shutting down"); + isRunning = false; sendBroadcast(new Intent(ACTION_FEED_SYNC_COMPLETED)); mediaplayer.release(); unregisterReceiver(downloadReceiver); diff --git a/src/de/podfetcher/storage/DownloadRequester.java b/src/de/podfetcher/storage/DownloadRequester.java index 2707f8844..66b921d07 100644 --- a/src/de/podfetcher/storage/DownloadRequester.java +++ b/src/de/podfetcher/storage/DownloadRequester.java @@ -133,6 +133,16 @@ public class DownloadRequester { } return null; } + + /** Returns true if there is at least one Feed in the downloads queue. */ + public boolean isDownloadingFeeds() { + for (FeedFile f : downloads) { + if (f.getClass() == Feed.class) { + return true; + } + } + return false; + } /** Remove an object from the downloads-list of the requester. */ public void removeDownload(FeedFile f) {