Search in sources :

Example 41 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class EpisodeItemListAdapter method onBindViewHolder.

@Override
public final void onBindViewHolder(EpisodeItemViewHolder holder, int pos) {
    // Reset state of recycled views
    holder.coverHolder.setVisibility(View.VISIBLE);
    holder.dragHandle.setVisibility(View.GONE);
    beforeBindViewHolder(holder, pos);
    FeedItem item = episodes.get(pos);
    holder.bind(item);
    holder.itemView.setOnClickListener(v -> {
        MainActivity activity = mainActivityRef.get();
        if (activity != null && !inActionMode()) {
            long[] ids = FeedItemUtil.getIds(episodes);
            int position = ArrayUtils.indexOf(ids, item.getId());
            activity.loadChildFragment(ItemPagerFragment.newInstance(ids, position));
        } else {
            toggleSelection(holder.getBindingAdapterPosition());
        }
    });
    holder.itemView.setOnCreateContextMenuListener(this);
    holder.itemView.setOnLongClickListener(v -> {
        longPressedItem = getItem(holder.getBindingAdapterPosition());
        longPressedPosition = holder.getBindingAdapterPosition();
        return false;
    });
    holder.itemView.setOnTouchListener((v, e) -> {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (e.isFromSource(InputDevice.SOURCE_MOUSE) && e.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                longPressedItem = getItem(holder.getBindingAdapterPosition());
                longPressedPosition = holder.getBindingAdapterPosition();
                return false;
            }
        }
        return false;
    });
    if (inActionMode()) {
        holder.secondaryActionButton.setVisibility(View.GONE);
        holder.selectCheckBox.setOnClickListener(v -> toggleSelection(holder.getBindingAdapterPosition()));
        holder.selectCheckBox.setChecked(isSelected(pos));
        holder.selectCheckBox.setVisibility(View.VISIBLE);
    } else {
        holder.selectCheckBox.setVisibility(View.GONE);
    }
    afterBindViewHolder(holder, pos);
    holder.hideSeparatorIfNecessary();
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) MainActivity(de.danoeh.antennapod.activity.MainActivity)

Example 42 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class ItemPagerFragment method openPodcast.

private void openPodcast() {
    Fragment fragment = FeedItemlistFragment.newInstance(item.getFeedId());
    ((MainActivity) getActivity()).loadChildFragment(fragment);
}
Also used : MainActivity(de.danoeh.antennapod.activity.MainActivity) Fragment(androidx.fragment.app.Fragment)

Example 43 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class QueueFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View root = inflater.inflate(R.layout.queue_fragment, container, false);
    toolbar = root.findViewById(R.id.toolbar);
    toolbar.setOnMenuItemClickListener(this);
    displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
    if (savedInstanceState != null) {
        displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
    }
    ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
    toolbar.inflateMenu(R.menu.queue);
    refreshToolbarState();
    infoBar = root.findViewById(R.id.info_bar);
    recyclerView = root.findViewById(R.id.recyclerView);
    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }
    recyclerView.setRecycledViewPool(((MainActivity) getActivity()).getRecycledViewPool());
    registerForContextMenu(recyclerView);
    SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
    swipeRefreshLayout.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance));
    swipeRefreshLayout.setOnRefreshListener(() -> {
        AutoUpdateManager.runImmediate(requireContext());
        new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false), getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
    });
    swipeActions = new QueueSwipeActions();
    swipeActions.setFilter(new FeedItemFilter(FeedItemFilter.QUEUED));
    swipeActions.attachTo(recyclerView);
    emptyView = new EmptyViewHandler(getContext());
    emptyView.attachToRecyclerView(recyclerView);
    emptyView.setIcon(R.drawable.ic_playlist);
    emptyView.setTitle(R.string.no_items_header_label);
    emptyView.setMessage(R.string.no_items_label);
    progLoading = root.findViewById(R.id.progLoading);
    progLoading.setVisibility(View.VISIBLE);
    speedDialView = root.findViewById(R.id.fabSD);
    speedDialView.setOverlayLayout(root.findViewById(R.id.fabSDOverlay));
    speedDialView.inflate(R.menu.episodes_apply_action_speeddial);
    speedDialView.removeActionItemById(R.id.mark_read_batch);
    speedDialView.removeActionItemById(R.id.mark_unread_batch);
    speedDialView.removeActionItemById(R.id.add_to_queue_batch);
    speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() {

        @Override
        public boolean onMainActionSelected() {
            return false;
        }

        @Override
        public void onToggleChanged(boolean open) {
            if (open && recyclerAdapter.getSelectedCount() == 0) {
                ((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.no_items_selected, Snackbar.LENGTH_SHORT);
                speedDialView.close();
            }
        }
    });
    speedDialView.setOnActionSelectedListener(actionItem -> {
        new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), recyclerAdapter.getSelectedItems()).handleAction(actionItem.getId());
        recyclerAdapter.endSelectMode();
        return true;
    });
    return root;
}
Also used : SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) FeedItemFilter(de.danoeh.antennapod.model.feed.FeedItemFilter) FeedItemMenuHandler(de.danoeh.antennapod.menuhandler.FeedItemMenuHandler) Handler(android.os.Handler) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) EpisodeMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler) EpisodeMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler) MainActivity(de.danoeh.antennapod.activity.MainActivity) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) EpisodeItemListRecyclerView(de.danoeh.antennapod.view.EpisodeItemListRecyclerView) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView)

Aggregations

MainActivity (de.danoeh.antennapod.activity.MainActivity)43 View (android.view.View)15 TextView (android.widget.TextView)11 Nullable (androidx.annotation.Nullable)6 Context (android.content.Context)5 ImageView (android.widget.ImageView)5 Fragment (androidx.fragment.app.Fragment)5 EpisodeItemListRecyclerView (de.danoeh.antennapod.view.EpisodeItemListRecyclerView)5 DialogInterface (android.content.DialogInterface)4 Bundle (android.os.Bundle)4 MenuItem (android.view.MenuItem)4 NonNull (androidx.annotation.NonNull)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 ConfirmationDialog (de.danoeh.antennapod.core.dialog.ConfirmationDialog)4 EmptyViewHandler (de.danoeh.antennapod.view.EmptyViewHandler)4 Activity (android.app.Activity)3 Handler (android.os.Handler)3 ViewGroup (android.view.ViewGroup)3 Toolbar (androidx.appcompat.widget.Toolbar)3 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)3