Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GDG Android - Android Adapter 어떻게 사용하는게 좋을까?
Search
TaeHwan
February 03, 2018
Programming
2
24k
GDG Android - Android Adapter 어떻게 사용하는게 좋을까?
2018/02/02 GDG Android Lightning Talk Announcement
TaeHwan
February 03, 2018
Tweet
Share
More Decks by TaeHwan
See All by TaeHwan
Compose 함수 나누는 조건은?
taehwandev
0
1.3k
Android MVVM 패턴의 접근법 - 2023 드로이드 나이츠
taehwandev
1
1.6k
안드로이드의 변화 - IO Extended 2023 - 송도
taehwandev
0
540
What’s new in Android?(Google IO ex 23-GDG Pangyo)
taehwandev
0
830
Jetpack Compose 상태 및 사이드 효과
taehwandev
0
1.1k
GDG DevFest2022 Songdo - KMM(Kotlin Multiplatform Mobile)
taehwandev
0
560
Kotlin Night 2022 - 코틀린 어노테이션으로 할 수 있는 것(GDG Seoul)
taehwandev
2
1.6k
Android module 개발 - Now in android 참고
taehwandev
3
16k
Android Compose Component - mapping.
taehwandev
2
4.6k
Other Decks in Programming
See All in Programming
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.4k
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
情報漏洩させないための設計
kubotak
3
500
Go の GC の不得意な部分を克服したい
taiyow
3
810
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
1
100
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
340
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
500
Security_for_introducing_eBPF
kentatada
0
110
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Statistics for Hackers
jakevdp
796
220k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Music & Morning Musume
bryan
46
6.2k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Transcript
Adapter যڌѱ Ӕೞݶ જਸө? Taehwan
ViewModel ਊೞৈ ܻ࠙ೞӝ
ೞ݅ ৈӝࢲࠗఠ द — SeongUg Steve Jung(GDE) : Adapter, ־ҳջ
ք? — Data? View?
Adapter ۧѱ ҳࢿغযભ?
ۧѱ ࢎਊೞભ? class SimpleAdapter(private val context: Context, private val list:
ArrayList<String>) : RecyclerView.Adapter<SimpleAdapter.ViewHolder>() { override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): SimpleAdapter.ViewHolder { return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_text_sample, parent)) } override fun getItemCount() = list.size override fun onBindViewHolder(holder: SimpleAdapter.ViewHolder?, position: Int) { holder?.itemView?.run { tv_message.text = "Set TEXT" } } class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) }
N ѐ ViewHolderо ਃೞ class ViewHolderOne(itemView: View) : RecyclerView.ViewHolder(itemView) class
ViewHolderTwo(itemView: View) : RecyclerView.ViewHolder(itemView) class ViewHolderThree(itemView: View) : RecyclerView.ViewHolder(itemView)
N ѐ ViewHolderо ਃೞ class SimpleAdapter(private val context: Context, private
val list: ArrayList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder { return when (viewType) { TYPE_ONE -> ViewHolderOne(LayoutInflater.from(context).inflate(R.layout.item_text_sample, parent)) } } override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { when (holder) { is ViewHolderOne -> { holder.itemView?.run { tv_message.text = "ViewHolder One" } } } } override fun getItemViewType(position: Int): Int { return when (position) { else -> TYPE_ONE } } }
ViewHolder по ܻೞب۾ abstract class BaseViewHolder<in ITEM : Any>( val
context: Context, @LayoutRes layoutRes: Int, parent: ViewGroup?) : RecyclerView.ViewHolder(LayoutInflater.from(context).inflate(layoutRes, parent, false)) { fun onBindViewHolder(item: Any?) { try { onViewCreated(item as? ITEM?) } catch (e: Exception) { itemView.visibility = View.GONE } } abstract fun onViewCreated(item: ITEM?) }
BaseRecyclerAdapterীࢲب ਃۧѱ abstract class BaseRecyclerAdapter(val context: Context?) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { (holder as? BaseViewHolder<*>)?.onBindViewHolder(getItem(position)) } // ࢤۚ }
MVP ܻ࠙о оמೠо? थש Ӗী ٮܲ ܻ࠙ — ViewHolder :
Viewਸ Ӓܻח ೡ݅ — View : Viewী ೠ interface — Model : Modelী ೠ interface -> Adapter : ୡӝച ߂ View/Model interface ࢚ࣘਸ ҳഅ -> ৻ࠗ Presenterীࢲ пп interface ഐ
ܻ࠙о оמೠо? interface ImageViewAdapterContract { interface View { val onItemTouchListener:
OnItemTouchListener? fun reload() } interface Model { fun addItem(item: RecentPhotoItem?) fun getItem(position: Int): RecentPhotoItem fun clear() } }
ܻ࠙о оמೠо? class ImageAdapter(private val context: Context) : RecyclerView.Adapter<BaseViewHolder<RecentPhotoItem>>(), ImageViewAdapterContract.View,
ImageViewAdapterContract.Model { val itemList: ArrayList<RecentPhotoItem> = ArrayList() override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int) = when (viewType) { VIEW_TYPE_ASYNC -> ImageAsyncViewHolder(context, parent, onItemTouchListener) } override fun onBindViewHolder(holder: BaseViewHolder<RecentPhotoItem>?, position: Int) { holder?.bindView(getItem(position), position) } override fun getItemViewType(position: Int) = getItem(position).viewType override fun addItem(item: RecentPhotoItem?) { item?.let { itemList.add(it) } } override fun getItem(position: Int) = itemList[position] override fun reload() { notifyDataSetChanged() } }
Ӓ۞ݶ ViewModel۽ ֈযо ࠁ
ViewModelਸ بੑ೧ࠅө? — ѱ ׳ۄח ࠗ࠙ হ݅ ViewModel۽ ҳࢿೞҊ र
— Adapterীࢲח onCreateViewHolder݅ ೞҊ र — BaseAdapter ݅ ੜ೧ࢲ ܻೞҊ र — Modelਸ ߹ب۽ ҙܻೠ -> Adapter ೡ ߹Ѣ হ
ViewModel ੌױ ٜ݅ interface BaseAdapterNavigator { fun getItemViewType(position: Int): Int
fun addItem(item: Any?, viewType: Int) fun clear() fun getItemCount(): Int }
ViewModel ੌױ ٜ݅ open class BaseAdapterViewModel(override val context: Context?) :
BaseAdapterNavigator { protected val itemList = mutableListOf<Pair<Any?, ViewHolderSealedData>>() override fun getItemViewType(position: Int): Int { val item = getPairItem(position) return when (item) { is ViewHolderInfo -> item.viewType else -> -1 } } override fun addItem(item: Any?, viewType: Int) { itemList.add(Pair(item, ViewHolderInfo(viewType))) } override fun clear() { itemList.clear() } override fun getItemCount() = itemList.size }
item ਬোೠ ࢎਊਸ ਤ೧ ViewType/ӝఋ ࠁܳ ਬোೞѱ о۰Ҋ, ইې sealed
class sealed class ViewHolderSealedData data class ViewHolderInfo( val viewType: Int) : ViewHolderSealedData()
Adapterীࢲ Model ܳ ܻ࠙ — Adapterীࢲ Model ܻ࠙ —
Adapterח ԇؘӝܳ ࢤࢿೞח ೡ ࠗ (onCreateViewHolder) — ViewHolderীࢲب BaseAdapterNavigatorਸ ా೧ࢲ Ӕ — ߡౡ ܼ द Navigator ܳ ా೧ Ӕ — ਃী ٮۄ Adapter ӝࠄ ViewModel ೧ࢲ ࢎਊ
Adapter ୡӝചח? private val adapter: BaseRecyclerAdapter by lazy { object
: BaseRecyclerAdapter(this, BaseAdapterViewModel(this)) { override fun onCreateViewHolder( parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder { // ࢤۚ } } }
؊ જ ߑध Adapter Ӕߨ? — Adapter ࢚ࣘ ҳഅਸ ୭ࣗച
दఃӝ ਤೣ — ViewModel ୡӝച݅ ೞৈ ࢎਊ оמ — ViewHolderীࢲח View ೡ݅ ೞب۾ ܻ -> ߈ࠂ ٬ਸ ӝ ਤೣ