Search in sources :

Example 1 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project UltimateRecyclerView by cymcsg.

the class LauncherActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    ultimateRecyclerView = (UltimateRecyclerView) findViewById(R.id.ultimate_recycler_view);
    ultimateRecyclerView.setHasFixedSize(false);
    final List<String> stringList = new ArrayList<>();
    stringList.add("111");
    stringList.add("aaa");
    stringList.add("222");
    stringList.add("33");
    stringList.add("44");
    stringList.add("55");
    stringList.add("66");
    stringList.add("11771");
    simpleRecyclerViewAdapter = new SimpleAdapter(stringList);
    linearLayoutManager = new LinearLayoutManager(this);
    ultimateRecyclerView.setLayoutManager(linearLayoutManager);
    StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(simpleRecyclerViewAdapter);
    ultimateRecyclerView.addItemDecoration(headersDecor);
    // //        ultimateRecyclerView.setEmptyView(getResources().getIdentifier("empty_view","layout",getPackageName()));
    // ultimateRecyclerView.showEmptyView();
    // ultimateRecyclerView.enableLoadmore();
    // simpleRecyclerViewAdapter.setCustomLoadMoreView(LayoutInflater.from(this)
    // .inflate(R.layout.custom_bottom_progressbar, null));
    ultimateRecyclerView.setLoadMoreView(LayoutInflater.from(this).inflate(R.layout.custom_bottom_progressbar, null));
    ultimateRecyclerView.setParallaxHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
    // //   ultimateRecyclerView.setNormalHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
    ultimateRecyclerView.setOnParallaxScroll(new UltimateRecyclerView.OnParallaxScroll() {

        @Override
        public void onParallaxScroll(float percentage, float offset, View parallax) {
            Drawable c = toolbar.getBackground();
            c.setAlpha(Math.round(127 + percentage * 128));
            toolbar.setBackgroundDrawable(c);
        }
    });
    ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff"));
    ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    simpleRecyclerViewAdapter.insert(moreNum++ + "  Refresh things", 0);
                    ultimateRecyclerView.setRefreshing(false);
                    // ultimateRecyclerView.scrollBy(0, -50);
                    linearLayoutManager.scrollToPosition(0);
                // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
                // simpleRecyclerViewAdapter.notifyDataSetChanged();
                }
            }, 1000);
        }
    });
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(simpleRecyclerViewAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(ultimateRecyclerView.mRecyclerView);
    simpleRecyclerViewAdapter.setOnDragStartListener(new SimpleAdapter.OnStartDragListener() {

        @Override
        public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
            mItemTouchHelper.startDrag(viewHolder);
        }
    });
    ultimateRecyclerView.reenableLoadmore();
    ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
    ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {

        @Override
        public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                public void run() {
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                // linearLayoutManager.scrollToPositionWithOffset(maxLastVisiblePosition,-1);
                // linearLayoutManager.scrollToPosition(maxLastVisiblePosition);
                }
            }, 1000);
        }
    });
    // ultimateRecyclerView.setDefaultSwipeToRefreshColorScheme(getResources().getColor(android.R.color.holo_blue_bright),
    // getResources().getColor(android.R.color.holo_green_light),
    // getResources().getColor(android.R.color.holo_orange_light),
    // getResources().getColor(android.R.color.holo_red_light));
    // ultimateRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
    // @Override
    // public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // 
    // }
    // 
    // @Override
    // public void onDownMotionEvent() {
    // 
    // }
    // 
    // @Override
    // public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
    // //                if (observableScrollState == ObservableScrollState.DOWN) {
    // //                    ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // //                    ultimateRecyclerView.showFloatingActionMenu();
    // //                } else if (observableScrollState == ObservableScrollState.UP) {
    // //                    ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // //                    ultimateRecyclerView.hideFloatingActionMenu();
    // //                } else if (observableScrollState == ObservableScrollState.STOP) {
    // //                }
    // URLogs.d("onUpOrCancelMotionEvent");
    // if (observableScrollState == ObservableScrollState.UP) {
    // ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // ultimateRecyclerView.hideFloatingActionMenu();
    // } else if (observableScrollState == ObservableScrollState.DOWN) {
    // ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // ultimateRecyclerView.showFloatingActionMenu();
    // }
    // }
    // });
    ultimateRecyclerView.showFloatingButtonView();
    // 
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
    for (Type type : Type.values()) {
        spinnerAdapter.add(type.name());
    }
    spinner.setAdapter(spinnerAdapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ultimateRecyclerView.setItemAnimator(Type.values()[position].getAnimator());
            ultimateRecyclerView.getItemAnimator().setAddDuration(500);
            ultimateRecyclerView.getItemAnimator().setRemoveDuration(500);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            simpleRecyclerViewAdapter.insert("newly added item", 1);
        }
    });
    findViewById(R.id.del).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            simpleRecyclerViewAdapter.remove(1);
        }
    });
// 
}
Also used : SimpleItemTouchHelperCallback(com.marshalchen.ultimaterecyclerview.itemTouchHelper.SimpleItemTouchHelperCallback) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) StickyRecyclerHeadersDecoration(com.marshalchen.ultimaterecyclerview.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ContextualCardsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getContext();
    final View rootView = inflater.inflate(R.layout.settings_homepage, container, false);
    mCardsContainer = rootView.findViewById(R.id.card_container);
    mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, GridLayoutManager.VERTICAL, false);
    mCardsContainer.setLayoutManager(mLayoutManager);
    mContextualCardsAdapter = new ContextualCardsAdapter(context, this, /* lifecycleOwner */
    mContextualCardManager);
    mCardsContainer.setAdapter(mContextualCardsAdapter);
    mContextualCardManager.setListener(mContextualCardsAdapter);
    mCardsContainer.setListener(this);
    mItemTouchHelper = new ItemTouchHelper(new SwipeDismissalDelegate(mContextualCardsAdapter));
    mItemTouchHelper.attachToRecyclerView(mCardsContainer);
    return rootView;
}
Also used : Context(android.content.Context) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SwipeDismissalDelegate(com.android.settings.homepage.contextualcards.slices.SwipeDismissalDelegate) View(android.view.View)

Example 3 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project AntennaPod by AntennaPod.

the class NewEpisodesFragment method onCreateView.

@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = super.onCreateView(inflater, container, savedInstanceState);
    emptyView.setTitle(R.string.no_new_episodes_head_label);
    emptyView.setMessage(R.string.no_new_episodes_label);
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, 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) {
            EpisodeItemViewHolder holder = (EpisodeItemViewHolder) viewHolder;
            FeedItemMenuHandler.removeNewFlagWithUndo(NewEpisodesFragment.this, holder.getFeedItem());
        }
    };
    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) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NonNull(androidx.annotation.NonNull)

Example 4 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project kdeconnect-android by KDE.

the class CustomDevicesAdapter method onAttachedToRecyclerView.

@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(adapterPos -> callback.onCustomDeviceDismissed(customDevices.get(adapterPos))));
    itemTouchHelper.attachToRecyclerView(recyclerView);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) TextViewCompat(androidx.core.widget.TextViewCompat) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) CustomDeviceItemBinding(org.kde.kdeconnect_tp.databinding.CustomDeviceItemBinding) Drawable(android.graphics.drawable.Drawable) ViewGroup(android.view.ViewGroup) R(org.kde.kdeconnect_tp.R) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) View(android.view.View) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) Build(android.os.Build)

Example 5 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project materialistic by hidroh.

the class SinglePageItemRecyclerViewAdapter method attach.

@Override
public void attach(Context context, RecyclerView recyclerView) {
    super.attach(context, recyclerView);
    mLevelIndicatorWidth = AppUtils.getDimensionInDp(mContext, R.dimen.level_indicator_width);
    mColors = mResourcesProvider.obtainTypedArray(R.array.color_codes);
    mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {

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

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            Item item = getItem(viewHolder.getAdapterPosition());
            if (item == null || item.getKidCount() == 0) {
                return 0;
            }
            return super.getSwipeDirs(recyclerView, viewHolder);
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            int position = viewHolder.getAdapterPosition();
            Item item = getItem(position);
            if (item != null) {
                notifyItemChanged(position);
                toggleKids(item);
            }
        }

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
            float swipeWidth = viewHolder.itemView.getWidth() * getSwipeThreshold(viewHolder);
            dX = Math.max(dX, -swipeWidth);
            dX = Math.min(dX, swipeWidth);
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }

        @Override
        public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
            return 0.1f;
        }
    });
    mItemTouchHelper.attachToRecyclerView(recyclerView);
    recyclerView.addOnScrollListener(mScrollListener);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) Item(io.github.hidroh.materialistic.data.Item) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)6 View (android.view.View)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 NonNull (androidx.annotation.NonNull)3 Canvas (android.graphics.Canvas)2 Drawable (android.graphics.drawable.Drawable)2 EpisodeItemViewHolder (de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 Build (android.os.Build)1 Handler (android.os.Handler)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Spinner (android.widget.Spinner)1 Nullable (androidx.annotation.Nullable)1 AppCompatResources (androidx.appcompat.content.res.AppCompatResources)1 TextViewCompat (androidx.core.widget.TextViewCompat)1 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)1