Added intermediate progressbar to main Activity

This commit is contained in:
daniel oeh 2012-06-25 12:35:11 +02:00
parent a2e0c6eecc
commit 703972e3c0
5 changed files with 70 additions and 31 deletions

View File

@ -56,13 +56,4 @@
android:textStyle="bold"
android:visibility="gone" />
<ImageView
android:id="@+id/imgvRefreshing"
android:src="@drawable/navigation_refresh"
android:layout_width="55dip"
android:layout_height="55dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="gone" />
</RelativeLayout>

View File

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

View File

@ -44,29 +44,25 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
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);
} else {
int newItems = feed.getNumOfNewItems();
if (newItems > 0) {
holder.newEpisodes.setText(Integer.toString(newItems));
@ -74,7 +70,6 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
} else {
holder.newEpisodes.setVisibility(View.INVISIBLE);
}
}
if (feed.getImage() != null) {
holder.image.setImageBitmap(feed.getImage().getImageBitmap()); // TODO
@ -96,7 +91,6 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
TextView numberOfEpisodes;
TextView newEpisodes;
ImageView image;
ImageView refreshing;
}
}

View File

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

View File

@ -134,6 +134,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) {
downloads.remove(f);