1 /* <lambda>null2 * Copyright (C) 2024 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.healthconnect.controller.selectabledeletion 17 18 import android.app.Dialog 19 import android.os.Bundle 20 import android.view.View 21 import android.widget.ImageView 22 import android.widget.TextView 23 import androidx.fragment.app.DialogFragment 24 import androidx.fragment.app.setFragmentResult 25 import com.android.healthconnect.controller.R 26 import com.android.healthconnect.controller.selectabledeletion.DeletionConstants.CONFIRMATION_KEY 27 import com.android.healthconnect.controller.shared.dialog.AlertDialogBuilder 28 import com.android.healthconnect.controller.utils.AttributeResolver 29 import com.android.healthconnect.controller.utils.logging.DeletionDialogConfirmationElement 30 31 class NewDeletionConfirmationDialogFragment : DialogFragment() { 32 33 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { 34 val view: View = layoutInflater.inflate(R.layout.dialog_custom_layout, null) 35 val title: TextView = view.findViewById(R.id.dialog_title) 36 val message: TextView = view.findViewById(R.id.dialog_custom_message) 37 val icon: ImageView = view.findViewById(R.id.dialog_icon) 38 val iconDrawable = AttributeResolver.getNullableDrawable(view.context, R.attr.deleteIcon) 39 40 title.setText(R.string.some_data_selected_deletion_confirmation_dialog) 41 message.setText(R.string.confirming_question_message) 42 iconDrawable?.let { 43 icon.setImageDrawable(it) 44 icon.visibility = View.VISIBLE 45 } 46 47 val alertDialogBuilder = 48 AlertDialogBuilder( 49 this, DeletionDialogConfirmationElement.DELETION_DIALOG_CONFIRMATION_CONTAINER) 50 .setView(view) 51 .setPositiveButton( 52 R.string.confirming_question_delete_button, 53 // TODO: create new log elements for new IA dialogs 54 DeletionDialogConfirmationElement.DELETION_DIALOG_CONFIRMATION_DELETE_BUTTON) { 55 _, 56 _ -> 57 setFragmentResult(CONFIRMATION_KEY, Bundle()) 58 } 59 .setNeutralButton( 60 android.R.string.cancel, 61 DeletionDialogConfirmationElement.DELETION_DIALOG_CONFIRMATION_CANCEL_BUTTON) 62 63 return alertDialogBuilder.create() 64 } 65 66 companion object { 67 const val TAG = "NewDeletionConfirmationDialog" 68 } 69 } 70