1 /*
<lambda>null2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.remoteauth.introduction
18 
19 import android.os.Bundle
20 import android.view.LayoutInflater
21 import android.view.View
22 import android.view.ViewGroup
23 import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
24 import com.android.settings.R
25 import com.android.settings.remoteauth.RemoteAuthEnrollBase
26 import com.google.android.setupcompat.template.FooterButton
27 import com.google.android.setupdesign.template.RequireScrollMixin
28 
29 /**
30  * Provides introductory info about remote authenticator unlock.
31  */
32 class RemoteAuthEnrollIntroduction :
33     RemoteAuthEnrollBase(
34         layoutResId = R.layout.remote_auth_enroll_introduction,
35         glifLayoutId = R.id.setup_wizard_layout,
36     ) {
37     private val navController by lazy { findNavController(this) }
38 
39     override fun onCreateView(
40         inflater: LayoutInflater,
41         viewGroup: ViewGroup?,
42         savedInstanceArgs: Bundle?
43     ) =
44         super.onCreateView(inflater, viewGroup, savedInstanceArgs).also {
45             initializeRequireScrollMixin(it)
46         }
47 
48 
49     override fun initializePrimaryFooterButton(): FooterButton {
50         return FooterButton.Builder(context!!)
51             .setText(R.string.security_settings_remoteauth_enroll_introduction_agree)
52             .setListener(::onPrimaryFooterButtonClick)
53             .setButtonType(FooterButton.ButtonType.OPT_IN)
54             .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary)
55             .build()
56     }
57 
58     override fun initializeSecondaryFooterButton(): FooterButton {
59         return FooterButton.Builder(context!!)
60             .setText(R.string.security_settings_remoteauth_enroll_introduction_disagree)
61             .setListener(::onSecondaryFooterButtonClick)
62             .setButtonType(FooterButton.ButtonType.NEXT)
63             .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary)
64             .build()
65     }
66 
67     private fun onPrimaryFooterButtonClick(view: View) {
68         navController.navigate(R.id.action_introduction_to_enrolling)
69     }
70 
71     private fun onSecondaryFooterButtonClick(view: View) {
72         navController.navigateUp()
73     }
74 
75     private fun initializeRequireScrollMixin(view: View) {
76         val layout = checkNotNull(getGlifLayout(view))
77         secondaryFooterButton?.visibility = View.INVISIBLE
78         val requireScrollMixin = layout.getMixin(RequireScrollMixin::class.java)
79         requireScrollMixin.requireScrollWithButton(
80             requireContext(),
81             primaryFooterButton,
82             R.string.security_settings_remoteauth_enroll_introduction_more,
83             ::onPrimaryFooterButtonClick
84         )
85         requireScrollMixin.setOnRequireScrollStateChangedListener { scrollNeeded ->
86             if (scrollNeeded) {
87                 primaryFooterButton.setText(
88                     requireContext(),
89                     R.string.security_settings_remoteauth_enroll_introduction_more
90                 )
91             } else {
92                 primaryFooterButton.setText(
93                     requireContext(),
94                     R.string.security_settings_remoteauth_enroll_introduction_agree
95                 )
96                 secondaryFooterButton?.visibility = View.VISIBLE
97             }
98         }
99     }
100 
101     private companion object {
102         const val TAG = "RemoteAuthEnrollIntro"
103     }
104 }
105