• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2025 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 androidx.fragment.app.DialogFragment
21 import androidx.fragment.app.activityViewModels
22 import androidx.navigation.fragment.findNavController
23 import com.android.healthconnect.controller.R
24 import com.android.healthconnect.controller.shared.dialog.AlertDialogBuilder
25 import com.android.healthconnect.controller.utils.logging.SuccessDialogElement
26 import dagger.hilt.android.AndroidEntryPoint
27 
28 
29 /**
30  * A deletion {@link DialogFragment} notifying user about a successful deletion.
31  *
32  * <p> Does not show the See connected apps negative button if the Connected Apps fragment is
33  * already in the stack.
34  */
35 @AndroidEntryPoint(DialogFragment::class)
36 class SuccessDialogFragment : Hilt_SuccessDialogFragment() {
37 
38     private val viewModel: DeletionViewModel by activityViewModels()
39 
40     override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
41         // Get the navigation action depending on the deletion type
42         val deletionType = viewModel.getDeletionType()
43         val navAction =
44             when (deletionType) {
45                 is DeletionType.DeleteHealthPermissionTypes -> {
46                     R.id.action_allDataFragment_to_connectedApps
47                 }
48                 is DeletionType.DeleteEntries,
49                 is DeletionType.DeleteInactiveAppData -> {
50                     R.id.action_entriesAndAccess_to_connectedApps
51                 }
52                 // Connected Apps fragment is already in the stack, no need to navigate.
53                 is DeletionType.DeleteEntriesFromApp,
54                 is DeletionType.DeleteHealthPermissionTypesFromApp,
55                 is DeletionType.DeleteAppData -> {
56                     null
57                 }
58             }
59 
60         val dialogBuilder =
61             AlertDialogBuilder(this, SuccessDialogElement.DELETION_DIALOG_SUCCESS_CONTAINER)
62                 .setIcon(R.attr.successIcon)
63                 .setTitle(R.string.delete_dialog_success_title)
64                 .setMessage(R.string.delete_dialog_success_message)
65                 .setPositiveButton(
66                     R.string.delete_dialog_success_got_it_button,
67                     SuccessDialogElement.DELETION_DIALOG_SUCCESS_DONE_BUTTON,
68                 )
69 
70         navAction?.let {
71             dialogBuilder.setNegativeButton(
72                 R.string.delete_dialog_see_connected_apps_button,
73                 SuccessDialogElement.DELETION_DIALOG_SUCCESS_SEE_CONNECTED_APPS_BUTTON,
74                 onClickListener = { _, _ ->
75                     this.dismiss()
76                     val navController = findNavController()
77                     if (navController.currentDestination?.id == R.id.entriesAndAccessFragment) {
78                         findNavController().navigate(it)
79                     }
80                 },
81             )
82         }
83         return dialogBuilder.create()
84     }
85 
86     companion object {
87         const val TAG = "SuccessDialogFragment"
88     }
89 }
90