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 com.android.healthconnect.controller.utils.pref 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 68 private val mCheckForUpdates: HealthPreference by pref(CHECK_FOR_UPDATES) 69 70 private val mSeeAllCompatibleApps: HealthPreference by pref(SEE_ALL_COMPATIBLE_APPS) 71 72 private val mSendFeedback: HealthPreference by pref(SEND_FEEDBACK) 73 onCreatePreferencesnull74 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { 75 super.onCreatePreferences(savedInstanceState, rootKey) 76 setPreferencesFromResource(R.xml.help_and_feedback_screen, rootKey) 77 78 mCheckForUpdates.logName = AppPermissionsElement.CHECK_FOR_UPDATES_BUTTON 79 mCheckForUpdates.setOnPreferenceClickListener { 80 findNavController().navigate(R.id.action_cant_see_all_apps_to_updated_apps) 81 true 82 } 83 84 mSeeAllCompatibleApps.logName = AppPermissionsElement.SEE_ALL_COMPATIBLE_APPS_BUTTON 85 mSeeAllCompatibleApps.setOnPreferenceClickListener { 86 findNavController().navigate(R.id.action_cant_see_all_apps_to_play_store) 87 true 88 } 89 90 mSendFeedback.logName = AppPermissionsElement.SEND_FEEDBACK_BUTTON 91 mSendFeedback.setOnPreferenceClickListener { 92 val intent = Intent(Intent.ACTION_BUG_REPORT) 93 intent.putExtra("category_tag", APP_INTEGRATION_REQUEST_BUCKET_ID) 94 activity?.startActivityForResult(intent, FEEDBACK_INTENT_RESULT_CODE) 95 true 96 } 97 98 mSendFeedback.isVisible = deviceInfoUtils.isSendFeedbackAvailable(requireContext()) 99 mCheckForUpdates.isVisible = deviceInfoUtils.isPlayStoreAvailable(requireContext()) 100 mSeeAllCompatibleApps.isVisible = deviceInfoUtils.isPlayStoreAvailable(requireContext()) 101 } 102 } 103