package cn.yyxx.commsdk.platform.hnyy.floating;


import static cn.yyxx.commsdk.base.constants.Constants.CLICK_INTERVAL;

import android.app.Activity;
import android.graphics.BitmapFactory;



import cn.yyxx.commsdk.core.entity.SdkLoginInfo;
import cn.yyxx.commsdk.core.utils.ResourceUtil;
import cn.yyxx.commsdk.platform.hnyy.dialog.UserCenterDialog;

public class FloatViewManager {

    private static FloatViewManager manager = null;



    private FloatLogoMenu.Builder builder;


    private long clickLoginTime = 0L;


    private FloatViewManager(Activity activity) {
        initView(activity);
    }



    public static FloatViewManager getInstance(Activity activity) {

        if (manager == null) {
            synchronized (FloatViewManager.class) {
                if (manager == null) {
                    manager = new FloatViewManager(activity);
                }
            }
        }

        return manager;
    }

    public void initView(final Activity activity){

        if (builder == null) {

            builder = new FloatLogoMenu.Builder()
                    .withActivity(activity)
                    .logo(BitmapFactory.decodeResource(activity.getResources(), ResourceUtil.getMipmapId(activity,"hnyy_float_icon")))
                    .setBgDrawable(activity.getResources().getDrawable(ResourceUtil.getDrawableId(activity,"hnyy_game_float_menu_bg")))
                    .defaultLocation(FloatLogoMenu.LEFT)
                    .setOnFloatClickListener(new FloatLogoMenu.OnFloatClickListener() {
                        @Override
                        public void onClick() {

                            if (System.currentTimeMillis() - clickLoginTime < CLICK_INTERVAL) {

                                return;
                            }
                            String  info = SdkLoginInfo.getInstance().toString();
                            clickLoginTime = System.currentTimeMillis();
                            new UserCenterDialog(activity,ResourceUtil.getStyleId(activity,"hnyy_half_black_dialog"), SdkLoginInfo.getInstance().user_center).show();
                        }
                    });




        }
    }

    public void showFloat() {
        builder.show();
    }


    public void hideFloat() {
        builder.hide();
    }

    public void releaseFloat(){builder.release();}


}
