Skip to content

Instantly share code, notes, and snippets.

Avatar

Siddharth Thakkar sidthakkar12

  • Hiddenbrains Infotech Private Limited
  • Ahmedabad
View GitHub Profile
@sidthakkar12
sidthakkar12 / GridItemOffsetDecoration.kt
Last active Aug 10, 2020
Here's my custom class that allows equal spacing between grid cells in Kotlin:
View GridItemOffsetDecoration.kt
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
class GridItemOffsetDecoration(private val spanCount: Int, private var mItemOffset: Int) : ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView,
state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view)
@sidthakkar12
sidthakkar12 / EndlessRecyclerOnScrollListener.java
Created Oct 17, 2017 — forked from mustafasevgi/EndlessRecyclerOnScrollListener.java
RecyclerView position helper to get first and last visible positions
View EndlessRecyclerOnScrollListener.java
/**
* Custom Scroll listener for RecyclerView.
* Based on implementation https://gist.github.com/ssinss/e06f12ef66c51252563e
*/
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = "EndlessScrollListener";
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.