Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RunningActivity 생명주기 관찰 옵저버 생성 #83

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호라... 엑티비티의 lifecycleOwner에 옵저버를 부착해주는거군요??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 훨씬 깔끔하네요! 이런 방법이 있군요?

}

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)
}
}