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 package com.android.healthconnect.controller.migration 17 18 import android.content.Context 19 import android.os.Bundle 20 import android.util.Log 21 import android.view.LayoutInflater 22 import android.view.View 23 import android.view.ViewGroup 24 import android.widget.Button 25 import android.widget.Toast 26 import androidx.fragment.app.Fragment 27 import androidx.navigation.fragment.findNavController 28 import com.android.healthconnect.controller.R 29 import com.android.healthconnect.controller.utils.logging.HealthConnectLogger 30 import com.android.healthconnect.controller.utils.logging.MigrationElement 31 import com.android.healthconnect.controller.utils.logging.PageName 32 import dagger.hilt.android.AndroidEntryPoint 33 import javax.inject.Inject 34 35 @AndroidEntryPoint(Fragment::class) 36 class MigrationPausedFragment : Hilt_MigrationPausedFragment() { 37 38 @Inject lateinit var logger: HealthConnectLogger 39 40 companion object { 41 private const val TAG = "MigrationPausedFragment" 42 const val INTEGRATION_PAUSED_SEEN_KEY = "integration_paused_seen" 43 } 44 onCreateViewnull45 override fun onCreateView( 46 inflater: LayoutInflater, 47 container: ViewGroup?, 48 savedInstanceState: Bundle? 49 ): View? { 50 logger.setPageId(PageName.MIGRATION_PAUSED_PAGE) 51 return inflater.inflate(R.layout.migration_paused, container, false) 52 } 53 onViewCreatednull54 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 55 super.onViewCreated(view, savedInstanceState) 56 57 val resumeButton = view.findViewById<Button>(R.id.resume_button) 58 val cancelButton = view.findViewById<Button>(R.id.cancel_button) 59 logger.logImpression(MigrationElement.MIGRATION_PAUSED_CONTINUE_BUTTON) 60 resumeButton.setOnClickListener { 61 logger.logInteraction(MigrationElement.MIGRATION_PAUSED_CONTINUE_BUTTON) 62 try { 63 findNavController().navigate(R.id.action_migrationPausedFragment_to_migrationApk) 64 } catch (exception: Exception) { 65 Log.e(TAG, "Migration APK does not exist", exception) 66 Toast.makeText(requireContext(), R.string.default_error, Toast.LENGTH_SHORT).show() 67 } 68 } 69 70 cancelButton.setOnClickListener { 71 logger.logInteraction(MigrationElement.MIGRATION_UPDATE_NEEDED_CANCEL_BUTTON) 72 val sharedPreferences = 73 requireActivity() 74 .getSharedPreferences("USER_ACTIVITY_TRACKER", Context.MODE_PRIVATE) 75 val integrationPausedSeen = 76 sharedPreferences.getBoolean(INTEGRATION_PAUSED_SEEN_KEY, false) 77 if (!integrationPausedSeen) { 78 sharedPreferences.edit().apply { 79 putBoolean(INTEGRATION_PAUSED_SEEN_KEY, true) 80 apply() 81 } 82 findNavController() 83 .navigate(R.id.action_migrationPausedFragment_to_homeScreen) 84 } 85 requireActivity().finish() 86 } 87 88 } 89 onResumenull90 override fun onResume() { 91 super.onResume() 92 logger.logPageImpression() 93 } 94 } 95