-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathDragSwipeActivity.java
61 lines (51 loc) · 2.09 KB
/
DragSwipeActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.lin.poweradapter.example.dragswipe;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;
import com.lin.poweradapter.OnStartDragListener;
import com.lin.poweradapter.SimpleItemTouchHelperCallback;
import com.lin.poweradapter.example.Analog;
import com.lin.poweradapter.example.DatabaseService;
import com.lin.poweradapter.example.RecyclerViewActivity;
/**
* Created by lin18 on 2017/4/27.
*/
public class DragSwipeActivity extends RecyclerViewActivity<Analog, DragSwipeAdapter> implements OnStartDragListener {
private ItemTouchHelper mItemTouchHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
configure();
adapter.setItems(DatabaseService.getSampleData(50));
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter, false, true) {
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
super.onSelectedChanged(viewHolder, actionState);
swiprefresh.setEnabled(actionState == ItemTouchHelper.ACTION_STATE_IDLE);
}
};
mItemTouchHelper = new ItemTouchHelper(callback);
mItemTouchHelper.attachToRecyclerView(recyclerView);
}
@NonNull
@Override
protected DragSwipeAdapter createAdapter() {
return new DragSwipeAdapter(this);
}
@Override
public void onItemClick(View v, int position) {
super.onItemClick(v, position);
showToast("onItemClick-> position : " + position + " value : " + adapter.getItem(position).text);
}
@Override
public boolean onItemLongClick(View v, int position) {
showToast("onItemLongClick-> position : " + position + " value : " + adapter.getItem(position).text);
return true;
}
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
mItemTouchHelper.startDrag(viewHolder);
}
}