├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── drag_sort
│ │ └── dragsortrecyclerview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── drag_sort
│ │ │ └── dragsortrecyclerview
│ │ │ ├── MainActivity.java
│ │ │ └── channel
│ │ │ ├── ChannelActivity.java
│ │ │ ├── ChannelAdapter.java
│ │ │ ├── ChannelBean.java
│ │ │ ├── IItemHelper.java
│ │ │ ├── ToastUtil.java
│ │ │ ├── ToucheCallBcak.java
│ │ │ └── ViewHolder.java
│ └── res
│ │ ├── drawable
│ │ ├── bg_btn.xml
│ │ ├── bg_channel.xml
│ │ ├── bg_channel_n.xml
│ │ └── bg_channel_p.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── channel_activity.xml
│ │ ├── channel_item.xml
│ │ └── channel_title.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_channel_edit.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── drag_sort
│ └── dragsortrecyclerview
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ### DragSortRecyclerView
3 | 仿新闻类app频道切换页面,支持拖拽排序,交换频道等
4 |
5 | ### 效果图
6 |
7 | 
8 |
9 | ### 博客地址:
10 | https://livesun.github.io/2017/09/01/RecyclerThreeStep/
11 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "drag_sort.dragsortrecyclerview"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support:recyclerview-v7:25+'
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\as_sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/drag_sort/dragsortrecyclerview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("drag_sort.dragsortrecyclerview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import drag_sort.dragsortrecyclerview.channel.ChannelActivity;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 | findViewById(R.id.click).setOnClickListener(new View.OnClickListener() {
17 | @Override
18 | public void onClick(View v) {
19 | startActivity(new Intent(MainActivity.this, ChannelActivity.class));
20 | }
21 | });
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/channel/ChannelActivity.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview.channel;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.GridLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.helper.ItemTouchHelper;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import drag_sort.dragsortrecyclerview.R;
14 |
15 |
16 | /**
17 | * 类描述:
18 | * 创建人:livesun
19 | * 创建时间:2017/8/31
20 | * 修改人:
21 | * 修改时间:
22 | * github:https://github.com/livesun
23 | */
24 |
25 | public class ChannelActivity extends AppCompatActivity implements ChannelAdapter.OnStartDragListener {
26 |
27 | private RecyclerView channelRecyler;
28 | private ChannelAdapter mAdapter;
29 | private ItemTouchHelper mTouchHelper;
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.channel_activity);
35 | channelRecyler = (RecyclerView) findViewById(R.id.channl_recyler);
36 | mAdapter = new ChannelAdapter(this,getDatas(),channelRecyler);
37 | GridLayoutManager manager=new GridLayoutManager(this,4);
38 | manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
39 | @Override
40 | public int getSpanSize(int position) {
41 | int itemViewType = mAdapter.getItemViewType(position);
42 | if(itemViewType==mAdapter.CHANNEL_TITLE){
43 | return 4;
44 | }
45 | return 1;
46 | }
47 | });
48 | channelRecyler.setLayoutManager(manager);
49 | channelRecyler.setAdapter(mAdapter);
50 | //创建ItemTouchHelper
51 | mTouchHelper = new ItemTouchHelper(new ToucheCallBcak(mAdapter));
52 | //attach到RecyclerView中
53 | mTouchHelper.attachToRecyclerView(channelRecyler);
54 | mAdapter.setOnStartDragListener(this);
55 | }
56 |
57 | private List getDatas(){
58 | List beanList=new ArrayList<>();
59 | beanList.add(new ChannelBean("我的频道",1));
60 |
61 | for(int i=0;i<10;i++){
62 | beanList.add(new ChannelBean("频道"+i,2));
63 | }
64 |
65 | beanList.add(new ChannelBean("其他频道",1));
66 |
67 | for(int i=0;i<10;i++){
68 | beanList.add(new ChannelBean("其他"+i,3));
69 | }
70 |
71 | return beanList;
72 |
73 | }
74 |
75 | @Override
76 | public void startDrag(RecyclerView.ViewHolder holder) {
77 | mTouchHelper.startDrag(holder);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/channel/ChannelAdapter.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview.channel;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | import drag_sort.dragsortrecyclerview.R;
16 |
17 |
18 | /**
19 | * 类描述:
20 | * 创建人:livesun
21 | * 创建时间:2017/8/31
22 | * 修改人:
23 | * 修改时间:
24 | * github:https://github.com/livesun
25 | */
26 |
27 | public class ChannelAdapter extends RecyclerView.Adapter implements IItemHelper {
28 | //标题
29 | public static final int CHANNEL_TITLE=1;
30 | //我的频道
31 | public static final int MY_CHANNEL=2;
32 | //其他频道
33 | public static final int OTHER_CHANNEL=3;
34 | private final Context mContext;
35 | private List mDatas=new ArrayList<>();
36 | //我的频道集合。
37 | List mMyChannel=new ArrayList<>();
38 | //其他频道集合
39 | List mOtherChannel=new ArrayList<>();
40 |
41 | private final LayoutInflater mInflater;
42 | private RecyclerView mRecyclerView;
43 | //是否编辑模式
44 | private boolean isEdit;
45 |
46 | public ChannelAdapter(Context context, List datas,RecyclerView recyclerView){
47 | this.mContext = context;
48 | this.mDatas = datas;
49 | mInflater = LayoutInflater.from(context);
50 | this.mRecyclerView = recyclerView;
51 | for(int i=0;imMyChannel.size()+1){
200 | int i = position - 2 - mMyChannel.size();
201 | //其他
202 | ChannelBean item = mOtherChannel.get(position-2-mMyChannel.size());
203 | mOtherChannel.remove(item);
204 | item.setTypeView(2);
205 | mMyChannel.add(item);
206 | //这里实现的不择手段了,,之后再改改
207 | notifyData();
208 | notifyItemMoved(position, mMyChannel.size());
209 |
210 | }else if(position>0&&position<=mMyChannel.size()){
211 | //我的
212 | ChannelBean item = mMyChannel.get(position-1);
213 | mMyChannel.remove(item);
214 | item.setTypeView(3);
215 | mOtherChannel.add(0, item);
216 |
217 | notifyData();
218 | notifyItemMoved(position, mMyChannel.size() + 2);
219 | }
220 | }
221 |
222 |
223 | @Override
224 | public void itemMoved(int oldPosition, int newPosition) {
225 | ChannelBean channelBean = mMyChannel.get(oldPosition - 1);
226 | mMyChannel.remove(oldPosition - 1);
227 | mMyChannel.add(newPosition-1,channelBean);
228 | notifyData();
229 | notifyItemMoved(oldPosition, newPosition);
230 | }
231 |
232 | private void notifyData(){
233 | //这里实现的不择手段了,,之后再改改
234 | mDatas.clear();
235 | mDatas.add(new ChannelBean("我的频道",1));
236 | mDatas.addAll(mMyChannel);
237 | mDatas.add(new ChannelBean("其他频道",1));
238 | mDatas.addAll(mOtherChannel);
239 | }
240 |
241 | @Override
242 | public void itemDismiss(int position) {
243 | }
244 |
245 | private OnStartDragListener onStartDragListener;
246 |
247 | public interface OnStartDragListener{
248 | void startDrag(RecyclerView.ViewHolder holder);
249 | }
250 |
251 | public void setOnStartDragListener(OnStartDragListener onStartDragListener){
252 |
253 | this.onStartDragListener = onStartDragListener;
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/channel/ChannelBean.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview.channel;
2 |
3 | /**
4 | * 类描述:
5 | * 创建人:livesun
6 | * 创建时间:2017/8/31
7 | * 修改人:
8 | * 修改时间:
9 | * github:https://github.com/livesun
10 | */
11 |
12 | public class ChannelBean {
13 |
14 | String src;
15 | int typeView;
16 |
17 | public ChannelBean(String src, int typeView) {
18 | this.src = src;
19 | this.typeView = typeView;
20 | }
21 |
22 | public String getSrc() {
23 | return src;
24 | }
25 |
26 | public void setSrc(String src) {
27 | this.src = src;
28 | }
29 |
30 | public int getTypeView() {
31 | return typeView;
32 | }
33 |
34 | public void setTypeView(int typeView) {
35 | this.typeView = typeView;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/channel/IItemHelper.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview.channel;
2 |
3 | /**
4 | * Created by 29028 on 2017/8/19.
5 | */
6 |
7 | public interface IItemHelper {
8 |
9 | void itemMoved(int oldPosition, int newPosition);
10 | void itemDismiss(int position);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/channel/ToastUtil.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview.channel;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 |
7 | /**
8 | * Created by ChenWentan on 2016/8/23.
9 | */
10 | public class ToastUtil {
11 | private static Toast toast;
12 |
13 | /**
14 | * 默认短时间显示 Toast
15 | *
16 | * @param sequence
17 | */
18 | public static void showShort(Context context,CharSequence sequence) {
19 |
20 | if (toast == null) {
21 | toast = Toast.makeText(context, sequence, Toast.LENGTH_SHORT);
22 |
23 | } else {
24 | toast.setText(sequence);
25 | }
26 | toast.show();
27 |
28 | }
29 |
30 | /**
31 | * 短时间显示Toast
32 | *
33 | * @param context
34 | * @param message
35 | */
36 | public static void showShort(Context context, int message) {
37 | if (null == toast) {
38 | toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
39 | // toast.setGravity(Gravity.CENTER, 0, 0);
40 | } else {
41 | toast.setText(message);
42 | }
43 | toast.show();
44 | }
45 |
46 | /**
47 | * 长时间显示Toast
48 | *
49 | * @param context
50 | * @param message
51 | */
52 | public static void showLong(Context context, CharSequence message) {
53 | if (null == toast) {
54 | toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
55 | // toast.setGravity(Gravity.CENTER, 0, 0);
56 | } else {
57 | toast.setText(message);
58 | }
59 | toast.show();
60 | }
61 |
62 | /**
63 | * 长时间显示Toast
64 | *
65 | * @param context
66 | * @param message
67 | */
68 | public static void showLong(Context context, int message) {
69 | if (null == toast) {
70 | toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
71 | // toast.setGravity(Gravity.CENTER, 0, 0);
72 | } else {
73 | toast.setText(message);
74 | }
75 | toast.show();
76 | }
77 |
78 | /**
79 | * 自定义显示时间
80 | *
81 | * @param context
82 | * @param sequence
83 | * @param duration
84 | */
85 | public static void show(Context context, CharSequence sequence, int duration) {
86 | if (toast == null) {
87 | toast = Toast.makeText(context, sequence, duration);
88 | } else {
89 | toast.setText(sequence);
90 | }
91 | toast.show();
92 |
93 | }
94 |
95 | /**
96 | * 隐藏toast
97 | */
98 | public static void hideToast() {
99 | if (toast != null) {
100 | toast.cancel();
101 | }
102 | }
103 |
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/channel/ToucheCallBcak.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview.channel;
2 |
3 | import android.graphics.Canvas;
4 | import android.support.v7.widget.GridLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.support.v7.widget.StaggeredGridLayoutManager;
7 | import android.support.v7.widget.helper.ItemTouchHelper;
8 |
9 | /**
10 | * Created by 29028 on 2017/8/19.
11 | */
12 |
13 | public class ToucheCallBcak extends ItemTouchHelper.Callback {
14 |
15 | private IItemHelper itemHelper;
16 |
17 | public ToucheCallBcak(IItemHelper itemHelper){
18 |
19 | this.itemHelper = itemHelper;
20 | }
21 |
22 | //声明不同转台下的移动方向
23 | @Override
24 | public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
25 | int dragFlags;
26 | RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
27 | if (manager instanceof GridLayoutManager || manager instanceof StaggeredGridLayoutManager) {
28 | dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
29 | } else {
30 | dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
31 | }
32 | // 如果想支持滑动(删除)操作, swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END
33 | int swipeFlags = 0;
34 | return makeMovementFlags(dragFlags, swipeFlags);
35 | }
36 |
37 | // 拖动的条目从旧位置--到新位置时调用
38 | @Override
39 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
40 | // 不同Type之间不可移动
41 | if (viewHolder.getItemViewType() != target.getItemViewType()) {
42 | return false;
43 | }
44 | itemHelper.itemMoved(viewHolder.getLayoutPosition(),target.getLayoutPosition());
45 | return false;
46 | }
47 |
48 | // 滑动到消失调用
49 | @Override
50 | public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
51 | itemHelper.itemDismiss(viewHolder.getLayoutPosition());
52 | }
53 |
54 | /**
55 | * true --开启长按
56 | * false --关闭长按拖动
57 | * @return
58 | */
59 | @Override
60 | public boolean isLongPressDragEnabled() {
61 | return false;
62 | }
63 |
64 | /**
65 | * 关闭侧滑
66 | * @return
67 | */
68 | @Override
69 | public boolean isItemViewSwipeEnabled() {
70 |
71 | return false;
72 | }
73 | //状态改变时调用 比如正在滑动,正在拖动
74 | @Override
75 | public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
76 | super.onSelectedChanged(viewHolder, actionState);
77 | //不是空闲状态--背景加深
78 | // if(actionState!= ItemTouchHelper.ACTION_STATE_IDLE){
79 | // viewHolder.itemView.setBackgroundColor(Color.GRAY);
80 | // }
81 | }
82 |
83 | //滑动完,拖动完调用
84 | @Override
85 | public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
86 | super.clearView(recyclerView, viewHolder);
87 | // viewHolder.itemView.setBackgroundColor(0);
88 | }
89 |
90 | //重写这个方法修改你的UI响应
91 | @Override
92 | public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
93 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
94 | //正在拖动
95 | if(actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
96 | /* final float alpha = 80 - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
97 | viewHolder.itemView.setAlpha(alpha);
98 | viewHolder.itemView.setTranslationX(dX);*/
99 |
100 | }else if(actionState==ItemTouchHelper.ACTION_STATE_IDLE){
101 | //正在滑动
102 | }else if(actionState==ItemTouchHelper.ACTION_STATE_DRAG){
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/drag_sort/dragsortrecyclerview/channel/ViewHolder.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview.channel;
2 |
3 | import android.support.annotation.DrawableRes;
4 | import android.support.annotation.IdRes;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.text.TextUtils;
7 | import android.util.SparseArray;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | /**
13 | * 类描述:ViewHolder
14 | * 创建人:livesun
15 | * 创建时间:2017/8/25
16 | * 修改人:
17 | * 修改时间:
18 | * github:https://github.com/livesun
19 | */
20 | public class ViewHolder extends RecyclerView.ViewHolder {
21 | private SparseArray mViews;
22 | public ViewHolder(View itemView) {
23 | super(itemView);
24 | mViews=new SparseArray();
25 | }
26 |
27 | /**
28 | * 获取View方法
29 | * @param id
30 | * @param
31 | * @return
32 | */
33 | public T getView(@IdRes int id){
34 | View view= mViews.get(id);
35 |
36 | if(view==null){
37 | view =itemView.findViewById(id);
38 | mViews.put(id,view);
39 | }
40 |
41 | return (T) view;
42 | }
43 |
44 | /**
45 | * 设置文本
46 | */
47 | public ViewHolder setText(@IdRes int id, CharSequence text){
48 | TextView textView = getView(id);
49 | if(TextUtils.isEmpty(text)){
50 | textView.setText("");
51 | }else{
52 | textView.setText(text);
53 | }
54 |
55 | return this;
56 | }
57 |
58 |
59 |
60 | /**
61 | * 设置图片
62 | */
63 | public ViewHolder setImageResource(@IdRes int id, @DrawableRes int resId){
64 | ImageView view = getView(id);
65 | view.setImageResource(resId);
66 | return this;
67 | }
68 |
69 | /**
70 | * 设置网络图片
71 | */
72 |
73 | public ViewHolder setImage(@IdRes int id, ImageLoader loader){
74 | ImageView view = getView(id);
75 | loader.loadImage(view,loader.mPath);
76 | return this;
77 | }
78 |
79 | /**
80 | * 解耦图片处理
81 | */
82 | public abstract static class ImageLoader{
83 | String mPath;
84 | public ImageLoader(String path){
85 | this.mPath=path;
86 | }
87 |
88 | protected abstract void loadImage(ImageView imageView,String path);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_channel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_channel_n.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_channel_p.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/channel_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/channel_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
18 |
19 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/channel_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
13 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/livesun/DragSortRecyclerView/891579045eab83312a4c9cdba87cb98b80e83033/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/livesun/DragSortRecyclerView/891579045eab83312a4c9cdba87cb98b80e83033/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_channel_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/livesun/DragSortRecyclerView/891579045eab83312a4c9cdba87cb98b80e83033/app/src/main/res/mipmap-xhdpi/ic_channel_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/livesun/DragSortRecyclerView/891579045eab83312a4c9cdba87cb98b80e83033/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/livesun/DragSortRecyclerView/891579045eab83312a4c9cdba87cb98b80e83033/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/livesun/DragSortRecyclerView/891579045eab83312a4c9cdba87cb98b80e83033/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #9c9c9c
8 | #DDDDDD
9 | #ef4836
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DragSortRecyclerView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/drag_sort/dragsortrecyclerview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package drag_sort.dragsortrecyclerview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/livesun/DragSortRecyclerView/891579045eab83312a4c9cdba87cb98b80e83033/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------