Search in sources :

Example 91 with FeedItem

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);
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem)

Example 92 with FeedItem

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;
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) EpisodeItemViewHolder(de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder) EpisodeItemViewHolder(de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) NonNull(androidx.annotation.NonNull) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NonNull(androidx.annotation.NonNull)

Example 93 with FeedItem

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);
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) AutoUpdateManager(de.danoeh.antennapod.core.util.download.AutoUpdateManager) NonNull(androidx.annotation.NonNull) Dialog(android.app.Dialog) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) DownloadLogEvent(de.danoeh.antennapod.core.event.DownloadLogEvent) EventBus(org.greenrobot.eventbus.EventBus) Menu(android.view.Menu) ClipboardManager(android.content.ClipboardManager) View(android.view.View) DownloaderUpdate(de.danoeh.antennapod.core.event.DownloaderUpdate) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) Feed(de.danoeh.antennapod.model.feed.Feed) Downloader(de.danoeh.antennapod.core.service.download.Downloader) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) R(de.danoeh.antennapod.R) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ThreadMode(org.greenrobot.eventbus.ThreadMode) MenuItemUtils(de.danoeh.antennapod.core.menuhandler.MenuItemUtils) MainActivity(de.danoeh.antennapod.activity.MainActivity) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Subscribe(org.greenrobot.eventbus.Subscribe) DownloadLogAdapter(de.danoeh.antennapod.adapter.DownloadLogAdapter) DownloadEvent(de.danoeh.antennapod.core.event.DownloadEvent) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) DBReader(de.danoeh.antennapod.core.storage.DBReader) ListFragment(androidx.fragment.app.ListFragment) ListView(android.widget.ListView) Snackbar(com.google.android.material.snackbar.Snackbar) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) ClipboardManager(android.content.ClipboardManager) Downloader(de.danoeh.antennapod.core.service.download.Downloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) ClipData(android.content.ClipData) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 94 with FeedItem

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;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Playable(de.danoeh.antennapod.model.playback.Playable) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) PlaybackControlsDialog(de.danoeh.antennapod.dialog.PlaybackControlsDialog) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) Intent(android.content.Intent) Nullable(androidx.annotation.Nullable)

Example 95 with FeedItem

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);
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

FeedItem (de.danoeh.antennapod.model.feed.FeedItem)178 Feed (de.danoeh.antennapod.model.feed.Feed)74 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)48 Date (java.util.Date)47 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)46 File (java.io.File)26 Cursor (android.database.Cursor)20 NonNull (androidx.annotation.NonNull)15 Nullable (androidx.annotation.Nullable)11 Subscribe (org.greenrobot.eventbus.Subscribe)9 Intent (android.content.Intent)7 FeedFilter (de.danoeh.antennapod.model.feed.FeedFilter)7 View (android.view.View)6 LongList (de.danoeh.antennapod.core.util.LongList)6 SQLException (android.database.SQLException)5 Playable (de.danoeh.antennapod.model.playback.Playable)5 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)5 ExecutionException (java.util.concurrent.ExecutionException)5 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)4