Feeds can now be removed in the background
This commit is contained in:
parent
9533323167
commit
22918164c7
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue