package com.mints.goodmoney.manager;

import android.content.Context;
import android.widget.FrameLayout;

import com.mints.goodmoney.MintsApplication;

public class TTPreLoadExpressManager {

    private static TTPreLoadExpressManager _inst;

    private FrameLayout ttFrameLayout;
    private TTNativeExpressManager ttNativeExpressManager;

    public static TTPreLoadExpressManager getInstance() {
        if (_inst != null) {
            return _inst;
        } else {
            _inst = new TTPreLoadExpressManager();
            return _inst;
        }
    }

    private TTPreLoadExpressManager() {
        init();
    }

    private void init() {
        ttNativeExpressManager = new TTNativeExpressManager();
        ttNativeExpressManager.initTTAd(false);
    }

    public FrameLayout getTtFrameLayout() {
        return ttFrameLayout;
    }

    /**
     * 预加载 信息流
     */
    public void loadTtFrameLayout() {
        Context context= MintsApplication.getContext();
        try {
            ttFrameLayout = new FrameLayout(context);
            ttNativeExpressManager.getNativeExpressInit(TtCsjAdManager.TT_AD_NATIVEEXPRESS_AWARD, ttFrameLayout, 310, 0);
            ttNativeExpressManager.setTTNativeExpressManagerListener(new TTNativeExpressManager.TTNativeExpressManagerListener() {
                @Override
                public void setTtExpressView(FrameLayout view) {
                    if (view == null) {
                        ttFrameLayout = null;
                    } else {

                        try {
                            ttFrameLayout = view;
                        } catch (Exception e) {
                            e.printStackTrace();
                            ttFrameLayout = null;
                        }
                    }
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
        ttFrameLayout = null;
    }
}
