package com.base.appzxhy.ui.main

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import com.base.appzxhy.BuildConfig
import com.base.appzxhy.GlobalConfig.URL_PRIVACY
import com.base.appzxhy.SpConstObject.cleanedSize
import com.base.appzxhy.base.BaseFragment
import com.base.appzxhy.databinding.FragmentSettingsBinding
import com.base.appzxhy.utils.KotlinExt.toFormatSize
import androidx.core.net.toUri
import androidx.core.view.updatePadding
import com.base.appzxhy.R
import com.base.appzxhy.business.ads.AdsMgr
import com.base.appzxhy.utils.MyAnimationUtils


class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsBinding::inflate) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (requireActivity() is SettingActivity) {
            (requireActivity() as SettingActivity).insetsCallBack = {
                binding.clTop.updatePadding(0, it.top, 0, 0)
            }
        }
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        super.initView()



        binding.tvVersion.text = "v${BuildConfig.VERSION_NAME}"
        MyAnimationUtils.rotation(binding.ivBlade)
        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_native_custom)
    }

    override fun initListener() {
        super.initListener()
        binding.clPrivacyPolicy.setOnClickListener {
            startActivity(Intent(Intent.ACTION_VIEW, URL_PRIVACY.toUri()))
        }
        binding.clRateUs.setOnClickListener {

        }

    }

    override fun onResume() {
        super.onResume()
        binding.tvCleanedUp.text = cleanedSize.toFormatSize()
    }
}