Skip to content

Commit 765621d

Browse files
committed
♻️ 코드리뷰 피드백 반영하여 수정
1 parent f44317a commit 765621d

File tree

7 files changed

+48
-25
lines changed

7 files changed

+48
-25
lines changed

data/src/main/java/com/whyranoid/data/account/AccountDataSourceImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import javax.inject.Inject
1616

1717
class AccountDataSourceImpl @Inject constructor(
1818
private val dataStoreDb: DataStore<Preferences>,
19-
private val fireBaseDb: FirebaseFirestore
19+
private val fireBaseDb: FirebaseFirestore,
20+
private val auth: FirebaseAuth
2021
) : AccountDataSource {
2122

22-
private val auth = FirebaseAuth.getInstance()
2323
private val currentUser = auth.currentUser
2424

2525
private object PreferenceKeys {
@@ -67,12 +67,13 @@ class AccountDataSourceImpl @Inject constructor(
6767
}
6868

6969
override suspend fun signOut(): Result<Boolean> = runCatching {
70-
signOut()
70+
auth.signOut()
7171
true
7272
}
7373

74-
override suspend fun withDrawal(): Result<Boolean> {
75-
TODO("Not yet implemented")
74+
override suspend fun withDrawal(): Result<Boolean> = runCatching {
75+
currentUser?.delete()
76+
true
7677
}
7778

7879
companion object {

data/src/main/java/com/whyranoid/data/di/UserDataBaseModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.datastore.core.DataStore
55
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
66
import androidx.datastore.preferences.core.Preferences
77
import androidx.datastore.preferences.preferencesDataStoreFile
8+
import com.google.firebase.auth.FirebaseAuth
89
import dagger.Module
910
import dagger.Provides
1011
import dagger.hilt.InstallIn
@@ -26,4 +27,8 @@ object UserDataBaseModule {
2627
appContext.preferencesDataStoreFile(USER_PREFERENCES)
2728
}
2829
)
30+
31+
@Singleton
32+
@Provides
33+
fun provideFirebaseAuth(): FirebaseAuth = FirebaseAuth.getInstance()
2934
}

presentation/src/main/java/com/whyranoid/presentation/model/RunningHistoryUiModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package com.whyranoid.presentation.model
22

3+
import android.os.Parcelable
34
import com.whyranoid.domain.model.RunningHistory
5+
import kotlinx.parcelize.Parcelize
46

7+
@Parcelize
58
data class RunningHistoryUiModel(
9+
val historyId: String,
610
val date: String,
711
val totalRunningTime: String,
812
val startedAt: String,
913
val finishedAt: String,
1014
val totalDistance: String,
1115
val pace: String
12-
)
16+
) : Parcelable
1317

1418
// TODO 원하는 형태로 변환하도록 코드 수정해야함
1519
fun RunningHistory.toRunningHistoryUiModel(): RunningHistoryUiModel {
1620
return RunningHistoryUiModel(
21+
historyId = historyId,
1722
date = startedAt.toString(),
1823
totalRunningTime = totalRunningTime.toString(),
1924
startedAt = startedAt.toString(),

presentation/src/main/java/com/whyranoid/presentation/myrun/CalendarDayBinder.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.time.LocalDate
1414
class CalendarDayBinder(
1515
private val calendarView: CalendarView
1616
) : DayBinder<CalendarDayBinder.DayContainer> {
17-
private var calendar: Pair<LocalDate?, LocalDate?> = null to null
17+
private var calendar: CalendarRange = CalendarRange(null, null)
1818

1919
class DayContainer(
2020
val binding: ItemCalendarDayBinding
@@ -50,6 +50,7 @@ class CalendarDayBinder(
5050
R.color.black
5151
)
5252
)
53+
container.binding.root.background = null
5354
}
5455

5556
if (isInRange(day.date)) {
@@ -83,3 +84,8 @@ class CalendarDayBinder(
8384
return startDate == date || endDate == date || (startDate != null && endDate != null && startDate < date && date < endDate)
8485
}
8586
}
87+
88+
data class CalendarRange(
89+
val startDate: LocalDate?,
90+
val endDate: LocalDate?
91+
)

presentation/src/main/java/com/whyranoid/presentation/myrun/MyRunFragment.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ internal class MyRunFragment : BaseFragment<FragmentMyRunBinding>(R.layout.fragm
2828
private val runningHistoryAdapter = MyRunningHistoryAdapter()
2929

3030
private val currentMonth = YearMonth.now()
31-
private val firstMonth = currentMonth.minusMonths(5)
32-
private val lastMonth = currentMonth.plusMonths(5)
31+
private val firstMonth = currentMonth.minusMonths(MONTH_OFFSET)
32+
private val lastMonth = currentMonth.plusMonths(MONTH_OFFSET)
3333
private val firstDayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek
3434

3535
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
3636
super.onViewCreated(view, savedInstanceState)
3737

3838
initViews()
39-
observeInfo()
39+
observeState()
4040
}
4141

4242
private fun initViews() = with(binding) {
@@ -69,7 +69,7 @@ internal class MyRunFragment : BaseFragment<FragmentMyRunBinding>(R.layout.fragm
6969
}
7070
}
7171

72-
private fun observeInfo() {
72+
private fun observeState() {
7373
viewLifecycleOwner.repeatWhenUiStarted {
7474
viewModel.nickName.collect { nickName ->
7575
binding.tvNickName.text = nickName
@@ -120,4 +120,8 @@ internal class MyRunFragment : BaseFragment<FragmentMyRunBinding>(R.layout.fragm
120120
binding.calendarView.smoothScrollToMonth(currentMonth)
121121
}
122122
}
123+
124+
companion object {
125+
private const val MONTH_OFFSET = 120L
126+
}
123127
}

presentation/src/main/java/com/whyranoid/presentation/myrun/MyRunViewModel.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package com.whyranoid.presentation.myrun
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5-
import com.whyranoid.domain.model.RunningHistory
65
import com.whyranoid.domain.usecase.GetNicknameUseCase
76
import com.whyranoid.domain.usecase.GetProfileUriUseCase
87
import com.whyranoid.domain.usecase.GetRunningHistoryUseCase
98
import com.whyranoid.domain.usecase.GetUidUseCase
109
import com.whyranoid.domain.usecase.UpdateNicknameUseCase
10+
import com.whyranoid.presentation.model.RunningHistoryUiModel
11+
import com.whyranoid.presentation.model.toRunningHistoryUiModel
1112
import dagger.hilt.android.lifecycle.HiltViewModel
1213
import kotlinx.coroutines.flow.MutableStateFlow
1314
import kotlinx.coroutines.flow.StateFlow
@@ -42,8 +43,8 @@ class MyRunViewModel @Inject constructor(
4243
val profileImgUri: StateFlow<String>
4344
get() = _profileImgUri.asStateFlow()
4445

45-
private val _runningHistoryList = MutableStateFlow<List<RunningHistory>>(emptyList())
46-
val runningHistoryList: StateFlow<List<RunningHistory>>
46+
private val _runningHistoryList = MutableStateFlow<List<RunningHistoryUiModel>>(emptyList())
47+
val runningHistoryList: StateFlow<List<RunningHistoryUiModel>>
4748
get() = _runningHistoryList.asStateFlow()
4849

4950
private fun getUid() {
@@ -83,7 +84,9 @@ class MyRunViewModel @Inject constructor(
8384
private fun getRunningHistoryList() {
8485
viewModelScope.launch {
8586
getRunningHistoryUseCase().collect { runningHistoryList ->
86-
_runningHistoryList.value = runningHistoryList
87+
_runningHistoryList.value = runningHistoryList.map { runningHistory ->
88+
runningHistory.toRunningHistoryUiModel()
89+
}
8790
}
8891
}
8992
}

presentation/src/main/java/com/whyranoid/presentation/myrun/MyRunningHistoryAdapter.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import android.view.ViewGroup
66
import androidx.recyclerview.widget.DiffUtil
77
import androidx.recyclerview.widget.ListAdapter
88
import androidx.recyclerview.widget.RecyclerView
9-
import com.whyranoid.domain.model.RunningHistory
109
import com.whyranoid.presentation.R
1110
import com.whyranoid.presentation.databinding.ItemRunningHistoryBinding
12-
import com.whyranoid.presentation.model.toRunningHistoryUiModel
11+
import com.whyranoid.presentation.model.RunningHistoryUiModel
1312

1413
class MyRunningHistoryAdapter :
15-
ListAdapter<RunningHistory, RunningHistoryViewHolder>(
14+
ListAdapter<RunningHistoryUiModel, RunningHistoryViewHolder>(
1615
MyRunningHistoryDiffCallback()
1716
) {
1817

@@ -27,17 +26,17 @@ class MyRunningHistoryAdapter :
2726
}
2827

2928
companion object {
30-
class MyRunningHistoryDiffCallback : DiffUtil.ItemCallback<RunningHistory>() {
29+
class MyRunningHistoryDiffCallback : DiffUtil.ItemCallback<RunningHistoryUiModel>() {
3130
override fun areItemsTheSame(
32-
oldItem: RunningHistory,
33-
newItem: RunningHistory
31+
oldItem: RunningHistoryUiModel,
32+
newItem: RunningHistoryUiModel
3433
): Boolean {
3534
return oldItem.historyId == newItem.historyId
3635
}
3736

3837
override fun areContentsTheSame(
39-
oldItem: RunningHistory,
40-
newItem: RunningHistory
38+
oldItem: RunningHistoryUiModel,
39+
newItem: RunningHistoryUiModel
4140
): Boolean {
4241
return oldItem == newItem
4342
}
@@ -48,7 +47,7 @@ class MyRunningHistoryAdapter :
4847
class RunningHistoryViewHolder(view: View) : RecyclerView.ViewHolder(view) {
4948
private val binding = ItemRunningHistoryBinding.bind(view)
5049

51-
fun bind(runningHistory: RunningHistory) {
52-
binding.runningHistory = runningHistory.toRunningHistoryUiModel()
50+
fun bind(runningHistory: RunningHistoryUiModel) {
51+
binding.runningHistory = runningHistory
5352
}
5453
}

0 commit comments

Comments
 (0)