package com.danding.yang800;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.danding.yang800.Adapter.LogisticsAdapter;
import com.danding.yang800.Entity.LogisticInfo;
import com.danding.yang800.General.Yang800App;
import com.danding.yang800.Presenter.LogisticsActivityPresenter;
import com.danding.yang800.Util.LogUtil;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.View.CustomProgressDialog;
import com.yanzhenjie.sofia.Sofia;

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

public class LogisticsActivity extends BaseActivity {
//    ListView logostics_listview;
//    LogisticsAdapter adapter;
    ImageView logistics_shopIV;
    @BindView(R.id.logistics_shopnumberTV)
    TextView logistics_shopnumberTV;
    @BindView(R.id.logistics_backTv)
    TextView logistics_backTv;
    @BindView(R.id.logistics_companyTv)
    TextView logistics_companyTv;
    @BindView(R.id.logistics_numTv)
    TextView logistics_numTv;
    @BindView(R.id.logistics_phoneTv)
    TextView logistics_phoneTv;
    LogisticsActivityPresenter presenter;
    @BindView(R.id.logistic_webview)
    WebView logistic_webview;

    @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_logistics);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        ButterKnife.bind(this);
        findView();
        Intent intent = getIntent();
        String packageSn = intent.getStringExtra("packageSn");
        LogUtil.d(packageSn + "packageSn");
//        adapter = new LogisticsAdapter(this);
        presenter = new LogisticsActivityPresenter(this);
        presenter.getInfo(packageSn);
//        presenter = new LogisticsActivityPresenter(this, adapter);
//        presenter.getOrderstatus(order_id);
    }

    private void initWeb() {
        WebSettings wSet = logistic_webview.getSettings();
        wSet.setJavaScriptEnabled(true);
//        logistic_webview.clearCache(true);
//        logistic_webview.setWebChromeClient(new WebChromeClient() {
//        });
//        logistic_webview.getSettings().setAllowFileAccess(true);
//        logistic_webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
////        logistic_webview.getSettings().setJavaScriptEnabled(true);
//        logistic_webview.getSettings().setUseWideViewPort(true);
//        logistic_webview.getSettings().setLoadWithOverviewMode(true);
        logistic_webview.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    }

    @OnClick({R.id.logistics_backTv
    })
    public void onViewClicked(View view) {

        switch (view.getId()) {
            case R.id.logistics_backTv:
                finish();
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    private void findView() {
//        logostics_listview = (ListView) findViewById(R.id.logostics_listview);
//        logistics_statusTV = (TextView) findViewById(R.id.logistics_statusTV);
//        logistics_companyTV = (TextView) findViewById(R.id.logistics_companyTV);
//        logistics_snTV = (TextView) findViewById(R.id.logistics_snTV);
        logistics_shopIV = (ImageView) findViewById(R.id.logistics_shopIV);
        initWeb();
    }

    public void initData(String comName, String nu, String comcontact, String goodsImg, String goodsNum, String expressUrl) {
        Glide.with(this).load(goodsImg).error(R.drawable.huisebeijing).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(logistics_shopIV);
//        logostics_listview.setAdapter(adapter);
        logistics_shopnumberTV.setText(goodsNum + "件商品");
        logistics_companyTv.setText("物流公司：" + comName);
        logistics_numTv.setText("物流单号：" + nu);
        logistics_phoneTv.setText("官方电话：" + comcontact);
        logistic_webview.loadUrl(expressUrl);

    }
}
