Skip to content

KotlinKenya/lazy-adapter

Repository files navigation

Lazy Adapter

JitPack

A simple and minimal utility class to handle recyclerview lists

InstallationUsageContributing

Installation (Kotlin DSLGroovy )

Kotlin DSL

  • Install jitpack

Locate your build.gradle.kts file in the root project and add :

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { setUrl("https://jitpack.io") } // add this line
    }
}

For those with a higher gradle version, find settings.gradle.kts in the root project folder and add :

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { setUrl("https://jitpack.io") } // add this line
    }
}
  • Add the lazy adapter dependency

In your app module find build.gradle.kts and add :

  implementation("com.github.KotlinKenya:lazy-adapter:$version")
  • Sync gradle and proceed use the library

Groovy

  • Install jitpack

Locate your build.gradle file in the root project and add :

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" } // add this line
    }
}

For those with a higher gradle version, find settings.gradle and add :

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }  // add this line
    }
}
  • Add Image Picker dependency

In your app module find build.gradle and add :

  implementation 'com.github.KotlinKenya:lazy-adapter:$version'

Usage

  • let your data class extend the LazyCompare()
      data class Item (val name: String) : LazyCompare()
  • create an xml file for your object
    <!-- in this example our layout is item_layout.xml  -->
    
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout ...>
    
      <androidx.cardview.widget.CardView ...>
    
          <TextView
              android:id="@+id/tv_text"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:padding="16dp"
              android:text="TextView" />
    
      </androidx.cardview.widget.CardView>
    
    </androidx.constraintlayout.widget.ConstraintLayout>
  • create an adapter from the LazyAdapter class
       val adapter = LazyAdapter<Item, LayoutItemBinding>()
  • initialize the view
    adapter.onCreate { parent: ViewGroup -> 
      val inflater = LayoutInflater.from(parent.context)
      LayoutItemBinding.inflate(inflater, parent, false) 
    }
  • bind the views
    adapter.onBind {item : Item ->
      // you can access all views in here
      tvText.text = item.name
    }
  • set the adapter to the recyclerview and submitList
      recyclerview.adapter = adapter
      adapter.submitList(listOf<Item>()) // populate your list

Contributing

GitHub tag (latest by date) GitHub contributors GitHub last commit Good first issues GitHub issues GitHub pull requests

Your contributions are especially welcome. Whether it comes in the form of code patches, ideas, discussion, bug reports, encouragement or criticism, your input is needed.

Visit issues to get started.

About

A utility class to handle recyclerview lists

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages