• Stars
    star
    299
  • Rank 139,269 (Top 3 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

科学分包,动态扩展,功能完善,书写简洁,按需依赖,合理抽象,超高内聚,超低耦合,没有最好,只有更好,希望能帮助到您,🙏❤️🙏❤️

RecyclerViewAdapter

It has been written 100% in Kotlin. ❤️ 重新定义RecyclerView Adapter的封装,追求既简单又实用,结合Kotlin的高级特性,优化代码书写方式,真正做到高内聚低耦合

设计图

Adapter.jpeg

特点

  • DSL写法,简单易用
  • 充分考虑ViewHolder复用逻辑,科学防止触碰事件抖动问题
  • 抽象合理,高可复用
  • 分包依赖,也可以一次性依赖
  • 自带Lifecycle生命周期管理
  • 动态扩展,耦合降低到了极致
  • 部分真泛型,优化泛型问题

库大小

名字 release aar size 其他
Core 32kb 核心库目前包含ListAdapter的实现,最基础且最实用的扩展
DataBinding 22kb 适配DataBinding布局,适用本项目所有Adapter扩展
Sorted 10kb SortedListAdapter扩展实现
Paging 13kb PagingListAdapter扩展适配
Diff 6kb 适配DiffUtil,目前适用ListAdapter
FlexBox 9kb 适配FlexBox布局
Selectable 8kb 动态扩展单选、多选、最大可选项功能
Expandable 8kb 动态扩展可展开功能,支持仅单展开或多展开配置
UI 17kb 扩展空布局
Animators 14kb 扩展动画,包括布局初加载动画,添加Item动画,更新Item动画等
Filter 9kb 按照条件过滤列表子项

各个Adapter的优势在哪,如何选择?

名字 优势 劣势 适合做什么
ListAdapter 简单实用,易扩展,ViewHolder复用率高,DSL支持写法优美 对于需要排序的列表处理麻烦性能低 不考虑排序的一般列表
SortedListAdapter 排序超级容易 侵入性高,需要继承SortedModel实现Model层,目前优化为接口,增加了可使用范围 任何需要排序的列表
PagingListAdapter 自带加载状态,后台计算完成后通知刷新,加载效率高 侵入性高,需要Model层继承实现,学习成本高,掌握难度高 适合自动加载分页的列表

各个ViewModel

适用范围

名字 ListAdapter SortedListAdapter PagingListAdapter
LayoutViewModel 支持 支持 支持
BindingViewModel 支持 支持 支持

如何选择

名字 功能 优势 其他
LayoutViewModel 加载XML布局 灵活,易懂,易用
BindingViewModel 加载DataBinding布局 省去绑定View的过程,代码逻辑简洁

如何依赖?

提示:按需依赖哦,没必要全部依赖哦

allprojects {
    repositories {
        // 首先项目根目录的build.gradle文件中加入这一行 
        maven { url 'https://jitpack.io' }
    }
}

//一次性依赖,会自动引入全部AAR
implementation 'com.github.ibaozi-cn.RecyclerViewAdapter:1.2.5'

//以下为分包依赖
def adapterVersion = '1.2.5'

//核心库
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-core:$adapterVersion"

//下面都是可选项

//diffutil 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-diff:$adapterVersion"
//data binding扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-binding:$adapterVersion"
// paging3 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-paging:$adapterVersion"
// sortedlist 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-sorted:$adapterVersion"
// flexbox 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-flex:$adapterVersion"
// UI 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-ui:$adapterVersion"
// Selectable 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-selectable:$adapterVersion"
// Expandable 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-expandable:$adapterVersion"
// Animators 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-animators:$adapterVersion"
// Filter 扩展
implementation "com.github.ibaozi-cn.RecyclerViewAdapter:adapter-filter:$adapterVersion"

环境需要

  • Kotlin
  • JAVA
  • AndroidX 抱歉目前按照最新的AndroidX适配的,如有其他需要请私聊我。

怎么用?

看一个最简单的例子 DSL的支持

//xml布局加载示例
fun createViewModelList(max: Int = 10) = (0..max).map { _ ->
    layoutViewModelDsl(R.layout.item_test, ModelTest("title", "subTitle")) {
        onBindViewHolder {
            val model = getModel<ModelTest>()
            getView<TextView>(R.id.tv_title).text = model?.title
            getView<TextView>(R.id.tv_subTitle).text = model?.subTitle
        }
        itemView.setOnClickListener {
            val vm = getViewModel<LayoutViewModel<ModelTest>>()
            //修改Model数据
            vm?.model?.title = "测试更新${Random.nextInt(10000)}"
            //用Adapter更新数据
            getAdapter<ListAdapter>()?.set(adapterPosition, vm)
        }
    }
}
//binding layout布局加载示例
fun createBindingViewModelList(max: Int = 10) = (0..max).map {
    bindingViewModelDsl(
        R.layout.item_binding_layout,
        BR.model,
        ModelTest("title", "bindingViewModelDsl")
    ) {
        itemView.setOnClickListener {
            val viewModel = getViewModel<BindingViewModel<ModelTest>>()
            viewModel?.model?.title = "${java.util.Random().nextInt(100)}"
            getAdapter<ListAdapter>()?.set(adapterPosition, viewModel)
        }
    }
}

//添加到Adapter中,并绑定RecyclerView
listAdapter {
   addAll(createViewModelList(3))
   addAll(createBindingViewModelList(3))
   // 绑定 RecyclerView
   into(rv_list_dsl)
}

开发者

License

Copyright 2020 Mike Penz

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.

More Repositories

1

flutter-jetpack

Flutter jetpack project help you find better dependency library. Welcome to my website (http://jetpack.net.cn)
CSS
107
star
2

ibaozi

ibaozi.cn flutter web 、android 、ios project
Dart
56
star
3

wechatrobot

微信智能聊天机器人
JavaScript
36
star
4

Coroutines

kotlin 协程简单易懂的封装框架
Kotlin
31
star
5

mmipc

使用mmap实现的跨进程通信组件
C++
23
star
6

KotlinMvpDemo

Kotlin语言 在android中mvp的实践
Kotlin
19
star
7

Multi-Process-Audio-Recorder

多进程录音服务共享,可共享,可单享,多App代码无差别集成
Kotlin
19
star
8

flutter_dynamic_form

An easy to use framework for flutter dynamic from。
Dart
17
star
9

Table

android kotlin dynamic form
Kotlin
11
star
10

CloseXiaomiAdvertising

帮助你关闭小米手机里面所有的广告,支持无障碍自动化操作
Kotlin
9
star
11

DynamicForm

react native dynamic form
JavaScript
7
star
12

ZRecyclerView

定制RecyclerView,实现MVVM框架。
Java
7
star
13

KLifecycle

Kotlin 实现的Lifecycle 生命周期管理,用于其他对象观察当前activity、fragment的生命周期状态变化
Kotlin
5
star
14

JLSharedPreference

对腾讯MMKV的包使用,方便后期无缝切换
Kotlin
2
star
15

file-cloud-storage

针对客户端脚本打包后自动上传云存储,最终通知到钉钉群
JavaScript
2
star
16

fast-run

idea 插件,启动监控项目文件服务,并触发增量编译
Kotlin
2
star
17

flutter-app-demo

一个flutter小项目练习
Dart
1
star
18

SuperBinder

SuperBinder is a high-performance Android inter-process communication framework designed to address the bottlenecks of the Android Binder framework. By using this framework, developers can easily pass data and invoke methods between different processes, improving the performance and stability of their applications.
Kotlin
1
star