Search in sources :

Example 1 with OnItemLongClickListener

use of xyz.zpayh.adapter.OnItemLongClickListener in project SherlockAdapter by EvilBT.

the class MultiItemActivity method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mGridLayoutManager = new GridLayoutManager(this, 3);
    mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(mGridLayoutManager);
    mIsGrid = true;
    mAdapter = new MyMultiAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(@NonNull View view, final int adapterPosition) {
            new AlertDialog.Builder(MultiItemActivity.this).setTitle("是否删除第" + adapterPosition + "项").setPositiveButton("确定", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mAdapter.removeData(adapterPosition);
                }
            }).setNegativeButton("取消", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create().show();
            return true;
        }
    });
    mData = new ArrayList<>();
    initGridData();
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

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

                @Override
                public void run() {
                    mAdapter.setData(mData);
                    refreshLayout.setRefreshing(false);
                }
            }, 500);
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) OnItemLongClickListener(xyz.zpayh.adapter.OnItemLongClickListener) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) MyMultiAdapter(xyz.zpayh.myadapter.adapter.MyMultiAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with OnItemLongClickListener

use of xyz.zpayh.adapter.OnItemLongClickListener in project SherlockAdapter by EvilBT.

the class ExpandableActivity method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mGridLayoutManager = new GridLayoutManager(this, 2);
    mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
    mAdapter = new MyExpandableAdapter();
    // mAdapter.setAlwaysShowFoot(true);
    // mAdapter.setAlwaysShowHead(true);
    mAdapter.addHeadLayout(R.layout.item_head);
    mAdapter.addFootLayout(R.layout.item_foot2);
    // 设置DiffUtil效果
    mAdapter.setCallback(new DiffUtilCallback<IMultiItem>() {

        @Override
        public boolean areItemsTheSame(IMultiItem oldItem, IMultiItem newItem) {
            if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
                return TextUtils.equals(((ImageLabel) oldItem).getData(), ((ImageLabel) newItem).getData());
            }
            if (oldItem instanceof Card && newItem instanceof Card) {
                return ((Card) oldItem).getData().mImageResId == ((Card) newItem).getData().mImageResId;
            }
            return false;
        }

        @Override
        public boolean areContentsTheSame(IMultiItem oldItem, IMultiItem newItem) {
            if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
                return true;
            }
            if (oldItem instanceof Card && newItem instanceof Card) {
                return TextUtils.equals(((Card) oldItem).getData().mImageTitle, ((Card) newItem).getData().mImageTitle);
            }
            return false;
        }
    });
    mRecyclerView.setAdapter(mAdapter);
    // 屏障默认的Change动画
    ((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    // 点击展开/折叠事件
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(@NonNull View view, int adapterPosition) {
            if (view.getId() == R.id.label_root) {
                IMultiItem item = mAdapter.getData(adapterPosition);
                if (item instanceof IExpandable) {
                    IExpandable expandable = (IExpandable) item;
                    if (expandable.isExpandable()) {
                        // 修复issue#2
                        // 这个支持包的bug: https://issuetracker.google.com/issues/37034096
                        mStaggeredGridLayoutManager.invalidateSpanAssignments();
                        mAdapter.collapseAll(adapterPosition);
                    } else {
                        mAdapter.expandAll(adapterPosition);
                    }
                }
            }
        }
    });
    mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(@NonNull View view, int adapterPosition) {
            mAdapter.removeData(adapterPosition);
            return true;
        }
    });
    final SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
    refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refreshData();
            refresh.setRefreshing(false);
        }
    });
    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshData();
        }
    });
    initData();
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) OnItemClickListener(xyz.zpayh.adapter.OnItemClickListener) ImageLabel(xyz.zpayh.myadapter.data.ImageLabel) IExpandable(xyz.zpayh.adapter.IExpandable) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) IMultiItem(xyz.zpayh.adapter.IMultiItem) OnItemLongClickListener(xyz.zpayh.adapter.OnItemLongClickListener) Card(xyz.zpayh.myadapter.data.Card) ImageCard(xyz.zpayh.myadapter.data.ImageCard) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) MyExpandableAdapter(xyz.zpayh.myadapter.adapter.MyExpandableAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with OnItemLongClickListener

use of xyz.zpayh.adapter.OnItemLongClickListener in project SherlockAdapter by EvilBT.

the class BasicActivity method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mFullSpan1 = (CheckBox) findViewById(R.id.cb_head1);
    mFullSpan2 = (CheckBox) findViewById(R.id.cb_head2);
    mSpanSize1 = (EditText) findViewById(R.id.et_span_count1);
    mSpanSize2 = (EditText) findViewById(R.id.et_span_count2);
    mGridLayoutManager = new GridLayoutManager(this, 3);
    mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(mGridLayoutManager);
    mIsGrid = true;
    mAdapter = new MyMultiAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.addHeadLayout(R.layout.item_head1, false, 0);
    mAdapter.addHeadLayout(R.layout.item_head2, false, 0);
    // mAdapter.addFootLayout(R.layout.item_head1,false,0);
    // mAdapter.addFootLayout(R.layout.item_head2,false,0);
    mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(@NonNull View view, final int adapterPosition) {
            new AlertDialog.Builder(BasicActivity.this).setTitle("是否删除第" + adapterPosition + "项").setPositiveButton("确定", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mAdapter.removeData(adapterPosition);
                }
            }).setNegativeButton("取消", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create().show();
            return true;
        }
    });
    mData = new ArrayList<>();
    initGridData();
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

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

                @Override
                public void run() {
                    mAdapter.setData(mData);
                    refreshLayout.setRefreshing(false);
                }
            }, 500);
        }
    });
    mFullSpan1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            changeHead();
        }
    });
    mFullSpan2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            changeHead();
        }
    });
    mSpanSize1.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changeHead();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mSpanSize2.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changeHead();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) OnItemLongClickListener(xyz.zpayh.adapter.OnItemLongClickListener) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) MyMultiAdapter(xyz.zpayh.myadapter.adapter.MyMultiAdapter) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) CompoundButton(android.widget.CompoundButton) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)3 GridLayoutManager (android.support.v7.widget.GridLayoutManager)3 RecyclerView (android.support.v7.widget.RecyclerView)3 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)3 Toolbar (android.support.v7.widget.Toolbar)3 View (android.view.View)3 OnItemLongClickListener (xyz.zpayh.adapter.OnItemLongClickListener)3 DialogInterface (android.content.DialogInterface)2 MyMultiAdapter (xyz.zpayh.myadapter.adapter.MyMultiAdapter)2 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 CompoundButton (android.widget.CompoundButton)1 IExpandable (xyz.zpayh.adapter.IExpandable)1 IMultiItem (xyz.zpayh.adapter.IMultiItem)1 OnItemClickListener (xyz.zpayh.adapter.OnItemClickListener)1 MyExpandableAdapter (xyz.zpayh.myadapter.adapter.MyExpandableAdapter)1 Card (xyz.zpayh.myadapter.data.Card)1 ImageCard (xyz.zpayh.myadapter.data.ImageCard)1 ImageLabel (xyz.zpayh.myadapter.data.ImageLabel)1