All Projects → ironSource → Oneadapter

ironSource / Oneadapter

Licence: mit
A Viewholderless Adapter for RecyclerView, who supports builtin diffing, states (paging, empty...), events (clicking, swiping...), and more.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Oneadapter

Fastadapter
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
Stars: ✭ 3,512 (+994.08%)
Mutual labels:  adapter, swipe, android-ui, recyclerview-adapter
Tableview
TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
Stars: ✭ 2,928 (+812.15%)
Mutual labels:  adapter, android-ui, recyclerview-adapter
BaseToolsLibrary
Android通用适配器和常用的工具类
Stars: ✭ 24 (-92.52%)
Mutual labels:  adapter, recyclerview-adapter
MultiTypeAdapter
RecyclerView通用多类型适配器MultiTypeAdapter,以布局文件为单位更细粒度的条目复用。
Stars: ✭ 18 (-94.39%)
Mutual labels:  adapter, recyclerview-adapter
ArcPageIndicator
Android Page Indicator for ViewPager with original animations. It uses an ellipse to dispose indication spots, and can draw a hand, like in old elevators.
Stars: ✭ 73 (-77.26%)
Mutual labels:  animations, android-ui
Poweradapter
Adapter for RecyclerView(only 21KB).RecyclerView万能适配器(仅21KB)
Stars: ✭ 112 (-65.11%)
Mutual labels:  adapter, recyclerview-adapter
Kau
An extensive collection of Kotlin Android Utils
Stars: ✭ 182 (-43.3%)
Mutual labels:  adapter, swipe
PrimeAdapter
PrimeAdapter makes working with RecyclerView easier.
Stars: ✭ 54 (-83.18%)
Mutual labels:  adapter, recyclerview-adapter
Primer
Intro Animation like Google Primer
Stars: ✭ 230 (-28.35%)
Mutual labels:  animations, android-ui
recycler-adapter
RecyclerView-driven declarative UIs
Stars: ✭ 124 (-61.37%)
Mutual labels:  adapter, android-ui
RecyclerELE
Android Library for easy addition of Empty, Loading and Error views in a RecyclerView
Stars: ✭ 27 (-91.59%)
Mutual labels:  android-ui, recyclerview-adapter
Flagchatadapter
FlagChatAdapter is easy to implement enchanting recycler view adapter. Just extend your adapter with FlagChatAdapter, impliment some methods and voila! You have got the most beautiful looking chat on your phone. Zero boilerplate code, just put your variables in the right direction.
Stars: ✭ 39 (-87.85%)
Mutual labels:  adapter, recyclerview-adapter
Candyview
Implement any RecyclerView in just 1 Line. CandyView handles everything for you.
Stars: ✭ 15 (-95.33%)
Mutual labels:  adapter, recyclerview-adapter
Multiselectadapter
MultiSelectAdapter可以让你的Adapter快速实现多选和批量操作
Stars: ✭ 195 (-39.25%)
Mutual labels:  adapter, multiselect
Recyclerviewevent
RecyclerView onItemClick、onItemLongClick、drag、swipe、divider、reuse disorder RecyclerView 梳理:点击&长按事件、分割线、拖曳排序、滑动删除、优雅解决 EditText 和 CheckBox 复用错乱问题
Stars: ✭ 265 (-17.45%)
Mutual labels:  swipe, recyclerview-adapter
Modular2Recycler
Modular²Recycler is a RecyclerView.Adapter that is modular squared.
Stars: ✭ 72 (-77.57%)
Mutual labels:  adapter, recyclerview-adapter
Flutter swipe action cell
A flutter UI package provides ListView leading and trailing swipe action menu.
Stars: ✭ 65 (-79.75%)
Mutual labels:  animations, swipe
Konfetti
Celebrate more with this lightweight confetti particle system 🎊
Stars: ✭ 2,278 (+609.66%)
Mutual labels:  animations, android-ui
E-commerceCustomerFYP
Android E-commerce Platform. Allow customer to buy product, chat, feedback rating, make payment to retailer
Stars: ✭ 41 (-87.23%)
Mutual labels:  android-ui, recyclerview-adapter
Sequent
A simple continuous animation library for Android UI.
Stars: ✭ 263 (-18.07%)
Mutual labels:  animations, android-ui

Logo

OneAdapter

Download Android Arsenal Android Weekly CN

OneAdapter is made to simplify and enhance the use of the RecyclerView's Adapter while preventing common mistakes. With multiple modules and hooks, you don't have to think about writing an adapter anymore, and just focus on what matters.

For better understanding what drove me to write this library and what use cases it solves best, please refer to my Medium post: https://medium.com/@idanatsmon/adapting-your-recyclerview-the-2019-approach-e47edf2fc4f3

What's new:

Version 2.0.0 is out with a brand new Kotlin API!
Kotlin is now the first priority of this library and as such comes a full API change, every Module, Hook and State is now created using dedicated DSLs.
Check the example below or sample project for reference for Kotlin & Java use.

Features:

Include in your project

dependencies {
  implementation "com.ironsource.aura.oneadapter:oneadapter:${LATEST_VERSION}"
}

Note that library interfaces and API may change slightly while the library design matures.
Please see the changes in the CHANGELOG file before upgrading.

Preview

Example

You can try out the example project that includes basic and advanced usage in Kotlin.

Screenshots



Basic Usage

1. Implement Item Module

Item Modules are used for the creation and binding of all ViewHolders for you. In the onBind method, you will receive as a parameter the model associated with this view and a ViewBinder class that lets you find (and cache) the views defined in the associated layout file.

class MessageModule : ItemModule<MessageModel>() {
    init {
        config {
            layoutResource = R.layout.message_model
        }
        onBind { model, viewBinder, metadata ->
            val title = viewBinder.findViewById<TextView>(R.id.title)
            title.text = model.title
        }
        onUnbind { model, viewBinder, metadata ->
            // unbind logic like stop animation, release webview resources, etc.
        }
    }
}

2. Implement Diffable

The Adapter is calculating the difference between its current data and the modified data on a background thread and posting the result to the main thread. In order for this magic to work without writing tons of DiffUtil.Callback, your models need to implement one simple interface:

class MessageModel : Diffable {
    private val id: Long = 0L
    private val title: String? = null

    override val uniqueIdentifier: Long = id
    override fun areContentTheSame(other: Any): Boolean = other is MessageModel && title == other.title
}

3. Attach To OneAdapter & Use

val oneAdapter = OneAdapter(recyclerView) {
    itemModule += MessageModule()
} 
oneAdapter.setItems(...) 



Advanced Usage

Modules

Multiple Types

Have more than one view type? not a problem, just create another ItemModule and attach it to OneAdapter in the same way.

1. Implement Multiple Item Modules

class MessageModule : ItemModule<MessageModel> { ... }
class StoryModule : ItemModule<StoryModel> { ... }

2. Attach To OneAdapter

val oneAdapter = OneAdapter(recyclerView) {
    itemModule += MessageModule()
    itemModule += StoryModule()
    ...
}



Paging Module

Paging Module is used for creating and binding a specific ViewHolder at the end of the list when the Adapter reaches a load more state. The visible threshold configuration is used to indicate how many items before the end of the list the onLoadMore callback should be invoked.

1. Implement Paging Modules

class PagingModuleImpl : PagingModule() {
    init {
        config {
            layoutResource = R.layout.load_more // can be some spinner animation
            visibleThreshold = 3 // invoke onLoadMore 3 items before the end
        }
        onLoadMore { currentPage ->
            // place your load more logic here, like asking the ViewModel to load the next page of data.
        }
    }
}

2. Attach To OneAdapter

val oneAdapter = OneAdapter(recyclerView) {
    // itemModule += ...
    pagingModule = PagingModuleImpl()
}



Emptiness Module

Emptiness Module is used for creating and binding a specific ViewHolder when the Adapter has no data to render.

1. Implement Emptiness Modules

class EmptinessModuleImpl : EmptinessModule() {
    init {
    	config {
            layoutResource = R.layout.empty_state
        }
        onBind { viewBinder, metadata -> ... }
        onUnbind { viewBinder, metadata -> ... }
    }
}

2. Attach To OneAdapter

val oneAdapter = OneAdapter(recyclerView) {
    // itemModule += ...
    emptinessModule = EmptinessModuleImpl()
}



Selection Module

Selection Module is used for enabling single or multiple selection on Items.

1. Implement Selection Modules

class ItemSelectionModuleImpl : ItemSelectionModule() {
    init {
    	config {
            selectionType = SelectionType.Multiple // Or SelectionType.Single
        }
        onStartSelection {
            // place your general selection logic here, like changing the toolbar text to indicate the selected count.
        } 
        onUpdateSelection { selectedCount -> ... }
        onEndSelection { ... }
    }
}

2. Implement Selection State

class MessageModule : ItemModule<MessageModel>() {
    init {
        // config, onBind, etc...
        
        states += SelectionState<MessageModel>().apply {
            config {
                enabled = true // decide if the selection should be enabled for this model, true by default
                selectionTrigger = SelectionTrigger.LongClick // decide what trigger the selection, long or regular click
            }
            onSelected { model, selected ->
                // insert your selected logic here. 
                // right after this call you will receive an onBind call in order to reflect your changes on the relevant Item Module.
            }
        }
    }
}

3. Attach To OneAdapter

val oneAdapter = OneAdapter(recyclerView) {
    itemModule += MessageModule()
    itemSelectionModule = ItemSelectionModuleImpl()
}




Event Hooks

Item Modules can easily be enhanced with event hooks to get access to common events like clicking or swiping on an item.

Click Event Hook

Click Hook can be attached in order to recieve click events on an item.

1. Implement Click Event Hook

class MessageModule : ItemModule<MessageModel>() {
    init {
        // config, onBind, etc...
        
        eventHooks += ClickEventHook<MessageModel>().apply {
            onClick { model, viewBinder, metadata -> 
                // place your on click logic here. 
            }
        }
    }
}

2. Attach To OneAdapter

val oneAdapter = OneAdapter(recyclerView) {
    itemModule += MessageModule()
}



Swipe Event Hook

Swipe Hook can be attached in order to receive swiping (during and when completed) events on an item.

1. Implement Swipe Event Hook

class MessageModule : ItemModule<MessageModel>() {
    init {
        // config, onBind, etc...
        
        eventHooks += SwipeEventHook<MessageModel>().apply {
            config {
                swipeDirection = listOf(SwipeEventHook.SwipeDirection.Start, SwipeEventHook.SwipeDirection.End)
            }
            onSwipe { canvas, xAxisOffset, viewBinder ->
                // draw your swipe UI here.
                // like painting the canvas red with a delete icon.
            }
            onSwipeComplete { model, viewBinder, metadata ->
                // place your swipe logic here.
                // like removing an item after it was swiped right.
            }
        }
    }
}

2. Attach To OneAdapter

val oneAdapter = OneAdapter(recyclerView) {
    itemModule += MessageModule()
}




Others

First Bind Animation

The provided Animator will be animated on the first bind of the corresponding ItemModule's models.

class MessageModule : ItemModule<MessageModel>() {
    init {
        config {
            layoutResource = R.layout.message_model
            
            // can be implemented by inflating Animator Xml
            firstBindAnimation = AnimatorInflater.loadAnimator(this@FirstBindAnimationActivity, R.animator.item_animation_example)
			
            // or can be implemented by constructing ObjectAnimator
            firstBindAnimation = ObjectAnimator().apply {
                propertyName = "translationX"
                setFloatValues(-1080f, 0f)
                duration = 750
            }
        }
        onBind { model, viewBinder, metadata -> ... }
    }
}

View Binding

Built in support for Android View Binding (https://developer.android.com/topic/libraries/view-binding) Full example is provided in the example project.

class MessageModule : ItemModule<MessageModel>() {
    init {
        config {
            layoutResource = R.layout.message_model
        }
        onBind { model, viewBinder, _ ->
            viewBinder.bindings(MessageModelBinding::bind).run {
                title.text = model.title
                body.text = model.body
                Glide.with(viewBinder.rootView).load(model.avatarImageId).into(avatarImage)
            }
        }
    }
}

Data Binding

Built in support for Android Data Binding (https://developer.android.com/topic/libraries/data-binding) Full example is provided in the example project.

class MessageModule : ItemModule<ObservableMessageModel>() {
    init {
        config {
            layoutResource = R.layout.message_model
        }
        onBind { model, viewBinder, metadata ->
            viewBinder.dataBinding?.run {
                setVariable(BR.messageModel, model)
                lifecycleOwner = this@DataBindingActivity
                executePendingBindings()
            }
        }
    }
}



License

Copyright (c) 2019 Idan Atsmon

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].