All Projects → wuhenzhizao → Kotlin Adapter

wuhenzhizao / Kotlin Adapter

🔥 RecyclerView,AbsListView适配器, 支持多种视图样式, 支持吸顶、侧滑删除、拖拽效果

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kotlin Adapter

Easyadapter
Android 轻量级适配器,简化使用,适应所有的AbsListView、RecyclerView。支持HeaderView与FooterView~
Stars: ✭ 160 (+21.21%)
Mutual labels:  adapter, recyclerview, listview
Google Books Android Viewer
Android library to bridge between RecyclerView and sources like web page or database. Includes demonstrator (Google Books viewer)
Stars: ✭ 37 (-71.97%)
Mutual labels:  adapter, recyclerview, listview
Superadapter
[Deprecated]. 🚀 Adapter(BaseAdapter, RecyclerView.Adapter) wrapper for Android. 一个Adapter同时适用RecyclerView、ListView、GridView等。
Stars: ✭ 638 (+383.33%)
Mutual labels:  adapter, recyclerview, listview
adapster
Android library designed to enrich and make your RecyclerView adapters more SOLID
Stars: ✭ 17 (-87.12%)
Mutual labels:  adapter, listview, recyclerview
GenericRecyclerAdapter
Easiest way to use RecyclerView. Reduce boilerplate code! You don't need to write adapters for listing pages anymore!
Stars: ✭ 53 (-59.85%)
Mutual labels:  adapter, listview, recyclerview
Commonadapter
一个适用于ListView/GridView/RecyclerView的Adapter库,简化大量重复代码,支持多种布局,可自定义图片加载的实现。
Stars: ✭ 219 (+65.91%)
Mutual labels:  adapter, recyclerview, listview
Adapter
A quick adapter library for RecyclerView, GridView, ListView, ViewPager, Spinner
Stars: ✭ 376 (+184.85%)
Mutual labels:  adapter, recyclerview, listview
GenericAdapter
⛳️ Easy to use android databinding ready recyclerview adapter
Stars: ✭ 26 (-80.3%)
Mutual labels:  adapter, listview, recyclerview
recycler-adapter
RecyclerView-driven declarative UIs
Stars: ✭ 124 (-6.06%)
Mutual labels:  adapter, listview, recyclerview
Boardview
A draggable boardview for java android (Kanban style)
Stars: ✭ 309 (+134.09%)
Mutual labels:  adapter, recyclerview, listview
Swipemenulayout
🔥一个零耦合的侧滑菜单,支持RecyclerView、ListView、GridView等不同条目布局,支持菜单在左或在右,可选滑动阻塞,是否禁用等功能
Stars: ✭ 120 (-9.09%)
Mutual labels:  recyclerview, listview
Multiitem
一个优雅的实现多类型的RecyclerView类库 支持DataBinding Form表单录入 跨多个RecyclerView拖动
Stars: ✭ 381 (+188.64%)
Mutual labels:  adapter, recyclerview
Multityperecyclerviewadapter
一个专注于RecyclerView优雅刷新(接管资源和数据源)、高灵活、低耦合、健壮性以及高效性的MVP模式库,支持大多数Adapter
Stars: ✭ 763 (+478.03%)
Mutual labels:  adapter, recyclerview
Slimadapter
A slim & clean & typeable Adapter without# VIEWHOLDER
Stars: ✭ 939 (+611.36%)
Mutual labels:  adapter, recyclerview
Swipemenu
[DEPRECATED] A swipe menu for horizontal/vertical, support left/right and top/bottom directions
Stars: ✭ 817 (+518.94%)
Mutual labels:  recyclerview, listview
Flagchatadapter
FlagChatAdapter is easy to implement enchanting recycler view adapter. Just extend your adapter with FlagChatAdapter, impliment some methods and voila! You have got the most beautiful looking chat on your phone. Zero boilerplate code, just put your variables in the right direction.
Stars: ✭ 39 (-70.45%)
Mutual labels:  adapter, recyclerview
Imageviewer
🔮图片浏览器,支持图片手势缩放、拖拽等操作,`自定义View`的模式显示,自定义图片加载方式,更加灵活,易于扩展,同时也适用于RecyclerView、ListView的横向和纵向列表模式,最低支持版本为Android 3.0及以上...
Stars: ✭ 363 (+175%)
Mutual labels:  recyclerview, listview
Candyview
Implement any RecyclerView in just 1 Line. CandyView handles everything for you.
Stars: ✭ 15 (-88.64%)
Mutual labels:  adapter, recyclerview
Sectionedrecyclerviewadapter
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
Stars: ✭ 1,659 (+1156.82%)
Mutual labels:  adapter, recyclerview
Ultimaterefreshview
UltimateRefreshView 实现下拉刷新,上拉加载更多的轻量级库;支持RecyclerView ,ListView ,ScrollView & WebView
Stars: ✭ 64 (-51.52%)
Mutual labels:  recyclerview, listview

kotlin-adapter

RecyclerView,AbsListView适配器, 支持多种视图样式, 支持吸顶、侧滑删除、拖拽效果

Base adapter for recyclerView,absListView, support multiple item view type, sticky header(section), drag & drop, swipe dismiss

Demo Download

Features

  • 代码优雅,无需重写Adapter, ViewHolder,通过链式调用实现适配器创建;
  • 支持多种样式,解决视图复用导致的页面错乱问题;
  • 提供一系列回调方法,满足大部分场景下的业务需求,通过内联优化,减少资源占用;
  • 拓展ViewHolder,见AdapterExtensions, ViewHolderExtensions,简化View数据更新操作;
  • 支持DataBinding;
  • 封装了sticky header吸顶, swipe menu滑动菜单,拖拽等效果;

Preview

  • Single Item View Type
ListView RecyclerView RecyclerView + DataBinding
  • Multiple Item View Type
ListView RecyclerView
  • Extension(For RecyclerView)
Sticky Header Swipe Menu Drag & Drop
Swipe Dismiss

Setup

Download Download

dependencies {
    // 核心依赖
    compile 'com.wuhenzhizao:kotlin-adapter-core:1.2.1'
    // 拓展效果依赖
    compile 'com.wuhenzhizao:kotlin-adapter-extension:1.2.1'
}

Usage(更多用法见example)

★ 提供了如下几种适配器实现

类型 介绍
ListViewAdapter ListView适配器
RecyclerViewAdapter RecyclerView适配器
RecyclerViewBindingAdapter RecyclerView适配器,使用DataBinding
StickyRecyclerViewAdapter 支持Sticky Header效果的RecyclerView适配器
SwipeMenuRecyclerViewAdapter 支持侧滑菜单效果的RecyclerView适配器
SwipeMenuStickyRecyclerViewAdapter 同时支持Sticky Header和侧滑菜单效果的RecyclerView适配器(使用场景:京东购物车)
DragAndSwipeRecyclerViewAdapter 支持Drag & Drop和Swipe Dismiss效果的RecyclerView适配器

★ 创建适配器(以RecyclerViewAdapter为例)

val adapter = RecyclerViewAdapter<Product>(context)
    .match(Product::class, R.layout.item_single_type_recycler_view)
    .attach(binding.rv)
val adapter = RecyclerViewAdapter(context, list.provinceList)  
    .match(Time::class, R.layout.item_multiple_type_list_view_time)
    .match(TopNews::class, R.layout.item_multiple_type_list_view_top)
    .match(NormalNews::class, R.layout.item_multiple_type_list_view_normal)
    .holderCreateListener { holder ->
        // 布局创建时回调,用于对布局的处理,比如设置宽高(可省略)
    }
    .holderBindListener { holder, position ->
        // 布局绑定时回调,用于更新Item UI数据,也可以设置UI监听接口
        val province = adapter.getItem(position)
        holder.withView<TextView>(R.id.tv, { text = province.name })
                .withView<CheckBox>(R.id.cb, { isChecked = province.checked })
    }
    .clickListener { holder, position ->
        // Item最外层布局被点击回调(可省略)
    }
    .longClickListener { holder, position ->
        // Item最外层布局Long Click回调(可省略)
    }
    .attach(binding.lv)  // 绑定适配器到RecyclerView
val adapter = RecyclerViewAdapter<Any>(context)
    .layoutFactory {
        when (adapter.getItem(it)) {
             is BannerList -> R.layout.item_multiple_type_recycler_view_banner
             is Promotion -> R.layout.item_multiple_type_recycler_view_promotion
             is Divider -> R.layout.item_multiple_type_recycler_view_divider
             is HeaderLine -> R.layout.item_multiple_type_recycler_view_headine
             is HeaderLineProductList -> R.layout.item_multiple_type_recycler_view_headine_product
             is Recommend -> R.layout.item_multiple_type_recycler_view_recommend
             is RecommendProducts -> R.layout.item_multiple_type_recycler_view_recommend_item
             else -> {
                 0
             }
        }
    }
    .attach(binding.rv)
data class Content(val hasLiked: Int = 0) : BaseObservable() {
    fun getClickListener(): View.OnClickListener {
        return View.OnClickListener {
            // will be called when view clicked
        }
    }
}
<layout>
    <data>
        <variable
            name="vm"
            type="com.wuhenzhizao.adapter.example.bean.Content" />
    </data>
    ...
    <Button
        android:id="@+id/author_like"
        android:layout_width="50dp"
        android:layout_height="20dp"
        android:selected="@{vm.hasLiked == 1}"
        android:onClick="@{vm.clickListener}"
        android:text="@{vm.hasLiked == 1 ? @string/author_liked: @string/author_unlike}"
        android:textColor="@color/author_like_text_selector"
        android:textSize="11dp" />
    ...
</layout>
val adapter = RecyclerViewBindingAdapter<Content>(context)
    .match(Content::class, R.layout.item_single_type_recycler_view_binding, BR.vm)
    .attach(binding.rv)

★ 更新Item数据

  • 使用ViewHolder.withView()
holder.withView<DraweeImageView>(R.id.left_iv, { 
        GImageLoader.displayUrl(context, this, item.leftProduct.imageUrl) })
    .withView<TextView>(R.id.left_name, { text = item.leftProduct.name })
    .withView<TextView>(R.id.left_price, { text = "¥ ${item.leftProduct.price}" })
    .withView<TextView>(R.id.left_reviews, { text = item.leftProduct.reviews })
holder.displayImageUrl(R.id.iv_sku_logo, { imageView -> })
    .setText(R.id.tv_sku_name, item.name)
    .setText(R.id.tv_sku_price, item.priceShow)
    .setTextColor(R.id.tv_sku_price, Color.RED)
    .setOnClickListener(R.id.rl_delete, {
        showToast("${item.name} is deleted")
        adapter.closeAllItems()
        adapter.removeItemAt(position)
    })

拓展

创建支持Sticky Header效果的RecyclerView适配器

val adapter = StickyRecyclerViewAdapter<Country>(context)
    .match(Country::class, R.layout.item_sticky_recycler_view)
    .matchHeader(Country::class, R.layout.item_sticky_recycler_view_header)
    .holderBindListener { holder, position ->
        val country = adapter.getItem(position)
        holder.withView<TextView>(R.id.country_name, { text = country.countryName })
    }
    .headerHolderBindListener { holder, position ->
        val country = adapter.getItem(position)
        holder.withView<TextView>(R.id.sticky_name, { text = country.letter })
    }
    .headerClickListener { holder, clickView, position ->
        showToast("sticky header clicked, headerId = ${adapter.getHeaderId(position)}")
    }
    .attach(binding.rv)

创建支持SwipeMenu效果的RecyclerView适配器

val adapter = SwipeMenuStickyRecyclerViewAdapter<StickyBean>(context)
    .match(Notice::class, R.layout.item_shopping_cart_notice)
    .match(Divider::class, R.layout.item_shopping_cart_divider)
    .holderBindListener { holder, position ->
        holder.withView<DraweeImageView>(R.id.iv_sku_logo, { GImageLoader.displayUrl(context, it, item.imgUrl) })
            .withView<EditText>(R.id.et_sku_quantity_input, { setText(item.num.toString()) })
            .withView<TextView>(R.id.tv_shopping_cart_delete, {
                setOnClickListener {
                    showToast("${item.name} is deleted")
                    adapter.closeAllItems()
                    adapter.removeItemAt(position)
                }
            })
    }
   

创建支持拖拽效果的RecyclerView适配器

val recyclerView = binding.rv
recyclerView.isLongPressDragEnable = true    // 开启长按拖拽
recyclerView.isItemViewSwipeEnable = true    // 开启Swipe Dismiss
recyclerView.dragDirection =                 // 设置拖拽方向
    ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT or ItemTouchHelper.UP or ItemTouchHelper.DOWN

val adapter = DragAndSwipeRecyclerViewAdapter<Topic>(context)
    .match(Topic::class, R.layout.item_drag_recycler_view)
    .dragListener { from, target ->
        showToast("item is dragged, from ${from.adapterPosition} to ${target.adapterPosition}")
    }
    .swipeListener { holder, direction ->
        showToast("position ${viewHolder.adapterPosition} dismissed")
    }
    .attach(binding.rv)

Thanks

技术交流

QQ交流群
screenshot

License

Copyright 2017 wuhenzhizao

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