Dialog when podcast's auto download preference is changed

When the user changes a podcast's auto download setting, ask if this
new setting should be applied to the podcast's episodes
This commit is contained in:
Martin Fietz 2015-08-01 12:17:50 +02:00
parent 8721dab1bc
commit cf519ca0aa
5 changed files with 67 additions and 10 deletions

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.activity;
import android.content.ClipData;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
@ -14,21 +15,21 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsSpinner;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Spinner;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.TextView;
import android.widget.Toast;
import com.joanzapata.android.iconify.Iconify;
import com.squareup.picasso.Picasso;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedPreferences;
@ -150,6 +151,9 @@ public class FeedInfoActivity extends ActionBarActivity {
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
feed.getPreferences().setAutoDownload(checked);
feed.savePreferences(FeedInfoActivity.this);
ApplyToEpisodesDialog dialog = new ApplyToEpisodesDialog(FeedInfoActivity.this,
feed, checked);
dialog.createNewDialog().show();
}
});
spnAutoDelete.setOnItemSelectedListener(new OnItemSelectedListener() {
@ -272,4 +276,23 @@ public class FeedInfoActivity extends ActionBarActivity {
return super.onOptionsItemSelected(item);
}
}
private class ApplyToEpisodesDialog extends ConfirmationDialog {
private final Feed feed;
private final boolean autoDownload;
public ApplyToEpisodesDialog(Context context, Feed feed, boolean autoDownload) {
super(context, R.string.auto_download_apply_to_items_title,
R.string.auto_download_apply_to_items_message);
this.feed = feed;
this.autoDownload = autoDownload;
}
@Override
public void onConfirmButtonPressed(DialogInterface dialog) {
DBWriter.setFeedsItemsAutoDownload(context, feed, autoDownload);
}
}
}

View File

@ -4,7 +4,7 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.R;
/**
@ -12,9 +12,10 @@ import de.danoeh.antennapod.core.R;
* classes can handle events like confirmation or cancellation.
*/
public abstract class ConfirmationDialog {
private static final String TAG = "ConfirmationDialog";
Context context;
private static final String TAG = ConfirmationDialog.class.getSimpleName();
protected Context context;
int titleId;
int messageId;
@ -25,8 +26,7 @@ public abstract class ConfirmationDialog {
}
public void onCancelButtonPressed(DialogInterface dialog) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Dialog was cancelled");
Log.d(TAG, "Dialog was cancelled");
dialog.dismiss();
}

View File

@ -1110,9 +1110,34 @@ public class DBWriter {
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
}
});
}
/**
* Sets the 'auto_download'-attribute of specific FeedItem.
*
* @param context A context that is used for opening a database connection.
* @param feed This feed's episodes will be processed.
* @param autoDownload If true, auto download will be enabled for the feed's episodes. Else,
* it will be disabled.
*/
public static Future<?> setFeedsItemsAutoDownload(final Context context, final Feed feed,
final boolean autoDownload) {
Log.d(TAG, (autoDownload ? "Enabling" : "Disabling") + " auto download for items of feed " + feed.getId());
return dbExec.submit(new Runnable() {
@Override
public void run() {
final PodDBAdapter adapter = new PodDBAdapter(context);
adapter.open();
adapter.setFeedsItemsAutoDownload(feed, autoDownload);
adapter.close();
EventDistributor.getInstance().sendUnreadItemsUpdateBroadcast();
}
});
}
/**
* Set filter of the feed
*

View File

@ -861,6 +861,13 @@ public class PodDBAdapter {
new String[]{String.valueOf(feedItem.getId())});
}
public void setFeedsItemsAutoDownload(Feed feed, boolean autoDownload) {
final String sql = "UPDATE " + TABLE_NAME_FEED_ITEMS
+ " SET " + KEY_AUTO_DOWNLOAD + "="+ (autoDownload ? "1" : "0")
+ " WHERE " + KEY_FEED + "=" + feed.getId();
db.execSQL(sql);
}
public long getDownloadLogSize() {
final String query = String.format("SELECT COUNT(%s) FROM %s", KEY_ID, TABLE_NAME_DOWNLOAD_LOG);
Cursor result = db.rawQuery(query, null);

View File

@ -75,6 +75,8 @@
<string name="close_label">Close</string>
<string name="retry_label">Retry</string>
<string name="auto_download_label">Include in auto downloads</string>
<string name="auto_download_apply_to_items_title">Apply Setting to Episodes</string>
<string name="auto_download_apply_to_items_message">Do you want to apply the podcast\'s new <i>Auto Download</i> setting to all of its episodes?</string>
<string name="auto_delete_label">Auto Delete Episode\n(override global default)</string>
<string name="parallel_downloads_suffix">\u0020parallel downloads</string>
<string name="feed_auto_download_global">Global</string>