Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7주차/필수] XML repository 패턴 #18

Open
wants to merge 3 commits into
base: develop-xml
Choose a base branch
from

Conversation

leeseokchan00
Copy link
Collaborator

Related issue 🛠

Work Description ✏️

  • �sharedprefrence, room에 repository패턴 적용하기

To Reviewers 📢

Copy link

@gaeulzzang gaeulzzang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다

Comment on lines +7 to +30
class SharedPrefDataSourceImpl @Inject constructor(
private val sharedPreferences: SharedPreferences
) : SharedPrefDataSource {

override fun setUserId(key: String, value: Int) {
return sharedPreferences.edit().putInt(key, value).apply()
}

override fun getUserId(key: String): Int {
return sharedPreferences.getInt(key, 0)
}

override fun getBoolean(key: String): Boolean {
return sharedPreferences.getBoolean(key, false)
}

override fun setBoolean(key: String, value: Boolean) {
sharedPreferences.edit().putBoolean(key, value).apply()
}

override fun clearUserData() {
sharedPreferences.edit().clear().apply()
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 sharedPreferences에 레포 적용해봐야겠네요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 적용해봐야겠네요 !

@@ -46,8 +42,7 @@ class MainFragment : Fragment() {

initFloatingBtnClickListener()
initAdapter()
viewModel.getFriend()
FriendListObserver()
initFriendListObserver()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FriendList보다 Friends 네이밍이 좋다고 합니다

Copy link
Member

@yskim6772 yskim6772 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넘 잘하시네요 .. 수고하셨슴다 !

Comment on lines +13 to +27
@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Singleton
@Binds
abstract fun bindsFriendRepository(
friendRepository: FriendRepositoryImpl
): FriendRepository

@Singleton
@Binds
abstract fun bindsSharedPrefRepository(
sharedPrefRepository: SharedPrefRepositoryImpl
): SharedPrefRepository
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우왕 Dagger-Hilt Module 사용 신기하네요 .... 굿굿 !!

Comment on lines +120 to +126
is UiState.Failure -> {
Toast.makeText(requireContext(), "친구없음", Toast.LENGTH_SHORT).show()
}

is UiState.Empty -> {
Toast.makeText(requireContext(), "친구없음", Toast.LENGTH_SHORT).show()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toast 확장함수 추출해보면 어떨까요 !!

Comment on lines +6 to +9
suspend fun insertFriend(friendEntity: FriendEntity)
suspend fun getFriend(): List<FriendEntity>
suspend fun deleteFriend(id:Int)
suspend fun deleteAll()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

친구 추가랑 삭제까지 .... 와우 !!

Comment on lines +3 to +13
sealed interface UiState<out T> {
object Empty : UiState<Nothing>
data class Success<T>(
val data: T
) : UiState<T>

data class Failure(
val msg: String
) : UiState<Nothing>

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저도 UiState에 empty도 추가하는 등 보완해봐야겠네요 !! 👍

Comment on lines +7 to +30
class SharedPrefDataSourceImpl @Inject constructor(
private val sharedPreferences: SharedPreferences
) : SharedPrefDataSource {

override fun setUserId(key: String, value: Int) {
return sharedPreferences.edit().putInt(key, value).apply()
}

override fun getUserId(key: String): Int {
return sharedPreferences.getInt(key, 0)
}

override fun getBoolean(key: String): Boolean {
return sharedPreferences.getBoolean(key, false)
}

override fun setBoolean(key: String, value: Boolean) {
sharedPreferences.edit().putBoolean(key, value).apply()
}

override fun clearUserData() {
sharedPreferences.edit().clear().apply()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 적용해봐야겠네요 !

Copy link

@jihyunniiii jihyunniiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니당


interface FriendDataSource {
suspend fun insertFriend(friendEntity: FriendEntity)
suspend fun getFriend(): List<FriendEntity>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리스트를 가져오니까 getFriends 라는 네이밍을 사용하는 게 더 좋을 것 같아요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[7주차] repository 패턴
4 participants