/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mozilla.fenix.settings.sitepermissions import android.content.DialogInterface import android.content.Intent import android.net.Uri import android.os.Bundle import android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button import android.widget.RadioButton import androidx.appcompat.app.AlertDialog import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.navArgs import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissions.Status.ALLOWED import mozilla.components.feature.sitepermissions.SitePermissions.Status.BLOCKED import org.mozilla.fenix.R import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.settings.PhoneFeature import org.mozilla.fenix.settings.initBlockedByAndroidView import org.mozilla.fenix.settings.setStartCheckedIndicator @SuppressWarnings("TooManyFunctions") class SitePermissionsManageExceptionsPhoneFeatureFragment : Fragment() { private lateinit var phoneFeature: PhoneFeature private lateinit var sitePermissions: SitePermissions private lateinit var radioAllow: RadioButton private lateinit var radioBlock: RadioButton private lateinit var blockedByAndroidView: View val settings by lazy { requireContext().settings() } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val args by navArgs() phoneFeature = args.phoneFeatureId.toPhoneFeature() sitePermissions = args.sitePermissions showToolbar(phoneFeature.getLabel(requireContext())) } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val rootView = inflater.inflate(R.layout.fragment_manage_site_permissions_exceptions_feature_phone, container, false) initAskToAllowRadio(rootView) initBlockRadio(rootView) bindBlockedByAndroidContainer(rootView) initClearPermissionsButton(rootView) return rootView } override fun onResume() { super.onResume() initBlockedByAndroidView(phoneFeature, blockedByAndroidView) } private fun initAskToAllowRadio(rootView: View) { radioAllow = rootView.findViewById(R.id.ask_to_allow_radio) val askToAllowText = getString(R.string.preference_option_phone_feature_allowed) radioAllow.text = askToAllowText radioAllow.setOnClickListener { updatedSitePermissions(ALLOWED) } radioAllow.restoreState(ALLOWED) } private fun RadioButton.restoreState(status: SitePermissions.Status) { if (phoneFeature.getStatus(sitePermissions) == status) { this.isChecked = true this.setStartCheckedIndicator() } } private fun initBlockRadio(rootView: View) { radioBlock = rootView.findViewById(R.id.block_radio) radioBlock.setOnClickListener { updatedSitePermissions(BLOCKED) } radioBlock.restoreState(BLOCKED) } private fun initClearPermissionsButton(rootView: View) { val button = rootView.findViewById