FASTADAPTERは、リサイクルサービス用のアダプターの作成を簡素化するためにここにあります。もうアダプターについて心配しないでください。あなたのビュー/アイテムがどのように見えるかについてのロジックを書くだけで、あなたは完了です。それは速く燃えていて、記述する必要があるコードを最小限に抑え、簡単に拡張できます。
含まれているもの•セットアップ•移行ガイド? •使用する•サンプルアプリ
ライブラリは、コア、コモンズ、拡張機能に分割されています。コア関数は、次の依存関係に含まれています。
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 (Advanced Usageの下)セクションまでスクロールします。
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()アイテムが保持される場合はtrueを返し、アイテムを削除するには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 >()モデル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)FooterAdapterを作成します。これは、リストの最後にロードProgressBarを表示するために必要です。 ( 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で使用できるようにするモデルに保たれています)
SubItemsとその状態の処理方法の時点で、 identifierベースのStateManagementを使用することを強くお勧めします。 FastAdapterセットアップにwithPositionBasedStateManagement(false)を追加してください。
単純なアイテムは、 AbstractExpandableItemから拡張し、 ViewHolderタイプとして提供するだけです。
open class SimpleSubExpandableItem : AbstractExpandableItem < SimpleSubExpandableItem . ViewHolder >() {
/* *
* BASIC ITEM IMPLEMENTATION
*/
} //詳細については、サンプルアプリケーションのSimpleSubExpandableItem.ktを参照してください。
マイク・ペンツ:
マイク・ペンツ
ファビアン・テルホースト
この無料のオープンソースソフトウェアは、何時間ものハードワークを入れたボランティアのグループによっても可能になりました。詳細については、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.