package com.ym.zxhcsdk.view;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;

import com.ym.zxhcsdk.HcAdBean;
import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.listener.FeedAdListener;
import com.ym.zxhcsdk.listener.RewardVideoAdLoadListener;

import java.util.HashMap;
import java.util.Map;

public class ZXHCRewardVideoAD {
    private Activity context;
    private String codeId;

    public ZXHCRewardVideoAD(Activity context, String codeId) {
        this.context = context;
        this.codeId = codeId;
    }
    private HcAdBean adBean;
    public void loadRewardAD(RewardVideoAdLoadListener mlistener) {
        Map<String, String> map = new HashMap<>();
        map.put("pid", codeId);
        map.put("type", "api");
        map.put("ad_type", "3");
        map.put("ad_w",PhoneUtils.getInstance().getScreenWidth(context)+"");
        map.put("ad_h",PhoneUtils.getInstance().getScreenHeight(context)+"");
        HttpClientUtils.get(ZXHCConstant.BASE_URL, map, new HttpClientUtils.OnRequestCallBack() {
            @Override
            public void onSuccess(String json) {
                adBean = PhoneUtils.getInstance().jsonToObj(json);
                adBean.setShowReport(false);
                adBean.setClickReport(false);
                adBean.setClickDpLinkSucReport(false);
                adBean.setClickDpLinkfailReport(false);
                context.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (mlistener!=null){
                            mlistener.OnAdLoaded();
                        }
                    }
                });

                if (adBean.getSrcUrls().size() > 0) {

                }
            }

            @Override
            public void onError(String errorMsg) {
                context.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (mlistener!=null){
                            mlistener.OnLoadError(errorMsg);
                        }
                        //listener.OnError(errorMsg);
                    }
                });
            }
        });
    }

}
