From e6d1dea57377a4d7a3cfa419198da21694ec23ad Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Wed, 7 Dec 2022 22:19:01 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20RunningActivity=20=EC=83=9D?= =?UTF-8?q?=EB=AA=85=EC=A3=BC=EA=B8=B0=20=EA=B4=80=EC=B0=B0=20=EC=98=B5?= =?UTF-8?q?=EC=A0=80=EB=B2=84=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/running/RunningActivity.kt | 30 ++----------- .../running/RunningActivityObserver.kt | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 presentation/src/main/java/com/whyranoid/presentation/running/RunningActivityObserver.kt diff --git a/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt index d85ef9b6..e966fcd9 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt @@ -20,7 +20,7 @@ import com.whyranoid.presentation.databinding.ActivityRunningBinding import com.whyranoid.presentation.util.dateToString import com.whyranoid.presentation.util.repeatWhenUiStarted import dagger.hilt.android.AndroidEntryPoint -import java.util.* +import java.util.Date @AndroidEntryPoint internal class RunningActivity : @@ -89,36 +89,11 @@ internal class RunningActivity : } } - override fun onStart() { - super.onStart() - mapView.onStart() - } - - override fun onResume() { - super.onResume() - mapView.onResume() - } - - override fun onPause() { - mapView.onPause() - super.onPause() - } - override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) mapView.onSaveInstanceState(outState) } - override fun onStop() { - mapView.onStop() - super.onStop() - } - - override fun onDestroy() { - mapView.onDestroy() - super.onDestroy() - } - override fun onLowMemory() { super.onLowMemory() mapView.onLowMemory() @@ -135,11 +110,12 @@ internal class RunningActivity : private fun initViews(savedInstanceState: Bundle?) { mapView = binding.mapView - mapView.onCreate(savedInstanceState) mapView.getMapAsync(this) binding.vm = viewModel + this.onBackPressedDispatcher.addCallback(this, backPressedCallback) + lifecycle.addObserver(RunningActivityObserver(mapView, savedInstanceState)) } private fun observeState() { diff --git a/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivityObserver.kt b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivityObserver.kt new file mode 100644 index 00000000..b7d0a034 --- /dev/null +++ b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivityObserver.kt @@ -0,0 +1,42 @@ +package com.whyranoid.presentation.running + +import android.os.Bundle +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import com.naver.maps.map.MapView + +class RunningActivityObserver( + private val mapView: MapView, + private val savedInstanceState: Bundle? +) : DefaultLifecycleObserver { + + override fun onCreate(owner: LifecycleOwner) { + super.onCreate(owner) + mapView.onCreate(savedInstanceState) + } + + override fun onStart(owner: LifecycleOwner) { + super.onStart(owner) + mapView.onStart() + } + + override fun onResume(owner: LifecycleOwner) { + super.onResume(owner) + mapView.onResume() + } + + override fun onPause(owner: LifecycleOwner) { + mapView.onPause() + super.onPause(owner) + } + + override fun onStop(owner: LifecycleOwner) { + mapView.onStop() + super.onStop(owner) + } + + override fun onDestroy(owner: LifecycleOwner) { + mapView.onDestroy() + super.onDestroy(owner) + } +}