Search in sources :

Example 1 with DragSortRecycler

use of com.wm.remusic.widget.DragSortRecycler in project remusic by aa112901.

the class NetItemChangeActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.change_netmusic_item);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.actionbar_back);
    ab.setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    TextView defaultPosition = (TextView) findViewById(R.id.default_item_position);
    // 下划线
    defaultPosition.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    // 抗锯齿
    defaultPosition.getPaint().setAntiAlias(true);
    defaultPosition.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PreferencesUtility.getInstance(NetItemChangeActivity.this).setItemPostion("推荐歌单 最新专辑 主播电台");
        }
    });
    recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
    String str = PreferencesUtility.getInstance(this).getItemPosition();
    final String[] strs = str.split(" ");
    ArrayList<String> list = new ArrayList<>();
    for (String st : strs) {
        list.add(st);
    }
    mAdapter = new SelectAdapter(list);
    recyclerView.setAdapter(mAdapter);
    DragSortRecycler dragSortRecycler = new DragSortRecycler();
    dragSortRecycler.setViewHandleId(R.id.move);
    dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() {

        @Override
        public void onItemMoved(int from, int to) {
            Log.d("queue", "onItemMoved " + from + " to " + to);
            final String str = mAdapter.getMusicAt(from);
            mAdapter.removeSongAt(from);
            mAdapter.addStringTo(to, str);
            mAdapter.notifyDataSetChanged();
            String st = "";
            for (int i = 0; i < mAdapter.strs.size(); i++) {
                if (i == mAdapter.strs.size() - 1) {
                    st = st + mAdapter.strs.get(i);
                    continue;
                }
                st = st + mAdapter.strs.get(i) + " ";
            }
            PreferencesUtility.getInstance(NetItemChangeActivity.this).setItemPostion(st);
        // MusicPlayer.moveQueueItem(from, to);
        }
    });
    recyclerView.addItemDecoration(dragSortRecycler);
    recyclerView.addOnItemTouchListener(dragSortRecycler);
    recyclerView.addOnScrollListener(dragSortRecycler.getScrollListener());
    recyclerView.setHasFixedSize(true);
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(com.wm.remusic.widget.DividerItemDecoration) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Paint(android.graphics.Paint) TextView(android.widget.TextView) DragSortRecycler(com.wm.remusic.widget.DragSortRecycler)

Aggregations

Paint (android.graphics.Paint)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 DividerItemDecoration (com.wm.remusic.widget.DividerItemDecoration)1 DragSortRecycler (com.wm.remusic.widget.DragSortRecycler)1 ArrayList (java.util.ArrayList)1