Skip to content

Commit cef6ad0

Browse files
yonghanJubngsh
andcommitted
✨ 러닝 종료 시 결과를 받아서 러닝 종료화면으로 이동
Co-authored-by: bngsh <[email protected]>
1 parent f5d5e24 commit cef6ad0

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

presentation/src/main/java/com/whyranoid/presentation/runningstart/RunningStartFragment.kt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.whyranoid.presentation.runningstart
22

33
import android.Manifest
4+
import android.app.Activity
45
import android.content.Intent
56
import android.content.pm.PackageManager
67
import android.net.Uri
@@ -9,12 +10,16 @@ import android.view.View
910
import androidx.activity.result.contract.ActivityResultContracts
1011
import androidx.core.content.ContextCompat
1112
import androidx.fragment.app.viewModels
13+
import androidx.navigation.fragment.findNavController
1214
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1315
import com.google.android.material.snackbar.Snackbar
1416
import com.whyranoid.presentation.R
1517
import com.whyranoid.presentation.base.BaseFragment
1618
import com.whyranoid.presentation.databinding.FragmentRunningStartBinding
1719
import com.whyranoid.presentation.running.RunningActivity
20+
import com.whyranoid.presentation.running.RunningFinishData
21+
import com.whyranoid.presentation.running.RunningViewModel.Companion.RUNNING_FINISH_DATA_KEY
22+
import com.whyranoid.presentation.util.getSerializableData
1823
import com.whyranoid.presentation.util.gpsstate.GPSState
1924
import com.whyranoid.presentation.util.repeatWhenUiStarted
2025
import dagger.hilt.android.AndroidEntryPoint
@@ -23,16 +28,38 @@ import dagger.hilt.android.AndroidEntryPoint
2328
internal class RunningStartFragment :
2429
BaseFragment<FragmentRunningStartBinding>(R.layout.fragment_running_start) {
2530

31+
// 위치 권한 요청
2632
private val locationPermissionRequest = registerForActivityResult(
2733
ActivityResultContracts.RequestPermission()
2834
) { isGranted: Boolean ->
2935
if (isGranted) {
30-
startActivity(Intent(requireContext(), RunningActivity::class.java))
36+
runningActivityLauncher.launch(Intent(requireContext(), RunningActivity::class.java))
3137
} else {
3238
showPermissionRequestDialog()
3339
}
3440
}
3541

42+
// Running Activity 로 이동 런쳐(운동 결과를 받고 종료 화면으로 이동)
43+
private val runningActivityLauncher = registerForActivityResult(
44+
ActivityResultContracts.StartActivityForResult()
45+
) { activityResult ->
46+
if (activityResult.resultCode == Activity.RESULT_OK) {
47+
48+
// 결과 받아오기
49+
val runningFinishData =
50+
activityResult.data?.getSerializableData<RunningFinishData>(
51+
RUNNING_FINISH_DATA_KEY
52+
)
53+
54+
// 결과 넘겨주기
55+
val direction =
56+
RunningStartFragmentDirections.actionRunningStartFragmentToRunningFinish(
57+
runningFinishData
58+
)
59+
findNavController().navigate(direction)
60+
}
61+
}
62+
3663
private val viewModel by viewModels<RunningStartViewModel>()
3764

3865
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -70,7 +97,12 @@ internal class RunningStartFragment :
7097
requireContext(),
7198
Manifest.permission.ACCESS_FINE_LOCATION
7299
) == PackageManager.PERMISSION_GRANTED -> {
73-
startActivity(Intent(requireContext(), RunningActivity::class.java))
100+
runningActivityLauncher.launch(
101+
Intent(
102+
requireContext(),
103+
RunningActivity::class.java
104+
)
105+
)
74106
}
75107
shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION) -> {
76108
// 다이얼로그 띄우기, 거부된 상태

0 commit comments

Comments
 (0)