Kandy

Additional

Language
Kotlin
Version
N/A
Created
Dec 9, 2019
Updated
Feb 15, 2020
Owner
Kwezal
Contributor
Kaj (KajetanSuchanski)
1
Activity
Badge
Generate
Download
Source code
APK file

Announcement

Kandy

A Kotlin library set dedicated to Android platform which will make programming sweet again!

Repository

All modules are available on the jcenter. In order to import them, make sure your project includes the appropriate repository.

Project build.gradle

repositories {
    // ...
    jcenter()
}

Kandy List Views

Highly flexible list view which will help you to write much less code and spend much less time for such basic thing as list view. Forget about writing copy-pasting another RecyclerView.Adapter. Let Kandy List Views set everything up for you. Basically, all you need to do is write a custom view holder for each model you want to see as a list item.

Flexibility

You can use any number of any types of list items within a single adapter. KandyListAdapter will take care of defining and managing view types.

Convenience

onBind method of a view holder provide you a type-safe getter of a list item. No need to keep an eye on a collection of data you've passed to the list view adapter. Let this method retrieve the appropriate object for you (including the inside of event listeners.)

Minimal working example

Custom view holder definition

class StringViewHolder(itemView: View) : AbstractDefaultKandyViewHolder<String>(itemView) {
    private val textView = itemView as TextView
    override fun onBind(position: Int, adapter: KandyListAdapter, listItemGetter: () -> KandyListItem<String>) {
        textView.text = listItemGetter().item
    }
}

Adapter initialization

val adapter = KandyListAdapter(
    KandyListItem(
        "String item",
        KandyItemView {TextView(this)}
    ) {itemView -> StringViewHolder(itemView)}
)

Full example

For full example, please refer to this file.

Import

Module build.gradle

dependencies {
    // ...
    implementation("com.kwezal.kandy:listviews:${kandy_version}@aar")
            { transitive = true } // Includes RecyclerView dependency
}

Kandy Dialogs

Simple DSL-like wrapper for AlertDialogs. Not only it makes the code shorter and prettier, but also more convenient to use.

The simplest example

show { dialog("Message", "Title") { positiveButton = button("OK") } }

Full example

For full example, please refer to this file.

Import

Module build.gradle

dependencies {
    // ...
    implementation("com.kwezal.kandy:dialogs:${kandy_version}@aar")
}

The rest

Other modules of this set of libraries will be published soon. As for now I'd appreciate any kind of feedback or contribution.