package com.danding.yang800;

import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.danding.yang800.Adapter.GiftListAdapter;
import com.danding.yang800.Entity.GiftListInfo;
import com.danding.yang800.Entity.InviteNoteInfo;
import com.danding.yang800.Presenter.GiftListActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.View.XListView;
import com.yanzhenjie.sofia.Sofia;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GiftListActivity extends BaseActivity implements XListView.IXListViewListener {
    @BindView(R.id.giftList_list)
    XListView giftList_list;
    @BindView(R.id.giftList_backTv)
    TextView giftList_backTv;
    GiftListAdapter adapter;
    GiftListActivityPresenter presenter;
    int page = 1;
    int Count = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        int type = StatusColorUtil.StatusBarLightMode(this);
//        if (type > 0) {
//            StatusColorUtil.setStatusBarColor(this, R.color.white);
//            StatusColorUtil.StatusBarLightMode(this, type);
//        }
        setContentView(R.layout.activity_gift_list);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        ButterKnife.bind(this);
        initView();
        adapter = new GiftListAdapter(this);
        presenter = new GiftListActivityPresenter(this, adapter);
        presenter.getInfo(page + "");
    }

    private void initView() {
        giftList_list.setPullRefreshEnable(false);
        giftList_list.setPullLoadEnable(false);
        giftList_list.setAutoLoadEnable(true);
        giftList_list.setXListViewListener(this);
    }


    @OnClick({R.id.giftList_backTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.giftList_backTv:
                finish();
                break;
        }
    }

    public void initData(int pageTotal) {
        Count = pageTotal;
        if (page == 1) {
            giftList_list.setAdapter(adapter);
        } else {
            adapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMore() {
        if (page < Count) {
            page++;
            presenter.getInfo(page + "");
        } else {
            onLoad();
        }
    }

    private void onLoad() {
        giftList_list.stopRefresh();
        giftList_list.stopLoadMore();
    }

    public void toGiftInfo(String storeSkuSn) {
        Intent intent=new Intent(GiftListActivity.this,GiftInfoActivity.class);
        intent.putExtra("storeSkuSn",storeSkuSn);
        startActivity(intent);
    }
}
