package com.dskj.daikuan.ui.activity;


import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.widget.FrameLayout;

import androidx.lifecycle.ViewModelProviders;

import com.azhon.basic.base.BaseActivity;
import com.dskj.daikuan.InitApp;
import com.dskj.daikuan.R;
import com.dskj.daikuan.bean.VideoIndexBean;
import com.dskj.daikuan.databinding.ActivityStartUpBinding;

import com.dskj.daikuan.utils.ToastUtils;
import com.dskj.daikuan.viewModel.home.MainViewModel;

import java.util.ArrayList;
import java.util.Collections;


/**
 * 启动页 项目入口
 *
 * @author xuhuixiang
 */
public class StartUpActivity extends BaseActivity<MainViewModel, ActivityStartUpBinding> {

    @Override
    protected int initLayout() {

        return R.layout.activity_start_up;
    }

    @Override
    protected void initView() {

        viewModel.getAccessToken();

        viewModel.getTokenBeanMutableLiveData().observe(this,bean ->{
            if(bean.getExpires_in()!=-1000){
                InitApp.setToken(bean.getAccess_token());
                goToMainActivity();
            }else{
                ToastUtils.showShort(dataBinding.showBg,bean.getAccess_token());

            }
        });
    }

    /**
     * 跳转到主页面
     */
    private void goToMainActivity() {
        if(!TextUtils.isEmpty(InitApp.getUserToken())){
            startActivity(new Intent(StartUpActivity.this, ShenQingActivity.class));
        }else{
            startActivity(new Intent(StartUpActivity.this,LoginActivity.class));
        }
        overridePendingTransition(0,0);
        finish();
    }

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

    @Override
    protected void initData() {
        dataBinding.setModel(viewModel);
    }

    @Override
    protected MainViewModel initViewModel() {
        return ViewModelProviders.of(this).get(MainViewModel.class);
    }

    @Override
    protected void showError(Object obj) {

    }

    /**
     * 设置一个变量来控制当前开屏页面是否可以跳转，当开屏广告为普链类广告时，点击会打开一个广告落地页，此时开发者还不能打开自己的App主页。当从广告落地页返回以后，
     * 才可以跳转到开发者自己的App主页；当开屏广告是App类广告时只会下载App。
     */
    private void next() {
        goToMainActivity();
    }

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

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

    }

}
