package com.swiftcleaner.chovey.view.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.gyf.immersionbar.ImmersionBar;
import com.swiftcleaner.chovey.databinding.ActivityEndCleanJunkBinding;
import com.swiftcleaner.chovey.view.dialog.CustomScoreDialog;
import com.zxdemo.admob.AdmobHelper;
import com.zxdemo.http.ZxHttp;

public class EndCleanJunkActivity extends AppCompatActivity {
    ActivityEndCleanJunkBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityEndCleanJunkBinding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);
        ZxHttp.INSTANCE.getHttpReportInterface("page_EndCleanJunkActivity", "", null);
        initBar();
        initShow();
    }

    private void initShow() {
        Intent intent = getIntent();
        String stringExtra = intent.getStringExtra("cleanstr");
        binding.endCleanJunkFileNum.setText("Cleaned "+ stringExtra +" junk files");
        binding.ivReturn.setOnClickListener(v->{
            initCustDialog();
        });
        binding.buttonBatteryInfoCheckNo.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, InfoActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, InfoActivity.class));
                        finish();
                        return null;
                    }
            );

        });
        binding.buttonAppManagerCheckNo.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, BatteryInfoActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, BatteryInfoActivity.class));
                        finish();
                        return null;
                    }
            );

        });
        binding.buttonWhatsappCheckNo.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, WhatsAppActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, WhatsAppActivity.class));
                        finish();
                        return null;
                    }
            );

        });
        binding.buttonAppProcessCheckNo.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, AppProcessActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, AppProcessActivity.class));
                        finish();
                        return null;
                    }
            );

        });
        binding.buttonCleanJunkCleanNo.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, CleanJunkActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, CleanJunkActivity.class));
                        finish();
                        return null;
                    }
            );

        });
        binding.buttonLargefilecleanerCleanUp.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, LargeFileActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, LargeFileActivity.class));
                        finish();
                        return null;
                    }
            );

        });
        binding.buttonSimilarPhotos.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, SimilarPhotosActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, SimilarPhotosActivity.class));
                        finish();
                        return null;
                    }
            );

        });
        binding.buttonScreenshot.setOnClickListener(v->{
            AdmobHelper.INSTANCE.showInterstitialAd(this,
                    () -> {
                        startActivity(new Intent(this, ScreenShotActivity.class));
                        finish();
                        return null;
                    },
                    () -> {

                        return null;
                    },
                    () -> {
                        startActivity(new Intent(this, ScreenShotActivity.class));
                        finish();
                        return null;
                    }
            );

        });
    }

    private void initBar() {
        ImmersionBar.with(this)
                .transparentStatusBar()  // 透明状态栏
                .statusBarDarkFont(false)  // 状态栏字体颜色为浅色
                .navigationBarDarkIcon(true)  // 导航栏图标颜色为浅色
                .init();
    }

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

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

            @Override
            public void onSubmit() {
                AdmobHelper.INSTANCE.showInterstitialAd(EndCleanJunkActivity.this, () -> {
                            finish();
                            return null;
                        },
                        () -> {
                            return null;
                        },
                        () -> {
                            finish();
                            return null;
                        });
            }
        });
        customScoreDialog.show();
    }
}