package com.fxy;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;

import com.jaeger.library.StatusBarUtil;
import com.fxy.baselibrary.base.BaseActivity;
import com.fxy.baselibrary.language.other.CommSharedUtil;
import com.fxy.constant.BaseConfig;
import com.fxy.login.LoginActivity;

import java.lang.reflect.Field;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.wangyuwei.particleview.ParticleView;

/**
 * 启动动画
 * @author James.Jiang
 * @date 2020-02-25
 */
public class LauncherActivity extends BaseActivity {
    private Context mContext = this;
    @BindView(R.id.pv_2)
    ParticleView mPv2;

    @Override
    public boolean showToolBar() {
        return false;
    }

    @Override
    public int getContentViewResId() {
        return R.layout.activity_laucher;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    public boolean isPlayMusic() {
        return true;
    }

    @Override
    protected void initView() {
        StatusBarUtil.setColor(this, ContextCompat.getColor(this, R.color.md_blue_500), 0);
        ButterKnife.bind(this);
        // 更新欢迎语
        setPvText();

        // 注册启动动画监听
        mPv2.setOnParticleAnimListener(new ParticleView.ParticleAnimListener() {
            @Override
            public void onAnimationEnd() {
                Intent intent = new Intent(LauncherActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
        mPv2.postDelayed(new Runnable() {
            @Override
            public void run() {
                mPv2.startAnim();
            }
        }, 150);
    }

    @Override
    public boolean openEventBus() {
        return false;
    }


    private void setPvText(){
        try {

            CommSharedUtil commSharedUtil = CommSharedUtil.getInstance(LauncherActivity.this);

            String welcomeTitle = BuildConfig.WELCOME_TITLE; //根据打包设置标题
            String serviceType = commSharedUtil.getString(BaseConfig.SERVICE_TYPE,"PROD");
            if (!serviceType.toUpperCase().equals("PROD")){
                welcomeTitle = serviceType.toLowerCase()+" "+welcomeTitle;
            }

            //String welcomeTitle = BuildConfig.WELCOME_TITLE;
            String versionNum   = BuildConfig.VERSION_NUM;

            ParticleView particleView = findViewById(R.id.pv_2);

            Field mParticleText = ParticleView.class.getDeclaredField("mParticleText");
            mParticleText.setAccessible(true);
            mParticleText.set(particleView,versionNum);

            Field mHostText = ParticleView.class.getDeclaredField("mHostText");
            mHostText.setAccessible(true);
            mHostText.set(particleView,welcomeTitle);

        }catch (NoSuchFieldException e) {
            e.printStackTrace();
        }catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
