package com.ar.drawing.assistant.paint.ui_activity;

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

import androidx.appcompat.app.AppCompatActivity;

import com.ar.drawing.assistant.paint.ad.AdManager;
import com.ar.drawing.assistant.paint.ad.CountAction;
import com.ar.drawing.assistant.paint.ad.GoMainAction;
import com.ar.drawing.assistant.paint.databinding.ActWelcomeBinding;
import com.ar.drawing.assistant.paint.utils.Common;

public class ActWelcome extends AppCompatActivity {

    private ActWelcomeBinding binding;
    private long time = 11000;
    private CountDownTimer countDownTimer;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActWelcomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Common.setStatusBarTextColor(this, true);
        AdManager.loadAllAd();
        countDownTimer = AdManager.showWelcomeAd(ActWelcome.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(ActWelcome.this, ActMain.class);
        startActivity(intent);
        finish();
    }

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