package com.sxyz.rfid.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.sxyz.rfid.ui.login.LoginActivity;
import com.sxyz.rfid.utils.LocalUtils;

import java.util.Timer;
import java.util.TimerTask;

@SuppressLint("CustomSplashScreen")
public class SplashActivity extends AppCompatActivity {
    private Timer timer;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        startActivity(new Intent(SplashActivity.this, MainActivity.class));//跳转首页
//        finish();
        timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                if (LocalUtils.isLogin()) {
                    startActivity(new Intent(SplashActivity.this, MainActivity2.class));//跳转首页
                    finish();
                } else {
                    startActivity(new Intent(SplashActivity.this, LoginActivity.class));
//                    startActivity(new Intent(SplashActivity.this, MainActivity2.class));
                    finish();
                }
            }
        };
        timer.scheduleAtFixedRate(task, 500, 2000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel();
        }
    }
}
