Android library for the adapter view (RecyclerView, ViewPager, ViewPager2)

Overview

Antonio

Android library for the adapter view (RecyclerView, ViewPager, ViewPager2)

  • Free from implementation of the adapter's boilerplate code !
  • Reuse view dependencies and Isolate view logic!
  • Manage the recycler view state on your view model!
  • Implement nested recycler view or pager efficiently!
  • You don't need to learn anything for new theories if you already know about adapter views (RecyclerView, ViewPager, ViewPager2)!
                 _              _       
     /\         | |            (_)      
    /  \   _ __ | |_ ___  _ __  _  ___  
   / /\ \ | '_ \| __/ _ \| '_ \| |/ _ \ 
  / ____ \| | | | || (_) | | | | | (_) |
 /_/    \_\_| |_|\__\___/|_| |_|_|\___/ 

Install

Without data binding

dependencies {
    def antonioVersion = '1.0.0-alpha'
    def antonioAnnotationVersion = '0.0.1-alpha'
  
    implementation "io.github.naverz:antonio:$antonioVersion"

    implementation "io.github.naverz:antonio-annotation:$antonioAnnotationVersion"

    //For java
    annotationProcessor "io.github.naverz:antonio-compiler:$antonioAnnotationVersion"

    //For kotlin
    kapt "io.github.naverz:antonio-annotation:$antonioAnnotationVersion"

    //For paging2
    implementation "io.github.naverz:antonio-paging2:$antonioVersion"

    //For paging3
    implementation "io.github.naverz:antonio-paging3:$antonioVersion"
}

With data binding

dependencies {
    def antonioVersion = '1.0.0-alpha'
    def antonioAnnotationVersion = '0.0.1-alpha'
  
    implementation "io.github.naverz:antonio-databinding:$antonioVersion"

    implementation "io.github.naverz:antonio-annotation:$antonioAnnotationVersion"

    //For java
    annotationProcessor "io.github.naverz:antonio-compiler:$antonioAnnotationVersion"

    //For kotlin
    kapt "io.github.naverz:antonio-annotation:$antonioAnnotationVersion"

    //For paging2
    implementation "io.github.naverz:antonio-databinding-paging2:$antonioVersion"

    //For paging3
    implementation "io.github.naverz:antonio-databinding-paging3:$antonioVersion'
}

Basic Usage

There are four steps for RecyclerView (ViewPager, ViewPager2 also supported)

  1. Implement AntonioModel to bind model on your view holder.

data class ContentSmallModel(
  val id: String,
  @DrawableRes val iconRes: Int,
  val price: Int,
  val onClick: (id: String) -> Unit,
  val onLongClick: (id: String) -> Boolean,
  val selectedIds: LiveData<Set<String>>
):AntonioModel
  1. Implement TypedViewHolder. (You can skip this step with Antonio data binding)
class SmallContentViewHolder(parent: ViewGroup) :
  TypedViewHolder<ContentSmallModel>(
      itemView = LayoutInflater.from(parent.context)
          .inflate(R.layout.view_holder_content_small, parent, false)
  ) {
  init {
      // onCreateView process
  }

  override fun onBindViewHolder(data: ContentSmallModel, position: Int, payloads: List<Any>?) {
      super.onBindViewHolder(data, position, payloads)
      // onBindViewHolder process
  }

  override fun onViewAttachedToWindow(viewHolder: RecyclerView.ViewHolder) {
      super.onViewAttachedToWindow(viewHolder)
  }

  override fun onViewDetachedFromWindow(viewHolder: RecyclerView.ViewHolder) {
      super.onViewDetachedFromWindow(viewHolder)
  }

  override fun onViewRecycled() {
      super.onViewRecycled()
  }
}
  1. Link AntonioModel and TypedViewHolder with DependencyBuilder on the global container. (You can skip this step with Antonio Annotation)
  private fun linkAntonio() {
      AntonioSettings.viewHolderContainer.add(
          ContentSmallModel::class.java,
          ViewHolderBuilder { parent ->
              return@ViewHolderBuilder SmallContentViewHolder(parent)
          })
  }
  1. Declare AntonioAdapter (or AntonioListAdapter) and Set adapter with your data to RecyclerView.
 private fun initAdapter(){
     // You also can specify the type of Antonio model for the adapter, if you don't need various view types.
     // e.g., AntonioAdapter
   
    ()
   
      binding.recyclerView.adapter =
          AntonioAdapter<AntonioModel>().apply { currentList = viewModel.antonioModels }
      viewModel.onDataSetChanged.observe(this) {
          binding.recyclerView.adapter?.notifyDataSetChanged()
      }
 }

With Antonio Annotation

You can skip linking AntonioModel and View dependency with antonio-annotations

How to use

Declare MappedWithViewDependency annotation on your AntonioModel class

@MappedWithViewDependency(viewClass = SmallContentViewHolder::class)
data class ContentSmallModel(
    val id: String,
    @DrawableRes val iconRes: Int,
    val price: Int,
    val onClick: (id: String) -> Unit,
    val onLongClick: (id: String) -> Boolean,
    val selectedIds: LiveData<Set<String>>
) : AntonioModel 

Write AntonioAnnotation.init on the place where the app is initialized. (e.g., Application.onCreate)

AntonioAnnotation.init()

Preconditions for the annotation

  • Only TypedViewHolder, PagerViewDependency, AntonioFragment are supported.
      @MappedWithViewDependency(
          // It can use the class that is implemented by one of the three classes above only.
          viewClass = SmallContentViewHolder::class)
    
  • ViewHolder's constructor must have only one viewGroup parameter.
    • e.g.,
      class SmallContentViewHolder(
          // Require view group only for the constructor's parameter.
          parent: ViewGroup
      ) :
          TypedViewHolder<ContentSmallModel>(
              itemView = LayoutInflater.from(parent.context)
                  .inflate(R.layout.view_holder_content_small, parent, false)
          ) {
      }
  • PagerViewDependency constructor, Fragment constructor must not have any parameters.
  • If you need additional parameters for the view dependency constructor, You can link manually like Basic Usage, Step 3

With Data Binding

We strongly recommend using Antonio with DataBinding.

You don't need to implement ViewHolder class with antonio-databinding.
Just Implement the layout xml file, then Antonio will bind the model automatically at onBindViewHolder point.

How to use

Implement AntonioBindingModel to bind model on your view holder xml.

data class ContentSmallModel(
    val id: String,
    @DrawableRes val iconRes: Int,
    val price: Int,
    val onClick: (id: String) -> Unit,
    val onLongClick: (id: String) -> Boolean,
    val selectedIds: LiveData<Set<String>>
) : AntonioBindingModel {
    // Layout id to be inflated
    override fun layoutId(): Int = R.layout.view_holder_content_small
    // Variable id in XML to be bind every time when the view is attached
    // (e.g., onBindViewHolder in ViewHolder, onViewCreated in Fragment).
    override fun bindingVariableId(): Int = BR.model
}

view_holder_content_small.xml

">
xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    >
    <data>
        <variable
            name="model"
            type="io.github.naverz.antonio.sample.ContentSmallModel"
        />
    data>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:onClick="@{()->model.onClick.invoke(model.id)}"
        android:onLongClick="@{(view)->model.onLongClick.invoke(model.id)}"
        android:orientation="vertical"
        android:padding="5dp"
        >
        
    LinearLayout>
layout>

After writing the code above, Just use ContentSmallModel to AntonioAdapter.
(It can be used with another AntonioModel, which you want to implement view holder class.)

LifecycleOwner

LifecycleOwner, which is nearest from the view, will be automatically injected on All of XML inflated from AutoBindingModel in order to use LiveData for the one or two-way binding.

Plug-in

  • ViewPager, ViewPager2
  • Paging 2,3
  • RecyclerView state

Sample

The sample module is available!

License

Antonio
Copyright (c) 2021-present NAVER Z Corp.

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.
You might also like...
Epoxy is an Android library for building complex screens in a RecyclerView

Epoxy Epoxy is an Android library for building complex screens in a RecyclerView. Models are automatically generated from custom views or databinding

Renderers is an Android library created to avoid all the boilerplate needed to use a RecyclerView/ListView with adapters.
Renderers is an Android library created to avoid all the boilerplate needed to use a RecyclerView/ListView with adapters.

Renderers Renderers is an Android library created to avoid all the RecyclerView/Adapter boilerplate needed to create a list/grid of data in your app a

Android library to auto-play/pause videos from url in recyclerview.
Android library to auto-play/pause videos from url in recyclerview.

AutoplayVideos Show some ❤️ and star the repo to support the project This library is created with the purpose to implement recyclerview with videos ea

:page_with_curl: [Android Library] Giving powers to RecyclerView
:page_with_curl: [Android Library] Giving powers to RecyclerView

Android library that provides most common functions around recycler-view like Swipe to dismiss, Drag and Drop, Divider in the ui, events for when item

Generate data-view-binding adapters of android recycler view.

Items 这个库可以为 Android 的 RecyclerView 生成基于 Data-View-Binding 的 Adapter。 对比其他一些类似的开源库,它有以下的一些优势: 更好的拓展性。这个库不需要你继承特定的 Adapter 或 ViewHolder 类,你可以继承任何第三方提供的

The powerfull Diff Util in Android Recycler View

DiffUtil The powerfull Diff Util in Android Recycler View What is RecyclerView ? RecyclerView is flexible and efficient version of ListView. It is an

Vector map library and writer - running on Android and Desktop.
Vector map library and writer - running on Android and Desktop.

Mapsforge See the integration guide and changelog. And read through how to contribute guidelines. If you have any questions or problems, don't hesitat

[] Easy Adapters library for Android

Deprecated Due to the growing use of the RecyclerView and the RecyclerView.Adapter provided adapter class, Easy-Adapter is now deprecated. Whilst the

This library provides GridAdapters(ListGridAdapter & CursorGridAdapter) which enable you to bind your data in grid card fashion within android.widget.ListView, Also provides many other features related to GridListView.
This library provides GridAdapters(ListGridAdapter & CursorGridAdapter) which enable you to bind your data in grid card fashion within android.widget.ListView, Also provides many other features related to GridListView.

GridListViewAdapters This libarary enables you to implement GridView like card layout within ListView with added capabilites like Paginations, Additio

Comments
  • 샘플앱에서 ViewPagerWithTabLayout 기능 관련 문의 있습니다.,

    샘플앱에서 ViewPagerWithTabLayout 기능 관련 문의 있습니다.,

    일단 너무 괜찮은 라이브러리 제공에 감사합니다.

    현재 ViewPager2 를 사용해서 개발 중이고 Tablayout 과 같이 사용하려고 합니다.

    샘플앱에서 궁금한게 있습니다.

    @MappedWithViewDependency(viewClass = ViewHolderPagerWithTabLayout::class) class ViewPagerWithTabLayout(val viewPagerState: ViewPagerState) : AntonioModel

    샘플 앱에서 보면 위와같이 MappedWithViewDependency 으로 viewHolder 의 의존성을 주는거 같은데 라이브러리 배포된 것에서는 MappedWithViewDependency를 찾아보기 어렵더라구요.

    샘플에서 처럼 ViewHolderPagerWithTabLayout 처럼 AntonioViewHolder를 상속받아 사용하고 싶은데 라이브러리 사용해서는 어떻게 적용할 수 있을까요 ?

    help wanted 
    opened by Gurumigun 2
  • add FlexboxLayoutManager type recyclerview to sample

    add FlexboxLayoutManager type recyclerview to sample

    add FlexboxLayoutManager type recyclerview to sample

    • Add flexbox to gradle dependency
    • Add model, model generator and viewholder for flexbox sample

    Results are here image

    good first issue 
    opened by seoft 0
Owner
NAVER Z
NAVER Z
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.

⚠️ Archived: this repository is no longer going to be maintained. SectionedRecyclerViewAdapter An Adapter that allows a RecyclerView to be split into

Gustavo Pagani 1.7k Dec 21, 2022
Rx based RecyclerView Adapter

RxRecyclerAdapter Rx based generic RecyclerView Adapter Library. How to use it? Example! Enable Databinding by adding these lines to your build.gradle

Ahmed Rizwan 193 Jun 18, 2022
This Repository simplifies working with RecyclerView Adapter

AutoAdapter This Repository simplifies working with RecyclerView Adapter Gradle: Add it in your root build.gradle at the end of repositories: allproj

George Dzotsenidze 151 Aug 15, 2021
Generic RecyclerView adapter

Generic RecyclerView Adapter. Lightweight library which simplifies creating RecyclerView adapters and illuminates writing boilerplate code. Creating a

Leonid Ustenko 77 Dec 24, 2022
Small, smart and generic adapter for recycler view with easy and advanced data to ViewHolder binding.

smart-recycler-adapter Never code any boilerplate RecyclerAdapter again! This library will make it easy and painless to map your data item with a targ

Manne Öhlund 405 Dec 30, 2022
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

FastAdapter The FastAdapter is here to simplify creating adapters for RecyclerViews. Don't worry about the adapter anymore. Just write the logic for h

Mike Penz 3.7k Jan 8, 2023
Android - A ListView adapter with support for multiple choice modal selection

MultiChoiceAdapter MultiChoiceAdapter is an implementation of ListAdapter which adds support for modal multiple choice selection as in the native Gmai

Manuel Peinado Gallego 855 Nov 11, 2022
Adapter Kit is a set of useful adapters for Android.

Adapter Kit Adapter Kit is a set of useful adapters for Android. The kit currently includes, Instant Adapter Instant Cursor Adapter Simple Section Ada

Ragunath Jawahar 368 Nov 25, 2022
Simplify Adapter creation for your Android ListViews.

FunDapter takes the pain and hassle out of creating a new Adapter class for each ListView you have in your Android app. It is a new approach to custom

Ami Goldenberg 287 Dec 22, 2022
A slim & clean & typeable Adapter without# VIEWHOLDER

PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED First At A Glance :) Intro A slim & clean & typeable Adapter without# VIEWHOLDER Features No V

lin 940 Dec 30, 2022