Added confirmation dialog when deleting a feed
This commit is contained in:
parent
b20bdea18e
commit
1dce5a3061
|
@ -174,6 +174,7 @@
|
|||
<string name="pref_display_only_episodes_title">Display only episodes</string>
|
||||
<string name="pref_display_only_episodes_sum">Display only items which also have an episode.</string>
|
||||
<string name="user_interface_label">User Interface</string>
|
||||
<string name="feed_delete_confirmation_msg">Please confirm that you want to delete this feed and ALL episodes of this feed that you have downloaded.</string>
|
||||
|
||||
|
||||
</resources>
|
|
@ -1,6 +1,7 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -16,6 +17,7 @@ import com.actionbarsherlock.view.Window;
|
|||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.asynctask.FeedRemover;
|
||||
import de.danoeh.antennapod.dialog.ConfirmationDialog;
|
||||
import de.danoeh.antennapod.feed.Feed;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.fragment.FeedlistFragment;
|
||||
|
@ -88,19 +90,25 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
|||
} else {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.remove_item:
|
||||
FeedRemover remover = new FeedRemover(this) {
|
||||
final FeedRemover remover = new FeedRemover(
|
||||
FeedItemlistActivity.this, feed) {
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
finish();
|
||||
}
|
||||
};
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
feed);
|
||||
} else {
|
||||
remover.execute(feed);
|
||||
}
|
||||
ConfirmationDialog conDialog = new ConfirmationDialog(this,
|
||||
R.string.remove_feed_label,
|
||||
R.string.feed_delete_confirmation_msg) {
|
||||
|
||||
@Override
|
||||
public void onConfirmButtonPressed(DialogInterface dialog) {
|
||||
dialog.dismiss();
|
||||
remover.executeAsync();
|
||||
}
|
||||
};
|
||||
conDialog.createNewDialog().show();
|
||||
break;
|
||||
case R.id.search_item:
|
||||
onSearchRequested();
|
||||
|
@ -120,7 +128,5 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
|||
startSearch(null, false, bundle, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,28 +9,24 @@ import android.content.DialogInterface.OnCancelListener;
|
|||
import android.os.AsyncTask;
|
||||
|
||||
/** Removes a feed in the background. */
|
||||
public class FeedRemover extends AsyncTask<Feed, Void, Void> {
|
||||
public class FeedRemover extends AsyncTask<Void, Void, Void> {
|
||||
Context context;
|
||||
ProgressDialog dialog;
|
||||
|
||||
public FeedRemover(Context context) {
|
||||
Feed feed;
|
||||
|
||||
public FeedRemover(Context context, Feed feed) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.feed = feed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Feed... params) {
|
||||
protected Void doInBackground(Void... params) {
|
||||
FeedManager manager = FeedManager.getInstance();
|
||||
for (Feed feed : params) {
|
||||
manager.deleteFeed(context, feed);
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
manager.deleteFeed(context, feed);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
dialog.dismiss();
|
||||
|
@ -50,13 +46,19 @@ public class FeedRemover extends AsyncTask<Feed, Void, Void> {
|
|||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
cancel(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void executeAsync() {
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public abstract class ConfirmationDialog {
|
|||
dialog.dismiss();
|
||||
}
|
||||
|
||||
public abstract void onConfirmButtonPressed();
|
||||
public abstract void onConfirmButtonPressed(DialogInterface dialog);
|
||||
|
||||
public final AlertDialog createNewDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
@ -41,7 +41,7 @@ public abstract class ConfirmationDialog {
|
|||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onConfirmButtonPressed();
|
||||
onConfirmButtonPressed(dialog);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel_label,
|
||||
|
|
|
@ -144,6 +144,14 @@ public class FeedManager {
|
|||
|
||||
/** Remove a feed with all its items and media files and its image. */
|
||||
public void deleteFeed(final Context context, final Feed feed) {
|
||||
contentChanger.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
feeds.remove(feed);
|
||||
sendFeedUpdateBroadcast(context);
|
||||
}
|
||||
});
|
||||
dbExec.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -183,14 +191,6 @@ public class FeedManager {
|
|||
|
||||
adapter.removeFeed(feed);
|
||||
adapter.close();
|
||||
contentChanger.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
feeds.remove(feed);
|
||||
sendFeedUpdateBroadcast(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment;
|
|||
import de.danoeh.antennapod.activity.*;
|
||||
import de.danoeh.antennapod.adapter.FeedlistAdapter;
|
||||
import de.danoeh.antennapod.asynctask.FeedRemover;
|
||||
import de.danoeh.antennapod.dialog.ConfirmationDialog;
|
||||
import de.danoeh.antennapod.feed.*;
|
||||
import de.danoeh.antennapod.service.DownloadService;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
|
@ -16,6 +17,7 @@ import android.app.Activity;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.LayoutInflater;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
@ -173,19 +175,21 @@ public class FeedlistFragment extends SherlockFragment implements
|
|||
} else {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.remove_item:
|
||||
FeedRemover remover = new FeedRemover(getSherlockActivity()) {
|
||||
final FeedRemover remover = new FeedRemover(getSherlockActivity(), selectedFeed) {
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
fla.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
selectedFeed);
|
||||
} else {
|
||||
remover.execute(selectedFeed);
|
||||
}
|
||||
ConfirmationDialog conDialog = new ConfirmationDialog(getActivity(), R.string.remove_feed_label, R.string.feed_delete_confirmation_msg){
|
||||
|
||||
@Override
|
||||
public void onConfirmButtonPressed(DialogInterface dialog) {
|
||||
dialog.dismiss();
|
||||
remover.executeAsync();
|
||||
}};
|
||||
conDialog.createNewDialog().show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue