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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package de.danoeh.antennapod.util.menuhandler;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.FeedInfoActivity;
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.service.download.DownloadService;
import de.danoeh.antennapod.storage.DBTasks;
import de.danoeh.antennapod.storage.DBWriter;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.ShareUtils;
import de.danoeh.antennapod.util.flattr.FlattrStatus;
/** Handles interactions with the FeedItemMenu. */
public class FeedMenuHandler {
private static final String TAG = "FeedMenuHandler";
public static boolean onCreateOptionsMenu(MenuInflater inflater, Menu menu) {
inflater.inflate(R.menu.feedlist, menu);
return true;
}
public static boolean onPrepareOptionsMenu(Menu menu, Feed selectedFeed) {
if (selectedFeed == null) {
return true;
}
if (AppConfig.DEBUG)
Log.d(TAG, "Preparing options menu");
menu.findItem(R.id.mark_all_read_item).setVisible(
selectedFeed.hasNewItems(true));
if (selectedFeed.getPaymentLink() != null && selectedFeed.getFlattrStatus().flattrable())
menu.findItem(R.id.support_item).setVisible(true);
else
menu.findItem(R.id.support_item).setVisible(false);
MenuItem refresh = menu.findItem(R.id.refresh_item);
if (DownloadService.isRunning
&& DownloadRequester.getInstance().isDownloadingFile(
selectedFeed)) {
refresh.setVisible(false);
} else {
refresh.setVisible(true);
}
return true;
}
/**
* NOTE: This method does not handle clicks on the 'remove feed' - item.
*
* @throws DownloadRequestException
*/
public static boolean onOptionsItemClicked(Context context, MenuItem item,
Feed selectedFeed) throws DownloadRequestException {
switch (item.getItemId()) {
case R.id.show_info_item:
Intent startIntent = new Intent(context, FeedInfoActivity.class);
startIntent.putExtra(FeedInfoActivity.EXTRA_FEED_ID,
selectedFeed.getId());
context.startActivity(startIntent);
break;
case R.id.refresh_item:
DBTasks.refreshFeed(context, selectedFeed);
break;
case R.id.mark_all_read_item:
DBWriter.markFeedRead(context, selectedFeed.getId());
break;
case R.id.visit_website_item:
Uri uri = Uri.parse(selectedFeed.getLink());
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
case R.id.support_item:
DBTasks.flattrFeedIfLoggedIn(context, selectedFeed);
break;
case R.id.share_link_item:
ShareUtils.shareFeedlink(context, selectedFeed);
break;
case R.id.share_source_item:
ShareUtils.shareFeedDownloadLink(context, selectedFeed);
break;
default:
return false;
}
return true;
}
}
|