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

영화 목록 출력 #22

Open
wants to merge 17 commits into
base: handnew04
Choose a base branch
from
Open

Conversation

handnew04
Copy link
Collaborator

No description provided.

@handnew04 handnew04 self-assigned this Mar 8, 2020
@handnew04 handnew04 requested review from devLibCH and dlwls5201 March 8, 2020 15:23
Copy link
Collaborator

@zion830 zion830 left a comment

Choose a reason for hiding this comment

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

안녕하세요
몇가지 리뷰 남겨보았습니다 🙂


@BindingAdapter("bind:replace")
fun RecyclerView.replaceAll(item: List<SearchMovieData>?) {
if (!item.isNullOrEmpty()) (adapter as? MainMoviePostingRecyclerAdapter)!!.setItemList(item as ArrayList<SearchMovieData>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

as?는 타입 캐스팅에 실패했을 경우 null을 반환하기 때문에, 만약 캐스팅이 실패한다면 setItemList가 호출될 때 NPE가 발생하게 됩니다. !! 대신 ?를 사용하는 것이 좋아 보입니다 ㅎㅎ

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

앗 감사합니다!
8ab4e5e

@BindingAdapter("bind:bindImage")
fun bindImage(imageView: ImageView, imageUri: String) {
if (imageUri.isNotEmpty())
Glide.with(imageView.context).load(imageUri).into(imageView)
Copy link
Collaborator

Choose a reason for hiding this comment

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

kotlin style guide에 따르면, 실행문이 단문이더라도 괄호로 감싸주는 것이 권장사항입니다.
관련 링크 : https://developer.android.com/kotlin/style-guide/#braces

Copy link
Collaborator

Choose a reason for hiding this comment

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

RecyclerView와 마찬가지로 확잠 하수로 만들면 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

혹시 이렇게 바꾸면 말씀하신 확장함수일까요 ? 검색해보니 이런 형태인것 같아서요
8ab4e5e

Copy link
Collaborator

Choose a reason for hiding this comment

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

@handnew04 네 맞습니다 ㅎㅎ

import retrofit2.Response

class MovieRemoteDataSourceImpl() : MovieRemoteDataSource {
val APP_KEY = "e29f73abf94a892a99c8df777d038279"
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 클래스 내부에서만 쓰이는 KEY 값이므로 private를 붙여야할거같네요 ㅎㅎ

Copy link
Collaborator

Choose a reason for hiding this comment

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

현재 앱 같은경우는 크게 관계 없겠지만
appKey나 서버주소 같은 내용들은 숨겨지는 편이 좋습니다.
app모듈의 build.gradle에서 BuildConfig내부 변수로 추가하시는 편을 추천 드립니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

10c37b6
BuildConfig 변수라는 거 처음알았어요ㅜㅜ 감사합니당!!

val id: String,
val poster_path: String
) {
fun getPosterUrl(): String = "https://image.tmdb.org/t/p/w200/$poster_path"
Copy link
Collaborator

Choose a reason for hiding this comment

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

이미지를 부를때 사용하는 이 URL(https://image.tmdb.org/t/p/w200/)이 재사용되거나 수정되는 상황을 고려했을 때, 상수로 따로 분리하면 좋을 것 같아요~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cce7801
감사합니다. 상수를 따로 파일을 만들어서 뒀는데 이렇게 하는게 좋을까요?


data class SearchMovieData(
val id: String,
val poster_path: String
Copy link
Collaborator

Choose a reason for hiding this comment

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

변수 네이밍은 Camel case로 하는 것이 공식 가이드입니다.
json key에 맞춰서 쓰신거라면 모든 프로퍼티에 개별적으로 @SerializedName을 붙이면 될 거 같아요!
관련 링크 : https://developer.android.com/kotlin/style-guide/#naming_2


@GET("search/movie")
fun requestSearchMovie(
@Query("api_key") api_key: String,
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 마찬가지로 camel case로 바꿔야할것 같네용

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

c04fe6d
감사합니다!


class MainActivity : AppCompatActivity() {
lateinit var binding: ActivityMainBinding
lateinit var adapter: MainMoviePostingRecyclerAdapter
Copy link
Collaborator

Choose a reason for hiding this comment

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

adapter는 context가 필요하지 않아서 굳이 lateinit로 선언하지 않아도 될것같네요.
실수로 adapter가 초기화되기 전에 사용하면 NPE가 발생할 수 있기 때문에 선언과 동시에 초기화하는 편이 좋을 것 같습니다 ~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

c04fe6d
그 부분은 생각하지 못했는데, 감사합니다!

binding.rcvPoster.adapter = adapter
}

private fun test() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기선 test 보다는 초기화, 데이터 로딩, 시작 등의 의미가 느껴지는 네이밍을 사용한다면 역할이 더 잘 와닿을거 같습니다 ㅎㅎ

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

c04fe6d
수정했습니다. 감사합니다!

private fun initBinding() {
binding.vm = mainViewModel
binding.lifecycleOwner = this@MainActivity
binding.rcvPoster.adapter = adapter
Copy link
Collaborator

Choose a reason for hiding this comment

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

동일한 표현이지만 한 객체의 여러 프로퍼티를 초기화한다면 apply도 사용 가능합니다

        binding.apply {
            viewModel = mainViewModel
            lifecycleOwner = this@MainActivity
            rcvPoster.adapter = adapter
        }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

c04fe6d
앗 감사합니다!

return ViewHolder(binding)
}

override fun getItemCount(): Int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

= 로 더 간결하게 표현이 가능합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

c04fe6d
감사합니다. 계속 return 을 쓰네요.. ㅠㅠ

}
isLoading.value = true
}
isLoading.value = false
Copy link
Collaborator

@dlwls5201 dlwls5201 Mar 14, 2020

Choose a reason for hiding this comment

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

isLoading.value = true 과 isLoading.value = flase 를 각각 하나의 함수로 만들어서 의미를 명확히 표현하는게 어떨까요?

showLoading(), hideLoading() 등등

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

3b18433
늦어서 죄송해요 감사합니다.

val isLoading = MutableLiveData<Boolean>()

fun searchMovie() {
runBlocking {
Copy link
Collaborator

Choose a reason for hiding this comment

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

저도 공부중이지만 안드앱에서 runBlocking 사용은 매우 위험하다고 합니다.
viewModel을 사용하신다면 viewModelScope를 사용해 보시면 좋을 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

55dbfed
감사합니다!

Copy link
Collaborator

@devLibCH devLibCH left a comment

Choose a reason for hiding this comment

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

늦은 감이 있지만 코드리뷰 드립니다~
다른분들이 잘 해주셔서 내용이 별로 없네요

import retrofit2.Response

class MovieRemoteDataSourceImpl() : MovieRemoteDataSource {
val APP_KEY = "e29f73abf94a892a99c8df777d038279"
Copy link
Collaborator

Choose a reason for hiding this comment

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

현재 앱 같은경우는 크게 관계 없겠지만
appKey나 서버주소 같은 내용들은 숨겨지는 편이 좋습니다.
app모듈의 build.gradle에서 BuildConfig내부 변수로 추가하시는 편을 추천 드립니다.

val query = MutableLiveData<String>()

fun searchMovie() {
MovieRepositoryImpl.getMovieData(query.toString(), success = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

liveData를 사용하셨으므로 query.value를 사용하는 것 이 좋을 것 같네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

3b18433
늦어서 죄송해요. 감사합니다 ! ㅜㅜ


inner class ViewHolder(val binding: ItemMainBinding) : RecyclerView.ViewHolder(binding.root) {
init {
binding.root.setOnClickListener({
Copy link
Collaborator

Choose a reason for hiding this comment

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

dataBinding을 사용하시니까 xml에서 직접 clickListener를 사용하는 것이 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

3b18433
감사합니다 ㅜㅜ!

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="@{vm.isLoading() ? View.VISIBLE : View.GONE}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

extension함수를 만들어서 사용하는게 좋을 것 같습니다

Copy link
Collaborator

Choose a reason for hiding this comment

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

[질문] VISIBLE, GONE 중 하나만 선택하면 되는 간단한 분기라 custom attribute가 필요해보이지 않는데, 확장 함수를 사용하면 어떤 장점이 있는지 궁금합니당

Copy link
Collaborator

Choose a reason for hiding this comment

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

[질문] VISIBLE, GONE 중 하나만 선택하면 되는 간단한 분기라 custom attribute가 필요해보이지 않는데, 확장 함수를 사용하면 어떤 장점이 있는지 궁금합니당

개인적으로는

  1. View를 import 하지 않아도 된다.
  2. View.{함수} 형식으로 모든 뷰에서 일괄적으로 관리할 수 있다.

더 있을까요 ?_?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bc145e2
감사합니당!

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.

4 participants