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_title">Display only episodes</string>
|
||||||
<string name="pref_display_only_episodes_sum">Display only items which also have an episode.</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="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>
|
</resources>
|
|
@ -1,6 +1,7 @@
|
||||||
package de.danoeh.antennapod.activity;
|
package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -16,6 +17,7 @@ import com.actionbarsherlock.view.Window;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.asynctask.FeedRemover;
|
import de.danoeh.antennapod.asynctask.FeedRemover;
|
||||||
|
import de.danoeh.antennapod.dialog.ConfirmationDialog;
|
||||||
import de.danoeh.antennapod.feed.Feed;
|
import de.danoeh.antennapod.feed.Feed;
|
||||||
import de.danoeh.antennapod.feed.FeedManager;
|
import de.danoeh.antennapod.feed.FeedManager;
|
||||||
import de.danoeh.antennapod.fragment.FeedlistFragment;
|
import de.danoeh.antennapod.fragment.FeedlistFragment;
|
||||||
|
@ -88,19 +90,25 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
||||||
} else {
|
} else {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.remove_item:
|
case R.id.remove_item:
|
||||||
FeedRemover remover = new FeedRemover(this) {
|
final FeedRemover remover = new FeedRemover(
|
||||||
|
FeedItemlistActivity.this, feed) {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void result) {
|
protected void onPostExecute(Void result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
ConfirmationDialog conDialog = new ConfirmationDialog(this,
|
||||||
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
R.string.remove_feed_label,
|
||||||
feed);
|
R.string.feed_delete_confirmation_msg) {
|
||||||
} else {
|
|
||||||
remover.execute(feed);
|
@Override
|
||||||
}
|
public void onConfirmButtonPressed(DialogInterface dialog) {
|
||||||
|
dialog.dismiss();
|
||||||
|
remover.executeAsync();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
conDialog.createNewDialog().show();
|
||||||
break;
|
break;
|
||||||
case R.id.search_item:
|
case R.id.search_item:
|
||||||
onSearchRequested();
|
onSearchRequested();
|
||||||
|
@ -121,6 +129,4 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,25 +9,21 @@ import android.content.DialogInterface.OnCancelListener;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
/** Removes a feed in the background. */
|
/** Removes a feed in the background. */
|
||||||
public class FeedRemover extends AsyncTask<Feed, Void, Void> {
|
public class FeedRemover extends AsyncTask<Void, Void, Void> {
|
||||||
Context context;
|
Context context;
|
||||||
ProgressDialog dialog;
|
ProgressDialog dialog;
|
||||||
|
Feed feed;
|
||||||
|
|
||||||
public FeedRemover(Context context) {
|
public FeedRemover(Context context, Feed feed) {
|
||||||
super();
|
super();
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.feed = feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Feed... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
FeedManager manager = FeedManager.getInstance();
|
FeedManager manager = FeedManager.getInstance();
|
||||||
for (Feed feed : params) {
|
manager.deleteFeed(context, feed);
|
||||||
manager.deleteFeed(context, feed);
|
|
||||||
if (isCancelled()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +53,12 @@ public class FeedRemover extends AsyncTask<Feed, Void, Void> {
|
||||||
dialog.show();
|
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();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onConfirmButtonPressed();
|
public abstract void onConfirmButtonPressed(DialogInterface dialog);
|
||||||
|
|
||||||
public final AlertDialog createNewDialog() {
|
public final AlertDialog createNewDialog() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
@ -41,7 +41,7 @@ public abstract class ConfirmationDialog {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
onConfirmButtonPressed();
|
onConfirmButtonPressed(dialog);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.cancel_label,
|
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. */
|
/** Remove a feed with all its items and media files and its image. */
|
||||||
public void deleteFeed(final Context context, final Feed feed) {
|
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() {
|
dbExec.execute(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -183,14 +191,6 @@ public class FeedManager {
|
||||||
|
|
||||||
adapter.removeFeed(feed);
|
adapter.removeFeed(feed);
|
||||||
adapter.close();
|
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.activity.*;
|
||||||
import de.danoeh.antennapod.adapter.FeedlistAdapter;
|
import de.danoeh.antennapod.adapter.FeedlistAdapter;
|
||||||
import de.danoeh.antennapod.asynctask.FeedRemover;
|
import de.danoeh.antennapod.asynctask.FeedRemover;
|
||||||
|
import de.danoeh.antennapod.dialog.ConfirmationDialog;
|
||||||
import de.danoeh.antennapod.feed.*;
|
import de.danoeh.antennapod.feed.*;
|
||||||
import de.danoeh.antennapod.service.DownloadService;
|
import de.danoeh.antennapod.service.DownloadService;
|
||||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||||
|
@ -16,6 +17,7 @@ import android.app.Activity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
@ -173,19 +175,21 @@ public class FeedlistFragment extends SherlockFragment implements
|
||||||
} else {
|
} else {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.remove_item:
|
case R.id.remove_item:
|
||||||
FeedRemover remover = new FeedRemover(getSherlockActivity()) {
|
final FeedRemover remover = new FeedRemover(getSherlockActivity(), selectedFeed) {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void result) {
|
protected void onPostExecute(Void result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
fla.notifyDataSetChanged();
|
fla.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
ConfirmationDialog conDialog = new ConfirmationDialog(getActivity(), R.string.remove_feed_label, R.string.feed_delete_confirmation_msg){
|
||||||
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
|
||||||
selectedFeed);
|
@Override
|
||||||
} else {
|
public void onConfirmButtonPressed(DialogInterface dialog) {
|
||||||
remover.execute(selectedFeed);
|
dialog.dismiss();
|
||||||
}
|
remover.executeAsync();
|
||||||
|
}};
|
||||||
|
conDialog.createNewDialog().show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue