Skip to content

Commit e459074

Browse files
committed
♻️ 코드 리뷰 피드백 반영해서 수정
1 parent dbc911b commit e459074

File tree

11 files changed

+76
-47
lines changed

11 files changed

+76
-47
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ interface RunningHistoryDao {
1212
@Insert(onConflict = OnConflictStrategy.ABORT)
1313
suspend fun addRunningHistory(runningHistory: RunningHistoryEntity)
1414

15-
@Query("SELECT * FROM running_history ORDER BY startedAt ASC")
15+
@Query("SELECT * FROM running_history ORDER BY started_at ASC")
1616
fun getRunningHistory(): Flow<List<RunningHistoryEntity>>
1717
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.whyranoid.data.account
22

3+
import androidx.room.ColumnInfo
34
import androidx.room.Entity
45
import androidx.room.PrimaryKey
56
import com.whyranoid.domain.model.RunningHistory
@@ -8,11 +9,11 @@ import com.whyranoid.domain.model.RunningHistory
89
data class RunningHistoryEntity(
910
@PrimaryKey
1011
val historyId: String,
11-
val startedAt: Long,
12-
val finishedAt: Long,
13-
val totalRunningTime: Int,
14-
val pace: Double,
15-
val totalDistance: Double
12+
@ColumnInfo(name = "started_at") val startedAt: Long,
13+
@ColumnInfo(name = "finished_at") val finishedAt: Long,
14+
@ColumnInfo(name = "total_running_time") val totalRunningTime: Int,
15+
@ColumnInfo(name = "pace") val pace: Double,
16+
@ColumnInfo(name = "total_distance") val totalDistance: Double
1617
)
1718

1819
fun RunningHistoryEntity.toRunningHistory(): RunningHistory {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import kotlinx.coroutines.flow.map
66
import javax.inject.Inject
77

88
class RunningHistoryLocalDataSourceImpl @Inject constructor(
9-
private val roomDb: RunningHistoryLocalDataBase
9+
private val runningHistoryDao: RunningHistoryDao
1010
) : RunningHistoryLocalDataSource {
1111

1212
override fun getRunningHistory(): Flow<List<RunningHistory>> {
13-
return roomDb.runningHistoryDao().getRunningHistory().map { runningHistoryList ->
13+
return runningHistoryDao.getRunningHistory().map { runningHistoryList ->
1414
runningHistoryList.map { runningHistoryEntity ->
1515
runningHistoryEntity.toRunningHistory()
1616
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.whyranoid.data.di
2+
3+
import android.content.Context
4+
import androidx.room.Room
5+
import com.whyranoid.data.account.RunningHistoryDao
6+
import com.whyranoid.data.account.RunningHistoryLocalDataBase
7+
import dagger.Module
8+
import dagger.Provides
9+
import dagger.hilt.InstallIn
10+
import dagger.hilt.android.qualifiers.ApplicationContext
11+
import dagger.hilt.components.SingletonComponent
12+
import javax.inject.Singleton
13+
14+
@Module
15+
@InstallIn(SingletonComponent::class)
16+
object RunningHistoryDataBaseModule {
17+
@Singleton
18+
@Provides
19+
fun provideRoomDataBase(
20+
@ApplicationContext appContext: Context
21+
): RunningHistoryLocalDataBase = Room.databaseBuilder(
22+
appContext,
23+
RunningHistoryLocalDataBase::class.java,
24+
"mogakrun_running_history.db"
25+
)
26+
.build()
27+
28+
@Singleton
29+
@Provides
30+
fun provideRunningHistoryDao(runningHistoryLocalDataBase: RunningHistoryLocalDataBase): RunningHistoryDao =
31+
runningHistoryLocalDataBase.runningHistoryDao()
32+
}

data/src/main/java/com/whyranoid/data/di/DataBaseModule.kt renamed to data/src/main/java/com/whyranoid/data/di/UserDataBaseModule.kt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ 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 androidx.room.Room
9-
import com.whyranoid.data.account.RunningHistoryLocalDataBase
108
import dagger.Module
119
import dagger.Provides
1210
import dagger.hilt.InstallIn
@@ -16,22 +14,7 @@ import javax.inject.Singleton
1614

1715
@Module
1816
@InstallIn(SingletonComponent::class)
19-
object DataBaseModule {
20-
@Singleton
21-
@Provides
22-
fun provideRoomDataBase(
23-
@ApplicationContext appContext: Context
24-
): RunningHistoryLocalDataBase = Room.databaseBuilder(
25-
appContext,
26-
RunningHistoryLocalDataBase::class.java,
27-
"mogakrun_running_history.db"
28-
)
29-
.build()
30-
}
31-
32-
@Module
33-
@InstallIn(SingletonComponent::class)
34-
object DataStoreModule {
17+
object UserDataBaseModule {
3518

3619
private const val USER_PREFERENCES = "user_preferences"
3720

presentation/src/main/java/com/whyranoid/presentation/myrun/RunningHistoryUiModel.kt renamed to presentation/src/main/java/com/whyranoid/presentation/model/RunningHistoryUiModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.whyranoid.presentation.myrun
1+
package com.whyranoid.presentation.model
22

33
import com.whyranoid.domain.model.RunningHistory
44

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ internal class MyRunFragment : BaseFragment<FragmentMyRunBinding>(R.layout.fragm
4040

4141
topAppBar.setOnMenuItemClickListener { menuItem ->
4242
when (menuItem.itemId) {
43-
R.id.my_run_setting ->
44-
findNavController().navigate(R.id.action_myRunFragment_to_settingFragment)
43+
R.id.my_run_setting -> {
44+
val direction = MyRunFragmentDirections.actionMyRunFragmentToSettingFragment()
45+
findNavController().navigate(direction)
46+
}
4547
}
4648
true
4749
}
@@ -77,7 +79,10 @@ internal class MyRunFragment : BaseFragment<FragmentMyRunBinding>(R.layout.fragm
7779
.setPositiveButton(
7880
getString(R.string.my_run_edit_nick_name_dialog_positive)
7981
) { dialog, _ ->
80-
viewModel.updateNickName(viewModel.uid.value, dialogView.findViewById<EditText>(R.id.et_change_nick_name).text.toString())
82+
viewModel.updateNickName(
83+
viewModel.uid.value,
84+
dialogView.findViewById<EditText>(R.id.et_change_nick_name).text.toString()
85+
)
8186
dialog.dismiss()
8287
}
8388
.setNegativeButton(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class MyRunViewModel @Inject constructor(
3030
getProfileImgUri()
3131
}
3232

33-
private val EMPTY_STRING = ""
34-
3533
private val _uid = MutableStateFlow(EMPTY_STRING)
3634
val uid: StateFlow<String>
3735
get() = _uid.asStateFlow()
@@ -89,4 +87,8 @@ class MyRunViewModel @Inject constructor(
8987
}
9088
}
9189
}
90+
91+
companion object {
92+
private const val EMPTY_STRING = ""
93+
}
9294
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package com.whyranoid.presentation.myrun
33
import android.view.LayoutInflater
44
import android.view.View
55
import android.view.ViewGroup
6+
import androidx.recyclerview.widget.DiffUtil
67
import androidx.recyclerview.widget.ListAdapter
78
import androidx.recyclerview.widget.RecyclerView
89
import com.whyranoid.domain.model.RunningHistory
910
import com.whyranoid.presentation.R
1011
import com.whyranoid.presentation.databinding.ItemRunningHistoryBinding
12+
import com.whyranoid.presentation.model.toRunningHistoryUiModel
1113

1214
class MyRunningHistoryAdapter :
1315
ListAdapter<RunningHistory, RunningHistoryViewHolder>(
@@ -23,6 +25,24 @@ class MyRunningHistoryAdapter :
2325
override fun onBindViewHolder(holder: RunningHistoryViewHolder, position: Int) {
2426
holder.bind(getItem(position))
2527
}
28+
29+
companion object {
30+
class MyRunningHistoryDiffCallback : DiffUtil.ItemCallback<RunningHistory>() {
31+
override fun areItemsTheSame(
32+
oldItem: RunningHistory,
33+
newItem: RunningHistory
34+
): Boolean {
35+
return oldItem.historyId == newItem.historyId
36+
}
37+
38+
override fun areContentsTheSame(
39+
oldItem: RunningHistory,
40+
newItem: RunningHistory
41+
): Boolean {
42+
return oldItem == newItem
43+
}
44+
}
45+
}
2646
}
2747

2848
class RunningHistoryViewHolder(view: View) : RecyclerView.ViewHolder(view) {

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

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

0 commit comments

Comments
 (0)