package com.dskj.trustlend;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProviders;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.azhon.basic.base.BaseActivity;
import com.dskj.trustlend.databinding.ActivityHomeBinding;
import com.dskj.trustlend.databinding.ActivityMainBinding;
import com.dskj.trustlend.fragment.FaqsFragment;
import com.dskj.trustlend.fragment.HomeFragment;
import com.dskj.trustlend.fragment.IndexFragment;
import com.dskj.trustlend.fragment.MeFragment;
import com.dskj.trustlend.fragment.StatusFragment;
import com.dskj.trustlend.home.MainViewModel;
import com.dskj.trustlend.utils.ToastUtils;
import com.google.android.material.bottomnavigation.BottomNavigationMenuView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;

import java.util.ArrayList;
import java.util.List;

public class StartupActivity extends BaseActivity<MainViewModel, ActivityMainBinding> {
    @Override
    protected int initLayout() {
        return R.layout.activity_main;
    }

    @SuppressLint("WrongConstant")
    @Override
    protected void initView() {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        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());

            }
        });
    }

    @Override
    protected void initData() {

    }

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


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

    @Override
    protected void showError(Object obj) {

    }
}