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
HW-4 DataBinding 적용 #543
HW-4 DataBinding 적용 #543
Conversation
val linearLayoutManager = LinearLayoutManager(this) | ||
rvMovies.layoutManager = linearLayoutManager | ||
binding.rvMovies.layoutManager = linearLayoutManager |
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.
LayoutManager는 xml에서 설정 할 수 있어요
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.
5d6aff2
수정했습니다.
...itectureStudy/app/src/main/java/com/mtjin/androidarchitecturestudy/ui/search/MovieAdapter.kt
Show resolved
Hide resolved
android:id="@+id/et_input" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:hint="입력" | ||
android:inputType="text" | ||
app:layout_constraintBottom_toTopOf="@+id/guideline" | ||
app:layout_constraintEnd_toStartOf="@+id/btn_search" | ||
app:layout_constraintHorizontal_weight="8" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<Button | ||
android:id="@+id/btn_search" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:onClick="@{()->search.onSearchClick()}" | ||
android:text="검색" | ||
app:layout_constraintBottom_toTopOf="@id/guideline" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_weight="2" | ||
app:layout_constraintStart_toEndOf="@+id/et_input" | ||
app:layout_constraintTop_toTopOf="parent" /> |
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.
xml에서도 텍스트는 string.xml에서 관리해주는 습관이 좋아요
string.xml에서 텍스트를 관리하면, 기기의 언어가 바뀔 때 바뀐 언어의 string.xml에서 id에 해당하는 텍스트값을 가져와 자연스럽게 다국어 지원이 가능하기도 해요
ex)
values-ko/string.xml
로그인
values-en/string.xml
login
그리고 의 text가 android:text="@string/login_btn"이면, 기기의 설정이 영어일땐 login을, 한글일 땐 로그인을 가져오게 되요
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.
android studio 에서
Analyze - Run Inspection by Name 에서
hard coded string / hard coded text를 검색하면 내 프로젝트에 하드 코딩된 텍스트나 스트링 값을 쉽게 검색할 수 있기도 합니다 ㅎㅎ
scrollListener = object : | ||
EndlessRecyclerViewScrollListener(binding.rvMovies.layoutManager as LinearLayoutManager) { |
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.
커밋에 xml에 linearlayoutManager 추가하는 코드가 빠진것같아요 ~~
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.
앗그렇군요 ... 제가못봤었네요 @sooakim approve하였습니다 ~~
@kangraemin |
|
||
@BindingAdapter("bind:urlImage") | ||
fun setUrlImage(imageView: ImageView, url: String) { | ||
Glide.with(imageView.context).load(url) |
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.
Glide.with를 쓸 때 imageView.context대신 imageView를 넣어주세요.
with를 통해 넘어오는 파라미터의 생명주기에 따라 RequestManager 인스턴스를 자동으로 관리 해주는데 imageView.context를 쓰면 View가 어디에 위치하던지 activity의 생명주기를 따르게 돼요.
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.
1aef5d3
수정했습니다.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
textView.text = Html.fromHtml(html, Html.FROM_HTML_MODE_COMPACT) | ||
} else { | ||
textView.text = Html.fromHtml(html) | ||
} |
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.
이부분은 HtmlCompat을 써서 버전 분기 없이 한줄로 줄 일 수 있어요.
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.
af549d9
수정했습니다.
import com.mtjin.androidarchitecturestudy.R | ||
|
||
|
||
@BindingAdapter("bind:htmlText") |
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.
android:text와 같이 기본 attr에 대한 어댑터를 사용할 때는 prefix가 필요하지만 그 경우가 아니라면 bind prefix를 붙일 필요가 없어요.
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.
88f5031
수정했습니다.
} | ||
} | ||
|
||
@BindingAdapter("bind:urlImage") |
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.
bind: 제거
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.
.into(imageView) | ||
} | ||
|
||
@BindingAdapter("bind:movieRating") |
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.
bind: 제거
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.
@mtjin xml에서는 유지해주세요.
BindingAdapter에서 bind를 붙이지 않았더라도, xml에서는 bind를 붙일 수 있어요.
사실 xml에서는 아무거나 같다붙여도 동작하고, prefix가 없어도 동작해요. bind는 아무의미가 없기때문이죠. xml에서 bind를 붙여주는건 단순히 다른 attr과의 구분을 줘서 가독성을 높이기위해서에요.
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.
af06d28
수정했습니다.
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.
LGTM ✊ ✌️ 👋
No description provided.