1 /* <lambda>null2 * Copyright (C) 2024 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 package com.android.healthconnect.controller.exportimport 18 19 import android.os.Bundle 20 import android.view.LayoutInflater 21 import android.view.View 22 import android.view.ViewGroup 23 import android.widget.Button 24 import android.widget.RadioGroup 25 import androidx.fragment.app.Fragment 26 import androidx.fragment.app.activityViewModels 27 import androidx.navigation.fragment.findNavController 28 import com.android.healthconnect.controller.R 29 import com.android.healthconnect.controller.exportimport.api.ExportFrequency 30 import com.android.healthconnect.controller.exportimport.api.ExportSettingsViewModel 31 import dagger.hilt.android.AndroidEntryPoint 32 33 /** Export frequency fragment for Health Connect. */ 34 @AndroidEntryPoint(Fragment::class) 35 class ExportFrequencyFragment : Hilt_ExportFrequencyFragment() { 36 37 private val viewModel: ExportSettingsViewModel by activityViewModels() 38 39 // TODO: b/325917283 - Add proper logging for the export frequency fragment. 40 override fun onCreateView( 41 inflater: LayoutInflater, 42 container: ViewGroup?, 43 savedInstanceState: Bundle? 44 ): View? { 45 val view = inflater.inflate(R.layout.export_frequency_screen, container, false) 46 47 val backButton = view.findViewById<Button>(R.id.export_import_cancel_button) 48 val nextButton = view.findViewById<Button>(R.id.export_import_next_button) 49 50 backButton.text = getString(R.string.export_back_button) 51 nextButton.text = getString(R.string.export_next_button) 52 53 backButton.setOnClickListener { requireActivity().finish() } 54 nextButton.setOnClickListener { 55 findNavController() 56 .navigate(R.id.action_exportFrequencyFragment_to_exportDestinationFragment) 57 } 58 59 val radioGroup = view.findViewById<RadioGroup>(R.id.radio_group_frequency) 60 viewModel.selectedExportFrequency.observe(viewLifecycleOwner) { 61 exportFrequency: ExportFrequency? -> 62 when (exportFrequency) { 63 ExportFrequency.EXPORT_FREQUENCY_WEEKLY -> 64 radioGroup?.check(R.id.radio_button_weekly) 65 ExportFrequency.EXPORT_FREQUENCY_MONTHLY -> 66 radioGroup?.check(R.id.radio_button_monthly) 67 ExportFrequency.EXPORT_FREQUENCY_DAILY -> radioGroup?.check(R.id.radio_button_daily) 68 ExportFrequency.EXPORT_FREQUENCY_NEVER -> radioGroup?.check(R.id.radio_button_daily) 69 else -> radioGroup?.check(R.id.radio_button_daily) 70 } 71 } 72 73 radioGroup?.setOnCheckedChangeListener { _, checkedId -> 74 when (checkedId) { 75 R.id.radio_button_daily -> 76 viewModel.updateSelectedFrequency(ExportFrequency.EXPORT_FREQUENCY_DAILY) 77 R.id.radio_button_weekly -> 78 viewModel.updateSelectedFrequency(ExportFrequency.EXPORT_FREQUENCY_WEEKLY) 79 R.id.radio_button_monthly -> 80 viewModel.updateSelectedFrequency(ExportFrequency.EXPORT_FREQUENCY_MONTHLY) 81 } 82 } 83 84 return view 85 } 86 } 87