package com.app.wallpaper.myact;

import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.animation.DecelerateInterpolator;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.app.wallpaper.databinding.ActivityLogin2Binding;
import com.app.wallpaper.max.WelComManager;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;

public class LoginActivity extends AppCompatActivity {
    private ActivityLogin2Binding binding;
    private Handler handler = new Handler();

    private CountDownTimer countDownTimer;

    private long time = 10000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityLogin2Binding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        EdgeToEdge.enable(this);

        countDownTimer = WelComManager.initTimer(LoginActivity.this, time, new Function1<Long, Unit>() {
            @Override
            public Unit invoke(Long aLong) {
                float percentage = 100 - ((float) aLong / time) * 100;
                int round = Math.round(percentage);
                binding.progressBar.setProgress(round);
                return null;
            }
        }, new Function0<Unit>() {
            @Override
            public Unit invoke() {
                binding.progressBar.setProgress(100);
                goMain();
                return null;
            }
        });


    }


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

    private void goMain() {
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        startActivity(intent);
        finish(); // 可选：结束当前 Activity
    }

}