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);
}
Aggregations