FastAdapter는 RecyclerViews의 어댑터 작성을 단순화하기 위해 여기에 있습니다. 더 이상 어댑터에 대해 걱정하지 마십시오. 보기/항목의 모습에 대한 논리를 작성하면 완료됩니다. 빠르게 타격을 입히고 작성해야 할 코드를 최소화하며 확장하기 쉽습니다.
포함 된 사항 • 설정 • 마이그레이션 가이드? • • 샘플 앱에서 사용합니다
라이브러리는 핵심, 커먼즈 및 확장으로 나뉩니다. 핵심 함수는 다음 종속성에 포함됩니다.
implementation " com.mikepenz:fastadapter: ${ latestFastAdapterRelease } "
implementation " androidx.appcompat:appcompat: ${ androidX } "
implementation " androidx.recyclerview:recyclerview: ${ androidX } "확장 가능한 지원이 포함되어 있으며이를 통해 추가 할 수 있습니다.
implementation " com.mikepenz:fastadapter-extensions-expandable: ${ latestFastAdapterRelease } "많은 도우미 클래스가 다음 종속성에 포함됩니다.
implementation " com.mikepenz:fastadapter-extensions-binding: ${ latestFastAdapterRelease } " // view binding helpers
implementation " com.mikepenz:fastadapter-extensions-diff: ${ latestFastAdapterRelease } " // diff util helpers
implementation " com.mikepenz:fastadapter-extensions-drag: ${ latestFastAdapterRelease } " // drag support
implementation " com.mikepenz:fastadapter-extensions-paged: ${ latestFastAdapterRelease } " // paging support
implementation " com.mikepenz:fastadapter-extensions-scroll: ${ latestFastAdapterRelease } " // scroll helpers
implementation " com.mikepenz:fastadapter-extensions-swipe: ${ latestFastAdapterRelease } " // swipe support
implementation " com.mikepenz:fastadapter-extensions-ui: ${ latestFastAdapterRelease } " // pre-defined ui components
implementation " com.mikepenz:fastadapter-extensions-utils: ${ latestFastAdapterRelease } " // needs the `expandable`, `drag` and `scroll` extension.
// required for the ui components and the utils
implementation " com.google.android.material:material: ${ androidX } " 아래 그림과 같이 AbstractItem 확장하는 클래스 만 작성하십시오. 메소드를 구현하면 항목이 준비되었습니다.
open class SimpleItem : AbstractItem < SimpleItem . ViewHolder >() {
var name : String? = null
var description : String? = null
/* * defines the type defining this item. must be unique. preferably an id */
override val type : Int
get() = R .id.fastadapter_sample_item_id
/* * defines the layout which will be used for this item in the list */
override val layoutRes : Int
get() = R .layout.sample_item
override fun getViewHolder ( v : View ): ViewHolder {
return ViewHolder (v)
}
class ViewHolder ( view : View ) : FastAdapter.ViewHolder<SimpleItem>(view) {
var name : TextView = view.findViewById( R .id.material_drawer_name)
var description : TextView = view.findViewById( R .id.material_drawer_description)
override fun bindView ( item : SimpleItem , payloads : List < Any >) {
name.text = item.name
description.text = item.name
}
override fun unbindView ( item : SimpleItem ) {
name.text = null
description.text = null
}
}
}
class BindingIconItem : AbstractBindingItem < IconItemBinding >() {
var name : String? = null
override val type : Int
get() = R .id.fastadapter_icon_item_id
override fun bindView ( binding : IconItemBinding , payloads : List < Any >) {
binding.name.text = name
}
override fun createBinding ( inflater : LayoutInflater , parent : ViewGroup ? ): IconItemBinding {
return IconItemBinding .inflate(inflater, parent, false )
}
} 이를 위해 응용 프로그램에서 binding 연장 종속성을 사용하십시오.
// create the ItemAdapter holding your Items
val itemAdapter = ItemAdapter < SimpleItem >()
// create the managing FastAdapter, by passing in the itemAdapter
val fastAdapter = FastAdapter . with (itemAdapter)
// set our adapters to the RecyclerView
recyclerView.setAdapter(fastAdapter)
// set the items to your ItemAdapter
itemAdapter.add( ITEMS ) 기본적으로 FastAdapter 기본 기능 만 제공하며,이 기능은 Item 및 Model 로서 항목의 추상화와 함께 제공됩니다. 요소를 추가/제거/수정하는 일반적인 기능. 선택 또는 확장형을 활성화하려면 제공된 확장을 활성화해야합니다.
// Gets (or creates and attaches if not yet existing) the extension from the given `FastAdapter`
val selectExtension = fastAdapter.getSelectExtension()
// configure as needed
selectExtension.isSelectable = true
selectExtension.multiSelect = true
selectExtension.selectOnLongClick = false
// see the API of this class for more options. 이를 위해서는
fastadapter-extensions-expandable확장이 필요합니다.
// Gets (or creates and attaches if not yet existing) the extension.
val expandableExtension = fastAdapter.getExpandableExtension()
// configure as needed
expandableExtension.isOnlyOneExpandedItem = true 자세한 내용은 ExpandableItems (고급 사용) 섹션으로 스크롤합니다.
fastAdapter.onClickListener = { view, adapter, item, position ->
// Handle click here
false
} // just add an `EventHook` to your `FastAdapter` by implementing either a `ClickEventHook`, `LongClickEventHook`, `TouchEventHook`, `CustomEventHook`
fastAdapter.addEventHook( object : ClickEventHook < SimpleImageItem >() {
override fun onBind ( viewHolder : RecyclerView . ViewHolder ): View ? {
// return the views on which you want to bind this event
return if (viewHolder is SimpleImageItem . ViewHolder ) {
viewHolder.viewWhichReactsOnClick
} else {
null
}
}
override fun onClick ( v : View , position : Int , fastAdapter : FastAdapter < SimpleImageItem >, item : SimpleImageItem ) {
// react on the click event
}
}) // Call this in onQueryTextSubmit() & onQueryTextChange() when using SearchView
itemAdapter.filter( " yourSearchTerm " )
itemAdapter.itemFilter.filterPredicate = { item : SimpleItem , constraint : CharSequence? ->
item.name?.text.toString().contains(constraint.toString(), ignoreCase = true )
} filter() 품목을 유지하려면 ()를 반환하고 항목을 제거하려면 false를 반환해야합니다.
이를 위해서는
fastadapter-extensions-drag확장이 필요합니다.
먼저 ItemTouchHelper RecyclerView에 첨부하십시오.
val dragCallback = SimpleDragCallback ()
val touchHelper = ItemTouchHelper (dragCallback)
touchHelper.attachToRecyclerView(recyclerView) 활동에서 ItemTouchCallback 인터페이스를 구현하고 itemTouchOnMove() 메소드를 무시하십시오.
override fun itemTouchOnMove ( oldPosition : Int , newPosition : Int ): Boolean {
DragDropUtil .onMove(fastItemAdapter.itemAdapter, oldPosition, newPosition) // change position
return true
}어댑터 초기화로 시작하십시오.
// Header is a model class for your header
val headerAdapter = ItemAdapter < Header >()Model FastAdapter 초기화 :
val itemAdapter = GenericItemAdapter ()마지막으로 어댑터를 설정하십시오.
val fastAdapter : GenericFastAdapter = FastAdapter . with (headerAdapter, itemAdapter) // the order defines in which order the items will show up
// alternative the super type of both item adapters can be used. e.g.:
recyclerView.setAdapter(fastAdapter) 바르 테라 디프터를 만듭니다. 목록 끝에 로딩 진행 바를 표시하려면이 작업이 필요합니다. ( FastAdapter.with(..) 에 전달하는 것을 잊지 마십시오.
val footerAdapter = ItemAdapter < ProgressItem >()ProgressItem은 FastAdapter의 확장에 의해 제공됩니다.
recyclerView.addOnScrollListener( object : EndlessRecyclerOnScrollListener (footerAdapter) {
override fun onLoadMore ( currentPage : Int ) {
footerAdapter.clear()
footerAdapter.add( ProgressItem ())
// Load your items here and add it to FastAdapter
itemAdapter.add( NEWITEMS )
}
})전체 튜토리얼 및 다중 선택 및 택시와 같은 더 많은 기능은 샘플 앱을 확인하십시오.
FastAdapter 사용하는 데 더 이상 알려진 요구 사항이 없습니다. FastAdapter 확장 가능한 품목을 지원합니다. 의존성을 추가 한 후 : Expandable 확장을 통해 다음을 설정하십시오.
val expandableExtension = fastAdapter.getExpandableExtension() 확장 가능한 항목은 IExpandable 인터페이스와 하위 항목을 ISubItem 인터페이스로 구현해야합니다. 이것은 더 나은 지원을 허용합니다. 샘플 앱은 이들의 샘플 구현을 제공합니다. (샘플에있는 사람은 다른 부모 / 서브 하위와 함께 사용할 수있는 모델이 유지됩니다)
SubItems 과 해당 상태가 어떻게 처리되는지에 따라 identifier 기반 StateManagement 사용하는 것이 좋습니다. FastAdapter 설정에 withPositionBasedStateManagement(false) 를 추가하십시오.
간단한 항목은 AbstractExpandableItem 에서 확장하고 ViewHolder 유형으로 제공하면됩니다.
open class SimpleSubExpandableItem : AbstractExpandableItem < SimpleSubExpandableItem . ViewHolder >() {
/* *
* BASIC ITEM IMPLEMENTATION
*/
} // 자세한 내용은 샘플 응용 프로그램의 SimpleSubExpandableItem.kt 를 참조하십시오.
Mike Penz :
마이크 펜츠
Fabian Terhorst
이 무료 오픈 소스 소프트웨어는 또한 많은 시간의 열심히 일하는 자원 봉사자 그룹에 의해 가능해졌습니다. 자세한 내용은 Contributors.md 파일을 참조하십시오.
이 라이브러리에 많은 개선 사항을 추가 한 매우 적극적인 기고자들에게 특별한 감사를드립니다.
Copyright 2021 Mike Penz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.