Skip to content

Commit 1d6c90d

Browse files
authored
๐Ÿ”€ #79 from boostcampwm-2022/feat/community_create_running_post
์ธ์ฆ๊ธ€ ์ž‘์„ฑํ•˜๊ธฐ ๋ฒ„๊ทธ ์ˆ˜์ •, ์šด๋™ ๋‚ด์—ญ ๋‹จ์ผ ์„ ํƒ ๊ธฐ๋Šฅ ๋ฒ„๊ทธ ์ˆ˜์ •, ์ „์ฒด์ ์ธ UI ์ˆ˜์ •
2 parents d7ca06e + 16305ae commit 1d6c90d

28 files changed

+372
-281
lines changed

โ€Žpresentation/src/main/java/com/whyranoid/presentation/community/runningpost/CommunityRunningHistoryAdapter.kt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.whyranoid.presentation.community.runningpost
22

3+
import android.content.res.ColorStateList
34
import android.graphics.Color
45
import android.view.LayoutInflater
56
import android.view.View
@@ -16,6 +17,7 @@ class CommunityRunningHistoryAdapter(private val selectRunningHistoryListener: R
1617
ListAdapter<RunningHistoryUiModel, CommunityRunningHistoryViewHolder>(
1718
MyRunningHistoryDiffCallback()
1819
) {
20+
1921
override fun onCreateViewHolder(
2022
parent: ViewGroup,
2123
viewType: Int
@@ -26,7 +28,7 @@ class CommunityRunningHistoryAdapter(private val selectRunningHistoryListener: R
2628
}
2729

2830
override fun onBindViewHolder(holder: CommunityRunningHistoryViewHolder, position: Int) {
29-
holder.bind(getItem(position))
31+
holder.bind(getItem(position), position)
3032
}
3133
}
3234

@@ -36,30 +38,49 @@ class CommunityRunningHistoryViewHolder(
3638
) : RecyclerView.ViewHolder(view) {
3739
private val binding = ItemRunningHistoryBinding.bind(view)
3840

39-
fun bind(runningHistory: RunningHistoryUiModel) {
41+
fun bind(runningHistory: RunningHistoryUiModel, itemPosition: Int) {
4042
// ์•„์ดํ…œ์ด ์„ ํƒ๋œ ๊ฐœ์ฒด์ธ์ง€ ํ™•์ธ
4143

4244
binding.runningHistory = runningHistory
45+
val isSelected = listener.checkRunningHistoryId(itemPosition)
4346

44-
binding.root.setBackgroundColor(Color.TRANSPARENT)
47+
if (isSelected) {
48+
binding.root.setBackgroundResource(R.drawable.background_rounded)
49+
binding.root.backgroundTintList = ColorStateList.valueOf(
50+
ContextCompat.getColor(
51+
binding.root.context,
52+
R.color.mogakrun_secondary
53+
)
54+
)
55+
} else {
56+
// ์„ ํƒ๋˜์–ด ์žˆ์ง€ ์•Š๋˜ ์•„์ดํ…œ์ด๋ฉด
57+
binding.root.setBackgroundColor(Color.TRANSPARENT)
58+
}
4559

4660
binding.root.setOnClickListener {
47-
val isSelected = listener.checkRunningHistoryId(runningHistory)
61+
val isAlreadySelected = listener.checkRunningHistoryId(itemPosition)
4862

49-
// ์ด๋ฏธ ์„ ํƒ๋˜์–ด ์žˆ๋˜ ์•„์ดํ…œ์ด๋ฉด
50-
if (isSelected) {
63+
// ์ด๋ฏธ ์„ ํƒ๋˜์–ด ์žˆ๋˜ ์•„์ดํ…œ์„ ๋ˆ„๋ฅธ ๊ฒฝ์šฐ
64+
if (isAlreadySelected) {
5165
listener.unSelectRunningHistory()
5266
it.setBackgroundColor(Color.TRANSPARENT)
5367
} else {
54-
// ์„ ํƒ๋˜์–ด ์žˆ์ง€ ์•Š๋˜ ์•„์ดํ…œ์ด๋ฉด
55-
listener.selectRunningHistory(runningHistory)
56-
it.setBackgroundColor(
68+
// ์„ ํƒ๋˜์–ด ์žˆ์ง€ ์•Š๋˜ ์•„์ดํ…œ์„ ๋ˆ„๋ฅธ ๊ฒฝ์šฐ
69+
listener.selectRunningHistory(runningHistory, itemPosition)
70+
binding.root.setBackgroundResource(R.drawable.background_rounded)
71+
binding.root.backgroundTintList = ColorStateList.valueOf(
5772
ContextCompat.getColor(
5873
binding.root.context,
59-
R.color.gray
74+
R.color.mogakrun_secondary
6075
)
6176
)
6277
}
6378
}
6479
}
6580
}
81+
82+
interface RunningHistoryItemListener {
83+
fun checkRunningHistoryId(itemPosition: Int): Boolean
84+
fun selectRunningHistory(runningHistory: RunningHistoryUiModel, itemPosition: Int)
85+
fun unSelectRunningHistory()
86+
}

โ€Žpresentation/src/main/java/com/whyranoid/presentation/community/runningpost/CreateRunningPostViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CreateRunningPostViewModel @Inject constructor(
2828

2929
val createPostButtonEnableState: StateFlow<Boolean>
3030
get() = runningPostContent.map { content ->
31-
content != null
31+
content.isNullOrBlank().not()
3232
}.stateIn(
3333
initialValue = false,
3434
started = SharingStarted.WhileSubscribed(5000),

โ€Žpresentation/src/main/java/com/whyranoid/presentation/community/runningpost/RunningHistoryItemListener.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

โ€Žpresentation/src/main/java/com/whyranoid/presentation/community/runningpost/SelectRunningHistoryFragment.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ internal class SelectRunningHistoryFragment :
9696
true
9797
}
9898
R.id.warning_select_running_history_button -> {
99-
Snackbar.make(binding.root, getString(R.string.community_select_running_history_snack_bar), Snackbar.LENGTH_SHORT).show()
99+
Snackbar.make(
100+
binding.root,
101+
getString(R.string.community_select_running_history_snack_bar),
102+
Snackbar.LENGTH_SHORT
103+
).show()
100104
true
101105
}
102106
else -> {
@@ -107,14 +111,27 @@ internal class SelectRunningHistoryFragment :
107111
}
108112
}
109113

110-
override fun checkRunningHistoryId(runningHistory: RunningHistoryUiModel): Boolean =
111-
viewModel.getSelectedRunningHistory()?.historyId == runningHistory.historyId
114+
override fun checkRunningHistoryId(itemPosition: Int): Boolean {
115+
// ์•„๋ฌด๊ฒƒ๋„ ์„ ํƒ์ด ๋˜์ง€ ์•Š์€ ์ƒํ™ฉ์ด๊ฑฐ๋‚˜ ์„ ํƒํ•œ ์šด๋™๋‚ด์—ญ์ด ์ด๋ฏธ ์„ ํƒ๋˜์–ด์žˆ๋Š” ์šด๋™๋‚ด์—ญ๊ณผ ๋‹ค๋ฅผ ๋•Œ false ๋ฐ˜ํ™˜ -> ์ผ๋ฐ˜ ๋ฐฐ๊ฒฝ์ƒ‰
116+
// true ๋ฐ˜ํ™˜ -> ์„ ํƒ๋œ ๋ฐฐ๊ฒฝ์ƒ‰
117+
return (viewModel.selectedItemPosition.value == NOTHING_SELECTED_ITEM_POSITION || viewModel.selectedItemPosition.value != itemPosition).not()
118+
}
112119

113-
override fun selectRunningHistory(runningHistory: RunningHistoryUiModel) {
120+
override fun selectRunningHistory(runningHistory: RunningHistoryUiModel, itemPosition: Int) {
121+
// ํ˜„์žฌ ์„ ํƒ๋˜์–ด ์žˆ๋Š” ์•„์ดํ…œ์˜ position์„ ๊ฐ€์ ธ์˜ด
122+
val currentSelectedItemPosition = viewModel.selectedItemPosition.value
114123
viewModel.setSelectedRunningHistory(runningHistory)
124+
viewModel.setSelectedItemPosition(itemPosition)
125+
// ์ด์ „์— ์„ ํƒ๋˜์–ด ์žˆ๋˜ ์•„์ดํ…œ์—๊ฒŒ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ค๋„๋ก ๋ช…๋ น
126+
runningHistoryAdapter.notifyItemChanged(currentSelectedItemPosition)
115127
}
116128

117129
override fun unSelectRunningHistory() {
118130
viewModel.setSelectedRunningHistory(null)
131+
viewModel.setSelectedItemPosition(NOTHING_SELECTED_ITEM_POSITION)
132+
}
133+
134+
companion object {
135+
private const val NOTHING_SELECTED_ITEM_POSITION = -1
119136
}
120137
}

โ€Žpresentation/src/main/java/com/whyranoid/presentation/community/runningpost/SelectRunningHistoryViewModel.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ class SelectRunningHistoryViewModel @Inject constructor(private val getRunningHi
2626
val runningHistoryListState: StateFlow<UiState<List<RunningHistoryUiModel>>>
2727
get() = _runningHistoryListState.asStateFlow()
2828

29-
// TODO ์ธ์ฆ๊ธ€ ์ž‘์„ฑ ๋„˜์–ด๊ฐ€๋„๋ก ํ•˜๋Š” ๋”๋ฏธ๋ฐ์ดํ„ฐ -> ์ธ์ฆ๊ธ€ ์ž‘์„ฑ ๋กœ์ง์ด ์™„๋ฃŒ๋˜๋ฉด ์‚ญ์ œํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
30-
private val _selectedRunningHistory = MutableStateFlow<RunningHistoryUiModel?>(RunningHistoryUiModel("seungmin_history_id", 8995875L, 2452, 24524L, 134L, 124.0, 23.0))
29+
private val _selectedRunningHistory = MutableStateFlow<RunningHistoryUiModel?>(null)
3130
val selectedRunningHistory: StateFlow<RunningHistoryUiModel?>
3231
get() = _selectedRunningHistory.asStateFlow()
3332

33+
private val _selectedItemPosition = MutableStateFlow(NOTHING_SELECTED_ITEM_POSITION)
34+
val selectedItemPosition: StateFlow<Int>
35+
get() = _selectedItemPosition.asStateFlow()
36+
3437
private fun getRunningHistoryList() {
3538
viewModelScope.launch {
3639
_runningHistoryListState.value = UiState.Loading
@@ -53,4 +56,12 @@ class SelectRunningHistoryViewModel @Inject constructor(private val getRunningHi
5356
fun setSelectedRunningHistory(runningHistoryUiModel: RunningHistoryUiModel?) {
5457
_selectedRunningHistory.value = runningHistoryUiModel
5558
}
59+
60+
fun setSelectedItemPosition(itemPosition: Int) {
61+
_selectedItemPosition.value = itemPosition
62+
}
63+
64+
companion object {
65+
private const val NOTHING_SELECTED_ITEM_POSITION = -1
66+
}
5667
}

โ€Žpresentation/src/main/java/com/whyranoid/presentation/myrun/CalendarDayBinder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CalendarDayBinder(
7777
container.binding.root.background =
7878
ContextCompat.getDrawable(
7979
calendarView.context,
80-
R.drawable.calendar_kong
80+
R.drawable.kong
8181
)
8282
}
8383
}
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:padding="10dp"
4+
android:shape="rectangle" >
5+
<solid android:color="@color/mogakrun_primary" />
6+
<corners
7+
android:topLeftRadius="12dp"
8+
android:topRightRadius="12dp" />
9+
</shape>

โ€Žpresentation/src/main/res/drawable/done_outline_icon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<vector android:height="24dp" android:tint="#ACD182"
1+
<vector android:height="24dp" android:tint="@color/gray"
22
android:viewportHeight="24" android:viewportWidth="24"
33
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
44
<path android:fillColor="@android:color/white" android:pathData="M19.77,5.03l1.4,1.4L8.43,19.17l-5.6,-5.6 1.4,-1.4 4.2,4.2L19.77,5.03m0,-2.83L8.43,13.54l-4.2,-4.2L0,13.57 8.43,22 24,6.43 19.77,2.2z"/>

โ€Žpresentation/src/main/res/drawable/done_solid_icon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<vector android:height="24dp" android:tint="#ACD182"
1+
<vector android:height="24dp" android:tint="?attr/colorOnPrimary"
22
android:viewportHeight="24" android:viewportWidth="24"
33
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
44
<path android:fillColor="@android:color/white" android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>

0 commit comments

Comments
ย (0)