Pro Yearly is on sale from $80 to $50! »

recyclerview-selection

 recyclerview-selection

at potatotips #50

3c4e24fd827c789cb67a9f759f057b06?s=128

Shinnosuke Kugimiya

April 19, 2018
Tweet

Transcript

  1. CONFIDENTIAL © DMM.com !LHNZTIJO QPUPUJQT 4VQQPSU-JCSBSZBMQIB SFDZDMFSWJFXTFMFDUJPO

  2. © DMM.com X w LHNZTIJOఝٶ ͗͘Έ΍  w "OESPJEΤϯδχΞ w

    %..DPNϥϘ$50ࣨॴଐ w ೥݄͔Β ࣗݾ঺հ
  3. © DMM.com X BHFOEB

  4. © DMM.com X w SFDZDMFSWJFXTFMFDUJPOͱ͸ʁ w ࢖͍ํ w લ४උ w

    4FMFDUJPO5SBDLFSΛ࡞Δ w બ୒ঢ়ଶΛ7JFXʹ൓ө͢Δ BHFOEB
  5. © DMM.com X SFDZDMFSWJFXTFMFDUJPO ͱ͸ʁ

  6. © DMM.com X TVQQPSUMJCSBSZBMQIB͔Β BMQIB͔Βಋೖ ΋ͪΖΜQSFWJFXͰ͢ ઌߦͯ͠ϦϦʔε͞Ε͍ͯΔBOESPJELUYͱಉ͡ ABOESPJEYAύοέʔδɻ ABOESPJEYA͸কདྷͷαϙʔτϥΠϒϥϦͰ࢖༻͞ΕΔ ύοέʔδͰ͢ɻ

    SFDZDMFSWJFXTFMFDUJPO͸ͦͷlকདྷͷαϙʔτϥΠϒϥ ϦzͷҰͭ
  7. © DMM.com X ͲΜͳػೳʁ

  8. © DMM.com X ࢖͍ํ

  9. © DMM.com X લ४උ data class Book( val id: Long,

    val title: String, val subTitle: String ) ͜ͷ#PPLͷϦετΛෳ਺બ୒Ͱ͖ΔΑ͏ʹ͠·͢
  10. © DMM.com X લ४උ 3FDZDMFS7JFXɺ7JFX)PMEFSɺ"EBQUFS͸Ұ୴௨ৗ௨Γ
 ͨͩɺTUBCMF*EΛ࢖͏Α͏ʹ͢Δ class BookAdapter( context: Context,

    private val bookList: List<Book> ) : RecyclerView.Adapter<BookViewHolder>() { init { setHasStableIds(true) } : override fun getItemId(position: Int): Long = bookList[position].id : }
  11. © DMM.com X લ४උ 3FDZDMFS7JFXɺ7JFX)PMEFSɺ"EBQUFS͸Ұ୴௨ৗ௨Γ
 ͨͩɺTUBCMF*EΛ࢖͏Α͏ʹ͢Δ class BookAdapter( context: Context,

    private val bookList: List<Book> ) : RecyclerView.Adapter<BookViewHolder>() { init { setHasStableIds(true) } : override fun getItemId(position: Int): Long = bookList[position].id : }
  12. © DMM.com X 4FMFDUJPO5SBDLFSΠϯελϯεΛ࡞Δ selectionTracker = SelectionTracker.Builder<Long>( "my-selection-id", binding.recyclerView, StableIdKeyProvider(binding.recyclerView),

    BookIdDetailsLookup(binding.recyclerView), StorageStrategy.createLongStorage()) .withOnItemActivatedListener { item, e -> Log.e("MainActivity", item.toString()) return@withOnItemActivatedListener true } .build()
  13. © DMM.com X 4FMFDUJPO5SBDLFSΠϯελϯεΛ࡞Δ selectionTracker = SelectionTracker.Builder<Long>( "my-selection-id", binding.recyclerView, StableIdKeyProvider(binding.recyclerView),

    BookIdDetailsLookup(binding.recyclerView), StorageStrategy.createLongStorage()) .withOnItemActivatedListener { item, e -> Log.e("MainActivity", item.toString()) return@withOnItemActivatedListener true } .build() ୈҰҾ਺ɻϢχʔΫͳจࣈྻΛɻ #VOEMFʹೖΕΔ,FZͱͯ͠࢖ΘΕ·͢ɻ
  14. © DMM.com X 4FMFDUJPO5SBDLFSΠϯελϯεΛ࡞Δ selectionTracker = SelectionTracker.Builder<Long>( "my-selection-id", binding.recyclerView, StableIdKeyProvider(binding.recyclerView),

    BookIdDetailsLookup(binding.recyclerView), StorageStrategy.createLongStorage()) .withOnItemActivatedListener { item, e -> Log.e("MainActivity", item.toString()) return@withOnItemActivatedListener true } .build() ୈೋҾ਺ɻ ֘౰ͷ3FDZDMFS7JFXΛࢦఆ͢Δɻ
  15. © DMM.com X 4FMFDUJPO5SBDLFSΠϯελϯεΛ࡞Δ selectionTracker = SelectionTracker.Builder<Long>( "my-selection-id", binding.recyclerView, StableIdKeyProvider(binding.recyclerView),

    BookIdDetailsLookup(binding.recyclerView), StorageStrategy.createLongStorage()) .withOnItemActivatedListener { item, e -> Log.e("MainActivity", item.toString()) return@withOnItemActivatedListener true } .build() ୈࡾҾ਺ɻબ୒தͷΞΠςϜͱબ୒தͷLFZͷରԠΛղܾ͢ Δ*E,FZ1SPWJEFSΛࢦఆ͢Δɻࠓճͩͱ͋ΔTUBCMF*E CPPLJE ʹ͍ͨͯ͠ͲΕ͕ର৅ͷ#PPL͔ͷؔ܎Λղܾ͢Δɻ
  16. © DMM.com X 4FMFDUJPO5SBDLFSΠϯελϯεΛ࡞Δ selectionTracker = SelectionTracker.Builder<Long>( "my-selection-id", binding.recyclerView, StableIdKeyProvider(binding.recyclerView),

    BookIdDetailsLookup(binding.recyclerView), StorageStrategy.createLongStorage()) .withOnItemActivatedListener { item, e -> Log.e("MainActivity", item.toString()) return@withOnItemActivatedListener true } .build() ୈ࢛Ҿ਺ɻ.PUJPO&WFOUΛ΋ͱʹࠓͲ͜ͷΞΠςϜΛબ୒ͯ͠ Δͷ͔Λղܾ͢ΔɻTUBCMF*E࢖༻࣌͸͚ͩࣗ͜͜࡞ɻ TUBCMF*Eඇ࢖༻࣌͸͚ͩ͜͜Ͱͳ͘*E,FZ1SPWJEFS΋ࣗ࡞͢Δɻ
  17. © DMM.com X 4FMFDUJPO5SBDLFSΠϯελϯεΛ࡞Δ selectionTracker = SelectionTracker.Builder<Long>( "my-selection-id", binding.recyclerView, StableIdKeyProvider(binding.recyclerView),

    BookIdDetailsLookup(binding.recyclerView), StorageStrategy.createLongStorage()) .withOnItemActivatedListener { item, e -> Log.e("MainActivity", item.toString()) return@withOnItemActivatedListener true } .build() ୈޒҾ਺ɻ TBWFE4UBUFʹԿΛอ࣋͢Δͷ͔Λղܾ͢Δਓɻ *UFNΛ4FMFDUJPO΍#VOEMFʹม׵͢ΔϝιουΛ࣋ͭɻ
  18. © DMM.com X 4FMFDUJPO5SBDLFSΠϯελϯεΛ࡞Δ selectionTracker = SelectionTracker.Builder<Long>( "my-selection-id", binding.recyclerView, StableIdKeyProvider(binding.recyclerView),

    BookIdDetailsLookup(binding.recyclerView), StorageStrategy.createLongStorage()) .withOnItemActivatedListener { item, e -> Log.e("MainActivity", item.toString()) return@withOnItemActivatedListener true } .build() ඞཁͩͬͨΒϦεφʔొ࿥ɻ
  19. © DMM.com X #PPL*E%FUBJMT-PPLVQΛ࡞Δ class BookIdDetailsLookup( private val recyclerView: RecyclerView

    ) : ItemDetailsLookup<Long>() { override fun getItemDetails(e: MotionEvent): ItemDetails<Long>? = recyclerView.findChildViewUnder( e.x, e.y )?.let { (recyclerView.getChildViewHolder(it) as? BookViewHolder)?.getItemIdDetails() } } ୈࡾҾ਺ͩͬͨ#PPL*E%FUBJMT-PPLVQͷ࣮૷ɻ λονΠϕϯτͷ࠲ඪ͔Βɺ֘౰ͷΞΠςϜΛฦ͚ͩ͢ ͷγϯϓϧͳ࣮૷ɻ
  20. © DMM.com X ͜͜·Ͱ࣮૷ͨ͠΋ͷΛݟͯΈΔ

  21. © DMM.com X 7JFXʹબ୒ঢ়ଶ͔Ͳ͏͔Λ൓ө͢Δ class BookAdapter( context: Context, private val

    bookList: List<Book> ) : RecyclerView.Adapter<BookViewHolder>() { ɿ override fun onBindViewHolder( holder: BookViewHolder, position: Int ) { val item = bookList[position] holder.bind( selectionChecker?.isSelected(item.id) ?: false, position, bookList[position] ) } } TFMFDUPSΛηοτ͓͍ͯͯ͠4FMFDUJPO5SBDLFSJT4FMFDUFEͷ݁ՌΛ 7JFXTFU"DUJWBUFEͰηοτ͢Δɻ
  22. © DMM.com X 7JFXʹબ୒ঢ়ଶ͔Ͳ͏͔Λ൓ө͢Δ class BookAdapter( context: Context, private val

    bookList: List<Book> ) : RecyclerView.Adapter<BookViewHolder>() { ɿ override fun onBindViewHolder( holder: BookViewHolder, position: Int ) { val item = bookList[position] holder.bind( selectionChecker?.isSelected(item.id) ?: false, position, bookList[position] ) } } TFMFDUPSΛηοτ͓͍ͯͯ͠4FMFDUJPO5SBDLFSJT4FMFDUFEͷ݁ՌΛ 7JFXTFU"DUJWBUFEͰηοτ͢Δɻ
  23. © DMM.com X ׬੒ʂ

  24. © DMM.com X ऴΘΓʹ

  25. © DMM.com X ฐࣾϒϩάͰɺ΋͏গ͠ৄ͘͠঺հͯ͠·͢ IUUQTJOTJEFENNDPNFOUSZSFDZDMFSWJFXTFMFDUJPO

  26. © DMM.com X αϯϓϧஔ͍ͯ·͢ɻ IUUQTHJUIVCDPNLHNZTIJOSFDZDMFSWJFXTFMFDUJPOTBNQMF ANBTUFSATUBCMFJEඇ࢖༻ϒϥϯν AVTF@TUBCMF@JEATUBCMFJE࢖༻ϒϥϯν

  27. © DMM.com X ࠓि೔༵Կͯ͠·͔͢ʁ๩͍͠Ͱ͔͢ʁٕज़ॻయདྷͯ΋Β͍͍ͬͯͰ͔͢ʁ ؔ܎ͳ͍಺༰Ͱ͝ΊΜͳ͍͞ʂ ,6(*#",0ͱ͍͏αʔΫϧ໊Ͱग़ళ͠·͢ʂ͓࣌ؒ͋Ε͹ੋඇʂ IUUQTNPUJEBKBQBOIBUFOBCMPHDPNFOUSZ

  28. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ