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 androidx.preference.Preference 38 import com.android.healthconnect.controller.R 39 import com.android.healthconnect.controller.shared.preference.HealthPreference 40 import com.android.healthconnect.controller.shared.preference.HealthPreferenceFragment 41 import com.android.healthconnect.controller.utils.DeviceInfoUtils 42 import com.android.healthconnect.controller.utils.logging.AppPermissionsElement 43 import com.android.healthconnect.controller.utils.logging.PageName 44 import dagger.hilt.android.AndroidEntryPoint 45 import javax.inject.Inject 46 47 /** Can't see all your apps fragment for Health Connect. */ 48 @AndroidEntryPoint(HealthPreferenceFragment::class) 49 class HelpAndFeedbackFragment : Hilt_HelpAndFeedbackFragment() { 50 51 companion object { 52 const val CHECK_FOR_UPDATES = "check_for_updates" 53 private const val SEE_ALL_COMPATIBLE_APPS = "see_all_compatible_apps" 54 private const val SEND_FEEDBACK = "send_feedback" 55 const val APP_INTEGRATION_REQUEST_BUCKET_ID = 56 "com.google.android.healthconnect.controller.APP_INTEGRATION_REQUEST" 57 const val USER_INITIATED_FEEDBACK_BUCKET_ID = 58 "com.google.android.healthconnect.controller.USER_INITIATED_FEEDBACK_REPORT" 59 const val FEEDBACK_INTENT_RESULT_CODE = 0 60 } 61 62 init { 63 this.setPageName(PageName.HELP_AND_FEEDBACK_PAGE) 64 } 65 66 @Inject lateinit var deviceInfoUtils: DeviceInfoUtils 67 <lambda>null68 private val mCheckForUpdates: HealthPreference? by lazy { 69 preferenceScreen.findPreference(CHECK_FOR_UPDATES) 70 } 71 <lambda>null72 private val mSeeAllCompatibleApps: HealthPreference? by lazy { 73 preferenceScreen.findPreference(SEE_ALL_COMPATIBLE_APPS) 74 } 75 <lambda>null76 private val mSendFeedback: Preference? by lazy { 77 preferenceScreen.findPreference(SEND_FEEDBACK) 78 } 79 onCreatePreferencesnull80 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { 81 super.onCreatePreferences(savedInstanceState, rootKey) 82 setPreferencesFromResource(R.xml.help_and_feedback_screen, rootKey) 83 84 mCheckForUpdates?.logName = AppPermissionsElement.CHECK_FOR_UPDATES_BUTTON 85 mCheckForUpdates?.setOnPreferenceClickListener { 86 findNavController().navigate(R.id.action_cant_see_all_apps_to_updated_apps) 87 true 88 } 89 90 mSeeAllCompatibleApps?.logName = AppPermissionsElement.SEE_ALL_COMPATIBLE_APPS_BUTTON 91 mSeeAllCompatibleApps?.setOnPreferenceClickListener { 92 findNavController().navigate(R.id.action_cant_see_all_apps_to_play_store) 93 true 94 } 95 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