Search in sources :

Example 21 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)

Example 22 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 23 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project iterable-android-sdk by Iterable.

the class IterableInboxFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    IterableLogger.printInfo();
    Bundle arguments = getArguments();
    if (arguments != null) {
        if (arguments.get(INBOX_MODE) instanceof InboxMode) {
            inboxMode = (InboxMode) arguments.get(INBOX_MODE);
        }
        if (arguments.getInt(ITEM_LAYOUT_ID, 0) != 0) {
            itemLayoutId = arguments.getInt(ITEM_LAYOUT_ID);
        }
        if (arguments.getString(IterableConstants.NO_MESSAGES_TITLE) != null) {
            noMessagesTitle = arguments.getString(IterableConstants.NO_MESSAGES_TITLE);
        }
        if (arguments.getString(IterableConstants.NO_MESSAGES_BODY) != null) {
            noMessagesBody = arguments.getString(IterableConstants.NO_MESSAGES_BODY);
        }
    }
    RelativeLayout relativeLayout = (RelativeLayout) inflater.inflate(R.layout.iterable_inbox_fragment, container, false);
    recyclerView = relativeLayout.findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    IterableInboxAdapter adapter = new IterableInboxAdapter(IterableApi.getInstance().getInAppManager().getInboxMessages(), IterableInboxFragment.this, adapterExtension, comparator, filter, dateMapper);
    recyclerView.setAdapter(adapter);
    noMessagesTitleTextView = relativeLayout.findViewById(R.id.emptyInboxTitle);
    noMessagesBodyTextView = relativeLayout.findViewById(R.id.emptyInboxMessage);
    noMessagesTitleTextView.setText(noMessagesTitle);
    noMessagesBodyTextView.setText(noMessagesBody);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new IterableInboxTouchHelper(getContext(), adapter));
    itemTouchHelper.attachToRecyclerView(recyclerView);
    return relativeLayout;
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) Bundle(android.os.Bundle) RelativeLayout(android.widget.RelativeLayout) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Nullable(androidx.annotation.Nullable)

Example 24 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project Signal-Android by signalapp.

the class StickerManagementActivity method initView.

private void initView() {
    this.list = findViewById(R.id.sticker_management_list);
    this.adapter = new StickerManagementAdapter(GlideApp.with(this), this, DeviceProperties.shouldAllowApngStickerAnimation(this));
    list.setLayoutManager(new LinearLayoutManager(this));
    list.setAdapter(adapter);
    new ItemTouchHelper(new StickerManagementItemTouchHelper(new ItemTouchCallback())).attachToRecyclerView(list);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)24 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 View (android.view.View)10 Intent (android.content.Intent)3 Canvas (android.graphics.Canvas)3 NonNull (androidx.annotation.NonNull)3 Context (android.content.Context)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 TextView (android.widget.TextView)2 Nullable (androidx.annotation.Nullable)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 Toolbar (androidx.appcompat.widget.Toolbar)2 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)2 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)2 BindView (butterknife.BindView)2 SwipeDismissalDelegate (com.android.settings.homepage.contextualcards.slices.SwipeDismissalDelegate)2 EpisodeItemViewHolder (de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder)2 ArrayList (java.util.ArrayList)2