Added new per-feed auto download override flag.

This commit is contained in:
Udi Finkelstein 2015-06-24 23:13:44 +03:00
parent 0d2f99a1a7
commit 85598f64a9
16 changed files with 137 additions and 22 deletions

View File

@ -14,11 +14,15 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsSpinner;
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.Toast;
import com.joanzapata.android.iconify.Iconify;
@ -41,6 +45,7 @@ import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
*/
public class FeedInfoActivity extends ActionBarActivity {
private static final String TAG = "FeedInfoActivity";
private boolean autoDeleteChanged = false;
public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId";
@ -55,6 +60,7 @@ public class FeedInfoActivity extends ActionBarActivity {
private EditText etxtUsername;
private EditText etxtPassword;
private CheckBox cbxAutoDownload;
private Spinner spnAutoDelete;
private final View.OnClickListener copyUrlToClipboard = new View.OnClickListener() {
@Override
@ -92,6 +98,7 @@ public class FeedInfoActivity extends ActionBarActivity {
txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
txtvUrl = (TextView) findViewById(R.id.txtvUrl);
cbxAutoDownload = (CheckBox) findViewById(R.id.cbxAutoDownload);
spnAutoDelete = (Spinner) findViewById(R.id.spnAutoDelete);
etxtUsername = (EditText) findViewById(R.id.etxtUsername);
etxtPassword = (EditText) findViewById(R.id.etxtPassword);
@ -111,6 +118,7 @@ public class FeedInfoActivity extends ActionBarActivity {
Log.d(TAG, "Language is " + feed.getLanguage());
Log.d(TAG, "Author is " + feed.getAuthor());
Log.d(TAG, "URL is " + feed.getDownload_url());
FeedPreferences prefs = feed.getPreferences();
imgvCover.post(new Runnable() {
@Override
@ -136,7 +144,7 @@ public class FeedInfoActivity extends ActionBarActivity {
Iconify.addIcons(txtvUrl);
cbxAutoDownload.setEnabled(UserPreferences.isEnableAutodownload());
cbxAutoDownload.setChecked(feed.getPreferences().getAutoDownload());
cbxAutoDownload.setChecked(prefs.getAutoDownload());
cbxAutoDownload.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -144,9 +152,38 @@ public class FeedInfoActivity extends ActionBarActivity {
feed.savePreferences(FeedInfoActivity.this);
}
});
spnAutoDelete.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
FeedPreferences.AutoDeleteAction auto_delete_action;
switch (parent.getSelectedItemPosition()) {
case 0:
auto_delete_action = FeedPreferences.AutoDeleteAction.GLOBAL;
break;
etxtUsername.setText(feed.getPreferences().getUsername());
etxtPassword.setText(feed.getPreferences().getPassword());
case 1:
auto_delete_action = FeedPreferences.AutoDeleteAction.YES;
break;
case 2:
auto_delete_action = FeedPreferences.AutoDeleteAction.NO;
break;
default: // TODO - add exceptions here
return;
}
feed.getPreferences().setAutoDeleteAction(auto_delete_action);// p
autoDeleteChanged = true;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
});
spnAutoDelete.setSelection(prefs.getAutoDeleteAction().ordinal());
etxtUsername.setText(prefs.getUsername());
etxtPassword.setText(prefs.getPassword());
etxtUsername.addTextChangedListener(authTextWatcher);
etxtPassword.addTextChangedListener(authTextWatcher);
@ -184,13 +221,18 @@ public class FeedInfoActivity extends ActionBarActivity {
@Override
protected void onPause() {
super.onPause();
if (feed != null && authInfoChanged) {
Log.d(TAG, "Auth info changed, saving credentials");
if (feed != null) {
FeedPreferences prefs = feed.getPreferences();
prefs.setUsername(etxtUsername.getText().toString());
prefs.setPassword(etxtPassword.getText().toString());
DBWriter.setFeedPreferences(this, prefs);
if (authInfoChanged) {
Log.d(TAG, "Auth info changed, saving credentials");
prefs.setUsername(etxtUsername.getText().toString());
prefs.setPassword(etxtPassword.getText().toString());
}
if (authInfoChanged || autoDeleteChanged) {
DBWriter.setFeedPreferences(this, prefs);
}
authInfoChanged = false;
autoDeleteChanged = false;
}
}

View File

@ -180,7 +180,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
url = URLChecker.prepareURL(url);
feed = new Feed(url, new Date(0));
if (username != null && password != null) {
feed.setPreferences(new FeedPreferences(0, false, username, password));
feed.setPreferences(new FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL, username, password));
}
String fileUrl = new File(getExternalCacheDir(),
FileNameGenerator.generateFileName(feed.getDownload_url())).toString();

View File

@ -97,7 +97,7 @@ public class NewEpisodesFragment extends AllEpisodesFragment {
long itemId = token.getFeedItemId();
FeedItem item = DBReader.getFeedItem(context, itemId);
FeedMedia media = item.getMedia();
if(media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
if(media != null && media.hasAlmostEnded() && item.getFeed().getPreferences().getCurrentAutoDelete(UserPreferences.isAutoDelete())) {
DBWriter.deleteFeedMediaOfItem(context, media.getId());
}
}

View File

@ -431,7 +431,7 @@ public class QueueFragment extends Fragment {
long itemId = token.getFeedItemId();
FeedItem item = DBReader.getFeedItem(context, itemId);
FeedMedia media = item.getMedia();
if(media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
if(media != null && media.hasAlmostEnded() && item.getFeed().getPreferences().getCurrentAutoDelete(UserPreferences.isAutoDelete())) {
DBWriter.deleteFeedMediaOfItem(context, media.getId());
}
}

View File

@ -62,7 +62,7 @@ public class PlayerWidgetService extends Service {
DBWriter.markItemRead(this, item, true, false);
DBWriter.removeQueueItem(this, item, false);
DBWriter.addItemToPlaybackHistory(this, media);
if (UserPreferences.isAutoDelete()) {
if (item.getFeed().getPreferences().getCurrentAutoDelete(UserPreferences.isAutoDelete())) {
Log.d(TAG, "Delete " + media.toString());
DBWriter.deleteFeedMediaOfItem(this, media.getId());
}

View File

@ -159,7 +159,38 @@
android:enabled="false"
android:textColor="?android:attr/textColorPrimary"
tools:background="@android:color/holo_red_light"
android:checked="false"/>
android:checked="false" />
<android.support.v7.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:columnCount="2"
app:rowCount="1">
<TextView
android:id="@+id/txtvFeedAutoDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/auto_delete_label"
app:layout_row="0"
app:layout_column="0"
app:layout_gravity="center_vertical"
android:layout_marginRight="10dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/spnAutoDelete"
android:entries="@array/spnAutoDeleteItems"
android:layout_marginTop="8dp"
app:layout_row="0"
app:layout_column="1"
android:spinnerMode="dropdown"
app:layout_gravity="center"
android:dropDownWidth="wrap_content"
android:clickable="false" />
</android.support.v7.widget.GridLayout>
<TextView
android:id="@+id/txtvAuthentication"

View File

@ -167,7 +167,7 @@ public class Feed extends FeedFile implements FlattrThing, PicassoImageResource
*/
public Feed(String url, Date lastUpdate, String title, String username, String password) {
this(url, lastUpdate, title);
preferences = new FeedPreferences(0, true, username, password);
preferences = new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL, username, password);
}

View File

@ -11,19 +11,26 @@ public class FeedPreferences {
private long feedID;
private boolean autoDownload;
public enum AutoDeleteAction {
GLOBAL,
YES,
NO
}
private AutoDeleteAction auto_delete_action;
private String username;
private String password;
public FeedPreferences(long feedID, boolean autoDownload, String username, String password) {
public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, String username, String password) {
this.feedID = feedID;
this.autoDownload = autoDownload;
this.auto_delete_action = auto_delete_action;
this.username = username;
this.password = password;
}
/**
* Compare another FeedPreferences with this one. The feedID and autoDownload attribute are excluded from the
* Compare another FeedPreferences with this one. The feedID, autoDownload and AutoDeleteAction attribute are excluded from the
* comparison.
*
* @return True if the two objects are different.
@ -41,7 +48,7 @@ public class FeedPreferences {
}
/**
* Update this FeedPreferences object from another one. The feedID and autoDownload attributes are excluded
* Update this FeedPreferences object from another one. The feedID, autoDownload and AutoDeleteAction attributes are excluded
* from the update.
*/
public void updateFromOther(FeedPreferences other) {
@ -67,6 +74,28 @@ public class FeedPreferences {
this.autoDownload = autoDownload;
}
public AutoDeleteAction getAutoDeleteAction() {
return auto_delete_action;
}
public void setAutoDeleteAction(AutoDeleteAction auto_delete_action) {
this.auto_delete_action = auto_delete_action;
}
public boolean getCurrentAutoDelete(boolean isAutoDelete) {
switch (auto_delete_action) {
case GLOBAL:
return isAutoDelete;
case YES:
return true;
case NO:
return false;
}
return false; // TODO - add exceptions here
}
public void save(Context context) {
DBWriter.setFeedPreferences(context, this);
}

View File

@ -891,7 +891,7 @@ public class DownloadService extends Service {
feed.setFile_url(request.getDestination());
feed.setId(request.getFeedfileId());
feed.setDownloaded(true);
feed.setPreferences(new FeedPreferences(0, true,
feed.setPreferences(new FeedPreferences(0, true, FeedPreferences.AutoDeleteAction.GLOBAL,
request.getUsername(), request.getPassword()));
feed.setPageNr(request.getArguments().getInt(DownloadRequester.REQUEST_ARG_PAGE_NR, 0));

View File

@ -584,7 +584,7 @@ public class PlaybackService extends Service {
}
// Delete episode if enabled
if(UserPreferences.isAutoDelete()) {
if(item.getFeed().getPreferences().getCurrentAutoDelete(UserPreferences.isAutoDelete())) {
DBWriter.deleteFeedMediaOfItem(PlaybackService.this, media.getId());
Log.d(TAG, "Episode Deleted");
}

View File

@ -196,7 +196,7 @@ public class PlaybackServiceMediaPlayer {
DBWriter.markItemRead(context, item, true, false);
DBWriter.removeQueueItem(context, item, false);
DBWriter.addItemToPlaybackHistory(context, oldMedia);
if (UserPreferences.isAutoDelete()) {
if (item.getFeed().getPreferences().getCurrentAutoDelete(UserPreferences.isAutoDelete())) {
Log.d(TAG, "Delete " + oldMedia.toString());
DBWriter.deleteFeedMediaOfItem(context, oldMedia.getId());
}

View File

@ -338,9 +338,9 @@ public final class DBReader {
if (image != null) {
image.setOwner(feed);
}
FeedPreferences preferences = new FeedPreferences(cursor.getLong(PodDBAdapter.IDX_FEED_SEL_STD_ID),
cursor.getInt(PodDBAdapter.IDX_FEED_SEL_PREFERENCES_AUTO_DOWNLOAD) > 0,
FeedPreferences.AutoDeleteAction.values()[cursor.getInt(PodDBAdapter.IDX_FEED_SEL_PREFERENCES_AUTO_DELETE_ACTION)],
cursor.getString(PodDBAdapter.IDX_FEED_SEL_PREFERENCES_USERNAME),
cursor.getString(PodDBAdapter.IDX_FEED_SEL_PREFERENCES_PASSWORD));

View File

@ -150,6 +150,7 @@ public class PodDBAdapter {
public static final String KEY_CHAPTER_TYPE = "type";
public static final String KEY_PLAYBACK_COMPLETION_DATE = "playback_completion_date";
public static final String KEY_AUTO_DOWNLOAD = "auto_download";
public static final String KEY_AUTO_DELETE_ACTION = "auto_delete_action";
public static final String KEY_PLAYED_DURATION = "played_duration";
public static final String KEY_USERNAME = "username";
public static final String KEY_PASSWORD = "password";
@ -187,7 +188,8 @@ public class PodDBAdapter {
+ KEY_IS_PAGED + " INTEGER DEFAULT 0,"
+ KEY_NEXT_PAGE_LINK + " TEXT,"
+ KEY_HIDE + " TEXT,"
+ KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0)";
+ KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0,"
+ KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0)";
public static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
@ -283,6 +285,7 @@ public class PodDBAdapter {
TABLE_NAME_FEEDS + "." + KEY_PASSWORD,
TABLE_NAME_FEEDS + "." + KEY_HIDE,
TABLE_NAME_FEEDS + "." + KEY_LAST_UPDATE_FAILED,
TABLE_NAME_FEEDS + "." + KEY_AUTO_DELETE_ACTION,
};
// column indices for FEED_SEL_STD
@ -306,6 +309,7 @@ public class PodDBAdapter {
public static final int IDX_FEED_SEL_STD_NEXT_PAGE_LINK = 17;
public static final int IDX_FEED_SEL_PREFERENCES_USERNAME = 18;
public static final int IDX_FEED_SEL_PREFERENCES_PASSWORD = 19;
public static final int IDX_FEED_SEL_PREFERENCES_AUTO_DELETE_ACTION = 22;
/**
* Select all columns from the feeditems-table except description and
@ -461,6 +465,7 @@ public class PodDBAdapter {
}
ContentValues values = new ContentValues();
values.put(KEY_AUTO_DOWNLOAD, prefs.getAutoDownload());
values.put(KEY_AUTO_DELETE_ACTION,prefs.getAutoDeleteAction().ordinal());
values.put(KEY_USERNAME, prefs.getUsername());
values.put(KEY_PASSWORD, prefs.getPassword());
db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(prefs.getFeedID())});

View File

@ -58,6 +58,7 @@
<string name="close_label">סגור</string>
<string name="retry_label">נסה שוב</string>
<string name="auto_download_label">כלול בהורדות אוטומטיות</string>
<string name="auto_delete_label">מחק לאחר ההשמעה (גובר על ההגדרה הגלובלית)</string>
<string name="parallel_downloads_suffix">\u0020הורדות במקביל</string>
<!--'Add Feed' Activity labels-->
<string name="feedurl_label">כתובת הזנה</string>

View File

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="spnAutoDeleteItems">
<item>Global</item>
<item>Always</item>
<item>Never</item>
</string-array>
<string-array name="smart_mark_as_played_values">
<item>0</item>
<item>15</item>

View File

@ -75,6 +75,7 @@
<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_delete_label">Auto Delete Episode\n(override global default)</string>
<string name="parallel_downloads_suffix">\u0020parallel downloads</string>
<!-- 'Add Feed' Activity labels -->