Skip to content

Instantly share code, notes, and snippets.


Svetlozar Kostadinov sevar83

View GitHub Profile
sevar83 / VarColumnGridLayoutManager
Last active Jan 10, 2020
GridLayoutManager with variable number of columns calculated based on the measured view width
View VarColumnGridLayoutManager
final VarColumnGridLayoutManager layoutManager
= new VarColumnGridLayoutManager(getContext(), OrientationHelper.VERTICAL, false);
VarColumnGridLayoutManager.ColumnCountProvider columnProvider
= new VarColumnGridLayoutManager.DefaultColumnCountProvider(getContext());
sevar83 / ControllerLifecycle.kt
Last active Aug 30, 2019
Conductor / Glide lifecycle integration
View ControllerLifecycle.kt
import com.bumptech.glide.manager.Lifecycle
import com.bumptech.glide.manager.LifecycleListener
import com.bumptech.glide.util.Util
import java.util.*
* A [com.bumptech.glide.manager.Lifecycle] implementation for tracking and notifying
* listeners of [com.bluelinelabs.conductor.Controller] lifecycle events.
class ControllerLifecycle : Lifecycle {
sevar83 / PaddingTransition.kt
Created Nov 24, 2017
Non-stretching Glide placeholder
View PaddingTransition.kt
import com.bumptech.glide.request.transition.Transition
class PaddingTransition<T : Drawable>(private val realTransition: Transition<in T>) : Transition<T> {
override fun transition(current: T, adapter: Transition.ViewAdapter): Boolean {
val width = current.intrinsicWidth
val height = current.intrinsicHeight
return realTransition.transition(current, PaddingViewAdapter(adapter, width, height))
sevar83 / ParcelSortedMapAdapter.kt
Created Feb 21, 2017
PaperParcel SortedSet and SortedMap adapters
View ParcelSortedMapAdapter.kt
class ParcelSortedMapAdapter<K, V>(
private val keyAdapter: TypeAdapter<K>,
private val valueAdapter: TypeAdapter<V>
) : TypeAdapter<@JvmSuppressWildcards SortedMap<K, V>> {
override fun readFromParcel(source: Parcel): SortedMap<K, V> {
val size = source.readInt()
val map = TreeMap<K, V>()
for (ignored in 1..size) {
val key = keyAdapter.readFromParcel(source)
sevar83 / HorizontalPaddingItemDecoration.kt
Created Feb 20, 2017
Adds start/end padding to first/last item of a horizontal RecyclerView (like Play Store app)
View HorizontalPaddingItemDecoration.kt
class HorizontalPaddingItemDecoration(
private val paddingStart: Int = 0,
private val paddingEnd: Int = 0
) : RecyclerView.ItemDecoration() {
private var isRtl: Boolean? = null
fun isRTL(ctx: Context): Boolean {
val config = ctx.resources.configuration
return config.layoutDirection == View.LAYOUT_DIRECTION_RTL
sevar83 /
Created Sep 3, 2016
Binding adapter for which assigns common parameters to a List/Grid RecyclerView. Automatically restores the state of the old LayoutManager into the new one.
public class LMBindingAdapter {
// TODO the creation and modification of a layout manager must be done in one class. The creation is in a factory, but the modification is here.
@BindingAdapter(value = {"viewMode", "orientation", "reverseLayout", "spanCount", "spanSizeLookup"}, requireAll = false)
public static void setLayoutManager(RecyclerView recyclerView,
RecyclerViewMode viewMode,
@LayoutManagers.Orientation int orientation,
boolean reverseLayout,
int spanCount,
final SpanSizeLookup spanSizeLookup) {
if (viewMode == null) {
sevar83 /
Created Jan 29, 2016
ListLayout - a LinearLayout getting its items from Adapter. Very simple alternative of RecyclerView when a nested list is needed. It wraps its content with just setting wrap_content as height easily in constrast of RecyclerView.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import android.content.Context;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Adapter;
import android.widget.LinearLayout;