Java Code Examples for android.support.v7.widget.helper.ItemTouchHelper#attachToRecyclerView()

The following examples show how to use android.support.v7.widget.helper.ItemTouchHelper#attachToRecyclerView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangeChannelActivity.java    From MicroReader with MIT License 6 votes vote down vote up
private void initView() {
    mToolbar.setTitle(getString(R.string.activity_change_channel_title));
    setSupportActionBar(mToolbar);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    setToolBar(null, mToolbar, true, true, null);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mRv.setLayoutManager(linearLayoutManager);
    ItemDragHelperCallback callback = new ItemDragHelperCallback();
    final ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(mRv);
    mRv.setHasFixedSize(true);
    mRv.setNestedScrollingEnabled(false);
    mChannelAdapter = new ChannelAdapter(this, helper, savedChannel, otherChannel);
    mRv.setAdapter(mChannelAdapter);
    mIChangeChannelPresenter.getChannel();
}
 
Example 2
Source File: NewsChannelActivity.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
private void initData() {
    final List<NewsChannelBean> enableItems = dao.query(Constant.NEWS_CHANNEL_ENABLE);
    final List<NewsChannelBean> disableItems = dao.query(Constant.NEWS_CHANNEL_DISABLE);

    GridLayoutManager manager = new GridLayoutManager(this, 4);
    recyclerView.setLayoutManager(manager);

    ItemDragHelperCallback callback = new ItemDragHelperCallback();
    final ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(recyclerView);

    adapter = new NewsChannelAdapter(this, helper, enableItems, disableItems);
    manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            int viewType = adapter.getItemViewType(position);
            return viewType == NewsChannelAdapter.TYPE_MY || viewType == NewsChannelAdapter.TYPE_OTHER ? 1 : 4;
        }
    });
    recyclerView.setAdapter(adapter);

    adapter.setOnMyChannelItemClickListener((v, position) -> Toast.makeText(NewsChannelActivity.this, enableItems.get(position).getChannelName() + position, Toast.LENGTH_SHORT).show());
}
 
Example 3
Source File: MainActivity.java    From Stock-Hawk with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activityComponent().inject(this);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    mRecyclerView.setAdapter(mStocksAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mStocksAdapter.setOnDismissStockListener(this);
    mMainPresenter.attachView(this);
    mMainPresenter.loadStocks();

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mStocksAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);

    if (getIntent().getBooleanExtra(EXTRA_TRIGGER_SYNC_FLAG, true)) {
        startService(SyncService.getStartIntent(this));
    }
}
 
Example 4
Source File: EditRoomOrderDialog.java    From PowerSwitch_Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected View initContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_edit_room_order_content, container);

    recyclerViewRooms = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    roomNameRecyclerViewAdapter = new RoomNameRecyclerViewAdapter(getContext(), rooms, this);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
    recyclerViewRooms.setLayoutManager(linearLayoutManager);
    recyclerViewRooms.setAdapter(roomNameRecyclerViewAdapter);

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(roomNameRecyclerViewAdapter);
    itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(recyclerViewRooms);

    return rootView;
}
 
Example 5
Source File: LanguagesEditorFragment.java    From OpenHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initFragment(Bundle savedInstanceState) {
    super.initFragment(savedInstanceState);
    setHasOptionsMenu(true);
    setCanLoadMore(false);
    if(LanguagesEditorActivity.LanguageEditorMode.Sort.equals(mPresenter.getMode())){
        ItemTouchHelperCallback callback = new ItemTouchHelperCallback(
                ItemTouchHelper.UP | ItemTouchHelper.DOWN,
                ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this);
        itemTouchHelper = new ItemTouchHelper(callback);
        itemTouchHelper.attachToRecyclerView(recyclerView);
        if(PrefUtils.isLanguagesEditorTipAble()){
            showOperationTip(R.string.languages_editor_tip);
            PrefUtils.set(PrefUtils.LANGUAGES_EDITOR_TIP_ABLE, false);
        }
    }
    addVerticalDivider();
    initSearchEditText();
}
 
Example 6
Source File: TypeEditActivity.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
private void initAdapter() {
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    mAdapter = new TypeEditAdapter(mTypes);
    ItemDragAndSwipeCallback itemDragAndSwipeCallback = new ItemDragAndSwipeCallback(mAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemDragAndSwipeCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);

    itemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START | ItemTouchHelper.END);
    mAdapter.enableSwipeItem();
    mAdapter.setOnItemSwipeListener(onItemSwipeListener);
    mAdapter.enableDragItem(itemTouchHelper);
    mAdapter.setOnItemDragListener(onItemDragListener);
    mRecyclerView.setAdapter(mAdapter);

    mRecyclerView.addOnItemTouchListener(new OnSimpleClickListener(){
        @Override
        public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
            Type data = (Type) baseQuickAdapter.getData().get(i);
            // 编辑分类
            Intent intent = new Intent(mContext, AddEditTypeActivity.class);
            intent.putExtra(AppConstants.EXTRA_ACCOUNT_TYPE, mType);
            intent.putExtra(AppConstants.EXTRA_DATA, data);
            startActivityForResult(intent, CODE_EDIT_TYPE);
        }
    });
}
 
Example 7
Source File: NPlaylistActivity.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("StaticFieldLeak")
void setAdapterClicks() {

    callback = new SimpleItemTouchHelperCallback(adapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);

    adapter.setOnSingleClickListener((view, position ,model, holder) -> {
        // Remove current queue song and make it current...

        for(int i=0;i<models.size();i++) {
            models.get(i).set_playing(false);
        }
        models.get(position).set_playing(true);

        /** For local playback stuff */
        if (!MusicService.localPlayBack)
            MainActivity.ChangeVideo(position);
        else MainActivity.ChangeVideoOffline(position);
        adapter.notifyDataSetChanged();
    });

    adapter.setOnCheckClickListener((view, position, model, holder) -> {
        CheckBox checkBox = (CheckBox) view;
        if (checkBox.isChecked()) {
            checklist.add("value="+position);
            setCheckedCallbacks();
        }else{
            checklist.remove("value="+position);
            setCheckedCallbacks();
        }
    });
}
 
Example 8
Source File: FollowSortActivity.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
public void init() {
    RecyclerView rvFollowSort = findView(R.id.rvFollowSort);
    if (mTicketTypeList != null) {
        ticketTypeAdapter = new TicketTypeSortAdapter(this, mTicketTypeList);
        rvFollowSort.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        rvFollowSort.addItemDecoration(new RecycleViewDivider(this,
                LinearLayoutManager.HORIZONTAL, 1, getResources().getColor(R.color.main_divider_color)));
        rvFollowSort.setAdapter(ticketTypeAdapter);
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(ticketTypeAdapter));
        itemTouchHelper.attachToRecyclerView(rvFollowSort);
    }

}
 
Example 9
Source File: NewsChannelActivity.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
private void initItemDragHelper() {
    ItemDragHelperCallback itemDragHelperCallback = new ItemDragHelperCallback(mMineAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemDragHelperCallback);
    itemTouchHelper.attachToRecyclerView(mMineRecyclerView);

    mMineAdapter.setItemDragHelperCallback(itemDragHelperCallback);
}
 
Example 10
Source File: IgnoreSetting.java    From MemoryCleaner with Apache License 2.0 5 votes vote down vote up
@Override
public void initViews(IgnoreListAdapter recyclerAdapter, Context context, ItemTouchHelper itemTouchHelper) {
    mWaveView.setVisibility(View.GONE);
    recyclerView.setLayoutManager(
            new LinearLayoutManager(context, LinearLayoutManager.VERTICAL,
                    false));
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(recyclerAdapter);
    //mSwipeRefreshLayout.setOnRefreshListener(mIgnoreSettingPresenter);
    mSwipeRefreshLayout.setColorSchemeColors(getColorPrimary());
    mRecyclerFastScroller.attachRecyclerView(recyclerView);
    mCollapsingToolbarLayout.setTitle(0 + "个应用");
    itemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example 11
Source File: CustomNewsActivity.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
private void initRecycle() {
    adapter = new ChannelCustomAdapter(CustomNewsActivity.this);
    adapter.setOnStartDragListener(CustomNewsActivity.this);
    adapter.setOnChangeListener(CustomNewsActivity.this);
    getBinding().content.setAdapter(adapter);
    getBinding().content.setHasFixedSize(true);

    ItemTouchHelper.Callback callback = simpleItemTouch(adapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(getBinding().content);
}
 
Example 12
Source File: WXPreviewControllerView.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
private void initPreviewList() {
    mPreviewRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
    previewAdapter = new MultiPreviewAdapter(selectedList, presenter);
    mPreviewRecyclerView.setAdapter(previewAdapter);
    SimpleItemTouchHelperCallback callback = new SimpleItemTouchHelperCallback(previewAdapter);
    ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(mPreviewRecyclerView);
}
 
Example 13
Source File: StepListFragment.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
private void setUpListContent(long taskId) {
    RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.rv_step_list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    stepListRecyclerViewAdapter = new StepListRecyclerViewAdapter(stepItemClickListener);
    recyclerView.setAdapter(stepListRecyclerViewAdapter);

    stepListRecyclerViewAdapter.setStepItemListItems(stepTemplateRepository.getAll(taskId));

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(stepListRecyclerViewAdapter);
    ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example 14
Source File: BookmarksFragment.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void initFragment(Bundle savedInstanceState) {
    super.initFragment(savedInstanceState);
    setLoadMoreEnable(true);
    ItemTouchHelperCallback callback = new ItemTouchHelperCallback(0,
            ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this);
    itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example 15
Source File: RubbishClean.java    From MemoryCleaner with Apache License 2.0 5 votes vote down vote up
@Override
public void initViews(CacheListAdapter recyclerAdapter, Context context, ItemTouchHelper itemTouchHelper) {
    recyclerView.setLayoutManager(
            new LinearLayoutManager(context, LinearLayoutManager.VERTICAL,
                    false));
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(recyclerAdapter);
    mSwipeRefreshLayout.setOnRefreshListener(mRubbishCleanPresenter);
    mSwipeRefreshLayout.setColorSchemeColors(getColorPrimary());
    itemTouchHelper.attachToRecyclerView(recyclerView);
    mRecyclerFastScroller.attachRecyclerView(recyclerView);
}
 
Example 16
Source File: MainActivity.java    From photosearcher with Apache License 2.0 5 votes vote down vote up
private void setupRightDrawer() {
    mTabListAdapter = new TabListAdapter(
            mTimelineManager,
            this,
            this::onDeleteQuery,
            this::onMoveTab,
            this::onTabSelect);

    mTabListTouchCallback = new TabListTouchHelperCallback(mTabListAdapter);

    mTabList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mTabList.setHasFixedSize(true);
    mTabList.setAdapter(mTabListAdapter);

    mItemTouchHelper = new ItemTouchHelper(mTabListTouchCallback);
    mItemTouchHelper.attachToRecyclerView(mTabList);

    mDrawerToggle = new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            UIUtil.hideKeyboard(MainActivity.this);

            int newPosition = mCurrentTabPosition;
            mDrawerToggle.syncState();

            mHandler.postDelayed(() -> mViewPager.setCurrentItem(newPosition, false), 100);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}
 
Example 17
Source File: NightTouchMoveActivity.java    From YCRefreshView with Apache License 2.0 5 votes vote down vote up
private void initCallBack() {
    ItemTouchHelpCallback callback = new ItemTouchHelpCallback(
            new ItemTouchHelpCallback.OnItemTouchCallbackListener() {
        @Override
        public void onSwiped(int adapterPosition) {
            // 滑动删除的时候,从数据库、数据源移除,并刷新UI
            if (personList != null) {
                //adapter.remove(adapterPosition);

                //1、删除数据
                personList.remove(adapterPosition);
                //2、刷新
                adapter.notifyItemRemoved(adapterPosition);
            }
        }

        @Override
        public boolean onMove(int srcPosition, int targetPosition) {
            if (personList != null) {
                // 更换数据源中的数据Item的位置
                Collections.swap(personList, srcPosition, targetPosition);
                // 更新UI中的Item的位置,主要是给用户看到交互效果
                adapter.notifyItemMoved(srcPosition, targetPosition);
                return true;
            }
            return true;
        }
    });
    callback.setDragEnable(true);
    callback.setSwipeEnable(true);
    callback.setColor(this.getResources().getColor(R.color.colorAccent));
    //创建helper对象,callback监听recyclerView item 的各种状态
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    //关联recyclerView,一个helper对象只能对应一个recyclerView
    itemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example 18
Source File: MinibarEditActivity.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_minibar_edit);
    ButterKnife.bind(this);
    setSupportActionBar(_toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    setTitle(R.string.minibar);

    _adapter = new FastItemAdapter<>();

    SimpleDragCallback touchCallback = new SimpleDragCallback(this);
    ItemTouchHelper touchHelper = new ItemTouchHelper(touchCallback);
    touchHelper.attachToRecyclerView(_recyclerView);

    _recyclerView.setLayoutManager(new LinearLayoutManager(this));
    _recyclerView.setAdapter(_adapter);

    final ArrayList<LauncherAction.ActionDisplayItem> minibarArrangement = AppSettings.get().getMinibarArrangement();
    for (LauncherAction.ActionDisplayItem item : LauncherAction.actionDisplayItems) {
        _adapter.add(new Item(item, minibarArrangement.contains(item)));
    }

    boolean minibarEnable = AppSettings.get().getMinibarEnable();
    _enableSwitch.setChecked(minibarEnable);
    _enableSwitch.setText(minibarEnable ? R.string.on : R.string.off);
    _enableSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            buttonView.setText(isChecked ? R.string.on : R.string.off);
            AppSettings.get().setMinibarEnable(isChecked);
            if (HomeActivity.Companion.getLauncher() != null) {
                HomeActivity.Companion.getLauncher().closeAppDrawer();
                HomeActivity.Companion.getLauncher().getDrawerLayout().setDrawerLockMode(isChecked ? DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            }
        }
    });

    setResult(RESULT_OK);
}
 
Example 19
Source File: UserFeedUpdateContentFragment.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
public void initEmptyView() {
    //初始化列表
    MyLinearLayoutManager linearLayoutManager = new MyLinearLayoutManager(getContext());
    recyclerView.setLayoutManager(linearLayoutManager);

    adapter = new UserFeedPostsVerticalAdapter(eList, getActivity(),null,null);
    adapter.bindToRecyclerView(recyclerView);
    mDecoration = new SuspensionDecoration(getActivity(), eList);
    recyclerView.addItemDecoration(mDecoration);

    recyclerView.setAdapter(adapter);



    SimpleItemTouchHelperCallback callback = new SimpleItemTouchHelperCallback(adapter,getContext(),eList);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);

    //
    adapter.setDecoration(mDecoration,callback);


}
 
Example 20
Source File: PracticalRecyclerView.java    From FastDownloader with Apache License 2.0 4 votes vote down vote up
public void attachItemTouchHelper(ItemTouchHelper itemTouchHelper) {
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
}