package com.ar.sketch.drawing.activity;

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

import androidx.appcompat.app.AppCompatActivity;

import com.ar.sketch.drawing.ad.AdManager;
import com.ar.sketch.drawing.ad.CountAction;
import com.ar.sketch.drawing.ad.GoMainAction;
import com.ar.sketch.drawing.databinding.ActivityWelBinding;
import com.ar.sketch.drawing.utils.MyUtils;

public class ActivityWelcome extends AppCompatActivity {

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



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


//        countDownTimer= new CountDownTimer(time,100) {
//            @Override
//            public void onTick(long millisUntilFinished) {
//                int progressPercentage = (int) ((100 * millisUntilFinished) / time);
//                int Percentage = 100 - progressPercentage;
//                binding.loadingPb.setProgress(Percentage);
//            }
//
//            @Override
//            public void onFinish() {
//                enterMain();
//            }
//        };
        countDownTimer= AdManager.showWelcomeAd(ActivityWelcome.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(ActivityWelcome.this, ActivityMain.class);
        startActivity(intent);
        finish();
    }

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