package com.paint.trace.drawing.view;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;

import androidx.appcompat.app.AppCompatActivity;

import com.paint.trace.drawing.databinding.ActivityWelcomeBinding;
import com.paint.trace.drawing.other.Utils;
import com.paint.trace.drawing.topon.AdManager;
import com.paint.trace.drawing.topon.CountAction;
import com.paint.trace.drawing.topon.GoMainAction;

public class WelActivity extends AppCompatActivity {

    private ActivityWelcomeBinding binding;
    private long time = 12000;
    private CountDownTimer countDownTimer;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityWelcomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Utils.setStatusBarTextColor(this, true);

        countDownTimer = AdManager.showWelcomeAd(this, time, new CountAction() {
            @Override
            public void onCount(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / time);
                int Percentage = 100 - progressPercentage;
                binding.loadingPb.setProgress(Percentage);
            }
        }, new GoMainAction() {
            @Override
            public void onGo() {
                enterMain();
            }
        });
        countDownTimer.start();
    }
    private void enterMain() {
        binding.loadingPb.setProgress(100);
        Intent intent = new Intent(WelActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

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