Search in sources :

Example 81 with Snackbar

use of android.support.design.widget.Snackbar in project AntennaPod by AntennaPod.

the class FavoriteEpisodesFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = super.onCreateViewHelper(inflater, container, savedInstanceState, R.layout.all_episodes_fragment);
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder) viewHolder;
            Log.d(TAG, "remove(" + holder.getItemId() + ")");
            if (subscription != null) {
                subscription.unsubscribe();
            }
            FeedItem item = holder.getFeedItem();
            if (item != null) {
                DBWriter.removeFavoriteItem(item);
                Snackbar snackbar = Snackbar.make(root, getString(R.string.removed_item), Snackbar.LENGTH_LONG);
                snackbar.setAction(getString(R.string.undo), v -> DBWriter.addFavoriteItem(item));
                snackbar.show();
            }
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    return root;
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) AllEpisodesRecycleAdapter(de.danoeh.antennapod.adapter.AllEpisodesRecycleAdapter) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Snackbar(android.support.design.widget.Snackbar)

Example 82 with Snackbar

use of android.support.design.widget.Snackbar 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);
    ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.queue_label);
    View root = inflater.inflate(R.layout.queue_fragment, container, false);
    infoBar = (TextView) root.findViewById(R.id.info_bar);
    recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity()).build());
    recyclerView.setHasFixedSize(true);
    registerForContextMenu(recyclerView);
    itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            int from = viewHolder.getAdapterPosition();
            int to = target.getAdapterPosition();
            Log.d(TAG, "move(" + from + ", " + to + ")");
            queue.add(to, queue.remove(from));
            recyclerAdapter.notifyItemMoved(from, to);
            DBWriter.moveQueueItem(from, to, true);
            return true;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            if (subscription != null) {
                subscription.unsubscribe();
            }
            final int position = viewHolder.getAdapterPosition();
            Log.d(TAG, "remove(" + position + ")");
            final FeedItem item = queue.get(position);
            final boolean isRead = item.isPlayed();
            DBWriter.markItemPlayed(FeedItem.PLAYED, false, item.getId());
            DBWriter.removeQueueItem(getActivity(), item, true);
            Snackbar snackbar = Snackbar.make(root, getString(R.string.marked_as_read_label), Snackbar.LENGTH_LONG);
            snackbar.setAction(getString(R.string.undo), v -> {
                DBWriter.addQueueItemAt(getActivity(), item.getId(), position, false);
                if (!isRead) {
                    DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
                }
            });
            snackbar.show();
        }

        @Override
        public boolean isLongPressDragEnabled() {
            return !UserPreferences.isQueueLocked();
        }

        @Override
        public boolean isItemViewSwipeEnabled() {
            return !UserPreferences.isQueueLocked();
        }

        @Override
        public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
            // We only want the active item
            if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
                if (viewHolder instanceof QueueRecyclerAdapter.ItemTouchHelperViewHolder) {
                    QueueRecyclerAdapter.ItemTouchHelperViewHolder itemViewHolder = (QueueRecyclerAdapter.ItemTouchHelperViewHolder) viewHolder;
                    itemViewHolder.onItemSelected();
                }
            }
            super.onSelectedChanged(viewHolder, actionState);
        }

        @Override
        public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            super.clearView(recyclerView, viewHolder);
            if (viewHolder instanceof QueueRecyclerAdapter.ItemTouchHelperViewHolder) {
                QueueRecyclerAdapter.ItemTouchHelperViewHolder itemViewHolder = (QueueRecyclerAdapter.ItemTouchHelperViewHolder) viewHolder;
                itemViewHolder.onItemClear();
            }
        }
    });
    itemTouchHelper.attachToRecyclerView(recyclerView);
    txtvEmpty = (TextView) root.findViewById(android.R.id.empty);
    txtvEmpty.setVisibility(View.GONE);
    progLoading = (ProgressBar) root.findViewById(R.id.progLoading);
    progLoading.setVisibility(View.VISIBLE);
    return root;
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) QueueRecyclerAdapter(de.danoeh.antennapod.adapter.QueueRecyclerAdapter) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 83 with Snackbar

use of android.support.design.widget.Snackbar in project teaTime by ancfdy.

the class SnackbarUtils method ShortSnackbar.

/**
     * 短显示Snackbar,自定义颜色
     * @param view
     * @param message
     * @param messageColor
     * @param backgroundColor
     * @return
     */
public static Snackbar ShortSnackbar(View view, String message, int messageColor, int backgroundColor) {
    Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
    setSnackbarColor(snackbar, messageColor, backgroundColor);
    return snackbar;
}
Also used : Snackbar(android.support.design.widget.Snackbar)

Example 84 with Snackbar

use of android.support.design.widget.Snackbar in project teaTime by ancfdy.

the class SnackbarUtils method LongSnackbar.

/**
     * 长显示Snackbar,可选预设类型
     * @param view
     * @param message
     * @param type
     * @return
     */
public static Snackbar LongSnackbar(View view, String message, int type) {
    Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_LONG);
    switchType(snackbar, type);
    return snackbar;
}
Also used : Snackbar(android.support.design.widget.Snackbar)

Example 85 with Snackbar

use of android.support.design.widget.Snackbar in project teaTime by ancfdy.

the class SnackbarUtils method SnackbarAddView.

/**
     * 向Snackbar中添加view
     * @param snackbar
     * @param layoutId
     * @param index 新加布局在Snackbar中的位置
     */
public static void SnackbarAddView(Snackbar snackbar, int layoutId, int index) {
    View snackbarview = snackbar.getView();
    Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbarview;
    View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId, null);
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    p.gravity = Gravity.CENTER_VERTICAL;
    snackbarLayout.addView(add_view, index, p);
}
Also used : TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Aggregations

Snackbar (android.support.design.widget.Snackbar)102 View (android.view.View)56 TextView (android.widget.TextView)25 Intent (android.content.Intent)13 RecyclerView (android.support.v7.widget.RecyclerView)13 BaseTransientBottomBar (android.support.design.widget.BaseTransientBottomBar)10 ImageView (android.widget.ImageView)10 ViewGroup (android.view.ViewGroup)8 DialogInterface (android.content.DialogInterface)7 LayoutInflater (android.view.LayoutInflater)6 AdapterView (android.widget.AdapterView)6 LinearLayout (android.widget.LinearLayout)6 ListView (android.widget.ListView)6 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)5 AlertDialog (android.app.AlertDialog)4 Context (android.content.Context)4 Nullable (android.support.annotation.Nullable)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 File (java.io.File)4 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)4