diff --git a/Corona-Warn-App/build.gradle b/Corona-Warn-App/build.gradle index 1d3229d5b65..d64e5f06f09 100644 --- a/Corona-Warn-App/build.gradle +++ b/Corona-Warn-App/build.gradle @@ -237,7 +237,8 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.work:work-runtime-ktx:2.3.4' - implementation 'android.arch.lifecycle:extensions:1.1.1' + implementation 'android.arch.lifecycle:extensions:2.2.0' + implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0' implementation 'androidx.annotation:annotation:1.1.0' // DAGGER @@ -247,6 +248,7 @@ dependencies { kapt 'com.google.dagger:dagger-compiler:2.28.1' kapt 'com.google.dagger:dagger-android-processor:2.28.1' + // QR implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false } // noinspection GradleDependency - needed for SDK 23 compatibility, in combination with com.journeyapps:zxing-android-embedded:4.1.0 diff --git a/Corona-Warn-App/src/device/java/de.rki.coronawarnapp/ui/main/MainFragment.kt b/Corona-Warn-App/src/device/java/de.rki.coronawarnapp/ui/main/MainFragment.kt index ec73b7aa81b..4b2300bc5c2 100644 --- a/Corona-Warn-App/src/device/java/de.rki.coronawarnapp/ui/main/MainFragment.kt +++ b/Corona-Warn-App/src/device/java/de.rki.coronawarnapp/ui/main/MainFragment.kt @@ -16,6 +16,7 @@ import de.rki.coronawarnapp.risk.TimeVariables import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.timer.TimerHelper import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel @@ -44,15 +45,14 @@ class MainFragment : Fragment() { private val tracingViewModel: TracingViewModel by activityViewModels() private val settingsViewModel: SettingsViewModel by activityViewModels() private val submissionViewModel: SubmissionViewModel by activityViewModels() - private var _binding: FragmentMainBinding? = null - private val binding: FragmentMainBinding get() = _binding!! + private var binding: FragmentMainBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentMainBinding.inflate(inflater) + binding = FragmentMainBinding.inflate(inflater) binding.tracingViewModel = tracingViewModel binding.settingsViewModel = settingsViewModel binding.submissionViewModel = submissionViewModel @@ -60,11 +60,6 @@ class MainFragment : Fragment() { return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestForAPIFragment.kt b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestForAPIFragment.kt index 3f4c4bc0908..355707092ea 100644 --- a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestForAPIFragment.kt +++ b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestForAPIFragment.kt @@ -48,6 +48,7 @@ import de.rki.coronawarnapp.storage.ExposureSummaryRepository import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.storage.tracing.TracingIntervalRepository import de.rki.coronawarnapp.transaction.RiskLevelTransaction +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel import de.rki.coronawarnapp.util.KeyFileHelper import kotlinx.android.synthetic.deviceForTesters.fragment_test_for_a_p_i.button_api_enter_other_keys @@ -118,8 +119,7 @@ class TestForAPIFragment : Fragment(), InternalExposureNotificationPermissionHel private lateinit var qrPagerAdapter: RecyclerView.Adapter // Data and View binding - private var _binding: FragmentTestForAPIBinding? = null - private val binding: FragmentTestForAPIBinding get() = _binding!! + private var binding: FragmentTestForAPIBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, @@ -128,7 +128,7 @@ class TestForAPIFragment : Fragment(), InternalExposureNotificationPermissionHel ): View? { // get the binding reference by inflating it with the current layout - _binding = FragmentTestForAPIBinding.inflate(inflater) + binding = FragmentTestForAPIBinding.inflate(inflater) // set the viewmmodel variable that will be used for data binding binding.tracingViewModel = tracingViewModel @@ -140,11 +140,6 @@ class TestForAPIFragment : Fragment(), InternalExposureNotificationPermissionHel return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestRiskLevelCalculationFragment.kt b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestRiskLevelCalculationFragment.kt index 56a61aa2094..d5de4bcac8c 100644 --- a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestRiskLevelCalculationFragment.kt +++ b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/TestRiskLevelCalculationFragment.kt @@ -33,6 +33,7 @@ import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.storage.RiskLevelRepository import de.rki.coronawarnapp.transaction.RetrieveDiagnosisKeysTransaction import de.rki.coronawarnapp.transaction.RiskLevelTransaction +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel @@ -59,8 +60,7 @@ class TestRiskLevelCalculationFragment : Fragment() { private val tracingViewModel: TracingViewModel by activityViewModels() private val settingsViewModel: SettingsViewModel by activityViewModels() private val submissionViewModel: SubmissionViewModel by activityViewModels() - private var _binding: FragmentTestRiskLevelCalculationBinding? = null - private val binding: FragmentTestRiskLevelCalculationBinding get() = _binding!! + private var binding: FragmentTestRiskLevelCalculationBinding by viewLifecycle() // reference to the client from the Google framework with the given application context private val exposureNotificationClient by lazy { @@ -72,7 +72,7 @@ class TestRiskLevelCalculationFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentTestRiskLevelCalculationBinding.inflate(inflater) + binding = FragmentTestRiskLevelCalculationBinding.inflate(inflater) binding.tracingViewModel = tracingViewModel binding.settingsViewModel = settingsViewModel binding.submissionViewModel = submissionViewModel @@ -80,11 +80,6 @@ class TestRiskLevelCalculationFragment : Fragment() { return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/ui/main/MainFragment.kt b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/ui/main/MainFragment.kt index 7565b87826f..add678b4840 100644 --- a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/ui/main/MainFragment.kt +++ b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/ui/main/MainFragment.kt @@ -16,6 +16,7 @@ import de.rki.coronawarnapp.risk.TimeVariables import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.timer.TimerHelper import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel @@ -44,15 +45,14 @@ class MainFragment : Fragment() { private val tracingViewModel: TracingViewModel by activityViewModels() private val settingsViewModel: SettingsViewModel by activityViewModels() private val submissionViewModel: SubmissionViewModel by activityViewModels() - private var _binding: FragmentMainBinding? = null - private val binding: FragmentMainBinding get() = _binding!! + private var binding: FragmentMainBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentMainBinding.inflate(inflater) + binding = FragmentMainBinding.inflate(inflater) binding.tracingViewModel = tracingViewModel binding.settingsViewModel = settingsViewModel binding.submissionViewModel = submissionViewModel @@ -60,11 +60,6 @@ class MainFragment : Fragment() { return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt index ed1f696f784..ed36ea61f2a 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt @@ -1,7 +1,15 @@ package de.rki.coronawarnapp.ui +import android.os.Handler +import android.os.Looper +import androidx.fragment.app.Fragment +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.Observer import androidx.navigation.NavController import androidx.navigation.NavDirections +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty /** * Extends NavController to prevent navigation error when the user clicks on two buttons at almost @@ -13,3 +21,47 @@ fun NavController.doNavigate(direction: NavDirections) { currentDestination?.getAction(direction.actionId) ?.let { navigate(direction) } } + +/** + * An extension to bind and unbind a value based on the view lifecycle of a Fragment. + * The binding will be unbound in onDestroyView. + * + * @throws IllegalStateException If the getter is invoked before the binding is set, + * or after onDestroyView an exception is thrown. + */ +fun Fragment.viewLifecycle(): ReadWriteProperty { + return object : ReadWriteProperty, DefaultLifecycleObserver { + + private var binding: T? = null + + init { + this@viewLifecycle + .viewLifecycleOwnerLiveData + .observe(this@viewLifecycle, Observer { owner: LifecycleOwner? -> + owner?.lifecycle?.addObserver(this) + }) + } + + override fun onDestroy(owner: LifecycleOwner) { + val handler = Handler(Looper.getMainLooper()) + handler.post { + binding = null + } + } + + override fun getValue( + thisRef: Fragment, + property: KProperty<*> + ): T { + return this.binding ?: error("Called before onCreateView or after onDestroyView.") + } + + override fun setValue( + thisRef: Fragment, + property: KProperty<*>, + value: T + ) { + this.binding = value + } + } +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationAboutFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationAboutFragment.kt index 5cc5be6d7aa..3b98d61d742 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationAboutFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationAboutFragment.kt @@ -11,6 +11,7 @@ import androidx.fragment.app.Fragment import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentInformationAboutBinding import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle /** * Basic Fragment which only displays static content. @@ -20,23 +21,17 @@ class InformationAboutFragment : Fragment() { private val TAG: String? = InformationAboutFragment::class.simpleName } - private var _binding: FragmentInformationAboutBinding? = null - private val binding: FragmentInformationAboutBinding get() = _binding!! + private var binding: FragmentInformationAboutBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentInformationAboutBinding.inflate(inflater) + binding = FragmentInformationAboutBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationContactFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationContactFragment.kt index 6b351030c0f..5d42b024caa 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationContactFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationContactFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentInformationContactBinding import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.util.ExternalActionHelper /** @@ -19,23 +20,17 @@ class InformationContactFragment : Fragment() { private val TAG: String? = InformationContactFragment::class.simpleName } - private var _binding: FragmentInformationContactBinding? = null - private val binding: FragmentInformationContactBinding get() = _binding!! + private var binding: FragmentInformationContactBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentInformationContactBinding.inflate(inflater) + binding = FragmentInformationContactBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationFragment.kt index 9a6bd0b92f0..418455b8bff 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationFragment.kt @@ -12,6 +12,7 @@ import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentInformationBinding import de.rki.coronawarnapp.ui.doNavigate import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.util.ExternalActionHelper /** @@ -22,23 +23,17 @@ class InformationFragment : Fragment() { private val TAG: String? = InformationFragment::class.simpleName } - private var _binding: FragmentInformationBinding? = null - private val binding: FragmentInformationBinding get() = _binding!! + private var binding: FragmentInformationBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentInformationBinding.inflate(inflater) + binding = FragmentInformationBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt index 6d102711f8e..a2407b577f6 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt @@ -11,6 +11,7 @@ import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentInformationLegalBinding import de.rki.coronawarnapp.ui.main.MainActivity import de.rki.coronawarnapp.util.convertToHyperlink +import de.rki.coronawarnapp.ui.viewLifecycle /** * Basic Fragment which only displays static content. @@ -20,23 +21,17 @@ class InformationLegalFragment : Fragment() { private val TAG: String? = InformationLegalFragment::class.simpleName } - private var _binding: FragmentInformationLegalBinding? = null - private val binding: FragmentInformationLegalBinding get() = _binding!! + private var binding: FragmentInformationLegalBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentInformationLegalBinding.inflate(inflater) + binding = FragmentInformationLegalBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationPrivacyFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationPrivacyFragment.kt index c445f900f15..2aede597361 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationPrivacyFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationPrivacyFragment.kt @@ -8,6 +8,7 @@ import android.view.accessibility.AccessibilityEvent import androidx.fragment.app.Fragment import de.rki.coronawarnapp.databinding.FragmentInformationPrivacyBinding import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle /** * Basic Fragment which only displays static content. @@ -17,23 +18,17 @@ class InformationPrivacyFragment : Fragment() { private val TAG: String? = InformationPrivacyFragment::class.simpleName } - private var _binding: FragmentInformationPrivacyBinding? = null - private val binding: FragmentInformationPrivacyBinding get() = _binding!! + private var binding: FragmentInformationPrivacyBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentInformationPrivacyBinding.inflate(inflater) + binding = FragmentInformationPrivacyBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTechnicalFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTechnicalFragment.kt index a4ee7576532..193fde9c264 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTechnicalFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTechnicalFragment.kt @@ -8,6 +8,7 @@ import android.view.accessibility.AccessibilityEvent import androidx.fragment.app.Fragment import de.rki.coronawarnapp.databinding.FragmentInformationTechnicalBinding import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle /** * Basic Fragment which only displays static content. @@ -17,23 +18,17 @@ class InformationTechnicalFragment : Fragment() { private val TAG: String? = InformationTechnicalFragment::class.simpleName } - private var _binding: FragmentInformationTechnicalBinding? = null - private val binding: FragmentInformationTechnicalBinding get() = _binding!! + private var binding: FragmentInformationTechnicalBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentInformationTechnicalBinding.inflate(inflater) + binding = FragmentInformationTechnicalBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTermsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTermsFragment.kt index 98a4079e6a0..592c36df7c4 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTermsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationTermsFragment.kt @@ -8,6 +8,7 @@ import android.view.accessibility.AccessibilityEvent import androidx.fragment.app.Fragment import de.rki.coronawarnapp.databinding.FragmentInformationTermsBinding import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle /** * Basic Fragment which only displays static content. @@ -17,23 +18,17 @@ class InformationTermsFragment : Fragment() { private val TAG: String? = InformationTermsFragment::class.simpleName } - private var _binding: FragmentInformationTermsBinding? = null - private val binding: FragmentInformationTermsBinding get() = _binding!! + private var binding: FragmentInformationTermsBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentInformationTermsBinding.inflate(inflater) + binding = FragmentInformationTermsBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainOverviewFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainOverviewFragment.kt index 67b6ebbe80b..aa437a80b60 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainOverviewFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainOverviewFragment.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import android.view.accessibility.AccessibilityEvent import androidx.fragment.app.Fragment import de.rki.coronawarnapp.databinding.FragmentMainOverviewBinding +import de.rki.coronawarnapp.ui.viewLifecycle /** * The fragment displays static informative content to the user @@ -21,23 +22,17 @@ class MainOverviewFragment : Fragment() { private val TAG: String? = MainOverviewFragment::class.simpleName } - private var _binding: FragmentMainOverviewBinding? = null - private val binding: FragmentMainOverviewBinding get() = _binding!! + private var binding: FragmentMainOverviewBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentMainOverviewBinding.inflate(inflater) + binding = FragmentMainOverviewBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainShareFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainShareFragment.kt index 52c0e3df59d..5dd447eaf6c 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainShareFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainShareFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentMainShareBinding +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel import de.rki.coronawarnapp.util.ExternalActionHelper @@ -24,25 +25,19 @@ class MainShareFragment : Fragment() { } private val tracingViewModel: TracingViewModel by activityViewModels() - private var _binding: FragmentMainShareBinding? = null - private val binding: FragmentMainShareBinding get() = _binding!! + private var binding: FragmentMainShareBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentMainShareBinding.inflate(inflater) + binding = FragmentMainShareBinding.inflate(inflater) binding.tracingViewModel = tracingViewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingFragment.kt index 6b18c084575..b1daa10c003 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingFragment.kt @@ -12,6 +12,7 @@ import androidx.navigation.fragment.findNavController import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentOnboardingBinding import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle /** * Onboarding starting point. @@ -21,23 +22,17 @@ class OnboardingFragment : Fragment() { private val TAG: String? = OnboardingFragment::class.simpleName } - private var _binding: FragmentOnboardingBinding? = null - private val binding: FragmentOnboardingBinding get() = _binding!! + private var binding: FragmentOnboardingBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentOnboardingBinding.inflate(inflater) + binding = FragmentOnboardingBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.onboardingButtonNext.setOnClickListener { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingNotificationsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingNotificationsFragment.kt index c6768a15f48..58131710993 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingNotificationsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingNotificationsFragment.kt @@ -9,6 +9,7 @@ import androidx.appcompat.app.AlertDialog import androidx.core.app.NotificationManagerCompat import androidx.fragment.app.Fragment import de.rki.coronawarnapp.databinding.FragmentOnboardingNotificationsBinding +import de.rki.coronawarnapp.ui.viewLifecycle /** * This fragment ask the user if he wants to get notifications and finishes the onboarding afterwards. @@ -21,23 +22,17 @@ class OnboardingNotificationsFragment : Fragment() { private val TAG: String? = OnboardingNotificationsFragment::class.simpleName } - private var _binding: FragmentOnboardingNotificationsBinding? = null - private val binding: FragmentOnboardingNotificationsBinding get() = _binding!! + private var binding: FragmentOnboardingNotificationsBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentOnboardingNotificationsBinding.inflate(inflater) + binding = FragmentOnboardingNotificationsBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingPrivacyFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingPrivacyFragment.kt index f15cbfbde6c..f81ec47d1e0 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingPrivacyFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingPrivacyFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import de.rki.coronawarnapp.databinding.FragmentOnboardingPrivacyBinding import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle /** * This fragment informs the user regarding privacy. @@ -18,23 +19,17 @@ class OnboardingPrivacyFragment : Fragment() { private val TAG: String? = OnboardingPrivacyFragment::class.simpleName } - private var _binding: FragmentOnboardingPrivacyBinding? = null - private val binding: FragmentOnboardingPrivacyBinding get() = _binding!! + private var binding: FragmentOnboardingPrivacyBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentOnboardingPrivacyBinding.inflate(inflater) + binding = FragmentOnboardingPrivacyBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTestFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTestFragment.kt index 2923d9ea0f0..aacc99a5e1d 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTestFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTestFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import de.rki.coronawarnapp.databinding.FragmentOnboardingTestBinding import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle /** * This fragment informs the user about test results. @@ -18,23 +19,17 @@ class OnboardingTestFragment : Fragment() { private val TAG: String? = OnboardingTestFragment::class.simpleName } - private var _binding: FragmentOnboardingTestBinding? = null - private val binding: FragmentOnboardingTestBinding get() = _binding!! + private var binding: FragmentOnboardingTestBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentOnboardingTestBinding.inflate(inflater) + binding = FragmentOnboardingTestBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTracingFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTracingFragment.kt index 23f302095ec..1d8e08fdffc 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTracingFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/onboarding/OnboardingTracingFragment.kt @@ -18,6 +18,7 @@ import de.rki.coronawarnapp.nearby.InternalExposureNotificationClient import de.rki.coronawarnapp.nearby.InternalExposureNotificationPermissionHelper import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.util.DialogHelper import kotlinx.coroutines.launch @@ -35,8 +36,7 @@ class OnboardingTracingFragment : Fragment(), } private lateinit var internalExposureNotificationPermissionHelper: InternalExposureNotificationPermissionHelper - private var _binding: FragmentOnboardingTracingBinding? = null - private val binding: FragmentOnboardingTracingBinding get() = _binding!! + private var binding: FragmentOnboardingTracingBinding by viewLifecycle() override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { internalExposureNotificationPermissionHelper.onResolutionComplete( @@ -56,15 +56,10 @@ class OnboardingTracingFragment : Fragment(), container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentOnboardingTracingBinding.inflate(inflater) + binding = FragmentOnboardingTracingBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/riskdetails/RiskDetailsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/riskdetails/RiskDetailsFragment.kt index d816080e094..db5bba73860 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/riskdetails/RiskDetailsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/riskdetails/RiskDetailsFragment.kt @@ -12,6 +12,7 @@ import de.rki.coronawarnapp.databinding.FragmentRiskDetailsBinding import de.rki.coronawarnapp.timer.TimerHelper import de.rki.coronawarnapp.ui.doNavigate import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel @@ -29,26 +30,20 @@ class RiskDetailsFragment : Fragment() { private val tracingViewModel: TracingViewModel by activityViewModels() private val settingsViewModel: SettingsViewModel by activityViewModels() - private var _binding: FragmentRiskDetailsBinding? = null - private val binding: FragmentRiskDetailsBinding get() = _binding!! + private var binding: FragmentRiskDetailsBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentRiskDetailsBinding.inflate(inflater) + binding = FragmentRiskDetailsBinding.inflate(inflater) binding.tracingViewModel = tracingViewModel binding.settingsViewModel = settingsViewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListeners() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsBackgroundPriorityFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsBackgroundPriorityFragment.kt index aa8218a169d..7385447600b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsBackgroundPriorityFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsBackgroundPriorityFragment.kt @@ -10,6 +10,7 @@ import androidx.fragment.app.activityViewModels import de.rki.coronawarnapp.databinding.FragmentSettingsBackgroundPriorityBinding import de.rki.coronawarnapp.ui.base.startActivitySafely import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel @@ -26,25 +27,19 @@ class SettingsBackgroundPriorityFragment : Fragment() { } private val settingsViewModel: SettingsViewModel by activityViewModels() - private var _binding: FragmentSettingsBackgroundPriorityBinding? = null - private val binding: FragmentSettingsBackgroundPriorityBinding get() = _binding!! + private var binding: FragmentSettingsBackgroundPriorityBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentSettingsBackgroundPriorityBinding.inflate(inflater) + binding = FragmentSettingsBackgroundPriorityBinding.inflate(inflater) binding.settingsViewModel = settingsViewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsFragment.kt index 33bc8f9b321..1f6338e182d 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsFragment.kt @@ -11,6 +11,7 @@ import androidx.navigation.fragment.findNavController import de.rki.coronawarnapp.databinding.FragmentSettingsBinding import de.rki.coronawarnapp.ui.doNavigate import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel @@ -28,26 +29,20 @@ class SettingsFragment : Fragment() { private val tracingViewModel: TracingViewModel by activityViewModels() private val settingsViewModel: SettingsViewModel by activityViewModels() - private var _binding: FragmentSettingsBinding? = null - private val binding: FragmentSettingsBinding get() = _binding!! + private var binding: FragmentSettingsBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentSettingsBinding.inflate(inflater) + binding = FragmentSettingsBinding.inflate(inflater) binding.tracingViewModel = tracingViewModel binding.settingsViewModel = settingsViewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt index 3acd7e6d9fa..7cbbccbfe2e 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import de.rki.coronawarnapp.databinding.FragmentSettingsNotificationsBinding import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel import de.rki.coronawarnapp.util.ExternalActionHelper @@ -28,25 +29,19 @@ class SettingsNotificationFragment : Fragment() { } private val settingsViewModel: SettingsViewModel by activityViewModels() - private var _binding: FragmentSettingsNotificationsBinding? = null - private val binding: FragmentSettingsNotificationsBinding get() = _binding!! + private var binding: FragmentSettingsNotificationsBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentSettingsNotificationsBinding.inflate(inflater) + binding = FragmentSettingsNotificationsBinding.inflate(inflater) binding.settingsViewModel = settingsViewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsResetFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsResetFragment.kt index 77b7043444b..bea672e29d7 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsResetFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsResetFragment.kt @@ -16,6 +16,7 @@ import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.nearby.InternalExposureNotificationClient import de.rki.coronawarnapp.ui.main.MainActivity import de.rki.coronawarnapp.ui.onboarding.OnboardingActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.util.DataRetentionHelper import de.rki.coronawarnapp.util.DialogHelper import de.rki.coronawarnapp.worker.BackgroundWorkScheduler @@ -33,23 +34,17 @@ class SettingsResetFragment : Fragment() { private val TAG: String? = SettingsResetFragment::class.simpleName } - private var _binding: FragmentSettingsResetBinding? = null - private val binding: FragmentSettingsResetBinding get() = _binding!! + private var binding: FragmentSettingsResetBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentSettingsResetBinding.inflate(inflater) + binding = FragmentSettingsResetBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.settingsResetButtonDelete.setOnClickListener { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt index afc6c1abf45..702eebc1705 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt @@ -17,6 +17,7 @@ import de.rki.coronawarnapp.nearby.InternalExposureNotificationClient import de.rki.coronawarnapp.nearby.InternalExposureNotificationPermissionHelper import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel import de.rki.coronawarnapp.util.DialogHelper @@ -43,8 +44,7 @@ class SettingsTracingFragment : Fragment(), private val tracingViewModel: TracingViewModel by activityViewModels() private val settingsViewModel: SettingsViewModel by activityViewModels() - private var _binding: FragmentSettingsTracingBinding? = null - private val binding: FragmentSettingsTracingBinding get() = _binding!! + private var binding: FragmentSettingsTracingBinding by viewLifecycle() private lateinit var internalExposureNotificationPermissionHelper: InternalExposureNotificationPermissionHelper @@ -53,18 +53,13 @@ class SettingsTracingFragment : Fragment(), container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentSettingsTracingBinding.inflate(inflater) + binding = FragmentSettingsTracingBinding.inflate(inflater) binding.tracingViewModel = tracingViewModel binding.settingsViewModel = settingsViewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionContactFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionContactFragment.kt index de00ac35c34..f2ee3d0aa60 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionContactFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionContactFragment.kt @@ -11,6 +11,7 @@ import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentSubmissionContactBinding import de.rki.coronawarnapp.ui.doNavigate import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.util.ExternalActionHelper /** @@ -18,8 +19,7 @@ import de.rki.coronawarnapp.util.ExternalActionHelper */ class SubmissionContactFragment : Fragment() { - private var _binding: FragmentSubmissionContactBinding? = null - private val binding: FragmentSubmissionContactBinding get() = _binding!! + private var binding: FragmentSubmissionContactBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, @@ -27,15 +27,10 @@ class SubmissionContactFragment : Fragment() { savedInstanceState: Bundle? ): View? { // get the binding reference by inflating it with the current layout - _binding = FragmentSubmissionContactBinding.inflate(inflater) + binding = FragmentSubmissionContactBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragment.kt index 0ae9e32603c..e43e1bcd89f 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragment.kt @@ -11,6 +11,7 @@ import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentSubmissionDispatcherBinding import de.rki.coronawarnapp.ui.doNavigate import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.util.DialogHelper class SubmissionDispatcherFragment : Fragment() { @@ -19,24 +20,18 @@ class SubmissionDispatcherFragment : Fragment() { private val TAG: String? = SubmissionDispatcherFragment::class.simpleName } - private var _binding: FragmentSubmissionDispatcherBinding? = null - private val binding: FragmentSubmissionDispatcherBinding get() = _binding!! + private var binding: FragmentSubmissionDispatcherBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentSubmissionDispatcherBinding.inflate(inflater) + binding = FragmentSubmissionDispatcherBinding.inflate(inflater) binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDoneFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDoneFragment.kt index 5efab5ef21f..1455ca3b610 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDoneFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionDoneFragment.kt @@ -9,14 +9,14 @@ import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import de.rki.coronawarnapp.databinding.FragmentSubmissionDoneBinding import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle /** * The [SubmissionDoneFragment] displays information to a user that submitted his exposure keys */ class SubmissionDoneFragment : Fragment() { - private var _binding: FragmentSubmissionDoneBinding? = null - private val binding: FragmentSubmissionDoneBinding get() = _binding!! + private var binding: FragmentSubmissionDoneBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, @@ -24,15 +24,9 @@ class SubmissionDoneFragment : Fragment() { savedInstanceState: Bundle? ): View? { // get the binding reference by inflating it with the current layout - _binding = FragmentSubmissionDoneBinding.inflate(inflater) + binding = FragmentSubmissionDoneBinding.inflate(inflater) return binding.root } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionIntroFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionIntroFragment.kt index 3ad69bd6b9a..b2e796a3615 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionIntroFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionIntroFragment.kt @@ -9,14 +9,14 @@ import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import de.rki.coronawarnapp.databinding.FragmentSubmissionIntroBinding import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle /** * The [SubmissionIntroFragment] displays information about how the corona warning system works */ class SubmissionIntroFragment : Fragment() { - private var _binding: FragmentSubmissionIntroBinding? = null - private val binding: FragmentSubmissionIntroBinding get() = _binding!! + private var binding: FragmentSubmissionIntroBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, @@ -24,15 +24,10 @@ class SubmissionIntroFragment : Fragment() { savedInstanceState: Bundle? ): View? { // get the binding reference by inflating it with the current layout - _binding = FragmentSubmissionIntroBinding.inflate(inflater) + binding = FragmentSubmissionIntroBinding.inflate(inflater) return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt index c6492216c45..d8eaf6e430c 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionQRCodeScanFragment.kt @@ -21,6 +21,7 @@ import de.rki.coronawarnapp.exception.http.CwaServerError import de.rki.coronawarnapp.exception.http.CwaWebException import de.rki.coronawarnapp.ui.doNavigate import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel import de.rki.coronawarnapp.util.CameraPermissionHelper import de.rki.coronawarnapp.util.DialogHelper @@ -37,8 +38,7 @@ class SubmissionQRCodeScanFragment : Fragment() { } private val viewModel: SubmissionViewModel by activityViewModels() - private var _binding: FragmentSubmissionQrCodeScanBinding? = null - private val binding: FragmentSubmissionQrCodeScanBinding get() = _binding!! + private var binding: FragmentSubmissionQrCodeScanBinding by viewLifecycle() private var showsPermissionDialog = false override fun onCreateView( @@ -46,7 +46,7 @@ class SubmissionQRCodeScanFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentSubmissionQrCodeScanBinding.inflate(inflater) + binding = FragmentSubmissionQrCodeScanBinding.inflate(inflater) binding.lifecycleOwner = this return binding.root } @@ -59,11 +59,6 @@ class SubmissionQRCodeScanFragment : Fragment() { binding.submissionQrCodeScanPreview.decodeSingle { decodeCallback(it) } } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - private fun buildErrorDialog(exception: CwaWebException): DialogHelper.DialogInstance { return when (exception) { is BadRequestException -> DialogHelper.DialogInstance( diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionResultPositiveOtherWarningFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionResultPositiveOtherWarningFragment.kt index 07e8fb165b5..d9a2cd6899b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionResultPositiveOtherWarningFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionResultPositiveOtherWarningFragment.kt @@ -20,6 +20,7 @@ import de.rki.coronawarnapp.exception.http.CwaServerError import de.rki.coronawarnapp.exception.http.ForbiddenException import de.rki.coronawarnapp.nearby.InternalExposureNotificationPermissionHelper import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel import de.rki.coronawarnapp.util.DialogHelper @@ -35,8 +36,7 @@ class SubmissionResultPositiveOtherWarningFragment : Fragment(), private val submissionViewModel: SubmissionViewModel by activityViewModels() private val tracingViewModel: TracingViewModel by activityViewModels() - private var _binding: FragmentSubmissionPositiveOtherWarningBinding? = null - private val binding: FragmentSubmissionPositiveOtherWarningBinding get() = _binding!! + private var binding: FragmentSubmissionPositiveOtherWarningBinding by viewLifecycle() private lateinit var internalExposureNotificationPermissionHelper: InternalExposureNotificationPermissionHelper @@ -61,18 +61,13 @@ class SubmissionResultPositiveOtherWarningFragment : Fragment(), ): View? { internalExposureNotificationPermissionHelper = InternalExposureNotificationPermissionHelper(this, this) - _binding = FragmentSubmissionPositiveOtherWarningBinding.inflate(inflater) + binding = FragmentSubmissionPositiveOtherWarningBinding.inflate(inflater) requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, backCallback) binding.submissionViewModel = submissionViewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - private fun buildErrorDialog(exception: Exception): DialogHelper.DialogInstance { return when (exception) { is BadRequestException -> DialogHelper.DialogInstance( diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTanFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTanFragment.kt index f648b300568..cc9e162e5a1 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTanFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTanFragment.kt @@ -17,6 +17,7 @@ import de.rki.coronawarnapp.exception.http.CwaServerError import de.rki.coronawarnapp.exception.http.CwaWebException import de.rki.coronawarnapp.ui.doNavigate import de.rki.coronawarnapp.ui.main.MainActivity +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel import de.rki.coronawarnapp.util.DialogHelper import de.rki.coronawarnapp.util.TanHelper @@ -31,8 +32,7 @@ class SubmissionTanFragment : Fragment() { private val viewModel: SubmissionTanViewModel by viewModels() private val submissionViewModel: SubmissionViewModel by activityViewModels() - private var _binding: FragmentSubmissionTanBinding? = null - private val binding: FragmentSubmissionTanBinding get() = _binding!! + private var binding: FragmentSubmissionTanBinding by viewLifecycle() override fun onCreateView( inflater: LayoutInflater, @@ -40,17 +40,12 @@ class SubmissionTanFragment : Fragment() { savedInstanceState: Bundle? ): View? { // get the binding reference by inflating it with the current layout - _binding = FragmentSubmissionTanBinding.inflate(inflater) + binding = FragmentSubmissionTanBinding.inflate(inflater) binding.viewmodel = viewModel binding.lifecycleOwner = this return binding.root } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - private fun buildErrorDialog(exception: CwaWebException): DialogHelper.DialogInstance { return when (exception) { is BadRequestException -> DialogHelper.DialogInstance( diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt index 34e9cbc9899..d884a34af43 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt @@ -17,6 +17,7 @@ import de.rki.coronawarnapp.exception.http.CwaClientError import de.rki.coronawarnapp.exception.http.CwaServerError import de.rki.coronawarnapp.exception.http.CwaWebException import de.rki.coronawarnapp.ui.doNavigate +import de.rki.coronawarnapp.ui.viewLifecycle import de.rki.coronawarnapp.ui.viewmodel.SubmissionViewModel import de.rki.coronawarnapp.ui.viewmodel.TracingViewModel import de.rki.coronawarnapp.util.DeviceUIState @@ -34,8 +35,7 @@ class SubmissionTestResultFragment : Fragment() { private val submissionViewModel: SubmissionViewModel by activityViewModels() private val tracingViewModel: TracingViewModel by activityViewModels() - private var _binding: FragmentSubmissionTestResultBinding? = null - private val binding: FragmentSubmissionTestResultBinding get() = _binding!! + private var binding: FragmentSubmissionTestResultBinding by viewLifecycle() private var skipInitialTestResultRefresh = false @@ -55,7 +55,7 @@ class SubmissionTestResultFragment : Fragment() { savedInstanceState: Bundle? ): View? { // get the binding reference by inflating it with the current layout - _binding = FragmentSubmissionTestResultBinding.inflate(inflater) + binding = FragmentSubmissionTestResultBinding.inflate(inflater) binding.submissionViewModel = submissionViewModel binding.lifecycleOwner = this // registers callback when the os level back is pressed @@ -111,11 +111,6 @@ class SubmissionTestResultFragment : Fragment() { } } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setButtonOnClickListener()