Skip to content

Commit 40ca5f8

Browse files
authored
๐Ÿ”€ #76 from boostcampwm-2022/feat/running_tab
๋Ÿฌ๋‹ํƒญ ๊ด€๋ จ ๋ฒ„๊ทธ ์ˆ˜์ •
2 parents cd54636 + 17dc5b2 commit 40ca5f8

File tree

5 files changed

+34
-38
lines changed

5 files changed

+34
-38
lines changed

โ€Žpresentation/src/main/java/com/whyranoid/presentation/running/RunningDataManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class RunningDataManager @Inject constructor() {
8484
distance
8585
)
8686
val newTotalDistance = prevRunningData.totalDistance + distance.first()
87-
val newPace = newTotalDistance / newRunningTime
87+
val newPace = if (newRunningTime == 0) 0.0 else newTotalDistance / newRunningTime
8888
val newRunningPositionList =
8989
prevRunningData.runningPositionList.toList().map { it.toMutableList() }
9090
.also { it[it.lastIndex].add(runningPosition) }

โ€Žpresentation/src/main/java/com/whyranoid/presentation/runningfinish/RunningFinishFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,16 @@ internal class RunningFinishFragment :
8484

8585
private fun handleEvent(event: Event) {
8686
when (event) {
87-
is Event.NegativeButtonButtonClick -> findNavController().popBackStack()
87+
is Event.NegativeButtonButtonClick -> handleNegativeButtonClicked()
8888
is Event.PositiveButtonClick -> handlePositiveButtonClicked(event.runningHistory)
8989
}
9090
}
9191

92+
private fun handleNegativeButtonClicked() {
93+
binding.mapFragmentLayout.visibility = View.INVISIBLE
94+
findNavController().popBackStack()
95+
}
96+
9297
private fun handlePositiveButtonClicked(runningHistory: RunningHistoryUiModel) {
9398
val direction = RunningFinishFragmentDirections.actionRunningFinishFragmentToCreateRunningPostFragment(
9499
runningHistory

โ€Žpresentation/src/main/java/com/whyranoid/presentation/runningstart/RunningStartFragment.kt

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,7 @@ internal class RunningStartFragment :
5252
RUNNING_FINISH_DATA_KEY
5353
)
5454

55-
// ๊ฒฐ๊ณผ ๋„˜๊ฒจ์ฃผ๊ธฐ
56-
if (runningFinishData?.runningPositionList.isNullOrEmpty().not()) {
57-
runningFinishData?.let {
58-
val direction =
59-
RunningStartFragmentDirections.actionRunningStartFragmentToRunningFinish(
60-
runningFinishData
61-
)
62-
findNavController().navigate(direction)
63-
} ?: Snackbar.make(binding.root, getString(R.string.running_start_error_message), Snackbar.LENGTH_SHORT)
64-
.show()
65-
}
55+
navigateToRunningFinish(runningFinishData)
6656
}
6757
}
6858

@@ -155,4 +145,21 @@ internal class RunningStartFragment :
155145
}
156146
.show()
157147
}
148+
149+
private fun navigateToRunningFinish(runningFinishData: RunningFinishData?) {
150+
runningFinishData?.let { it ->
151+
if (it.runningPositionList.flatten().isNotEmpty()) {
152+
val direction =
153+
RunningStartFragmentDirections.actionRunningStartFragmentToRunningFinish(
154+
it
155+
)
156+
findNavController().navigate(direction)
157+
}
158+
} ?: Snackbar.make(
159+
binding.root,
160+
getString(R.string.running_start_error_message),
161+
Snackbar.LENGTH_SHORT
162+
)
163+
.show()
164+
}
158165
}

โ€Žpresentation/src/main/res/layout/fragment_running_finish.xml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto">
44

55
<data>
6-
<import type="com.whyranoid.presentation.model.UiState"/>
7-
<import type="android.view.View"/>
6+
7+
<import type="com.whyranoid.presentation.model.UiState" />
8+
9+
<import type="android.view.View" />
810

911
<variable
1012
name="vm"
@@ -32,12 +34,13 @@
3234
</com.google.android.material.appbar.AppBarLayout>
3335

3436
<androidx.constraintlayout.widget.ConstraintLayout
37+
android:id="@+id/map_fragment_layout"
3538
android:layout_width="match_parent"
3639
android:layout_height="0dp"
3740
app:layout_constraintBottom_toTopOf="@id/running_history_item"
3841
app:layout_constraintTop_toBottomOf="@id/tool_bar">
3942

40-
<fragment xmlns:app="http://schemas.android.com/apk/res-auto"
43+
<fragment
4144
android:id="@+id/map_fragment"
4245
android:name="com.naver.maps.map.MapFragment"
4346
android:layout_width="match_parent"
@@ -82,26 +85,5 @@
8285
app:layout_constraintEnd_toEndOf="parent"
8386
app:layout_constraintStart_toEndOf="@id/btn_positive" />
8487

85-
<FrameLayout
86-
android:id="@+id/frame_progress_running"
87-
android:layout_width="match_parent"
88-
android:layout_height="match_parent"
89-
android:background="@color/black"
90-
android:alpha="0.8"
91-
android:translationZ="@{vm.runningFinishDataState instanceof UiState.Success ? 0f : 10f }"
92-
android:visibility="@{vm.runningFinishDataState instanceof UiState.Success ? View.GONE : View.VISIBLE }">
93-
94-
<com.google.android.material.progressindicator.CircularProgressIndicator
95-
android:id="@+id/progressindicator_running"
96-
android:layout_width="wrap_content"
97-
android:layout_height="wrap_content"
98-
android:layout_gravity="center"
99-
android:contentDescription="@string/running_finish_progress_description"
100-
android:indeterminate="true"
101-
android:visibility="@{vm.runningFinishDataState instanceof UiState.Success ? View.GONE : View.VISIBLE }"
102-
app:indicatorColor="?attr/colorOnPrimary" />
103-
104-
</FrameLayout>
105-
10688
</androidx.constraintlayout.widget.ConstraintLayout>
10789
</layout>

โ€Žpresentation/src/main/res/navigation/navigation_graph.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@
8888
app:argType="com.whyranoid.presentation.model.RunningHistoryUiModel" />
8989
<action
9090
android:id="@+id/action_createRunningPostFragment_to_communityFragment"
91-
app:destination="@id/communityFragment" />
91+
app:destination="@id/communityFragment"
92+
app:popUpTo="@id/runningStartFragment"
93+
app:popUpToInclusive="true" />
9294
</fragment>
9395
<fragment
9496
android:id="@+id/runningFinishFragment"

0 commit comments

Comments
ย (0)