Conversation
| private val clientId = "kHLvopePGjYBNBI1P4Us" | ||
| private val clientSecret = "GWjKNlXW_n" |
There was a problem hiding this comment.
고정적인 값은 상수로 사용하는게 좋아요
| private val clientId = "kHLvopePGjYBNBI1P4Us" | |
| private val clientSecret = "GWjKNlXW_n" | |
| private const val CLIENT_SECRET = "GWjKNlXW_n" |
| println("Success to execute request : $body") | ||
| private fun searchByKeyword(keyword: String) { | ||
| val retrofit = Retrofit.Builder() | ||
| .baseUrl("https://openapi.naver.com/") |
| @@ -0,0 +1,9 @@ | |||
| package com.example.navermovie | |||
|
|
|||
| data class MovieSearchRequest( | |||
There was a problem hiding this comment.
Request 보다는 Response 가 적절한 네이밍일 것 같고, (Request 할때 사용하는 값이 아님)
@SerializedName 을 붙여서 응답시 사용되는 클래스임을 명시적으로 나타내는게 좋을 것 같아요
| @Query("query") query: String, | ||
| @Query("display") display: Int? = null, | ||
| @Query("start") start: Int? = null | ||
| ):retrofit2.Call<MovieSearchRequest> |
There was a problem hiding this comment.
| ):retrofit2.Call<MovieSearchRequest> | |
| ): retrofit2.Call<MovieSearchRequest> |
| val webpage = Uri.parse("${data.link}") | ||
| val webIntent = Intent(Intent.ACTION_VIEW, webpage) | ||
| view.getContext().startActivity(webIntent); | ||
| view.context.startActivity(webIntent); |
There was a problem hiding this comment.
여기(ViewHolder)에서 startActivity가 되는게 아니라,
Activity로 item이 눌렸다는 사실(+ data.link) 를 전달만 하고
실제 startActivity 실행은 Activity에서 되도록 해보면 좋을 것 같아요.
| recyclerView.layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false) | ||
| recyclerView.setHasFixedSize(true) |
There was a problem hiding this comment.
recyclerView.run{} 방식으로 Scope 함수를 사용해 보시는 것도 괜찮은 방법일 것 같습니다.
| import kotlinx.android.synthetic.main.movie_item_layout.view.* | ||
|
|
||
| class RecyclerViewAdapter(private val homefeed: Homefeed) : | ||
| class RecyclerViewAdapter(private val test: MovieSearchRequest) : |
There was a problem hiding this comment.
조심스럽게 말씀드려봅니다..생성자 형태로 외부에서 주입받는 방식 말고 다른 방법을 사용해 보시는게 어떠신지...
There was a problem hiding this comment.
추후에 더 공부해보고 적용시키도록 하겠습니다!
| RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>(){ | ||
| override fun getItemCount(): Int { | ||
| return homefeed.items.count() | ||
| return test.items.count() |
There was a problem hiding this comment.
override fun getItemCount(): Int = test.items.count() 이런식으로도 가능하답니다.
There was a problem hiding this comment.
이러한 문법 차이가 그냥 단순한 문법 차이인 것인가요 ?
There was a problem hiding this comment.
음.. 제 주관적입니다만.. 더 직관적이지 않나 생각이 드네요.
| return ViewHolder(view) | ||
| } | ||
|
|
||
| class ViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { |
There was a problem hiding this comment.
ViewHolder 클래스를 따로 분류해서 관리해 보시는 방법도 있어요!
| fun bind(data: Item){ | ||
| Glide.with(view.context).load(data.image) | ||
| .apply(RequestOptions().override(300, 450)) | ||
| .apply(RequestOptions.centerCropTransform()) |
There was a problem hiding this comment.
음.. 꼭 빼야겠다 싶어서 뺸건 아니지만 기초단계라고 생각이 들어서 필수적인 요소인 것들만 코딩을 진행하고 싶었습니다
| @Header("X-Naver-Client-Id") clientId: String, | ||
| @Header("X-Naver-Client-Secret") clientSecret: String, | ||
| @Query("query") query: String, | ||
| @Query("display") display: Int? = null, |
There was a problem hiding this comment.
검색을 할 때에 필수 요청 변수가 아니라서 검색 필터로 사용하지 않으려고 null처리를 하였습니다.
레트로핏 통신