finds.dev← search

// the find

drakeet/MultiType

★ 5,753 · Kotlin · Apache-2.0 · updated Aug 2022

Flexible multiple types for Android RecyclerView.

A small Kotlin library that lets one RecyclerView adapter hold many item types, with each type handled by its own delegate class instead of a growing getItemViewType() switch. It suits Android developers maintaining mixed-content list screens, such as feeds or settings pages, who want to add item types without touching the adapter.

- ViewDelegate skips the ViewHolder for custom Views: you override onCreateView and onBindView, which removes a lot of boilerplate for simple item types.

- The one-to-many mapping (register(Data::class).to(...).withKotlinClassLinker) lets a single data class route to different delegates based on a field, without subclassing the adapter or maintaining a type-int lookup table.

- The per-delegate hooks are exposed directly: payload-aware onBindViewHolder, getItemId, onViewRecycled, onFailedToRecycleView and attach/detach callbacks. Partial updates and stable IDs work without reaching into the adapter.

- There are unit tests named for the core classes (MultiTypeAdapterTest, OneToManyBuilderTest, MutableTypesTest) and an androidTest suite covering the one-to-many sample, so the routing code has some direct coverage.

- The last push was 28 August 2022, more than four years ago. Nothing in the repo shows it being maintained against recent AndroidX or Kotlin releases, so check that it still builds with your toolchain before adopting it.

- The build badge points to travis-ci.org, which shut down in 2021, so the status shown in the README no longer means anything. The repo doesn't show where CI runs now.

- It is a thin layer over RecyclerView.Adapter. Nothing in the README suggests it integrates with DiffUtil or ListAdapter, so large lists with frequent updates need diffing wired up by hand.

- The one-to-many linker is a single lambda that switches on a data field. As a model gains subtypes, that when block becomes the one place all routing lives, and nothing in the library checks that every type is covered.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →