Check if items are already in the queue
This commit is contained in:
parent
fd7cdd3c71
commit
a766977e6d
|
@ -10,7 +10,9 @@ import org.apache.commons.lang3.Validate;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.core.util.LongList;
|
||||
|
||||
/**
|
||||
* Utility methods for the action button that is displayed on the right hand side
|
||||
|
@ -26,9 +28,21 @@ public class ActionButtonUtils {
|
|||
Validate.notNull(context);
|
||||
|
||||
this.context = context;
|
||||
drawables = context.obtainStyledAttributes(new int[]{
|
||||
R.attr.av_play, R.attr.navigation_cancel, R.attr.av_download, R.attr.av_pause, R.attr.navigation_accept});
|
||||
labels = new int[]{R.string.play_label, R.string.cancel_download_label, R.string.download_label, R.string.mark_read_label};
|
||||
drawables = context.obtainStyledAttributes(new int[] {
|
||||
R.attr.av_play,
|
||||
R.attr.navigation_cancel,
|
||||
R.attr.av_download,
|
||||
R.attr.av_pause,
|
||||
R.attr.navigation_accept,
|
||||
R.attr.content_new
|
||||
});
|
||||
labels = new int[] {
|
||||
R.string.play_label,
|
||||
R.string.cancel_download_label,
|
||||
R.string.download_label,
|
||||
R.string.mark_read_label,
|
||||
R.string.add_to_queue_label
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,18 +64,26 @@ public class ActionButtonUtils {
|
|||
butSecondary.setContentDescription(context.getString(labels[1]));
|
||||
} else {
|
||||
// item is not downloaded and not being downloaded
|
||||
butSecondary.setVisibility(View.VISIBLE);
|
||||
butSecondary.setImageDrawable(drawables.getDrawable(2));
|
||||
butSecondary.setContentDescription(context.getString(labels[2]));
|
||||
LongList queueIds = DBReader.getQueueIDList(context);
|
||||
if(DefaultActionButtonCallback.userAllowedMobileDownloads() ||
|
||||
!DefaultActionButtonCallback.userChoseAddToQueue() || queueIds.contains(item.getId())) {
|
||||
butSecondary.setVisibility(View.VISIBLE);
|
||||
butSecondary.setImageDrawable(drawables.getDrawable(2));
|
||||
butSecondary.setContentDescription(context.getString(labels[2]));
|
||||
} else {
|
||||
// mobile download not allowed yet, item is not in queue and user chose add to queue
|
||||
butSecondary.setVisibility(View.VISIBLE);
|
||||
butSecondary.setImageDrawable(drawables.getDrawable(5));
|
||||
butSecondary.setContentDescription(context.getString(labels[4]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// item is not being downloaded
|
||||
// item is downloaded
|
||||
butSecondary.setVisibility(View.VISIBLE);
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
butSecondary.setImageDrawable(drawables.getDrawable(3));
|
||||
} else {
|
||||
butSecondary
|
||||
.setImageDrawable(drawables.getDrawable(0));
|
||||
butSecondary.setImageDrawable(drawables.getDrawable(0));
|
||||
}
|
||||
butSecondary.setContentDescription(context.getString(labels[0]));
|
||||
}
|
||||
|
|
|
@ -14,12 +14,13 @@ import de.danoeh.antennapod.core.feed.FeedItem;
|
|||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction;
|
||||
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.core.util.LongList;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +32,7 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
|
||||
private final Context context;
|
||||
|
||||
private final int TEN_MINUTES_IN_MILLIS = 60 * 1000 * 10;
|
||||
private static final int TEN_MINUTES_IN_MILLIS = 60 * 1000 * 10;
|
||||
|
||||
// remember timestamp when user allowed downloading via mobile connection
|
||||
private static long allowMobileDownloadsTimestamp;
|
||||
|
@ -42,6 +43,14 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
public static boolean userAllowedMobileDownloads() {
|
||||
return System.currentTimeMillis() - allowMobileDownloadsTimestamp < TEN_MINUTES_IN_MILLIS;
|
||||
}
|
||||
|
||||
public static boolean userChoseAddToQueue() {
|
||||
return System.currentTimeMillis() - onlyAddToQueueTimeStamp < TEN_MINUTES_IN_MILLIS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionButtonPressed(final FeedItem item) {
|
||||
|
||||
|
@ -49,8 +58,8 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
final FeedMedia media = item.getMedia();
|
||||
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
|
||||
if (!isDownloading && !media.isDownloaded()) {
|
||||
if (UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi(context) ||
|
||||
(System.currentTimeMillis()-allowMobileDownloadsTimestamp) < TEN_MINUTES_IN_MILLIS) {
|
||||
LongList queueIds = DBReader.getQueueIDList(context);
|
||||
if (NetworkUtils.isDownloadAllowed(context) || userAllowedMobileDownloads()) {
|
||||
try {
|
||||
DBTasks.downloadFeedItems(context, item);
|
||||
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
|
||||
|
@ -58,13 +67,11 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
e.printStackTrace();
|
||||
DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
|
||||
}
|
||||
} else if(userChoseAddToQueue() && !queueIds.contains(item.getId())) {
|
||||
DBWriter.addQueueItem(context, item.getId());
|
||||
Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if(System.currentTimeMillis() - onlyAddToQueueTimeStamp < TEN_MINUTES_IN_MILLIS) {
|
||||
DBWriter.addQueueItem(context, item.getId());
|
||||
Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
confirmMobileDownload(context, item);
|
||||
}
|
||||
confirmMobileDownload(context, item);
|
||||
}
|
||||
} else if (isDownloading) {
|
||||
DownloadRequester.getInstance().cancelDownload(context, media);
|
||||
|
@ -118,17 +125,23 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.confirm_mobile_download_dialog_only_add_to_queue,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onlyAddToQueueTimeStamp = System.currentTimeMillis();
|
||||
DBWriter.addQueueItem(context, item.getId());
|
||||
Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel_label, null)
|
||||
});
|
||||
LongList queueIds = DBReader.getQueueIDList(context);
|
||||
if(!queueIds.contains(item.getId())) {
|
||||
builder.setNeutralButton(R.string.confirm_mobile_download_dialog_only_add_to_queue,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onlyAddToQueueTimeStamp = System.currentTimeMillis();
|
||||
DBWriter.addQueueItem(context, item.getId());
|
||||
Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.setMessage(context.getText(R.string.confirm_mobile_download_dialog_message_not_in_queue));
|
||||
} else {
|
||||
builder.setMessage(context.getText(R.string.confirm_mobile_download_dialog_message));
|
||||
}
|
||||
builder.setNegativeButton(R.string.cancel_label, null)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
|
||||
|
@ -19,8 +18,7 @@ public class FeedUpdateReceiver extends BroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "Received intent");
|
||||
boolean mobileUpdate = UserPreferences.isAllowMobileUpdate();
|
||||
if (mobileUpdate || NetworkUtils.connectedToWifi(context)) {
|
||||
if (NetworkUtils.isDownloadAllowed(context)) {
|
||||
DBTasks.refreshExpiredFeeds(context);
|
||||
} else {
|
||||
Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
|
||||
|
|
|
@ -68,6 +68,10 @@ public class NetworkUtils {
|
|||
return info != null && info.isConnected();
|
||||
}
|
||||
|
||||
public static boolean isDownloadAllowed(Context context) {
|
||||
return UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi(context);
|
||||
}
|
||||
|
||||
public static boolean connectedToWifi(Context context) {
|
||||
ConnectivityManager connManager = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
|
|
@ -147,7 +147,8 @@
|
|||
<string name="authentication_notification_title">Authentication required</string>
|
||||
<string name="authentication_notification_msg">The resource you requested requires a username and a password</string>
|
||||
<string name="confirm_mobile_download_dialog_title">Confirm Mobile Download</string>
|
||||
<string name="confirm_mobile_download_dialog_message">Downloading over mobile data connection disable in settings.\n\nEnable temporarily or just add to queue?\n\n<small>Your choice will be remember for 10 minutes.</small></string>
|
||||
<string name="confirm_mobile_download_dialog_message_not_in_queue">Downloading over mobile data connection disable in settings.\n\nEnable temporarily or just add to queue?\n\n<small>Your choice will be remember for 10 minutes.</small></string>
|
||||
<string name="confirm_mobile_download_dialog_message">Downloading over mobile data connection disable in settings.\n\nEnable temporarily?\n\n<small>Your choice will be remember for 10 minutes.</small></string>
|
||||
<string name="confirm_mobile_download_dialog_only_add_to_queue">Only add to Queue</string>
|
||||
<string name="confirm_mobile_download_dialog_enable_temporarily">Enable temporarily</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue