blob: 86a8047a95946a4ff4c835e3476ae3a5a195a0e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package de.danoeh.antennapod.adapter.actionbutton;
import android.content.Context;
import android.view.View;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UsageStatistics;
import de.danoeh.antennapod.core.util.NetworkUtils;
public class DownloadActionButton extends ItemActionButton {
public DownloadActionButton(FeedItem item) {
super(item);
}
@Override
@StringRes
public int getLabel() {
return R.string.download_label;
}
@Override
@DrawableRes
public int getDrawable() {
return R.drawable.ic_download;
}
@Override
public int getVisibility() {
return item.getFeed().isLocalFeed() ? View.INVISIBLE : View.VISIBLE;
}
@Override
public void onClick(Context context) {
final FeedMedia media = item.getMedia();
if (media == null || shouldNotDownload(media)) {
return;
}
UsageStatistics.logAction(UsageStatistics.ACTION_DOWNLOAD);
if (NetworkUtils.isEpisodeDownloadAllowed()) {
DownloadServiceInterface.get().downloadNow(context, item, false);
} else {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context)
.setTitle(R.string.confirm_mobile_download_dialog_title)
.setMessage(R.string.confirm_mobile_download_dialog_message)
.setPositiveButton(R.string.confirm_mobile_download_dialog_download_later,
(d, w) -> DownloadServiceInterface.get().downloadNow(context, item, false))
.setNeutralButton(R.string.confirm_mobile_download_dialog_allow_this_time,
(d, w) -> DownloadServiceInterface.get().downloadNow(context, item, true))
.setNegativeButton(R.string.cancel_label, null);
builder.show();
}
}
private boolean shouldNotDownload(@NonNull FeedMedia media) {
boolean isDownloading = DownloadServiceInterface.get().isDownloadingEpisode(media.getDownload_url());
return isDownloading || media.isDownloaded();
}
}
|