use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class EpisodesListFragment method onContextItemSelected.
@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
Log.d(TAG, "onContextItemSelected() called with: " + "item = [" + item + "]");
if (!getUserVisibleHint() || !isVisible() || !isMenuVisible()) {
// Apparently, none of the visibility check method works reliably on its own, so we just use all.
return false;
}
if (item.getItemId() == R.id.share_item) {
// avoids that the position is reset when we need it in the submenu
return true;
}
if (listAdapter.getLongPressedItem() == null) {
Log.i(TAG, "Selected item or listAdapter was null, ignoring selection");
return super.onContextItemSelected(item);
}
FeedItem selectedItem = listAdapter.getLongPressedItem();
return FeedItemMenuHandler.onMenuItemClicked(this, item.getItemId(), selectedItem);
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class FavoriteEpisodesFragment method onCreateView.
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
emptyView.setIcon(R.drawable.ic_star);
emptyView.setTitle(R.string.no_fav_episodes_head_label);
emptyView.setMessage(R.string.no_fav_episodes_label);
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int swipeDir) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder) viewHolder;
Log.d(TAG, String.format("remove(%s)", holder.getFeedItem().getId()));
if (disposable != null) {
disposable.dispose();
}
FeedItem item = holder.getFeedItem();
if (item != null) {
DBWriter.removeFavoriteItem(item);
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.removed_item, Snackbar.LENGTH_LONG).setAction(getString(R.string.undo), v -> DBWriter.addFavoriteItem(item));
}
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
return root;
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class DownloadLogFragment method onListItemClick.
@Override
public void onListItemClick(@NonNull ListView l, @NonNull View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object item = adapter.getItem(position);
if (item instanceof Downloader) {
DownloadRequest downloadRequest = ((Downloader) item).getDownloadRequest();
DownloadService.cancel(getContext(), downloadRequest.getSource());
if (downloadRequest.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
FeedMedia media = DBReader.getFeedMedia(downloadRequest.getFeedfileId());
FeedItem feedItem = media.getItem();
feedItem.disableAutoDownload();
DBWriter.setFeedItem(feedItem);
}
} else if (item instanceof DownloadStatus) {
DownloadStatus status = (DownloadStatus) item;
String url = "unknown";
String message = getString(R.string.download_successful);
if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
if (media != null) {
url = media.getDownload_url();
}
} else if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
Feed feed = DBReader.getFeed(status.getFeedfileId());
if (feed != null) {
url = feed.getDownload_url();
}
}
if (!status.isSuccessful()) {
message = status.getReasonDetailed();
}
String messageFull = getString(R.string.download_error_details_message, message, url);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.download_error_details);
builder.setMessage(messageFull);
builder.setPositiveButton(android.R.string.ok, null);
builder.setNeutralButton(R.string.copy_to_clipboard, (dialog, which) -> {
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(getString(R.string.download_error_details), messageFull);
clipboard.setPrimaryClip(clip);
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.copied_to_clipboard, Snackbar.LENGTH_SHORT);
});
Dialog dialog = builder.show();
((TextView) dialog.findViewById(android.R.id.message)).setTextIsSelectable(true);
}
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class AudioPlayerFragment method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem item) {
if (controller == null) {
return false;
}
Playable media = controller.getMedia();
if (media == null) {
return false;
}
@Nullable final FeedItem feedItem = (media instanceof FeedMedia) ? ((FeedMedia) media).getItem() : null;
if (feedItem != null && FeedItemMenuHandler.onMenuItemClicked(this, item.getItemId(), feedItem)) {
return true;
}
final int itemId = item.getItemId();
if (itemId == R.id.disable_sleeptimer_item || itemId == R.id.set_sleeptimer_item) {
new SleepTimerDialog().show(getChildFragmentManager(), "SleepTimerDialog");
return true;
} else if (itemId == R.id.audio_controls) {
PlaybackControlsDialog dialog = PlaybackControlsDialog.newInstance();
dialog.show(getChildFragmentManager(), "playback_controls");
return true;
} else if (itemId == R.id.open_feed_item) {
if (feedItem != null) {
Intent intent = MainActivity.getIntentToOpenFeed(getContext(), feedItem.getFeedId());
startActivity(intent);
}
return true;
}
return false;
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class CompletedDownloadsFragment method onEventMainThread.
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FeedItemEvent event) {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
if (items == null) {
return;
} else if (adapter == null) {
loadItems();
return;
}
for (int i = 0, size = event.items.size(); i < size; i++) {
FeedItem item = event.items.get(i);
int pos = FeedItemUtil.indexOfItemWithId(items, item.getId());
if (pos >= 0) {
items.remove(pos);
if (item.getMedia().isDownloaded()) {
items.add(pos, item);
adapter.notifyItemChangedCompat(pos);
} else {
adapter.notifyItemRemoved(pos);
}
}
}
}
Aggregations