All Projects → sjjeong → SimpleRecyclerView

sjjeong / SimpleRecyclerView

Licence: Apache-2.0 license
Do not create RecyclerView.Adapter and RecyclerView.ViewHolder anymore.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to SimpleRecyclerView

situp android proj
🚀一个基组件化、模块化、MVP + MVVM 计划 App,兼容安卓 10.0 9.0 8.0 等 🔥a app like keep, you can edit your plans here, and you can share your life to others by post, too.🔥
Stars: ✭ 15 (-85.71%)
Mutual labels:  mvp-android, mvvm-android, databinding-android
Android Mvp Mvvm Flytour
🔥🔥🔥 FlyTour是Android MVVM+MVP+Dagger2+Retrofit+RxJava+组件化+插件组成的双编码架构+双工程架构+双语言Android应用开发框架,通过不断的升级迭代该框架已经有了十个不同的版本,5.0之前工程架构采用gradle配置实现组件化,5.0之后的工程架构采用VirtualAPK实现了插件化,5.0之前采用Java编码实现,5.0之后采用Kotlin编码实现,编码架构由MVVM和MVP组成,工程架构和编码架构及编码语言开发者可根据自己具体的项目实际需求去决定选择使用,该框架是Android组件化、Android插件化、Android MVP架构、Android MVVM架构的集大成者,帮助你快速的搭建自己的App项目开发框架,以便把主要的精…
Stars: ✭ 2,948 (+2707.62%)
Mutual labels:  mvp-android, mvvm-android, databinding-android
Android-Kotlin-MVVM-Template
[In progress...] Chat APP | MVVM + Clean Architecture | Kotlin, LiveData, Koin, Databinding, Navigation Fragments, Rx, Room, Crashlytics, Circle CI config, commons classes for UI.
Stars: ✭ 314 (+199.05%)
Mutual labels:  mvvm-android, databinding-android
Jetpack Mvvm Best Practice
是 难得一见 的 Jetpack MVVM 最佳实践!在 以简驭繁 的代码中,对 视图控制器 乃至 标准化开发模式 形成正确、深入的理解!
Stars: ✭ 6,950 (+6519.05%)
Mutual labels:  mvvm-android, databinding-android
NoMoneyTrip
[SKT/한국관광공사] 2020 스마트 관광 앱 개발 공모전 '무전여행' 앱
Stars: ✭ 28 (-73.33%)
Mutual labels:  databinding-android
BakingApp
Udacity Android Developer Nanodegree, project 2.
Stars: ✭ 54 (-48.57%)
Mutual labels:  mvp-android
android-clean-architecture
🚀🚀🚀 The boilerplate for Android using Kotlin & Clean architecture.
Stars: ✭ 21 (-80%)
Mutual labels:  mvvm-android
InstantAppStarter
Starter Project Structure for Android Instant app. https://blog.mindorks.com/android-mvp-architecture-with-instant-app-support-11ba48241a82
Stars: ✭ 44 (-58.1%)
Mutual labels:  mvp-android
android-template
Template for android development at Tiki
Stars: ✭ 17 (-83.81%)
Mutual labels:  mvp-android
GithubTrendingRepos
Android - MVVM with Clean Architecture Blueprint Written In Kotlin
Stars: ✭ 50 (-52.38%)
Mutual labels:  mvvm-android
HiMusic
一个简单的 Android 音乐播放器
Stars: ✭ 17 (-83.81%)
Mutual labels:  mvp-android
socket-rxjava
基于socket 和rxjava 通信的项目 没有http
Stars: ✭ 19 (-81.9%)
Mutual labels:  mvp-android
Cheffaue
📯 Android app to demonstrate my Android Architecture phlosophy for designing apps.
Stars: ✭ 14 (-86.67%)
Mutual labels:  mvp-android
Klean-ArchiteKture
Kotlin Android clean-architecture demo project for a meetup talk. Slides: https://docs.google.com/presentation/d/1CxnntHf3CorNDicx_cDN5s1t5pEbUwjwWHZ5PNmfe6Y/edit?usp=sharing
Stars: ✭ 10 (-90.48%)
Mutual labels:  mvp-android
LifeHelper
我的毕业设计,功能还是比较完善的
Stars: ✭ 40 (-61.9%)
Mutual labels:  mvp-android
TeamCityApp
TeamCity in your pocket (Android application)
Stars: ✭ 48 (-54.29%)
Mutual labels:  databinding-android
MovieDb
No description or website provided.
Stars: ✭ 34 (-67.62%)
Mutual labels:  mvvm-android
Einsen
🎯 Einsen is a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built to Demonstrate use of Jetpack Compose with Modern Android Architecture Components & MVVM Architecture.
Stars: ✭ 821 (+681.9%)
Mutual labels:  mvvm-android
MVPDemo
MVP+动态代理的模式框架例子
Stars: ✭ 12 (-88.57%)
Mutual labels:  mvp-android
MVVM-Koin-Repository-Pattern
Experimenting with MVVM, Koin and Repository pattern in a simple TODO app.
Stars: ✭ 29 (-72.38%)
Mutual labels:  mvvm-android

SimpleRecyclerView

SimpleRecyclerView aims to help produce an easily usable implementation of a RecyclerView.Adapter and RecyclerView.ViewHolder

Attribute

name example description
dino_items bind:dino_items="@{vm.itemList}" Item List to show in RecyclerView
dino_itemLayout bind:dino_itemLayout="@{@layout/item_main}" Item Layout to show in RecyclerView
dino_diffCallback bind:dino_diffCallback="@{(Object)MainItem.Companion}" DiffUtil.ItemCallback
dino_eventHolder bind:dino_eventHolder="@{eventHolder}" Object that has a function for handling event separately from Item
dino_vm bind:dino_vm="@{vm}" Object that has a function for handling event separately from Item
dino_viewModel bind:dino_viewModel="@{viewModel}" Object that has a function for handling event separately from Item
dino_headerItem bind:dino_headerItem="@{vm.headerItem}" Item to show in Header
dino_headerItemLayout bind:dino_headerItemLayout="@{@layout/item_header}" Header Layout to show in RecyclerView
dino_footerItem bind:dino_footerItem="@{vm.footerItem}" Item to show in Footer
dino_footerItemLayout bind:dino_footerItemLayout="@{@layout/item_footer}" Footer Layout to show in RecyclerView
dino_itemSpace dino_itemSpace="@{@dimen/space}" Space for each item
dino_itemSpace dino_itemSpace="@{`8dp`}" Space for each item
dino_includeEdge dino_includeEdge="@{true}" Padding space for RecyclerView
dino_onLoad dino_onLoad="@{() -> vm.loadItem()}" Load more items event handling
dino_threshold dino_threshold="@{10}" A threshold of remaining items before they've hit the end

Dependency

Download

Then, add the library to your module build.gradle

dependencies {
    implementation 'com.dino.library:simplerecyclerview:x.y.z'
}

Enable DataBinding

SimpleRecyclerView use DataBinding

To configure your app to use data binding, add the dataBinding element to your build.gradle file in the app module (not root build.gradle file), as shown in the following example:

android {
    ...
    buildFeatures {
        dataBinding true
    }
}

Usage

There is a sample. Sample include architectures pattern such as mvp and mvvm.

item_layout.xml

<data>
    <variable
        name="item" <- very important
        type="com.your.package.YourItem"/>
</data>

<TextView
    android:text="@{item.title}"/>
<TextView
    android:text="@{item.content}"/>

if your item name of item_layout.xml is not "item", can't bind item in ViewHolder

RecyclerView.Adapter

<data>
    <import type="java.util.List" />
    <import type="com.your.package.YourItem" />
    <variable
        name="items"
        type="List&lt;YourItem>" />
</data>

...

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    bind:dino_itemLayout="@{@layout/item_layout}"
    bind:dino_items="@{items}" />

RecyclerView.SimpleAdapter

<data>
    <import type="java.util.List" />
    <import type="com.your.package.YourItem" />
    <variable
        name="items"
        type="List&lt;YourItem>" />
    <variable
        name="diffCallback"
        type="androidx.recyclerview.widget.DiffUtil.ItemCallback&lt;Object>" />
</data>

...

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    bind:dino_diffCallback="@{diffCallback}"
    bind:dino_itemLayout="@{@layout/item_layout}"
    bind:dino_items="@{items}" />

Don't set item, just set adapter

Just set null value in bind:items attribute.

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    bind:dino_itemLayout="@{@layout/item_layout}"
    bind:dino_items="@{null}" />

And item set programmatically(Not Recommended)

kotlin

recyclerView.setItems(items)

java

RecyclerViewExtKt.setItems(recyclerView, items)

This method has a timing issue. If you call a setItems function in (onCreate, onStart, onResume), the set of Adapters in the RecyclerView is called afterwards.

MVVM Sample

1. create item_layout.xml

CustomModel is enum class

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="item"
            type="com.dino.simplerecyclerview.model.CustomModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{item.title}" />

    </LinearLayout>
</layout>

2. create CustomViewModel

class CustomViewModel : ViewModel() {

    val customModelItems = ObservableField<List<CustomModel>>()

    init {
        createNewItem()
    }

    fun createNewItem() {
        customModelItems.set(CustomModel.values().toList())
    }
}

3. set list item in activity.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:bind="http://schemas.android.com/apk/res-auto">
    <data>
        <variable
            name="vm"
            type="com.dino.simplerecyclerview.ui.CustomViewModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            bind:dino_itemLayout="@{@layout/item_layout}"
            bind:dino_items="@{vm.customModelItems}" />

    </LinearLayout>
</layout>

How to handle click listener of item

Deprecated, Use "dino_eventHolder" or "dino_vm" or "dino_viewModel"

1. Add higher-order function to Item class

data class Item(
    val title: String,
    val onClick: (Item) -> Unit
)

2. Add BindingAdapter to root ViewGroup in item_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="item"
            type="com.dino.simplerecyclerview.model.Item" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:onClick="@{() -> item.onClick.invoke(item)}"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{item.title}" />

    </LinearLayout>
</layout>

Multi ViewType

Just implement ItemViewType

data class Item1(
    val title: String,
    override val itemLayoutResId: Int = R.layout.item_1
) : ItemViewType

data class Item2(
    val title: String,
    override val itemLayoutResId: Int = R.layout.item_2
) : ItemViewType

AdpaterPosition

Add adapterPosition variable to item layout

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="adapterPosition"
            type="int" />
    </data>

    ...
    
</layout>

License

Copyright 2019 Dino

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