Skip to content

Commit

Permalink
✨ RunningActivity 생명주기 관찰 옵저버 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghanJu committed Dec 7, 2022
1 parent 1d6c90d commit e6d1dea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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()
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit e6d1dea

Please sign in to comment.