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

전남대 Android_오진우_5주차 과제_Step1 #61

Open
wants to merge 10 commits into
base: fivejinw
Choose a base branch
from

Conversation

fiveJinw
Copy link

@fiveJinw fiveJinw commented Jul 25, 2024

오늘도 코드리뷰 부탁드립니다!

코드 작성하면서 어려웠던 점 & 느낀 점

  • Room 방식은 Step1에서 한번 학습을 하고 온 상태였기 때문에 어느정도 사용하는 방법을 알고 있었지만, 아키텍처 패턴에 맞게끔 사용하는 방식이 꽤나 햇갈렸습니다.
  • Hilt는 이번이 처음 사용이였습니다. Hilt를 통해 의존성 주입을 적용하는 과정에서 오류가 많이 발생해서 어려웠던 것 같습니다.

멘토님께서 중점적으로 리뷰해주셨으면 하는 부분

  • 의존성 주입이 제대로 이뤄지고 있는지
  • Room의 구현방식이 잘못구현된 부분이 있는지

추가로 궁금한 점

  • DatabaseModule 안의 provideDataStore 함수를 넣었는데 DataStoreModule을 따로 만들어서 나누는게 더 좋을 지 궁금합니다!
  • SavePlaceDatabase의 getInstance에서 경합상태를 예방하기 위한 처리를 따로 하였습니다.
    • SingleTon 어노테이션을 적용하면 이러한 처리가 필요없는지 궁금합니다.
    • 테스트하고 싶지만 고의적으로 그런 상태를 유발하는 방법을 몰라 여쭤봅니다....

언제나 감사드립니다!

Copy link

@bigstark bigstark left a comment

Choose a reason for hiding this comment

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

이번 step1 도 수고 많으셨어요 진우님!!

아직 hilt 를 사용하시는 것이 어색한 것 같아요. 모든 것은 SingletonComponent 로 제공될 필요는 없고, 한 화면에서만 사용될 예정이라면 ViewModelComponent 나 ActivityComponent 같은 것도 사용해보시는 것이 좋습니다!

또한 hilt 는 아키텍쳐에 요소를 많이 적용할수록 더욱 더 빛을 볼 수 있어요. 저번 과제에서 리뷰했던 것처럼 안드로이드에서 권장하는 아키텍쳐를 조금 더 적용해보시면 더더욱 좋을 것 같습니다 :)

또한 경합상태에 대한 테스트코드는 확실히 어렵긴 합니다만, hilt github 에서 race condition on injection 과 같이 검색해보시면 지원을 하는지 안하는지 알아보실 수 있을거에요

Comment on lines 31 to 35
@Singleton
@Provides
fun provideDataStore(@ApplicationContext context: Context) : DataStore<Preferences>{
return context.dataStore
}

Choose a reason for hiding this comment

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

DatabaseModule 이라고 정의했기 때문에 DataStore 는 따로 빼두시는 편이 좋죠. 다만 LocalDataSourceModule 이라고 정의한다면, 함께 있어도 괜찮습니다!

Comment on lines 16 to 27
companion object {
@Volatile
private var instance: SavedPlaceDatabase? = null

fun getInstance(context: Context): SavedPlaceDatabase {
return instance ?: synchronized(this) {
Room.databaseBuilder(
context, SavedPlaceDatabase::class.java, PlaceContract.DATABASE_NAME
).build().also { instance = it }
}
}
}

Choose a reason for hiding this comment

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

여기에서 정의하지 마시고, hilt 의 Provides 내부 구현으로 옮겨주시는 것이 좋을 것 같습니다!

Choose a reason for hiding this comment

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

hilt 를 사용하고 singleton 으로 제공한다면, 경합상태에 대한 고민을 크게 하지 않으셔도 됩니닷


class SharedPreferenceRepository(private val dataStore: DataStore<Preferences>) {
@Singleton
class SharedPreferenceRepository @Inject constructor(private val dataStore: DataStore<Preferences>) {

Choose a reason for hiding this comment

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

SharedPreferences 는 Data Source 의 개념이기 떄문에 이부분을 Repository 로 정의하기보다는 PlaceRepository 나 SavedPlaceRepository 로 로직을 옮기는 것이 어떨까요?

Comment on lines 45 to 54
lateinit var map: MapView
lateinit var inputField: EditText
lateinit var searchIcon: ImageView
lateinit var errorTextView: TextView
lateinit var kakaoMap : KakaoMap
lateinit var resultLauncher : ActivityResultLauncher<Intent>
lateinit var sharedPreferencesRepository: SharedPreferenceRepository
lateinit var bottomSheetLayout : ConstraintLayout
lateinit var placeNameField : TextView
lateinit var placeLocationField : TextView
lateinit var bottomSheetBehavior : BottomSheetBehavior<ConstraintLayout>

Choose a reason for hiding this comment

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

위에 viewbinding, databinding 의존성도 있던데, 이부분도 리팩토링 해보시면 어떨까요?

fun getSavedPlace() {
_savedPlace.value = (savedPlaceRepository.getAllSavedPlace())
viewModelScope.launch(Dispatchers.IO) {

Choose a reason for hiding this comment

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

Dispatcher 도 주입받을 수 있도록 처리해주시는 것이 더욱 더 좋습니다!

https://developer.android.com/kotlin/coroutines/coroutines-best-practices

fun getSavedPlace() {
_savedPlace.value = (savedPlaceRepository.getAllSavedPlace())
viewModelScope.launch(Dispatchers.IO) {
_savedPlace.postValue(savedPlaceRepository.getAllSavedPlace())

Choose a reason for hiding this comment

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

coroutine 을 사용하시는김에, 이부분도 StateFlow 로 변경하면 어때요?

https://developer.android.com/kotlin/flow/stateflow-and-sharedflow

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.

2 participants