-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop-xml
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다
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() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 sharedPreferences에 레포 적용해봐야겠네요
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FriendList보다 Friends 네이밍이 좋다고 합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넘 잘하시네요 .. 수고하셨슴다 !
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class RepositoryModule { | ||
@Singleton | ||
@Binds | ||
abstract fun bindsFriendRepository( | ||
friendRepository: FriendRepositoryImpl | ||
): FriendRepository | ||
|
||
@Singleton | ||
@Binds | ||
abstract fun bindsSharedPrefRepository( | ||
sharedPrefRepository: SharedPrefRepositoryImpl | ||
): SharedPrefRepository | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우왕 Dagger-Hilt Module 사용 신기하네요 .... 굿굿 !!
is UiState.Failure -> { | ||
Toast.makeText(requireContext(), "친구없음", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
is UiState.Empty -> { | ||
Toast.makeText(requireContext(), "친구없음", Toast.LENGTH_SHORT).show() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toast 확장함수 추출해보면 어떨까요 !!
suspend fun insertFriend(friendEntity: FriendEntity) | ||
suspend fun getFriend(): List<FriendEntity> | ||
suspend fun deleteFriend(id:Int) | ||
suspend fun deleteAll() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
친구 추가랑 삭제까지 .... 와우 !!
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> | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 저도 UiState에 empty도 추가하는 등 보완해봐야겠네요 !! 👍
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() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 적용해봐야겠네요 !
There was a problem hiding this 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리스트를 가져오니까 getFriends 라는 네이밍을 사용하는 게 더 좋을 것 같아요!
Related issue 🛠
Work Description ✏️
To Reviewers 📢