Konveyor


Source link: https://github.com/avito-tech/Konveyor

Overview

Konveyor is a tiny library which intends to battle RecyclerView.Adapter Hell by introducing "Composition over inheritance" approach when dealing with RecyclerView adapters. While making your Adapter related logic testable by providing abstraction layer over its logic, it will make you forget all of the ViewType hassle all together.

Contents

Installation

Gradle

Step 1. Add this in your root build.gradle

 allprojects {

repositories {

 maven {
 url 'https://jitpack.io' 
}

}
  
}

Step 2. Add the dependency

 dependencies {

 compile 'com.github.avito-tech:Konveyor:VERSION'  
}

If you like to stay on the bleeding edge, or use certain commit as your dependency, you can use the short commit hash or anyBranch-SNAPSHOT as the version

Maven

 <dependency>

<groupId>com.github.avito-tech</groupId>

<artifactId>Konveyor</artifactId>

<version>VERSION</version>  </dependency>

Structure

Konveyor introduces set of key abstractions to extract knowledge about ids and view types away from RecyclerView.Adapter, thus, making all of the associated logic easily extensible and testable.

Item

Item is an interface that represents data associated with a certain ViewType:

class Dog(override val id: Long) : Item

id — identifier, that RecyclerView.Adapter will use in its methods.

ItemView

ItemView is an abstraction over RecyclerView.ViewHolder

interface DogView : ItemView {

  fun setName(name: String) 
}
  class DogViewHolder(view: View): BaseViewHolder(view), DogView {

  private val name = view.findViewById(R.id.name) as TextView

override fun setName(name: String) {

this.name.text = name
  
}
 
}

Methods Overview

onUnbind() is called whenever RecyclerView.Adapter calls onViewRecycled() method for this ItemView. You can override this method in case you need, for example, unsubscribe from listeners or release some resources associated with this ViewHolder.

ItemPresenter

ItemPresenter connects Item and its view. Essentially, your implementation of the interface should contain everything you would normally do in onBindViewHolder() method of RecyclerView.Adapter

class DogPresenter: ItemPresenter<DogItemView, Dog> {

override fun bindView(view: DogView, item: Dog, position: Int) {

view.setName(item.name)
  
}
  
}

ItemBlueprint

ItemBlueprint is a key entity that ties together Android world with our abstractions

class DogBlueprint(override val presenter: ItemPresenter<DogView, Dog>)
  : ItemBlueprint<DogView, Dog> {

override val viewHolderProvider = ViewHolderBuilder.ViewHolderProvider(

  layoutId = R.layout.dog_item,

  creator = {
 _, view -> DogViewHolder(view) 
}

)

override fun isRelevantItem(item: Item): Boolean = item is Dog  
}

Methods Overview

  • presenter — presenter associated with this view and data.
  • viewHolderProvider — class to create associated RecyclerView.ViewHolder
  • isRelevantItem(item: Item) — you have to override this method to build connection between given Item and its ItemBlueprint. Please mind, in the list of registered ItemBlueprints every check has to be unique. If multiple registered ItemBlueprints respond true to a given Item, ViewTypeCollisionException will be thrown.

ItemBlueprint

AdapterPresenter is an abstraction over RecyclerView.Adapter, that we can easily use in our unit tests. Current library provides default implementation for this interface - SimpleAdapterPresenter, this will satisfy 99.9% of your needs, unless you need something exotic.

Example

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

super.onViewCreated(view, savedInstanceState)

val recycler = view.findViewById(R.id.recycler) as RecyclerView

val binder = ItemBinder.Builder()

 .registerItem(createDogBlueprint())

 .registerItem(createCatBlueprint())

 val adapterPresenter = SimpleAdapterPresenter(binder, binder)

recycler.adapter = SimpleRecyclerAdapter(adapterPresenter, binder)
  
}

In most cases SimpleRecyclerAdapter, provided by this library will satisfy your needs.

This way you don't have to think about providing unique ViewTypes for your data, as ItemBinder will handle this for you.

Author

Philip Uvarov ([email protected])

License

MIT

Resources

ExceptionWear is very simple library to solve problem of not passing exceptions from Android Wear devices to the phone. So if you release an app for smart-watches to Google Play and it will crash (and it will) you won't get any information about it.

ASignature is a library for drawing smooth signatures. It uses variable width Bézier curve interpolation based on Smoother Signatures. It works from API 8+ and doesn't depend on any external libraries.

QuickScroll is a library aimed at creating similar scrolling experiences to the native Contacts app's People view. It has the same scrolling capabilities as the ListView's native fast-scroll, but comes with a much a much more customizable design, two indicator styles and an always visible scrollbar. The two most common modes are popup and indicator. Works seamlessly with ListView and ExpandableListView.

ParallaxViewPager is an easy-to-use ViewPager subclass with parallax background.

Android - MaterialPreference

  • A simple backward-compatible implementation of a Material Design Preference aka settings item
  • XML layouts are taken from Android Platform Framework Base

An eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes