Skip to content

Feature/retrofit#4

Open
ko0chan wants to merge 6 commits intodevelopfrom
feature/retrofit
Open

Feature/retrofit#4
ko0chan wants to merge 6 commits intodevelopfrom
feature/retrofit

Conversation

@ko0chan
Copy link
Copy Markdown
Contributor

@ko0chan ko0chan commented Sep 2, 2020

레트로핏 통신

  • error 레트로핏으로 통신을 리팩토링 하면서 Recyclerview 와 연결오류

Comment on lines +20 to +21
private val clientId = "kHLvopePGjYBNBI1P4Us"
private val clientSecret = "GWjKNlXW_n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

고정적인 값은 상수로 사용하는게 좋아요

Suggested change
private val clientId = "kHLvopePGjYBNBI1P4Us"
private val clientSecret = "GWjKNlXW_n"
private const val CLIENT_SECRET = "GWjKNlXW_n"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

수정 완료했습니다!

println("Success to execute request : $body")
private fun searchByKeyword(keyword: String) {
val retrofit = Retrofit.Builder()
.baseUrl("https://openapi.naver.com/")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

base Url 도 상수로 관리하는게 좋아보여요

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

수정 완료했습니다!

@@ -0,0 +1,9 @@
package com.example.navermovie

data class MovieSearchRequest(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Request 보다는 Response 가 적절한 네이밍일 것 같고, (Request 할때 사용하는 값이 아님)
@SerializedName 을 붙여서 응답시 사용되는 클래스임을 명시적으로 나타내는게 좋을 것 같아요

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

수정하였습니다

@Query("query") query: String,
@Query("display") display: Int? = null,
@Query("start") start: Int? = null
):retrofit2.Call<MovieSearchRequest>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
):retrofit2.Call<MovieSearchRequest>
): retrofit2.Call<MovieSearchRequest>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

수정했습니다!

val webpage = Uri.parse("${data.link}")
val webIntent = Intent(Intent.ACTION_VIEW, webpage)
view.getContext().startActivity(webIntent);
view.context.startActivity(webIntent);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

여기(ViewHolder)에서 startActivity가 되는게 아니라,
Activity로 item이 눌렸다는 사실(+ data.link) 를 전달만 하고
실제 startActivity 실행은 Activity에서 되도록 해보면 좋을 것 같아요.

Comment on lines +34 to +35
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false)
recyclerView.setHasFixedSize(true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

recyclerView.run{} 방식으로 Scope 함수를 사용해 보시는 것도 괜찮은 방법일 것 같습니다.

import kotlinx.android.synthetic.main.movie_item_layout.view.*

class RecyclerViewAdapter(private val homefeed: Homefeed) :
class RecyclerViewAdapter(private val test: MovieSearchRequest) :
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

조심스럽게 말씀드려봅니다..생성자 형태로 외부에서 주입받는 방식 말고 다른 방법을 사용해 보시는게 어떠신지...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

추후에 더 공부해보고 적용시키도록 하겠습니다!

RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>(){
override fun getItemCount(): Int {
return homefeed.items.count()
return test.items.count()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

override fun getItemCount(): Int = test.items.count() 이런식으로도 가능하답니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

수정하였습니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

이러한 문법 차이가 그냥 단순한 문법 차이인 것인가요 ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

음.. 제 주관적입니다만.. 더 직관적이지 않나 생각이 드네요.

return ViewHolder(view)
}

class ViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ViewHolder 클래스를 따로 분류해서 관리해 보시는 방법도 있어요!

fun bind(data: Item){
Glide.with(view.context).load(data.image)
.apply(RequestOptions().override(300, 450))
.apply(RequestOptions.centerCropTransform())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이걸 빼신 이유가 무엇인가요??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

음.. 꼭 빼야겠다 싶어서 뺸건 아니지만 기초단계라고 생각이 들어서 필수적인 요소인 것들만 코딩을 진행하고 싶었습니다

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

그냥 궁금해서 ^^

@Header("X-Naver-Client-Id") clientId: String,
@Header("X-Naver-Client-Secret") clientSecret: String,
@Query("query") query: String,
@Query("display") display: Int? = null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

? = null 로 하신이유가 따로 있으신가요?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

검색을 할 때에 필수 요청 변수가 아니라서 검색 필터로 사용하지 않으려고 null처리를 하였습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants