Friday 27 November 2020

Disable onItemClick for recyclerView native ads in addOnItemTouchListener

In my recyclerView i display menu item and admob native ads then i have added addOnItemTouchListener to select multiple item.

recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, recyclerView, new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (isMultiSelect)
                    multi_select(position);
                else
                    Toast.makeText(getApplicationContext(), "Details Page", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(View view, int position) {
                if (!isMultiSelect) {
                    multiSelectList = new ArrayList<>();
                    isMultiSelect = true;
                    FVideosAdapter.enableOption(false);

                    if (mActionMode == null) {
                        mActionMode = startActionMode(mActionModeCallback);
                    }
                }
                multi_select(position);
            }
        }));

Now how do i disable onItemClick for UNIFIED_NATIVE_AD_VIEW_TYPE: when isMultiSelect is true ? I don't want to include UNIFIED_NATIVE_AD_VIEW_TYPE for multiselect.

public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
        int viewType = getItemViewType(position);
        switch (viewType) {
            case UNIFIED_NATIVE_AD_VIEW_TYPE:
                UnifiedNativeAd nativeAd = (UnifiedNativeAd) videosPath.get(position);
                populateNativeAdView(nativeAd, ((UnifiedNativeAdViewHolder) holder).getAdView());
                break;
            case MENU_ITEM_VIEW_TYPE:
            default:
                final FolderVideoAdapterViewHolder folderVideoAdapterViewHolder = (FolderVideoAdapterViewHolder) holder;
                final FolderVideoModel folderVideoModel = (FolderVideoModel) videosPath.get(position);
                folderVideoAdapterViewHolder.videoName.setText(folderVideoModel.getFileName());
                folderVideoAdapterViewHolder.duration.setText(folderVideoModel.getDuration());
                folderVideoAdapterViewHolder.size.setText(folderVideoModel.getSize());

                if(selected_usersList.contains(videosPath.get(position)))
                    ((FolderVideoAdapterViewHolder) holder).videoPath.setBackgroundColor(ContextCompat.getColor(mContext, R.color.list_item_selected_state));
                else
                    ((FolderVideoAdapterViewHolder) holder).videoPath.setBackgroundColor(ContextCompat.getColor(mContext, R.color.list_item_normal_state));
        }
    }

detailed multi-select code is here



from Disable onItemClick for recyclerView native ads in addOnItemTouchListener

No comments:

Post a Comment