package com.swiftcleaner.chovey.view.activity;

import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;

import com.clean.file.b.business.newAdmob.AdmobHelps;
import com.gyf.immersionbar.ImmersionBar;
import com.swiftcleaner.chovey.R;
import com.swiftcleaner.chovey.business.EventUtils;
import com.swiftcleaner.chovey.business.admob.AdmobManager;
import com.swiftcleaner.chovey.databinding.ActivityEndCleanJunkBinding;
import com.swiftcleaner.chovey.model.util.FinishMain;
import com.swiftcleaner.chovey.view.BaseActivity;
import com.swiftcleaner.chovey.view.BaseActivityKotlin;
import com.swiftcleaner.chovey.view.MainActivity;
import com.swiftcleaner.chovey.view.dialog.CustomScoreDialog;
import com.swiftcleaner.chovey.view.dialog.LoadingDialog;

public class EndCleanJunkActivity extends BaseActivity<ActivityEndCleanJunkBinding> {
    private CustomScoreDialog customScoreDialog;
    @Override
    protected ActivityEndCleanJunkBinding getViewBinding() {
        return ActivityEndCleanJunkBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView() {
        initBar();
    }

    @Override
    protected void initData() {
        EventUtils.INSTANCE.event("page_EndCleanJunkActivity", "", null);
        initPage();
        initShow();
    }

    @Override
    protected void onResume() {
        super.onResume();
        AdmobHelps.INSTANCE.showNativeAd(this,binding.flAd,R.layout.layout_ad_native_small,AdmobHelps.INSTANCE.isShowAdNativeBottom(),false);
    }

    private void initPage() {
        Intent intent = getIntent();
        String stringExtra = intent.getStringExtra("cleanstr");
        String title = intent.getStringExtra("title");
        binding.endCleanJunkFileNum.setText(stringExtra);
        binding.title.setText(title);
    }

    private void initShow() {

        binding.ivReturn.setOnClickListener(v -> initCustDialog());
        binding.buttonBatteryInfoCheckNo.setOnClickListener(v -> {
            Intent intent1 = new Intent(this, AnimatorActivity.class);
            intent1.putExtra("animator",2);
            startActivity(intent1);
            finish();
        });
        binding.buttonAppManagerCheckNo.setOnClickListener(v -> {
            Intent intent1 = new Intent(this, AnimatorActivity.class);
            intent1.putExtra("animator",7);
            startActivity(intent1);
            finish();
        });
        binding.buttonWhatsappCheckNo.setOnClickListener(v -> {
            Intent intent1 = new Intent(this, AnimatorActivity.class);
            intent1.putExtra("animator",8);
            startActivity(intent1);
            finish();
        });
        binding.buttonAppProcessCheckNo.setOnClickListener(v -> {
            Intent intent1 = new Intent(this, AnimatorActivity.class);
            intent1.putExtra("animator",6);
            startActivity(intent1);
            finish();
        });
        binding.buttonCleanJunkCleanNo.setOnClickListener(v -> {
            Intent intent1 = new Intent(this, AnimatorActivity.class);
            intent1.putExtra("animator",1);
            startActivity(intent1);
            finish();
        });
        binding.buttonLargefilecleanerCleanUp.setOnClickListener(v -> {
            Intent intent1 = new Intent(this, AnimatorActivity.class);
            intent1.putExtra("animator",3);
            startActivity(intent1);
            finish();
        });
        binding.buttonSimilarPhotos.setOnClickListener(v -> {
            startActivity(new Intent(EndCleanJunkActivity.this, SimilarPhotosActivity.class));
            finish();
        });
        binding.buttonScreenshot.setOnClickListener(v -> {
            Intent intent1 = new Intent(this, AnimatorActivity.class);
            intent1.putExtra("animator",4);
            startActivity(intent1);
            finish();
        });
    }

    private void initBar() {
        ImmersionBar.with(this)
                .transparentStatusBar()
                .statusBarDarkFont(false)
                .navigationBarDarkIcon(true)
                .init();
    }

    @Override
    public void onBackPressed() {
        initCustDialog();
    }

    private void initCustDialog(){
        customScoreDialog = new CustomScoreDialog(this);
        customScoreDialog.setOnDialogClickListener(new CustomScoreDialog.OnDialogClickListener() {
            @Override
            public void onCancel() {
                customScoreDialog.dismiss();
            }

            @Override
            public void onSubmit() {
                if (AdmobHelps.INSTANCE.isShowAdBackInter()){
                    AdmobHelps.INSTANCE.showInterstitialAd(
                            EndCleanJunkActivity.this,
                            () -> {
                                FinishMain.INSTANCE.finishToMain(EndCleanJunkActivity.this);
                                // 当广告被关闭时的逻辑
                                Log.d("AdmobHelps", "Interstitial Ad was dismissed.");
                                return null;
                            },
                            () -> {
                                // 当广告展示完成时的逻辑
                                Log.d("AdmobHelps", "Interstitial Ad was shown.");
                                return null;
                            },
                            () -> {
                                FinishMain.INSTANCE.finishToMain(EndCleanJunkActivity.this);
                                // 当广告加载失败时的逻辑
                                Log.d("AdmobHelps", "Interstitial Ad failed to load.");
                                return null;
                            },
                            false
                    );
                }else {
                    FinishMain.INSTANCE.finishToMain(EndCleanJunkActivity.this);
                }

            }
        });
        customScoreDialog.show();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (customScoreDialog!=null&&customScoreDialog.isShowing()){
            customScoreDialog.dismiss();
            customScoreDialog=null;
        }
    }
}