-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: handnew04
Are you sure you want to change the base?
영화 목록 출력 #22
Changes from 1 commit
bfa8270
f7e7548
3a1810a
34e7087
e174844
46a946a
8ddd99b
15754e2
ccc2a2b
c37aaab
8ab4e5e
10c37b6
cce7801
c04fe6d
3b18433
bc145e2
55dbfed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.toyproject.adapter | ||
|
||
import android.widget.ImageView | ||
import androidx.databinding.BindingAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
import com.example.toyproject.data.entity.SearchMovieData | ||
import com.example.toyproject.ui.main.MainMoviePostingRecyclerAdapter | ||
|
||
@BindingAdapter("bind:replace") | ||
fun RecyclerView.replaceAll(item: List<SearchMovieData>?) { | ||
if (!item.isNullOrEmpty()) (adapter as? MainMoviePostingRecyclerAdapter)!!.setItemList(item as ArrayList<SearchMovieData>) | ||
} | ||
|
||
@BindingAdapter("bind:bindImage") | ||
fun bindImage(imageView: ImageView, imageUri: String) { | ||
if (imageUri.isNotEmpty()) | ||
Glide.with(imageView.context).load(imageUri).into(imageView) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kotlin style guide에 따르면, 실행문이 단문이더라도 괄호로 감싸주는 것이 권장사항입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RecyclerView와 마찬가지로 확잠 하수로 만들면 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @handnew04 네 맞습니다 ㅎㅎ |
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.toyproject.ui.main | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.example.toyproject.data.entity.SearchMovieData | ||
import com.example.toyproject.data.repository.MovieRepositoryImpl | ||
|
||
class MainViewModel() : ViewModel() { | ||
val TAG = this.javaClass.name | ||
val movieData = MutableLiveData<List<SearchMovieData>>() | ||
val query = MutableLiveData<String>() | ||
|
||
fun searchMovie() { | ||
MovieRepositoryImpl.getMovieData(query.toString(), success = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. liveData를 사용하셨으므로 query.value를 사용하는 것 이 좋을 것 같네요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3b18433 |
||
movieData.value = it.searchMovieResults | ||
}, fail = { | ||
Log.e(TAG, it.message) | ||
}) | ||
} | ||
} |
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.
as?는 타입 캐스팅에 실패했을 경우 null을 반환하기 때문에, 만약 캐스팅이 실패한다면 setItemList가 호출될 때 NPE가 발생하게 됩니다.
!!
대신?
를 사용하는 것이 좋아 보입니다 ㅎㅎ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.
앗 감사합니다!
8ab4e5e