package com.base.pdfviewerscannerwhite.ui.set

import android.content.Intent
import android.net.Uri
import androidx.activity.addCallback
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.databinding.ActivitySetBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.helper.ConfigHelper
import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.ui.view.RateDialog.showRateDialog
import com.base.pdfviewerscannerwhite.utils.LogEx

class SetActivity : BaseActivity<ActivitySetBinding>() {

    private val TAG = "SetActivity"

    override val binding: ActivitySetBinding by lazy {
        LogEx.logDebug(TAG, "binding")
        ActivitySetBinding.inflate(layoutInflater)
    }


    override fun initView() {
        val ss = getString(R.string.language)
        LogEx.logDebug(TAG, "ss=$ss")
        binding.tvLanguage.text = ss
    }

    override fun initListener() {
        super.initListener()
        onBackPressedDispatcher.addCallback {
            finishToMain()
        }
        binding.flFanhui.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
        binding.llRate.setOnClickListener {
            showRateDialog(true)
        }
        binding.llFeedback.setOnClickListener {
            startActivity(Intent(this, FeedbackActivity::class.java))
        }
        binding.llPrivacy.setOnClickListener {
            val intent = Intent(
                Intent.ACTION_VIEW,
                Uri.parse(ConfigHelper.privacyPolicy)
            )
            startActivity(intent)

        }
        binding.llTerm.setOnClickListener {
            val intent = Intent(
                Intent.ACTION_VIEW,
                Uri.parse(ConfigHelper.termService)
            )
            startActivity(intent)
        }
        binding.llLanguage.setOnClickListener {
            startActivity(Intent(this, SetLanguageActivity::class.java).apply {
                putExtra("from", "Set")
            })
        }
    }

    override fun onResume() {
        super.onResume()
        updateAppLanguage(MyApplication.setLanguage, TAG) {
            MyApplication.setLanguage = it
        }
    }

}