1 /*
2  * 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  */
18 
19 /**
20  * Copyright (C) 2022 The Android Open Source Project
21  *
22  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23  * in compliance with the License. You may obtain a copy of the License at
24  *
25  * http://www.apache.org/licenses/LICENSE-2.0
26  *
27  * Unless required by applicable law or agreed to in writing, software distributed under the License
28  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29  * or implied. See the License for the specific language governing permissions and limitations under
30  * the License.
31  */
32 package com.android.healthconnect.controller.permissions.shared
33 
34 import android.content.Intent
35 import android.os.Bundle
36 import androidx.navigation.fragment.findNavController
37 import com.android.healthconnect.controller.R
38 import com.android.healthconnect.controller.shared.preference.HealthPreference
39 import com.android.healthconnect.controller.shared.preference.HealthPreferenceFragment
40 import com.android.healthconnect.controller.utils.DeviceInfoUtils
41 import com.android.healthconnect.controller.utils.logging.AppPermissionsElement
42 import com.android.healthconnect.controller.utils.logging.PageName
43 import dagger.hilt.android.AndroidEntryPoint
44 import javax.inject.Inject
45 
46 /** Can't see all your apps fragment for Health Connect. */
47 @AndroidEntryPoint(HealthPreferenceFragment::class)
48 class HelpAndFeedbackFragment : Hilt_HelpAndFeedbackFragment() {
49 
50     companion object {
51         const val CHECK_FOR_UPDATES = "check_for_updates"
52         private const val SEE_ALL_COMPATIBLE_APPS = "see_all_compatible_apps"
53         private const val SEND_FEEDBACK = "send_feedback"
54         const val APP_INTEGRATION_REQUEST_BUCKET_ID =
55             "com.google.android.healthconnect.controller.APP_INTEGRATION_REQUEST"
56         const val USER_INITIATED_FEEDBACK_BUCKET_ID =
57             "com.google.android.healthconnect.controller.USER_INITIATED_FEEDBACK_REPORT"
58         const val FEEDBACK_INTENT_RESULT_CODE = 0
59     }
60 
61     init {
62         this.setPageName(PageName.HELP_AND_FEEDBACK_PAGE)
63     }
64 
65     @Inject lateinit var deviceInfoUtils: DeviceInfoUtils
66 
<lambda>null67     private val mCheckForUpdates: HealthPreference? by lazy {
68         preferenceScreen.findPreference(CHECK_FOR_UPDATES)
69     }
70 
<lambda>null71     private val mSeeAllCompatibleApps: HealthPreference? by lazy {
72         preferenceScreen.findPreference(SEE_ALL_COMPATIBLE_APPS)
73     }
74 
<lambda>null75     private val mSendFeedback: HealthPreference? by lazy {
76         preferenceScreen.findPreference(SEND_FEEDBACK)
77     }
78 
onCreatePreferencesnull79     override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
80         super.onCreatePreferences(savedInstanceState, rootKey)
81         setPreferencesFromResource(R.xml.help_and_feedback_screen, rootKey)
82 
83         mCheckForUpdates?.logName = AppPermissionsElement.CHECK_FOR_UPDATES_BUTTON
84         mCheckForUpdates?.setOnPreferenceClickListener {
85             findNavController().navigate(R.id.action_cant_see_all_apps_to_updated_apps)
86             true
87         }
88 
89         mSeeAllCompatibleApps?.logName = AppPermissionsElement.SEE_ALL_COMPATIBLE_APPS_BUTTON
90         mSeeAllCompatibleApps?.setOnPreferenceClickListener {
91             findNavController().navigate(R.id.action_cant_see_all_apps_to_play_store)
92             true
93         }
94 
95         mSendFeedback?.logName = AppPermissionsElement.SEND_FEEDBACK_BUTTON
96         mSendFeedback?.setOnPreferenceClickListener {
97             val intent = Intent(Intent.ACTION_BUG_REPORT)
98             intent.putExtra("category_tag", APP_INTEGRATION_REQUEST_BUCKET_ID)
99             activity?.startActivityForResult(intent, FEEDBACK_INTENT_RESULT_CODE)
100             true
101         }
102 
103         mSendFeedback?.isVisible = deviceInfoUtils.isSendFeedbackAvailable(requireContext())
104         mCheckForUpdates?.isVisible = deviceInfoUtils.isPlayStoreAvailable(requireContext())
105         mSeeAllCompatibleApps?.isVisible = deviceInfoUtils.isPlayStoreAvailable(requireContext())
106     }
107 }
108