Git Product home page Git Product logo

antonio's Introduction

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.6-alpha'
    def antonioAnnotationVersion = '0.0.4-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-compiler:$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.6-alpha'
    def antonioAnnotationVersion = '0.0.4-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-compiler:$antonioAnnotationVersion"

    //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.

antonio's People

Contributors

lakelab avatar vagabond95 avatar seoft avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.