package com.dgrlucky.extend.ui.activity;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.dgrlucky.extend.R;
import com.dgrlucky.extend.base.BaseActivity;
import com.dgrlucky.extend.ui.mvp.model.entity.MeizhiList;
import com.dgrlucky.extend.ui.mvp.presenter.MainIPresenter;
import com.dgrlucky.extend.ui.mvp.view.IMainView;
import com.dgrlucky.extend.util.ExitUtil;
import com.library.view.loading.ProgressView;

import javax.inject.Inject;

import butterknife.BindView;
import me.fangx.haorefresh.HaoRecyclerView;
import me.fangx.haorefresh.LoadMoreListener;


public class OneActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener,
        IMainView, LoadMoreListener {

    @BindView(R.id.recycler_list)
    HaoRecyclerView mRecyclerList;
    @BindView(R.id.swipeRefresh_layout)
    SwipeRefreshLayout mSwipeRefreshLayout;

    @Inject
    MainIPresenter mMainPresenter;
    private long page = 1;

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    @Override
    protected View initView(Bundle savedInstanceState) {
        return null;
    }

    @Override
    protected int layoutId() {
        return R.layout.fragment_main;
    }

    @Override
    protected void onSaveState(Bundle savedInstanceState) {
        //mMainPresenter.attachView(this);
        //mMainPresenter.setDataLayer(getDataLayer());
        mSwipeRefreshLayout.setOnRefreshListener(this);
        mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
        RecyclerView.LayoutManager manager = new StaggeredGridLayoutManager(1,
                StaggeredGridLayoutManager.VERTICAL);
        mRecyclerList.setLayoutManager(manager);
        mRecyclerList.setLoadMoreListener(this);
        ProgressView footLoading = new ProgressView(this);
        footLoading.setIndicatorId(ProgressView.CubeTransition);
        footLoading.setIndicatorColor(getResources().getColor(R.color.colorPrimary));
        mRecyclerList.setFootLoadingView(footLoading);
        TextView textView = new TextView(this);
        textView.setText("宝宝心里苦...");
        mRecyclerList.setFootEndView(textView);
        //mMainPresenter.dataLoading(this);
    }

    @Override
    public void onRefresh() {
        page = 1;
        //mMainPresenter.onRefresh(page);
    }

    @Override
    public void onLoadMore() {
        page++;
        //mMainPresenter.onLoadMore(page);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void dataLoading(MeizhiList meizhis) {

    }

    @Override
    public void showError(String msg, View.OnClickListener onClickListener) {

    }

    @Override
    public void showEmpty(String msg, View.OnClickListener onClickListener, int imageId) {

    }

    @Override
    public void onBackPressed() {
        if (!ExitUtil.isClickAgain()) {
            Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
            return;
        }
        super.onBackPressed();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.settings, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        }
        return super.onOptionsItemSelected(item);
    }

}
