public class ChannelEntity {

    private Long id;
    private String name;
    private String tId;
    private Boolean isSelect;

    public ChannelEntity() {
    }

    public ChannelEntity(Long id) {
        this.id = id;
    }

    public ChannelEntity(Long id, String name, String tId, Boolean isSelect) {
        this.id = id;
        this.name = name;
        this.tId = tId;
        this.isSelect = isSelect;
    }

    public ChannelEntity(String name, String tId, Boolean isSelect) {
        this.name = name;
        this.tId = tId;
        this.isSelect = isSelect;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTId() {
        return tId;
    }

    public void setTId(String tId) {
        this.tId = tId;
    }

    public Boolean getIsSelect() {
        return isSelect;
    }

    public void setIsSelect(Boolean isSelect) {
        this.isSelect = isSelect;
    }

    @Override
    public String toString() {
        return this.name;
    }
} public class ChannelEntityDao extends AbstractDao<ChannelEntity, Long> {

    public static final String TABLENAME = "CHANNEL_ENTITY";

    /**
     * Properties of entity ChannelEntity.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property TId = new Property(2, String.class, "tId", false, "T_ID");
        public final static Property IsSelect = new Property(3, Boolean.class, "isSelect", false, "IS_SELECT");
    };


    public ChannelEntityDao(DaoConfig config) {
        super(config);
    }
    
    public ChannelEntityDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"CHANNEL_ENTITY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"NAME\" TEXT," + // 1: name
                "\"T_ID\" TEXT," + // 2: tId
                "\"IS_SELECT\" INTEGER);"); // 3: isSelect
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CHANNEL_ENTITY\"";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, ChannelEntity entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String tId = entity.getTId();
        if (tId != null) {
            stmt.bindString(3, tId);
        }
 
        Boolean isSelect = entity.getIsSelect();
        if (isSelect != null) {
            stmt.bindLong(4, isSelect ? 1L: 0L);
        }
    }

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    /** @inheritdoc */
    @Override
    public ChannelEntity readEntity(Cursor cursor, int offset) {
        ChannelEntity entity = new ChannelEntity( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // tId
            cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3) != 0 // isSelect
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, ChannelEntity entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setTId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setIsSelect(cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3) != 0);
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(ChannelEntity entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(ChannelEntity entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
} public class AppService {

    private RxNewsAPI mRxNewsAPI;
    private EventBus mEventBus;
    private static AppService mAppService;
    private RxCollection mRxCollection;
    private DBHelper mDBHelper;
    private ResultEntityDao mResultEntityDao;
    private ChannelEntityDao mChannelEntityDao;
    private Gson mGson;

    private static final Object WATCH_DOG = new Object();

    private AppService() {
        mEventBus = EventBus.getDefault();
        mRxCollection = RxCollection.getInstance();
        mRxNewsAPI = RxNewsFactory.getRxNewsAPIInstance();
        mDBHelper = DBHelper.getInstance(MyApplication.getContext());
        mResultEntityDao = mDBHelper.getResultEntityDao();
        mChannelEntityDao = mDBHelper.getChannelEntityDao();
        mGson = new Gson();
    }

    public EventBus getEventBus() {
        return mEventBus;
    }

    public RxNewsAPI getRxNewsAPI() {
        return mRxNewsAPI;
    }

    public RxCollection getRxCollection() {
        return mRxCollection;
    }

    public DBHelper getDBHelper() {
        return mDBHelper;
    }

    public ResultEntityDao getResultEntityDao() {
        return mResultEntityDao;
    }

    public ChannelEntityDao getChannelEntityDao() {
        return mChannelEntityDao;
    }

    public Gson getGson() {
        return mGson;
    }

    public static AppService getInstance() {
        if (mAppService == null) {
            synchronized (WATCH_DOG) {
                if (mAppService == null) {
                    mAppService = new AppService();
                }

            }
        }
        return mAppService;
    }

} public class Constant {

    public static final String BASE_URL = "http://c.m.163.com";

    // 头条
    public static final String HEADLINE_TYPE = "headline";
    // 北京
    public static final String LOCAL_TYPE = "local";
    // 房产
    public static final String HOUSE_TYPE = "house";
    // 其他
    public static final String OTHER_TYPE = "list";

    // 头条
    public static final String HEADLINE_ID = "T1348647909107";
    // 足球
    public static final String FOOTBALL_ID = "T1399700447917";
    // 娱乐
    public static final String ENTERTAINMENT_ID = "T1348648517839";
    // 体育
    public static final String SPORTS_ID = "T1348649079062";
    // 财经
    public static final String FINANCE_ID = "T1348648756099";
    // 科技
    public static final String TECH_ID = "T1348649580692";
    // 电影
    public static final String MOVIE_ID = "T1348648650048";
    // 汽车
    public static final String CAR_ID = "T1348654060988";
    // 笑话
    public static final String JOKE_ID = "T1350383429665";
    // 游戏
    public static final String GAME_ID = "T1348654151579";
    // 时尚
    public static final String FASHION_ID = "T1348650593803";
    // 情感
    public static final String EMOTION_ID = "T1348650839000";
    // 精选
    public static final String CHOICE_ID = "T1370583240249";
    // 电台
    public static final String RADIO_ID = "T1379038288239";
    // nba
    public static final String NBA_ID = "T1348649145984";
    // 数码
    public static final String DIGITAL_ID = "T1348649776727";
    // 移动
    public static final String MOBILE_ID = "T1351233117091";
    // 彩票
    public static final String LOTTERY_ID = "T1356600029035";
    // 教育
    public static final String EDUCATION_ID = "T1348654225495";
    // 论坛
    public static final String FORUM_ID = "T1349837670307";
    // 旅游
    public static final String TOUR_ID = "T1348654204705";
    // 手机
    public static final String PHONE_ID = "T1348649654285";
    // 博客
    public static final String BLOG_ID = "T1349837698345";
    // 社会
    public static final String SOCIETY_ID = "T1348648037603";
    // 家居
    public static final String FURNISHING_ID = "T1348654105308";
    // 暴雪游戏
    public static final String BLIZZARD_ID = "T1397016069906";
    // 亲子
    public static final String PATERNITY_ID = "T1397116135282";
    // CBA
    public static final String CBA_ID = "T1348649475931";
    // 消息
    public static final String MSG_ID = "T1371543208049";
    // 军事
    public static final String MILITARY_ID = "T1348648141035";

    /**
     * 视频 http://c.3g.163.com/nc/video/list/V9LG4B3A0/n/10-10.html
     */
    // 热点视频
    public static final String VIDEO_HOT_ID = "V9LG4B3A0";
    // 娱乐视频
    public static final String VIDEO_ENTERTAINMENT_ID = "V9LG4CHOR";
    // 搞笑视频
    public static final String VIDEO_FUN_ID = "V9LG4E6VR";
    // 精品视频
    public static final String VIDEO_CHOICE_ID = "00850FRB";

    public enum Result {
        SUCCESS, FAIL
    }

    public enum Tag {
        REFRESH, INIT, LOAD_MORE
    }

    public static final String[] VIDEO_TITLE_ARRAYS = new String[]{"热点", "娱乐", "搞笑", "精品"};

    /**
     * 频道
     */
    public static final List<ChannelEntity> CHANNEL_LIST = new ArrayList<ChannelEntity>(30) {
        {
            add(new ChannelEntity("头条", "T1348647909107", true));
            add(new ChannelEntity("足球", "T1399700447917", false));
            add(new ChannelEntity("娱乐", "T1348648517839", false));
            add(new ChannelEntity("体育", "T1348649079062", false));
            add(new ChannelEntity("财经", "T1348648756099", false));
            add(new ChannelEntity("科技", "T1348649580692", false));
            add(new ChannelEntity("电影", "T1348648650048", false));
            add(new ChannelEntity("汽车", "T1348654060988", false));
            add(new ChannelEntity("笑话", "T1350383429665", false));
            add(new ChannelEntity("游戏", "T1348654151579", false));

            add(new ChannelEntity("情感", "T1348650839000", false));
            add(new ChannelEntity("精选", "T1370583240249", false));
            add(new ChannelEntity("电台", "T1379038288239", false));
            add(new ChannelEntity("NBA", "T1348649145984", false));
            add(new ChannelEntity("数码", "T1348649776727", false));
            add(new ChannelEntity("移动", "T1351233117091", false));
            add(new ChannelEntity("彩票", "T1356600029035", false));
            add(new ChannelEntity("教育", "T1348654225495", false));
            add(new ChannelEntity("论坛", "T1349837670307", false));
            add(new ChannelEntity("旅游", "T1348654204705", false));

            add(new ChannelEntity("手机", "T1348649654285", false));
            add(new ChannelEntity("博客", "T1349837698345", false));
            add(new ChannelEntity("社会", "T1348648037603", false));
            add(new ChannelEntity("游戏", "T1397016069906", false));
            add(new ChannelEntity("亲子", "T1397116135282", false));
            add(new ChannelEntity("CBA", "T1348649475931", false));
            add(new ChannelEntity("旅游", "T1348654204705", false));
            add(new ChannelEntity("军事", "T1348648141035", false));

        }
    };

} public class VideoEvent extends BaseEvent {

    private List<Video> videos;

    private String id;

    private Constant.Tag tag;

    public VideoEvent(String id, List<Video> videos, Constant.Tag tag) {
        this.id = id;
        this.videos = videos;
        this.tag = tag;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Constant.Tag getTag() {
        return tag;
    }

    public void setTag(Constant.Tag tag) {
        this.tag = tag;
    }

    public List<Video> getVideos() {
        return videos;
    }

    public void setVideos(List<Video> videos) {
        this.videos = videos;
    }
} public class ChannelAdapter extends DragGridAdapter<ChannelEntity> {

    private Context context;

    public ChannelAdapter(Context context, List list) {
        super(list);
        this.context = context;
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        ChannelEntity channelEntity = getList().get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_channel_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_text.setText(channelEntity.getName());
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_text)
        TextView tv_text;

        public ViewHolder(View view) {
            ButterKnife.bind(this,view);
        }
    }


} public class FragmentAdapter extends FragmentPagerAdapter {

    private List<Fragment> list = new ArrayList<>();
    private List<String> titles = new ArrayList<>();

    public FragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    public void addFragment(Fragment fragment, String title) {
        list.add(fragment);
        titles.add(title);
    }

    public void clear() {
        if (list != null) {
            list.clear();
        }
        if (titles != null) {
            titles.clear();
        }
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }

    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
    }

} public class UnselectedAdapter extends BaseAdapter {

    private Context context;
    private List<ChannelEntity> list;

    public UnselectedAdapter(Context context, List list) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        ChannelEntity channelEntity = list.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_channel_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_text.setText(channelEntity.getName());
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_text)
        TextView tv_text;

        public ViewHolder(View view) {
            ButterKnife.bind(this,view);
        }
    }

} public class FragmentFactory {

    private FragmentFactory() {

    }

    public static Fragment createNewsFragment(String type, String id) {
        NewsFragment newsFragment = new NewsFragment();
        newsFragment.setParams(type, id);
        return newsFragment;
    }

    public static Fragment createVideoFragment(String id) {
        VideoFragment videoFragment = new VideoFragment();
        videoFragment.setParams(id);
        return videoFragment;
    }

} public class DragGridView extends GridView implements AdapterView.OnItemLongClickListener {

    private static final String TAG = "DragGridView";
    private WindowManager mWindowManager;

    private static final int MODE_DRAG = 1;
    private static final int MODE_NORMAL = 2;

    private int mode = MODE_NORMAL;
    private View view;
    private View dragView;
    // 要移动的item原先位置
    private int position;

    private int tempPosition;

    private WindowManager.LayoutParams layoutParams;
    // view的x差值
    private float mX;
    // view的y差值
    private float mY;
    // 手指按下时的x坐标(相对于整个屏幕)
    private float mWindowX;
    // 手指按下时的y坐标(相对于整个屏幕)
    private float mWindowY;
    private int windowHeight;

    public DragGridView(Context context) {
        this(context, null);
    }

    public DragGridView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DragGridView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        setOnItemLongClickListener(this);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mWindowX = ev.getRawX();
                mWindowY = ev.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
        }
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
        if (mode == MODE_DRAG) {
            return false;
        }
        this.view = view;
        this.position = position;
        this.tempPosition = position;
        mX = mWindowX - view.getLeft() - this.getLeft();
        mY = mWindowY - view.getTop() - this.getTop();
        initWindow();
        return true;
    }

    /**
     * 初始化window
     */
    private void initWindow() {
        if (dragView == null) {
            dragView = View.inflate(getContext(), R.layout.layout_channel_item, null);
            dragView.setAlpha(0.6f);
            TextView tv_text = (TextView) dragView.findViewById(R.id.tv_text);
            tv_text.setText(((TextView) view.findViewById(R.id.tv_text)).getText());
        }
        if (layoutParams == null) {
            layoutParams = new WindowManager.LayoutParams();
            layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
            layoutParams.format = PixelFormat.RGBA_8888;
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;  //悬浮窗的行为，比如说不可聚焦，非模态对话框等等
            layoutParams.width = view.getWidth();
            layoutParams.height = view.getHeight();
            layoutParams.x = view.getLeft() + this.getLeft();  //悬浮窗X的位置
            layoutParams.y = view.getTop() + this.getTop() + windowHeight;  //悬浮窗Y的位置
            view.setVisibility(INVISIBLE);
        }

        mWindowManager.addView(dragView, layoutParams);
        mode = MODE_DRAG;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_MOVE:
                if (mode == MODE_DRAG) {
                    updateWindow(ev);
                }
                break;
            case MotionEvent.ACTION_UP:
                if (mode == MODE_DRAG) {
                    closeWindow(ev.getX(), ev.getY());
                }
                break;
        }
        return super.onTouchEvent(ev);
    }

    /**
     * 触摸移动时，window更新
     *
     * @param ev
     */
    private void updateWindow(MotionEvent ev) {
        if (mode == MODE_DRAG) {
            float x = ev.getRawX() - mX;
            float y = ev.getRawY() - mY;
            if (layoutParams != null) {
                layoutParams.x = (int) x;
                layoutParams.y = (int) y + windowHeight;
                mWindowManager.updateViewLayout(dragView, layoutParams);
            }
            float mx = ev.getX();
            float my = ev.getY();
            int dropPosition = pointToPosition((int) mx, (int) my);
            Log.i(TAG, "dropPosition : " + dropPosition + " , tempPosition : " + tempPosition);
            if (dropPosition == tempPosition || dropPosition == GridView.INVALID_POSITION) {
                return;
            }
            itemMove(dropPosition);
        }
    }

        /**
     * 判断item移动
     *
     * @param dropPosition
     */
    private void itemMove(int dropPosition) {
        TranslateAnimation translateAnimation;
        if (dropPosition < tempPosition) {
            for (int i = dropPosition; i < tempPosition; i++) {
                View view = getChildAt(i);
                View nextView = getChildAt(i + 1);
                float xValue = (nextView.getLeft() - view.getLeft()) * 1f / view.getWidth();
                float yValue = (nextView.getTop() - view.getTop()) * 1f / view.getHeight();
                translateAnimation =
                        new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, xValue, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, yValue);
                translateAnimation.setInterpolator(new LinearInterpolator());
                translateAnimation.setFillAfter(true);
                translateAnimation.setDuration(300);
                if (i == tempPosition - 1) {
                    translateAnimation.setAnimationListener(animationListener);
                }
                view.startAnimation(translateAnimation);
            }
        } else {
            for (int i = tempPosition + 1; i <= dropPosition; i++) {
                View view = getChildAt(i);
                View prevView = getChildAt(i - 1);
                float xValue = (prevView.getLeft() - view.getLeft()) * 1f / view.getWidth();
                float yValue = (prevView.getTop() - view.getTop()) * 1f / view.getHeight();
                translateAnimation =
                        new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, xValue, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, yValue);
                translateAnimation.setInterpolator(new LinearInterpolator());
                translateAnimation.setFillAfter(true);
                translateAnimation.setDuration(300);
                if (i == dropPosition) {
                    translateAnimation.setAnimationListener(animationListener);
                }
                view.startAnimation(translateAnimation);
            }
        }
        tempPosition = dropPosition;
    }

    /**
     * 动画监听器
     */
    Animation.AnimationListener animationListener = new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // 在动画完成时将adapter里的数据交换位置
            ListAdapter adapter = getAdapter();
            if (adapter != null && adapter instanceof DragGridAdapter) {
                ((DragGridAdapter) adapter).exchangePosition(position, tempPosition, true);
            }
            position = tempPosition;
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    };

    /**
     * 关闭window
     *
     * @param x
     * @param y
     */
    private void closeWindow(float x, float y) {
        if (dragView != null) {
            mWindowManager.removeView(dragView);
            dragView = null;
            layoutParams = null;
        }
        itemDrop();
        mode = MODE_NORMAL;
    }

    /**
     * 手指抬起时，item下落
     */
    private void itemDrop() {
        if (tempPosition == position || tempPosition == GridView.INVALID_POSITION) {
            getChildAt(position).setVisibility(VISIBLE);
        } else {
            ListAdapter adapter = getAdapter();
            if (adapter != null && adapter instanceof DragGridAdapter) {
                ((DragGridAdapter) adapter).exchangePosition(position, tempPosition, false);
            }
        }
    }

    public void setWindowHeight(int windowHeight) {
        this.windowHeight = windowHeight;
    }
}
import android.animation.ObjectAnimator;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import com.yuqirong.greendao.ChannelEntity;
import com.yuqirong.greendao.ChannelEntityDao;
import com.yuqirong.rxnews.R;
import com.yuqirong.rxnews.app.AppService;
import com.yuqirong.rxnews.app.Constant;
import com.yuqirong.rxnews.event.VideoEvent;
import com.yuqirong.rxnews.ui.adapter.ChannelAdapter;
import com.yuqirong.rxnews.ui.adapter.FragmentAdapter;
import com.yuqirong.rxnews.ui.adapter.UnselectedAdapter;
import com.yuqirong.rxnews.ui.fragment.FragmentFactory;
import com.yuqirong.rxnews.ui.view.DragGridView;
import java.util.List;
import butterknife.Bind;
import butterknife.OnClick;
package com.yuqirong.rxnews.ui.activity;





public class MainActivity extends BaseActivity
        implements NavigationView.OnNavigationItemSelectedListener, ViewPager.OnPageChangeListener, AdapterView.OnItemClickListener {

    @Bind(R.id.mAppBarLayout)
    AppBarLayout mAppBarLayout;
    @Bind(R.id.toolbar)
    Toolbar mToolbar;
    @Bind(R.id.fab)
    FloatingActionButton mFAButton;
    @Bind(R.id.drawer_layout)
    DrawerLayout mDrawerLayout;
    @Bind(R.id.nav_view)
    NavigationView mNavigationView;
    @Bind(R.id.mTabLayout)
    TabLayout mTabLayout;
    @Bind(R.id.mViewPager)
    ViewPager mViewPager;
    @Bind(R.id.ib_arrow)
    ImageButton ib_arrow;

    private FragmentManager fm;
    private FragmentAdapter adapter;
    private List<ChannelEntity> selectList;
    private List<ChannelEntity> unselectList;
    private UnselectedAdapter unselectedAdapter;
    private ChannelAdapter selectedAdapter;

    @Override
    public int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setSupportActionBar(mToolbar);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        mDrawerLayout.setDrawerListener(toggle);
        toggle.syncState();
        mNavigationView.setNavigationItemSelectedListener(this);
        fm = getSupportFragmentManager();
        adapter = new FragmentAdapter(fm);

        List<ChannelEntity> selectChannel = getSelectChannel();

        for (ChannelEntity entity : selectChannel) {
            adapter.addFragment(FragmentFactory.createNewsFragment(Constant.OTHER_TYPE, entity.getTId()), entity.getName());
        }
        mViewPager.setAdapter(adapter);
        mViewPager.addOnPageChangeListener(this);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    // 从数据库中得到选中的栏目
    private List<ChannelEntity> getSelectChannel() {
        ChannelEntityDao channelEntityDao = AppService.getInstance().getChannelEntityDao();