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 package com.android.settings.biometrics2.ui.view
17 
18 import android.content.Context
19 import android.os.Bundle
20 import android.view.LayoutInflater
21 import android.view.View
22 import android.view.ViewGroup
23 import androidx.fragment.app.Fragment
24 import androidx.fragment.app.FragmentActivity
25 import androidx.lifecycle.ViewModelProvider
26 import com.android.settings.R
27 import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFinishViewModel
28 import com.google.android.setupcompat.template.FooterBarMixin
29 import com.google.android.setupcompat.template.FooterButton
30 import com.google.android.setupdesign.GlifLayout
31 
32 /**
33  * Fragment which concludes fingerprint enrollment.
34  */
35 class FingerprintEnrollFinishFragment : Fragment() {
36 
37     private var _viewModel: FingerprintEnrollFinishViewModel? = null
38     private val viewModel: FingerprintEnrollFinishViewModel
39         get() = _viewModel!!
40 
41     private val addButtonClickListener =
42         View.OnClickListener { _: View? -> viewModel.onAddButtonClick() }
43 
44     private val nextButtonClickListener =
45         View.OnClickListener { _: View? -> viewModel.onNextButtonClick() }
46     override fun onAttach(context: Context) {
47         super.onAttach(context)
48         _viewModel = ViewModelProvider(requireActivity())[
49             FingerprintEnrollFinishViewModel::class.java
50         ]
51     }
52 
53     override fun onCreateView(
54         inflater: LayoutInflater, container: ViewGroup?,
55         savedInstanceState: Bundle?
56     ) : View = (inflater.inflate(
57             if (viewModel.canAssumeSfps())
58                 R.layout.sfps_enroll_finish
59             else
60                 R.layout.fingerprint_enroll_finish,
61             container,
62             false
63         ) as GlifLayout).also {
64             requireActivity().bindFingerprintEnrollFinishFragment(
65                 view = it,
66                 isSuw = viewModel.request.isSuw,
67                 canAssumeSfps = viewModel.canAssumeSfps(),
68                 isAnotherFingerprintEnrollable = viewModel.isAnotherFingerprintEnrollable,
69                 nextButtonClickListener = nextButtonClickListener,
70                 addButtonClickListener = addButtonClickListener
71             )
72         }
73 }
74 
FragmentActivitynull75 fun FragmentActivity.bindFingerprintEnrollFinishFragment(
76     view: GlifLayout,
77     isSuw: Boolean,
78     canAssumeSfps: Boolean,
79     isAnotherFingerprintEnrollable: Boolean,
80     nextButtonClickListener: View.OnClickListener,
81     addButtonClickListener: View.OnClickListener
82 ) {
83     GlifLayoutHelper(this, view).apply {
84         setHeaderText(R.string.security_settings_fingerprint_enroll_finish_title)
85         setDescriptionText(
86             getString(
87                 if (canAssumeSfps && isAnotherFingerprintEnrollable)
88                     R.string.security_settings_fingerprint_enroll_finish_v2_add_fingerprint_message
89                 else
90                     R.string.security_settings_fingerprint_enroll_finish_v2_message
91             )
92         )
93     }
94 
95     view.getMixin(FooterBarMixin::class.java).also { footer ->
96         footer.primaryButton = FooterButton.Builder(this)
97             .setText(
98                 if (isSuw)
99                     R.string.next_label
100                 else
101                     R.string.security_settings_fingerprint_enroll_done
102             )
103             .setListener(nextButtonClickListener)
104             .setButtonType(FooterButton.ButtonType.NEXT)
105             .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary)
106             .build()
107         if (isAnotherFingerprintEnrollable) {
108             footer.secondaryButton = FooterButton.Builder(this)
109                 .setText(R.string.fingerprint_enroll_button_add)
110                 .setListener(addButtonClickListener)
111                 .setButtonType(FooterButton.ButtonType.SKIP)
112                 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary)
113                 .build()
114         }
115     }
116 
117 }
118