package com.danding.yang800;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.UriMatcher;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.danding.yang800.Adapter.SeeShopAdapter;
import com.danding.yang800.Adapter.SeeShopTwoAdapter;
import com.danding.yang800.Entity.SeeShopInfo;
import com.danding.yang800.Entity.SortListInfo;
import com.danding.yang800.General.Yang800App;
import com.danding.yang800.Presenter.SeeActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.View.NetworkProgressDialog;
import com.yanzhenjie.sofia.Sofia;

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

public class SeeActivity extends BaseActivity {
    ListView seeshop_list;
    SeeShopAdapter adapter;
    SeeShopTwoAdapter twoAdapter;
    GridView seeshop_gradlist;
    @BindView(R.id.see_backTv)
    TextView see_backTv;
    @BindView(R.id.see_scutcheon)
    LinearLayout see_scutcheon;
    @BindView(R.id.seeshop_scrollView)
    ScrollView seeshop_scrollView;
    @BindView(R.id.see_shopbackIv)
    ImageView see_shopbackIv;
    @BindView(R.id.see_shopIv)
    ImageView see_shopIv;
    @BindView(R.id.see_shopNameTv)
    TextView see_shopNameTv;
    @BindView(R.id.see_shopDesTv)
    TextView see_shopDesTv;
    SharedPreferences sp;
    private NetworkProgressDialog pd;
    SeeActivityPresenter presenter;
    @BindView(R.id.see_emptyLayout)
    RelativeLayout see_emptyLayout;

    @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_see);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        ButterKnife.bind(this);
        findView();
    }

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

    private void findView() {
        seeshop_list = (ListView) findViewById(R.id.seeshop_list);
        seeshop_gradlist = (GridView) findViewById(R.id.seeshop_gradlist);
        adapter = new SeeShopAdapter(this);
        twoAdapter = new SeeShopTwoAdapter(this);
        seeshop_scrollView.smoothScrollTo(0, 20);
        presenter = new SeeActivityPresenter(this, adapter, twoAdapter);
        seeshop_list.setVisibility(View.GONE);
        seeshop_gradlist.setVisibility(View.VISIBLE);
//
//        for (int i = 0; i < 20; i++) {
//            if (i < 10) {
//                twoAdapter.addData(new SeeShopInfo("贝亲奶嘴自然实感婴儿宽口径奶嘴S/M/L号两只装宝宝硅胶奶嘴/L号两只装宝宝硅胶奶嘴/L号两只装宝宝硅胶奶嘴",
//                        "http://static.b2b2cv2.javamall.com.cn/attachment/store/10/goods/201504021624395876_big.jpg",
//                        "150", "3"));
//            } else {
//                twoAdapter.addData(new SeeShopInfo("贝亲奶嘴自然实感婴儿宽口径奶嘴S/M/L号两只装宝宝硅胶奶嘴",
//                        "http://static.b2b2cv2.javamall.com.cn/attachment/store/10/goods/201504021624395876_big.jpg",
//                        "150", ""));
//            }
//        }
//        seeshop_gradlist.setAdapter(twoAdapter);
        initDialog();
        presenter.getGoodsInfo(sp.getString("storeId", ""));
    }

    public void initDialog() {
        if (pd == null) {
            pd = NetworkProgressDialog.createDialog(this);
            if (!pd.isShowing()) {
                pd.show();
            }
        }
    }

    public void dismissDialog() {
        if (pd != null) {
            pd.dismiss();
            pd = null;
            NetworkProgressDialog.clear();
        }
    }

    public void updateDate(String style, boolean authentication, String name, String des, String avatar, String img) {
        see_shopNameTv.setText(name);
        see_shopDesTv.setText(des);
        if (avatar.equals("")) {
            see_shopIv.setImageResource(R.drawable.main_myhead);
        } else {
            Glide.with(this).load(avatar).error(R.drawable.huisebeijing).
                    diskCacheStrategy(DiskCacheStrategy.SOURCE).into(see_shopIv);

        }
        if (img.equals("")) {
            see_shopbackIv.setImageResource(R.drawable.shop_design_back);
        } else {
            Glide.with(this).load(img).error(R.drawable.huisebeijing).
                    diskCacheStrategy(DiskCacheStrategy.SOURCE).into(see_shopbackIv);

        }
//        Glide.with(this).load("http://" + BuildConfig.HOSTURL + avatar).error(R.mipmap.ic_launcher).
//                diskCacheStrategy(DiskCacheStrategy.SOURCE).into(see_shopIv);
//        Glide.with(this).load("http://" + BuildConfig.HOSTURL + img).error(R.mipmap.ic_launcher).
//                diskCacheStrategy(DiskCacheStrategy.SOURCE).into(see_shopbackIv);
        if (adapter.getLists().size() == 0 && twoAdapter.getLists().size() == 0) {
            see_emptyLayout.setVisibility(View.VISIBLE);
            seeshop_list.setVisibility(View.GONE);
            seeshop_gradlist.setVisibility(View.GONE);
        } else if (style.equals("1")) {
            see_emptyLayout.setVisibility(View.GONE);
            seeshop_list.setVisibility(View.GONE);
            seeshop_gradlist.setVisibility(View.VISIBLE);
            seeshop_gradlist.setAdapter(twoAdapter);
        } else {
            see_emptyLayout.setVisibility(View.GONE);
            seeshop_list.setVisibility(View.VISIBLE);
            seeshop_gradlist.setVisibility(View.GONE);
            seeshop_list.setAdapter(adapter);
        }
        if (authentication) {
            see_scutcheon.setVisibility(View.VISIBLE);
        } else {
            see_scutcheon.setVisibility(View.GONE);
        }

        adapter.notifyDataSetChanged();
    }
}
