Antonio Save

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

Project README

Antonio

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

  • Free from implementation of the adapter's boilerplate code!
  • Free from implementation of the view holder with data-binding (Two-way binding OK)!
  • ViewPager, ViewPager2, Paging2, Paging3 supported!
  • Manage the recycler view state on your view model!
  • There is no things to learn, if you already know about adapter views (RecyclerView, ViewPager, ViewPager2)!

Install

Without data binding

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

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

    //For paging3
    implementation "io.github.naverz:antonio-paging3:$antonioVersion"
  
    // You can implement additional dependencies as bellow, if you want to use AntonioAnnotation.
    def antonioAnnotationVersion = '0.0.7-alpha'
    implementation "io.github.naverz:antonio-annotation:$antonioAnnotationVersion"
    //For java (You must select only one of kapt, ksp and annotationProcessor)
    annotationProcessor "io.github.naverz:antonio-compiler:$antonioAnnotationVersion"
    //For kotlin kapt (You must select only one of kapt, ksp and annotationProcessor)
    kapt "io.github.naverz:antonio-compiler:$antonioAnnotationVersion"
    //For kotlin ksp (You must select only one of kapt, ksp and annotationProcessor)
    ksp "io.github.naverz:antonio-compiler:$antonioAnnotationVersion"
}

With data binding

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

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

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

Basic Usage

  • Implement AntonioBindingModel to bind model on your view holder layout 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 on bind view holder
    // (e.g., onBindViewHolder in ViewHolder, onViewCreated in Fragment).
    override fun bindingVariableId(): Int = BR.model
}
  • Create your view holder layout xml with the AntonioBindingModel you implemented. view_holder_content_small.xml
<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <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>
  • 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<ContentSmallModel>()
        binding.recyclerView.adapter =
            AntonioAdapter<AntonioModel>().apply { currentList = viewModel.antonioModels }
        // Don't forget to set the layout manager to your recycler view :)
        binding.recyclerView.layoutManager = GridLayoutManager(context,4)    
        viewModel.onDataSetChanged.observe(this) {
            binding.recyclerView.adapter?.notifyDataSetChanged()
        }
   }
  

LifecycleOwner will be injected automatically!

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

Awesome wiki!

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.
Open Source Agenda is not affiliated with "Antonio" Project. README Source: naverz/Antonio
Stars
120
Open Issues
0
Last Commit
5 months ago
Repository
License

Open Source Agenda Badge

Open Source Agenda Rating