1 /** <lambda>null2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * ``` 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * ``` 10 * 11 * Unless required by applicable law or agreed to in writing, software distributed under the License 12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 13 * or implied. See the License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 package com.android.healthconnect.controller.deletion 17 18 import android.app.Dialog 19 import android.os.Bundle 20 import android.view.View 21 import android.widget.CheckBox 22 import android.widget.ImageView 23 import android.widget.TextView 24 import androidx.fragment.app.DialogFragment 25 import androidx.fragment.app.activityViewModels 26 import androidx.fragment.app.setFragmentResult 27 import com.android.healthconnect.controller.R 28 import com.android.healthconnect.controller.deletion.DeletionConstants.CONFIRMATION_EVENT 29 import com.android.healthconnect.controller.shared.dialog.AlertDialogBuilder 30 import com.android.healthconnect.controller.utils.AttributeResolver 31 import com.android.healthconnect.controller.utils.logging.DeletionDialogConfirmationElement 32 import com.android.healthconnect.controller.utils.logging.HealthConnectLogger 33 import dagger.hilt.android.AndroidEntryPoint 34 import javax.inject.Inject 35 36 @AndroidEntryPoint(DialogFragment::class) 37 @Deprecated("This won't be used once the NEW_INFORMATION_ARCHITECTURE feature is enabled.") 38 class DeletionAppDataConfirmationDialogFragment : Hilt_DeletionAppDataConfirmationDialogFragment() { 39 40 private val viewModel: DeletionViewModel by activityViewModels() 41 @Inject lateinit var logger: HealthConnectLogger 42 43 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { 44 var isInactiveApp = viewModel.isInactiveApp 45 46 val view: View = layoutInflater.inflate(R.layout.dialog_message_with_checkbox, null) 47 val iconView = view.findViewById(R.id.dialog_icon) as ImageView 48 val title = view.findViewById(R.id.dialog_title) as TextView 49 val message = view.findViewById(R.id.dialog_message) as TextView 50 val checkBox = view.findViewById(R.id.dialog_checkbox) as CheckBox 51 52 val appName = viewModel.deletionParameters.value?.getAppName() 53 val iconDrawable = AttributeResolver.getNullableDrawable(view.context, R.attr.deleteIcon) 54 iconDrawable?.let { 55 iconView.setImageDrawable(it) 56 iconView.visibility = View.VISIBLE 57 } 58 title.text = getString(R.string.confirming_question_app_data_all, appName) 59 message.text = getString(R.string.confirming_question_message) 60 if (isInactiveApp) { 61 checkBox.visibility = View.GONE 62 } else { 63 checkBox.visibility = View.VISIBLE 64 checkBox.text = 65 getString(R.string.confirming_question_app_remove_all_permissions, appName) 66 checkBox.setOnCheckedChangeListener { _, _ -> 67 logger.logInteraction( 68 DeletionDialogConfirmationElement 69 .DELETION_DIALOG_CONFIRMATION_REMOVE_APP_PERMISSIONS_BUTTON) 70 } 71 } 72 73 val alertDialogBuilder = 74 AlertDialogBuilder( 75 this, DeletionDialogConfirmationElement.DELETION_DIALOG_CONFIRMATION_CONTAINER) 76 .setView(view) 77 .setPositiveButton( 78 R.string.confirming_question_delete_button, 79 DeletionDialogConfirmationElement.DELETION_DIALOG_CONFIRMATION_DELETE_BUTTON) { 80 _, 81 _ -> 82 viewModel.setChosenRange(ChosenRange.DELETE_RANGE_ALL_DATA) 83 viewModel.setRemovePermissions(checkBox.isChecked) 84 setFragmentResult(CONFIRMATION_EVENT, Bundle()) 85 } 86 .setNeutralButton( 87 android.R.string.cancel, 88 DeletionDialogConfirmationElement.DELETION_DIALOG_CONFIRMATION_CANCEL_BUTTON) { 89 _, 90 _ -> 91 } 92 .setAdditionalLogging { 93 logger.logImpression( 94 DeletionDialogConfirmationElement 95 .DELETION_DIALOG_CONFIRMATION_REMOVE_APP_PERMISSIONS_BUTTON) 96 } 97 98 return alertDialogBuilder.create() 99 } 100 101 companion object { 102 const val TAG = "DeletionAppDataConfirmationDialogFragment" 103 } 104 } 105