Deepthought-Recycler

Data Binding Library for Android RecyclerView

License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

rocks.teagantotally
ArtifactId

ArtifactId

deepthoughtrecycler
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

aar
Description

Description

Deepthought-Recycler
Data Binding Library for Android RecyclerView
Project URL

Project URL

https://github.com/Teagan42/Deepthought-Recycler
Source Code Management

Source Code Management

https://github.com/Teagan42/Deepthought-Recycler.git

Download deepthoughtrecycler

How to add to project

<!-- https://jarcasting.com/artifacts/rocks.teagantotally/deepthoughtrecycler/ -->
<dependency>
    <groupId>rocks.teagantotally</groupId>
    <artifactId>deepthoughtrecycler</artifactId>
    <version>1.0.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/rocks.teagantotally/deepthoughtrecycler/
implementation 'rocks.teagantotally:deepthoughtrecycler:1.0.0'
// https://jarcasting.com/artifacts/rocks.teagantotally/deepthoughtrecycler/
implementation ("rocks.teagantotally:deepthoughtrecycler:1.0.0")
'rocks.teagantotally:deepthoughtrecycler:aar:1.0.0'
<dependency org="rocks.teagantotally" name="deepthoughtrecycler" rev="1.0.0">
  <artifact name="deepthoughtrecycler" type="aar" />
</dependency>
@Grapes(
@Grab(group='rocks.teagantotally', module='deepthoughtrecycler', version='1.0.0')
)
libraryDependencies += "rocks.teagantotally" % "deepthoughtrecycler" % "1.0.0"
[rocks.teagantotally/deepthoughtrecycler "1.0.0"]

Dependencies

compile (7)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 26.1.0
com.android.support » recyclerview-v7 jar 26.1.0
com.jakewharton.timber : timber jar 4.5.1
com.google.guava : guava jar 20.0
com.android.databinding » library jar 1.3.1
com.android.databinding : baseLibrary jar 2.3.3
com.android.databinding » adapters jar 1.3.1

Project Modules

There are no modules declared in this project.

Deepthought Recycler

Purpose

Facilitate databinding with the Android RecyclerView through dynamic item inflation and binding.

Architecture

ItemBinders

Item binders are a mapping of layout to binding variable identifier. This allows the recycler view to automatically inflate and bind your view model for each item in the array.

AbstractItemBinder is the base to all implementations of item binders.

ItemBinder

A simple mapping of a layout to a binding variable identifier.

ConditionalItemBinder

Maps a layout to a binding variable identifier and implements logic to determine if the item should be handled by this item binder.

CompositeItemBinder

A collection of ConditionalItemBinder objects, allowing for different layouts to be inflated in a single recycler view based on the logic inside each ConditionalItemBinder.

BindingRecyclerViewAdapter

The recycler view adapter that accepts any AbstractItemBinder and inflates the layout and binds your view model for you.

Usage

Project Setup

Your project must enable databinding, to enable databinding, add the following to your build.gradle file:

android {
    ...
    dataBinding {
        enabled = true;
    }
}

You will also need to add the RecyclerView dependency to your project:

dependencies {
    compile 'com.android.support:appcompat-v7:**.**.**'
    compile 'com.android.support:recyclerview-v7:**.**.**'
}

NOTE The support library versions will vary depending on your target SDK version.

Layout

Add a RecyclerView and xmlns:app namespace to your layout, and set a binding data variable:

<?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">

    <data>
        <variable
            name="vm"
            type="your.package.viewmodel.ListViewModel />
    </data>
    
    ...
    
    <android.support.v7.widget.RecyclerView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:adapter="@{vm.adapter}"
         app:layoutManager="@{vm.layoutManager}" />
    
    ...
    
</RelativeLayout>

The two attributes that are required for the binding to work are app:adapter and app:layoutManager.

The app:adapter must be bound to a BindingRecyclerViewAdapter. The app:layoutManager must be bound to a RecyclerView.LayoutManager.

RecyclerView Event Hooks

itemClickHandler

Invoked when an item in the RecyclerView is clicked, the bound object will be passed into this handler

itemLongClickHandler

Invoked when an item in the RecyclerView is long pressed, the bound object will be passed into this handler.

itemDoubleTapHandler

Invoked when an item in the RecyclerView is double tapped, the bound object will be passed into this handler.

viewAttachedHandler

Hooks into the RecyclerView.onViewAttachedFroWindow event hook, the View that was attached, along with it's bound object will be passed to this handler.

viewDetachedHandler

Hooks into the RecyclerView.onViewDetachedFromWindow event hook, the View that was detached, along with it's bound object will be passed to this handler.

viewRecycledHandler

Hooks into the RecyclerView.onViewRecycled event hook, the View that was recycled, along with it's bound object will be passed to this handler.

Item Interfaces

Included are interfaces your items can implement to hook into some of the RecyclerView events.

AttachedToWindowListener

Items that implement AttachedToWindowListener will be invoked when their associated view is being attached to the window. See <> for more information.

DetachedFromWindowListener

Items that implement DetachedFromWindowListener will be invoked when their associated view is being detached from the window. See <> for more information.

RecycledListener

Items that implement RecycledListener will be invoked when their associated views are recycled. See <> for more information.

Versions

Version
1.0.0