package com.base.datarecovery.activity.splash

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.text.SpannableString
import android.text.Spanned
import android.text.style.UnderlineSpan
import com.base.datarecovery.MyApplication
import com.base.datarecovery.bean.ConstObject.ifAgreePrivacy
import com.base.datarecovery.databinding.ActivitySplashBinding
import com.base.datarecovery.help.ConfigHelper


class PrivacyManager(
    private val binding: ActivitySplashBinding,
    private val context: Activity,
    private val listener: OnUserPrivacyAgreementListener
) {


    init {
        initView()
    }


    private fun initView() {


        val spannableString = SpannableString("Privacy Policy")
        spannableString.setSpan(
            UnderlineSpan(),
            0,
            spannableString.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        binding.idTvPrivacyPolicy.text = spannableString

        binding.idTvPrivacyPolicy.setOnClickListener {
            val intent = Intent(
                Intent.ACTION_VIEW,
                Uri.parse(ConfigHelper.privacyPolicy)
            )
            context.startActivity(intent)
        }

        var clicked = false
        binding.idTvStart.setOnClickListener {
            if (clicked) {
                return@setOnClickListener
            }
            clicked = true
            ifAgreePrivacy = true
            (context.application as MyApplication).initApp()
            listener.onAgreePrivacy()
        }
    }

    interface OnUserPrivacyAgreementListener {
        fun onAgreePrivacy()
    }

}