Feeds can now be removed in the background

This commit is contained in:
daniel oeh 2012-06-19 21:21:45 +02:00
parent 9533323167
commit 22918164c7
2 changed files with 71 additions and 2 deletions

View File

@ -0,0 +1,62 @@
package de.podfetcher.asynctask;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.AsyncTask;
/** Removes a feed in the background. */
public class FeedRemover extends AsyncTask<Feed, Void, Void> {
Context context;
ProgressDialog dialog;
public FeedRemover(Context context) {
super();
this.context = context;
}
@Override
protected Void doInBackground(Feed... params) {
FeedManager manager = FeedManager.getInstance();
for (Feed feed : params) {
manager.deleteFeed(context, feed);
if (isCancelled()) {
break;
}
}
return null;
}
@Override
protected void onCancelled() {
dialog.dismiss();
}
@Override
protected void onPostExecute(Void result) {
dialog.dismiss();
}
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(context);
dialog.setMessage("Removing Feed");
dialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
cancel(true);
}
});
dialog.show();
}
}

View File

@ -4,6 +4,7 @@ import de.podfetcher.R;
import de.podfetcher.feed.*;
import de.podfetcher.activity.*;
import de.podfetcher.adapter.FeedlistAdapter;
import de.podfetcher.asynctask.FeedRemover;
import de.podfetcher.storage.DownloadRequester;
import de.podfetcher.service.DownloadService;
import android.os.Bundle;
@ -148,8 +149,14 @@ public class FeedlistFragment extends SherlockListFragment {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.remove_item:
manager.deleteFeed(getSherlockActivity(), selectedFeed);
fla.notifyDataSetChanged();
FeedRemover remover = new FeedRemover(getSherlockActivity()){
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
fla.notifyDataSetChanged();
}
};
remover.execute(selectedFeed);
break;
}
mode.finish();